blob: eaf47a673be79cba6f6646e48ab40227b75cae9a [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,
Eli Friedmand8725a92010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000473
John McCall550e0c22009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCallb96ec562009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCallfcc33b02009-09-05 00:15:47 +0000495
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000500 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501
Mike Stump11289f42009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump11289f42009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000511 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
527 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
528 NestedNameSpecifier *NNS, QualType Named) {
529 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000530 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531
532 /// \brief Build a new typename type that refers to a template-id.
533 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000534 /// By default, builds a new DependentNameType type from the
535 /// nested-name-specifier and the given type. Subclasses may override
536 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000537 QualType RebuildDependentTemplateSpecializationType(
538 ElaboratedTypeKeyword Keyword,
539 NestedNameSpecifier *NNS,
540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
546 getDerived().RebuildTemplateName(NNS, *Name, QualType());
547
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCallc392f372010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
554 Keyword, NNS, Name, Args);
555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000561
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000564 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara6150c882010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarad7548482010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCallbf8c5192010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregore677daf2010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000610
Douglas Gregore677daf2010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000619
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000631
Abramo Bagnarad7548482010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 }
Mike Stump11289f42009-09-09 15:08:12 +0000642
Douglas Gregor1135c352009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregor71dc5092009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000694 const IdentifierInfo &II,
695 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000696
Douglas Gregor71395fa2009-11-04 00:56:37 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// overloaded operator name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
705 OverloadedOperatorKind Operator,
706 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000707
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 /// \brief Build a new compound statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
713 MultiStmtArg Statements,
714 SourceLocation RBraceLoc,
715 bool IsStmtExpr) {
716 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
717 IsStmtExpr);
718 }
719
720 /// \brief Build a new case statement.
721 ///
722 /// By default, performs semantic analysis to build the new statement.
723 /// Subclasses may override this routine to provide different behavior.
724 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
725 ExprArg LHS,
726 SourceLocation EllipsisLoc,
727 ExprArg RHS,
728 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000729 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 ColonLoc);
731 }
Mike Stump11289f42009-09-09 15:08:12 +0000732
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 /// \brief Attach the body to a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
737 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
738 getSema().ActOnCaseStmtBody(S.get(), move(Body));
739 return move(S);
740 }
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 /// \brief Build a new default statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000746 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 SourceLocation ColonLoc,
748 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000749 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000750 /*CurScope=*/0);
751 }
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 /// \brief Build a new label statement.
754 ///
755 /// By default, performs semantic analysis to build the new statement.
756 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000757 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 IdentifierInfo *Id,
759 SourceLocation ColonLoc,
760 StmtArg SubStmt) {
761 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
762 }
Mike Stump11289f42009-09-09 15:08:12 +0000763
Douglas Gregorebe10102009-08-20 07:17:43 +0000764 /// \brief Build a new "if" statement.
765 ///
766 /// By default, performs semantic analysis to build the new statement.
767 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000768 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000769 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000770 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000771 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000772 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 }
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000779 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
780 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000781 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000782 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
783 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 /// \brief Attach the body to the switch statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000790 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000791 StmtArg Switch, StmtArg Body) {
792 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
793 move(Body));
794 }
795
796 /// \brief Build a new while statement.
797 ///
798 /// By default, performs semantic analysis to build the new statement.
799 /// Subclasses may override this routine to provide different behavior.
800 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000801 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000802 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000804 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000805 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000806 }
Mike Stump11289f42009-09-09 15:08:12 +0000807
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 /// \brief Build a new do-while statement.
809 ///
810 /// By default, performs semantic analysis to build the new statement.
811 /// Subclasses may override this routine to provide different behavior.
812 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
813 SourceLocation WhileLoc,
814 SourceLocation LParenLoc,
815 ExprArg Cond,
816 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000817 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 move(Cond), RParenLoc);
819 }
820
821 /// \brief Build a new for statement.
822 ///
823 /// By default, performs semantic analysis to build the new statement.
824 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000825 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000827 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000828 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000830 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000831 DeclPtrTy::make(CondVar),
832 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 }
Mike Stump11289f42009-09-09 15:08:12 +0000834
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 /// \brief Build a new goto statement.
836 ///
837 /// By default, performs semantic analysis to build the new statement.
838 /// Subclasses may override this routine to provide different behavior.
839 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
840 SourceLocation LabelLoc,
841 LabelStmt *Label) {
842 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
843 }
844
845 /// \brief Build a new indirect goto statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
849 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
850 SourceLocation StarLoc,
851 ExprArg Target) {
852 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
853 }
Mike Stump11289f42009-09-09 15:08:12 +0000854
Douglas Gregorebe10102009-08-20 07:17:43 +0000855 /// \brief Build a new return statement.
856 ///
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
859 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
860 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000861
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
863 }
Mike Stump11289f42009-09-09 15:08:12 +0000864
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 /// \brief Build a new declaration statement.
866 ///
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
869 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000870 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000871 SourceLocation EndLoc) {
872 return getSema().Owned(
873 new (getSema().Context) DeclStmt(
874 DeclGroupRef::Create(getSema().Context,
875 Decls, NumDecls),
876 StartLoc, EndLoc));
877 }
Mike Stump11289f42009-09-09 15:08:12 +0000878
Anders Carlssonaaeef072010-01-24 05:50:09 +0000879 /// \brief Build a new inline asm statement.
880 ///
881 /// By default, performs semantic analysis to build the new statement.
882 /// Subclasses may override this routine to provide different behavior.
883 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
884 bool IsSimple,
885 bool IsVolatile,
886 unsigned NumOutputs,
887 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000888 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000889 MultiExprArg Constraints,
890 MultiExprArg Exprs,
891 ExprArg AsmString,
892 MultiExprArg Clobbers,
893 SourceLocation RParenLoc,
894 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000895 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000896 NumInputs, Names, move(Constraints),
897 move(Exprs), move(AsmString), move(Clobbers),
898 RParenLoc, MSAsm);
899 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000900
901 /// \brief Build a new Objective-C @try statement.
902 ///
903 /// By default, performs semantic analysis to build the new statement.
904 /// Subclasses may override this routine to provide different behavior.
905 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
906 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000907 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000908 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000909 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000910 move(Finally));
911 }
912
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000913 /// \brief Rebuild an Objective-C exception declaration.
914 ///
915 /// By default, performs semantic analysis to build the new declaration.
916 /// Subclasses may override this routine to provide different behavior.
917 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
918 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000919 return getSema().BuildObjCExceptionDecl(TInfo, T,
920 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000921 ExceptionDecl->getLocation());
922 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000923
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000924 /// \brief Build a new Objective-C @catch statement.
925 ///
926 /// By default, performs semantic analysis to build the new statement.
927 /// Subclasses may override this routine to provide different behavior.
928 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
929 SourceLocation RParenLoc,
930 VarDecl *Var,
931 StmtArg Body) {
932 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
933 Sema::DeclPtrTy::make(Var),
934 move(Body));
935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000936
Douglas Gregor306de2f2010-04-22 23:59:56 +0000937 /// \brief Build a new Objective-C @finally statement.
938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
942 StmtArg Body) {
943 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
944 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000945
Douglas Gregor6148de72010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000947 ///
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
951 ExprArg Operand) {
952 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000954
Douglas Gregor6148de72010-04-22 22:01:21 +0000955 /// \brief Build a new Objective-C @synchronized statement.
956 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
959 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
960 ExprArg Object,
961 StmtArg Body) {
962 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
963 move(Body));
964 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000965
966 /// \brief Build a new Objective-C fast enumeration statement.
967 ///
968 /// By default, performs semantic analysis to build the new statement.
969 /// Subclasses may override this routine to provide different behavior.
970 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
971 SourceLocation LParenLoc,
972 StmtArg Element,
973 ExprArg Collection,
974 SourceLocation RParenLoc,
975 StmtArg Body) {
976 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000977 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000978 move(Collection),
979 RParenLoc,
980 move(Body));
981 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000982
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /// \brief Build a new C++ exception declaration.
984 ///
985 /// By default, performs semantic analysis to build the new decaration.
986 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000987 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000988 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 IdentifierInfo *Name,
990 SourceLocation Loc,
991 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000992 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 TypeRange);
994 }
995
996 /// \brief Build a new C++ catch statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
1000 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1001 VarDecl *ExceptionDecl,
1002 StmtArg Handler) {
1003 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +00001004 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +00001005 Handler.takeAs<Stmt>()));
1006 }
Mike Stump11289f42009-09-09 15:08:12 +00001007
Douglas Gregorebe10102009-08-20 07:17:43 +00001008 /// \brief Build a new C++ try statement.
1009 ///
1010 /// By default, performs semantic analysis to build the new statement.
1011 /// Subclasses may override this routine to provide different behavior.
1012 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1013 StmtArg TryBlock,
1014 MultiStmtArg Handlers) {
1015 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1016 }
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 /// \brief Build a new expression that references a declaration.
1019 ///
1020 /// By default, performs semantic analysis to build the new expression.
1021 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001022 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1023 LookupResult &R,
1024 bool RequiresADL) {
1025 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1026 }
1027
1028
1029 /// \brief Build a new expression that references a declaration.
1030 ///
1031 /// By default, performs semantic analysis to build the new expression.
1032 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001033 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1034 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001035 ValueDecl *VD, SourceLocation Loc,
1036 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001037 CXXScopeSpec SS;
1038 SS.setScopeRep(Qualifier);
1039 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001040
1041 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001042
John McCallce546572009-12-08 09:08:17 +00001043 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 }
Mike Stump11289f42009-09-09 15:08:12 +00001045
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001047 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /// By default, performs semantic analysis to build the new expression.
1049 /// Subclasses may override this routine to provide different behavior.
1050 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1051 SourceLocation RParen) {
1052 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1053 }
1054
Douglas Gregorad8a3362009-09-04 17:36:40 +00001055 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001056 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001057 /// By default, performs semantic analysis to build the new expression.
1058 /// Subclasses may override this routine to provide different behavior.
1059 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1060 SourceLocation OperatorLoc,
1061 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001062 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001063 SourceRange QualifierRange,
1064 TypeSourceInfo *ScopeType,
1065 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001066 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001067 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001068
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001070 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 /// By default, performs semantic analysis to build the new expression.
1072 /// Subclasses may override this routine to provide different behavior.
1073 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1074 UnaryOperator::Opcode Opc,
1075 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001076 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Douglas Gregor882211c2010-04-28 22:16:22 +00001079 /// \brief Build a new builtin offsetof expression.
1080 ///
1081 /// By default, performs semantic analysis to build the new expression.
1082 /// Subclasses may override this routine to provide different behavior.
1083 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1084 TypeSourceInfo *Type,
1085 Action::OffsetOfComponent *Components,
1086 unsigned NumComponents,
1087 SourceLocation RParenLoc) {
1088 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1089 NumComponents, RParenLoc);
1090 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001091
Douglas Gregora16548e2009-08-11 05:31:07 +00001092 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001093 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 /// By default, performs semantic analysis to build the new expression.
1095 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001096 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001097 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001099 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 }
1101
Mike Stump11289f42009-09-09 15:08:12 +00001102 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001104 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 /// By default, performs semantic analysis to build the new expression.
1106 /// Subclasses may override this routine to provide different behavior.
1107 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1108 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001109 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1111 OpLoc, isSizeOf, R);
1112 if (Result.isInvalid())
1113 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 SubExpr.release();
1116 return move(Result);
1117 }
Mike Stump11289f42009-09-09 15:08:12 +00001118
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001120 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 /// By default, performs semantic analysis to build the new expression.
1122 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001123 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 SourceLocation LBracketLoc,
1125 ExprArg RHS,
1126 SourceLocation RBracketLoc) {
1127 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001128 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 RBracketLoc);
1130 }
1131
1132 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001133 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 /// By default, performs semantic analysis to build the new expression.
1135 /// Subclasses may override this routine to provide different behavior.
1136 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1137 MultiExprArg Args,
1138 SourceLocation *CommaLocs,
1139 SourceLocation RParenLoc) {
1140 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1141 move(Args), CommaLocs, RParenLoc);
1142 }
1143
1144 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001145 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 /// By default, performs semantic analysis to build the new expression.
1147 /// Subclasses may override this routine to provide different behavior.
1148 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001149 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001150 NestedNameSpecifier *Qualifier,
1151 SourceRange QualifierRange,
1152 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001153 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001154 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001155 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001156 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001157 if (!Member->getDeclName()) {
1158 // We have a reference to an unnamed field.
1159 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001160
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001161 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001162 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1163 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001164 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001165
Mike Stump11289f42009-09-09 15:08:12 +00001166 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001167 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001168 Member, MemberLoc,
1169 cast<FieldDecl>(Member)->getType());
1170 return getSema().Owned(ME);
1171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001173 CXXScopeSpec SS;
1174 if (Qualifier) {
1175 SS.setRange(QualifierRange);
1176 SS.setScopeRep(Qualifier);
1177 }
1178
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001179 Expr *BaseExpr = Base.takeAs<Expr>();
1180 getSema().DefaultFunctionArrayConversion(BaseExpr);
1181 QualType BaseType = BaseExpr->getType();
John McCall2d74de92009-12-01 22:10:20 +00001182
John McCall16df1e52010-03-30 21:47:33 +00001183 // FIXME: this involves duplicating earlier analysis in a lot of
1184 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001185 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1186 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001187 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001188 R.resolveKind();
1189
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001190 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1191 BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001192 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001193 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 }
Mike Stump11289f42009-09-09 15:08:12 +00001195
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
1200 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1201 BinaryOperator::Opcode Opc,
1202 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001203 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001204 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 }
1206
1207 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001208 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
1211 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1212 SourceLocation QuestionLoc,
1213 ExprArg LHS,
1214 SourceLocation ColonLoc,
1215 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001216 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 move(LHS), move(RHS));
1218 }
1219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001224 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1225 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation RParenLoc,
1227 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001228 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1229 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
1236 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001237 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 SourceLocation RParenLoc,
1239 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001240 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1241 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 }
Mike Stump11289f42009-09-09 15:08:12 +00001243
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001245 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 /// By default, performs semantic analysis to build the new expression.
1247 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001248 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 SourceLocation OpLoc,
1250 SourceLocation AccessorLoc,
1251 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001252
John McCall10eae182009-11-30 22:42:35 +00001253 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001254 QualType BaseType = ((Expr*) Base.get())->getType();
1255 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001256 OpLoc, /*IsArrow*/ false,
1257 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001258 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001259 AccessorLoc,
1260 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 }
Mike Stump11289f42009-09-09 15:08:12 +00001262
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001264 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
1267 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1268 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001269 SourceLocation RBraceLoc,
1270 QualType ResultTy) {
1271 OwningExprResult Result
1272 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1273 if (Result.isInvalid() || ResultTy->isDependentType())
1274 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001275
Douglas Gregord3d93062009-11-09 17:16:50 +00001276 // Patch in the result type we were given, which may have been computed
1277 // when the initial InitListExpr was built.
1278 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1279 ILE->setType(ResultTy);
1280 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 }
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001284 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
1287 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1288 MultiExprArg ArrayExprs,
1289 SourceLocation EqualOrColonLoc,
1290 bool GNUSyntax,
1291 ExprArg Init) {
1292 OwningExprResult Result
1293 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1294 move(Init));
1295 if (Result.isInvalid())
1296 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 ArrayExprs.release();
1299 return move(Result);
1300 }
Mike Stump11289f42009-09-09 15:08:12 +00001301
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001303 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// By default, builds the implicit value initialization without performing
1305 /// any semantic analysis. Subclasses may override this routine to provide
1306 /// different behavior.
1307 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1308 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1309 }
Mike Stump11289f42009-09-09 15:08:12 +00001310
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnara27db2392010-08-10 10:06:15 +00001315 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1316 ExprArg SubExpr, TypeSourceInfo *TInfo,
1317 SourceLocation RParenLoc) {
1318 return getSema().BuildVAArgExpr(BuiltinLoc,
1319 move(SubExpr), TInfo,
1320 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 }
1322
1323 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001324 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
1327 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1328 MultiExprArg SubExprs,
1329 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001330 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001331 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 }
Mike Stump11289f42009-09-09 15:08:12 +00001333
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001335 ///
1336 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// rather than attempting to map the label statement itself.
1338 /// Subclasses may override this routine to provide different behavior.
1339 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1340 SourceLocation LabelLoc,
1341 LabelStmt *Label) {
1342 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1343 }
Mike Stump11289f42009-09-09 15:08:12 +00001344
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001346 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
1349 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1350 StmtArg SubStmt,
1351 SourceLocation RParenLoc) {
1352 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_types_compatible_p expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
1359 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001360 TypeSourceInfo *TInfo1,
1361 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001363 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1364 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 RParenLoc);
1366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 /// \brief Build a new __builtin_choose_expr expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1373 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1374 SourceLocation RParenLoc) {
1375 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1376 move(Cond), move(LHS), move(RHS),
1377 RParenLoc);
1378 }
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// \brief Build a new overloaded operator call expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// The semantic analysis provides the behavior of template instantiation,
1384 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001385 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// argument-dependent lookup, etc. Subclasses may override this routine to
1387 /// provide different behavior.
1388 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1389 SourceLocation OpLoc,
1390 ExprArg Callee,
1391 ExprArg First,
1392 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001393
1394 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// reinterpret_cast.
1396 ///
1397 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001398 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// Subclasses may override this routine to provide different behavior.
1400 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1401 Stmt::StmtClass Class,
1402 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001403 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 SourceLocation RAngleLoc,
1405 SourceLocation LParenLoc,
1406 ExprArg SubExpr,
1407 SourceLocation RParenLoc) {
1408 switch (Class) {
1409 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001410 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001411 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 move(SubExpr), RParenLoc);
1413
1414 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001415 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001416 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001418
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001420 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001421 RAngleLoc, LParenLoc,
1422 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001426 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001427 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 default:
1431 assert(false && "Invalid C++ named cast");
1432 break;
1433 }
Mike Stump11289f42009-09-09 15:08:12 +00001434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 return getSema().ExprError();
1436 }
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// \brief Build a new C++ static_cast expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
1442 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1443 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001444 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation RAngleLoc,
1446 SourceLocation LParenLoc,
1447 ExprArg SubExpr,
1448 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001449 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1450 TInfo, move(SubExpr),
1451 SourceRange(LAngleLoc, RAngleLoc),
1452 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 }
1454
1455 /// \brief Build a new C++ dynamic_cast expression.
1456 ///
1457 /// By default, performs semantic analysis to build the new expression.
1458 /// Subclasses may override this routine to provide different behavior.
1459 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1460 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001461 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation RAngleLoc,
1463 SourceLocation LParenLoc,
1464 ExprArg SubExpr,
1465 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001466 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1467 TInfo, move(SubExpr),
1468 SourceRange(LAngleLoc, RAngleLoc),
1469 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
1471
1472 /// \brief Build a new C++ reinterpret_cast expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
1476 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1477 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001478 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation RAngleLoc,
1480 SourceLocation LParenLoc,
1481 ExprArg SubExpr,
1482 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001483 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1484 TInfo, move(SubExpr),
1485 SourceRange(LAngleLoc, RAngleLoc),
1486 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
1488
1489 /// \brief Build a new C++ const_cast expression.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
1493 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1494 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001495 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 SourceLocation RAngleLoc,
1497 SourceLocation LParenLoc,
1498 ExprArg SubExpr,
1499 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001500 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1501 TInfo, move(SubExpr),
1502 SourceRange(LAngleLoc, RAngleLoc),
1503 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 }
Mike Stump11289f42009-09-09 15:08:12 +00001505
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 /// \brief Build a new C++ functional-style cast expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001511 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 SourceLocation LParenLoc,
1513 ExprArg SubExpr,
1514 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001515 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001517 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001519 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001520 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 RParenLoc);
1522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new C++ typeid(type) expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001528 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1529 SourceLocation TypeidLoc,
1530 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001532 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001533 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new C++ typeid(expr) expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001540 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1541 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 ExprArg Operand,
1543 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001544 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1545 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001546 }
1547
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// \brief Build a new C++ "this" expression.
1549 ///
1550 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001551 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001553 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001554 QualType ThisType,
1555 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001557 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1558 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
1560
1561 /// \brief Build a new C++ throw expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1566 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1567 }
1568
1569 /// \brief Build a new C++ default-argument expression.
1570 ///
1571 /// By default, builds a new default-argument expression, which does not
1572 /// require any semantic analysis. Subclasses may override this routine to
1573 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001574 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001575 ParmVarDecl *Param) {
1576 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1577 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new C++ zero-initialization expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor747eb782010-07-08 06:14:04 +00001584 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 SourceLocation LParenLoc,
1586 QualType T,
1587 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001588 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1589 T.getAsOpaquePtr(), LParenLoc,
1590 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 0, RParenLoc);
1592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new C++ "new" expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001598 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 bool UseGlobal,
1600 SourceLocation PlacementLParen,
1601 MultiExprArg PlacementArgs,
1602 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001603 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 QualType AllocType,
1605 SourceLocation TypeLoc,
1606 SourceRange TypeRange,
1607 ExprArg ArraySize,
1608 SourceLocation ConstructorLParen,
1609 MultiExprArg ConstructorArgs,
1610 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001611 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 PlacementLParen,
1613 move(PlacementArgs),
1614 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001615 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 AllocType,
1617 TypeLoc,
1618 TypeRange,
1619 move(ArraySize),
1620 ConstructorLParen,
1621 move(ConstructorArgs),
1622 ConstructorRParen);
1623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 /// \brief Build a new C++ "delete" expression.
1626 ///
1627 /// By default, performs semantic analysis to build the new expression.
1628 /// Subclasses may override this routine to provide different behavior.
1629 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1630 bool IsGlobalDelete,
1631 bool IsArrayForm,
1632 ExprArg Operand) {
1633 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1634 move(Operand));
1635 }
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// \brief Build a new unary type trait expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 QualType T,
1645 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001646 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 T.getAsOpaquePtr(), RParenLoc);
1648 }
1649
Mike Stump11289f42009-09-09 15:08:12 +00001650 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 /// expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001655 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceRange QualifierRange,
1657 DeclarationName Name,
1658 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001659 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 CXXScopeSpec SS;
1661 SS.setRange(QualifierRange);
1662 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001663
1664 if (TemplateArgs)
1665 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1666 *TemplateArgs);
1667
1668 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new template-id expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001675 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1676 LookupResult &R,
1677 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001678 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001679 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new object-construction expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
1686 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001687 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 CXXConstructorDecl *Constructor,
1689 bool IsElidable,
1690 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001691 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001692 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001693 ConvertedArgs))
1694 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001695
Douglas Gregordb121ba2009-12-14 16:27:04 +00001696 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1697 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 }
1699
1700 /// \brief Build a new object-construction expression.
1701 ///
1702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
1704 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1705 QualType T,
1706 SourceLocation LParenLoc,
1707 MultiExprArg Args,
1708 SourceLocation *Commas,
1709 SourceLocation RParenLoc) {
1710 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1711 T.getAsOpaquePtr(),
1712 LParenLoc,
1713 move(Args),
1714 Commas,
1715 RParenLoc);
1716 }
1717
1718 /// \brief Build a new object-construction expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
1722 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1723 QualType T,
1724 SourceLocation LParenLoc,
1725 MultiExprArg Args,
1726 SourceLocation *Commas,
1727 SourceLocation RParenLoc) {
1728 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1729 /*FIXME*/LParenLoc),
1730 T.getAsOpaquePtr(),
1731 LParenLoc,
1732 move(Args),
1733 Commas,
1734 RParenLoc);
1735 }
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 /// \brief Build a new member reference expression.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001741 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001742 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 bool IsArrow,
1744 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 NestedNameSpecifier *Qualifier,
1746 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001747 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001749 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001750 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001752 SS.setRange(QualifierRange);
1753 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001754
John McCall2d74de92009-12-01 22:10:20 +00001755 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1756 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001757 SS, FirstQualifierInScope,
1758 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
1760
John McCall10eae182009-11-30 22:42:35 +00001761 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001765 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001766 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001767 SourceLocation OperatorLoc,
1768 bool IsArrow,
1769 NestedNameSpecifier *Qualifier,
1770 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001771 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001772 LookupResult &R,
1773 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001774 CXXScopeSpec SS;
1775 SS.setRange(QualifierRange);
1776 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001777
John McCall2d74de92009-12-01 22:10:20 +00001778 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1779 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001780 SS, FirstQualifierInScope,
1781 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001782 }
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 /// \brief Build a new Objective-C @encode expression.
1785 ///
1786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
1788 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001789 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001791 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001793 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001794
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001795 /// \brief Build a new Objective-C class message.
1796 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1797 Selector Sel,
1798 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001799 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 MultiExprArg Args,
1801 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001802 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1803 ReceiverTypeInfo->getType(),
1804 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001805 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 move(Args));
1807 }
1808
1809 /// \brief Build a new Objective-C instance message.
1810 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1811 Selector Sel,
1812 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001813 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001814 MultiExprArg Args,
1815 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001816 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1817 return SemaRef.BuildInstanceMessage(move(Receiver),
1818 ReceiverType,
1819 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001820 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001821 move(Args));
1822 }
1823
Douglas Gregord51d90d2010-04-26 20:11:03 +00001824 /// \brief Build a new Objective-C ivar reference expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
1828 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1829 SourceLocation IvarLoc,
1830 bool IsArrow, bool IsFreeIvar) {
1831 // FIXME: We lose track of the IsFreeIvar bit.
1832 CXXScopeSpec SS;
1833 Expr *Base = BaseArg.takeAs<Expr>();
1834 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1835 Sema::LookupMemberName);
1836 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1837 /*FIME:*/IvarLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001838 SS, DeclPtrTy(),
1839 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 if (Result.isInvalid())
1841 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001842
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 if (Result.get())
1844 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001845
1846 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001847 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001849 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001850 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001851 /*TemplateArgs=*/0);
1852 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001853
1854 /// \brief Build a new Objective-C property reference expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001858 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001859 ObjCPropertyDecl *Property,
1860 SourceLocation PropertyLoc) {
1861 CXXScopeSpec SS;
1862 Expr *Base = BaseArg.takeAs<Expr>();
1863 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1864 Sema::LookupMemberName);
1865 bool IsArrow = false;
1866 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1867 /*FIME:*/PropertyLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001868 SS, DeclPtrTy(),
1869 false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001870 if (Result.isInvalid())
1871 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001872
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 if (Result.get())
1874 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001875
1876 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001877 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001878 /*FIXME:*/PropertyLoc, IsArrow,
1879 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001880 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001881 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001882 /*TemplateArgs=*/0);
1883 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001884
1885 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001886 /// expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001889 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001890 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1891 ObjCMethodDecl *Getter,
1892 QualType T,
1893 ObjCMethodDecl *Setter,
1894 SourceLocation NameLoc,
1895 ExprArg Base) {
1896 // Since these expressions can only be value-dependent, we do not need to
1897 // perform semantic analysis again.
1898 return getSema().Owned(
1899 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1900 Setter,
1901 NameLoc,
1902 Base.takeAs<Expr>()));
1903 }
1904
Douglas Gregord51d90d2010-04-26 20:11:03 +00001905 /// \brief Build a new Objective-C "isa" expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1910 bool IsArrow) {
1911 CXXScopeSpec SS;
1912 Expr *Base = BaseArg.takeAs<Expr>();
1913 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1914 Sema::LookupMemberName);
1915 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1916 /*FIME:*/IsaLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001917 SS, DeclPtrTy(),
1918 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001919 if (Result.isInvalid())
1920 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001921
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 if (Result.get())
1923 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001924
1925 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001926 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001927 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001928 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001929 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001930 /*TemplateArgs=*/0);
1931 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 /// \brief Build a new shuffle vector expression.
1934 ///
1935 /// By default, performs semantic analysis to build the new expression.
1936 /// Subclasses may override this routine to provide different behavior.
1937 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1938 MultiExprArg SubExprs,
1939 SourceLocation RParenLoc) {
1940 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001941 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1943 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1944 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1945 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 // Build a reference to the __builtin_shufflevector builtin
1948 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001949 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001951 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001953
1954 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 unsigned NumSubExprs = SubExprs.size();
1956 Expr **Subs = (Expr **)SubExprs.release();
1957 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1958 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001959 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 RParenLoc);
1961 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 // Type-check the __builtin_shufflevector expression.
1964 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1965 if (Result.isInvalid())
1966 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001967
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001969 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001971};
Douglas Gregora16548e2009-08-11 05:31:07 +00001972
Douglas Gregorebe10102009-08-20 07:17:43 +00001973template<typename Derived>
1974Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1975 if (!S)
1976 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregorebe10102009-08-20 07:17:43 +00001978 switch (S->getStmtClass()) {
1979 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001980
Douglas Gregorebe10102009-08-20 07:17:43 +00001981 // Transform individual statement nodes
1982#define STMT(Node, Parent) \
1983 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1984#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001985#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001986
Douglas Gregorebe10102009-08-20 07:17:43 +00001987 // Transform expressions by calling TransformExpr.
1988#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001989#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001990#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001991#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001992 {
1993 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1994 if (E.isInvalid())
1995 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001996
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001997 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999 }
2000
Douglas Gregorebe10102009-08-20 07:17:43 +00002001 return SemaRef.Owned(S->Retain());
2002}
Mike Stump11289f42009-09-09 15:08:12 +00002003
2004
Douglas Gregore922c772009-08-04 22:27:00 +00002005template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00002006Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 if (!E)
2008 return SemaRef.Owned(E);
2009
2010 switch (E->getStmtClass()) {
2011 case Stmt::NoStmtClass: break;
2012#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002013#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002014#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002015 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002016#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002017 }
2018
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002020}
2021
2022template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002023NestedNameSpecifier *
2024TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002025 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002026 QualType ObjectType,
2027 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002028 if (!NNS)
2029 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregorebe10102009-08-20 07:17:43 +00002031 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 NestedNameSpecifier *Prefix = NNS->getPrefix();
2033 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002034 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002035 ObjectType,
2036 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002037 if (!Prefix)
2038 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002039
2040 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002041 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002042 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002043 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002044 }
Mike Stump11289f42009-09-09 15:08:12 +00002045
Douglas Gregor1135c352009-08-06 05:28:30 +00002046 switch (NNS->getKind()) {
2047 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002048 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002049 "Identifier nested-name-specifier with no prefix or object type");
2050 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2051 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002052 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002053
2054 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002055 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002056 ObjectType,
2057 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002058
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002060 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002062 getDerived().TransformDecl(Range.getBegin(),
2063 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002064 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 Prefix == NNS->getPrefix() &&
2066 NS == NNS->getAsNamespace())
2067 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregor1135c352009-08-06 05:28:30 +00002069 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2070 }
Mike Stump11289f42009-09-09 15:08:12 +00002071
Douglas Gregor1135c352009-08-06 05:28:30 +00002072 case NestedNameSpecifier::Global:
2073 // There is no meaningful transformation that one could perform on the
2074 // global scope.
2075 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002076
Douglas Gregor1135c352009-08-06 05:28:30 +00002077 case NestedNameSpecifier::TypeSpecWithTemplate:
2078 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002079 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002080 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2081 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002082 if (T.isNull())
2083 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002084
Douglas Gregor1135c352009-08-06 05:28:30 +00002085 if (!getDerived().AlwaysRebuild() &&
2086 Prefix == NNS->getPrefix() &&
2087 T == QualType(NNS->getAsType(), 0))
2088 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002089
2090 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2091 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002092 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002093 }
2094 }
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregor1135c352009-08-06 05:28:30 +00002096 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002097 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002098}
2099
2100template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002101DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002102TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002103 SourceLocation Loc,
2104 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002105 if (!Name)
2106 return Name;
2107
2108 switch (Name.getNameKind()) {
2109 case DeclarationName::Identifier:
2110 case DeclarationName::ObjCZeroArgSelector:
2111 case DeclarationName::ObjCOneArgSelector:
2112 case DeclarationName::ObjCMultiArgSelector:
2113 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002114 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002115 case DeclarationName::CXXUsingDirective:
2116 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregorf816bd72009-09-03 22:13:48 +00002118 case DeclarationName::CXXConstructorName:
2119 case DeclarationName::CXXDestructorName:
2120 case DeclarationName::CXXConversionFunctionName: {
2121 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002122 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002123 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002124 if (T.isNull())
2125 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002126
Douglas Gregorf816bd72009-09-03 22:13:48 +00002127 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002128 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002129 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002130 }
Mike Stump11289f42009-09-09 15:08:12 +00002131 }
2132
Douglas Gregorf816bd72009-09-03 22:13:48 +00002133 return DeclarationName();
2134}
2135
2136template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002137TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002138TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2139 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002140 SourceLocation Loc = getDerived().getBaseLocation();
2141
Douglas Gregor71dc5092009-08-06 06:41:21 +00002142 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002143 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002144 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002145 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2146 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002147 if (!NNS)
2148 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002149
Douglas Gregor71dc5092009-08-06 06:41:21 +00002150 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002151 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002152 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002153 if (!TransTemplate)
2154 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002155
Douglas Gregor71dc5092009-08-06 06:41:21 +00002156 if (!getDerived().AlwaysRebuild() &&
2157 NNS == QTN->getQualifier() &&
2158 TransTemplate == Template)
2159 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002160
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2162 TransTemplate);
2163 }
Mike Stump11289f42009-09-09 15:08:12 +00002164
John McCalle66edc12009-11-24 19:00:30 +00002165 // These should be getting filtered out before they make it into the AST.
2166 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 }
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002170 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002172 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2173 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002174 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002178 NNS == DTN->getQualifier() &&
2179 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregor71395fa2009-11-04 00:56:37 +00002182 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002183 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002184 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002185
2186 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002187 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 }
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002191 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002192 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002193 if (!TransTemplate)
2194 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregor71dc5092009-08-06 06:41:21 +00002196 if (!getDerived().AlwaysRebuild() &&
2197 TransTemplate == Template)
2198 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregor71dc5092009-08-06 06:41:21 +00002200 return TemplateName(TransTemplate);
2201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
John McCalle66edc12009-11-24 19:00:30 +00002203 // These should be getting filtered out before they reach the AST.
2204 assert(false && "overloaded function decl survived to here");
2205 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206}
2207
2208template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002209void TreeTransform<Derived>::InventTemplateArgumentLoc(
2210 const TemplateArgument &Arg,
2211 TemplateArgumentLoc &Output) {
2212 SourceLocation Loc = getDerived().getBaseLocation();
2213 switch (Arg.getKind()) {
2214 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002215 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002216 break;
2217
2218 case TemplateArgument::Type:
2219 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002220 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002221
John McCall0ad16662009-10-29 08:12:44 +00002222 break;
2223
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002224 case TemplateArgument::Template:
2225 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2226 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002227
John McCall0ad16662009-10-29 08:12:44 +00002228 case TemplateArgument::Expression:
2229 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2230 break;
2231
2232 case TemplateArgument::Declaration:
2233 case TemplateArgument::Integral:
2234 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002235 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002236 break;
2237 }
2238}
2239
2240template<typename Derived>
2241bool TreeTransform<Derived>::TransformTemplateArgument(
2242 const TemplateArgumentLoc &Input,
2243 TemplateArgumentLoc &Output) {
2244 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002245 switch (Arg.getKind()) {
2246 case TemplateArgument::Null:
2247 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002248 Output = Input;
2249 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002250
Douglas Gregore922c772009-08-04 22:27:00 +00002251 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002252 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002253 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002254 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002255
2256 DI = getDerived().TransformType(DI);
2257 if (!DI) return true;
2258
2259 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2260 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002261 }
Mike Stump11289f42009-09-09 15:08:12 +00002262
Douglas Gregore922c772009-08-04 22:27:00 +00002263 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002264 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002265 DeclarationName Name;
2266 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2267 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002268 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002269 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002270 if (!D) return true;
2271
John McCall0d07eb32009-10-29 18:45:58 +00002272 Expr *SourceExpr = Input.getSourceDeclExpression();
2273 if (SourceExpr) {
2274 EnterExpressionEvaluationContext Unevaluated(getSema(),
2275 Action::Unevaluated);
2276 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2277 if (E.isInvalid())
2278 SourceExpr = NULL;
2279 else {
2280 SourceExpr = E.takeAs<Expr>();
2281 SourceExpr->Retain();
2282 }
2283 }
2284
2285 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002286 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002287 }
Mike Stump11289f42009-09-09 15:08:12 +00002288
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002289 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002290 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002291 TemplateName Template
2292 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2293 if (Template.isNull())
2294 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002295
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002296 Output = TemplateArgumentLoc(TemplateArgument(Template),
2297 Input.getTemplateQualifierRange(),
2298 Input.getTemplateNameLoc());
2299 return false;
2300 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002301
Douglas Gregore922c772009-08-04 22:27:00 +00002302 case TemplateArgument::Expression: {
2303 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002304 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002305 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002306
John McCall0ad16662009-10-29 08:12:44 +00002307 Expr *InputExpr = Input.getSourceExpression();
2308 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2309
2310 Sema::OwningExprResult E
2311 = getDerived().TransformExpr(InputExpr);
2312 if (E.isInvalid()) return true;
2313
2314 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002315 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002316 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2317 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002318 }
Mike Stump11289f42009-09-09 15:08:12 +00002319
Douglas Gregore922c772009-08-04 22:27:00 +00002320 case TemplateArgument::Pack: {
2321 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2322 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002323 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002324 AEnd = Arg.pack_end();
2325 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002326
John McCall0ad16662009-10-29 08:12:44 +00002327 // FIXME: preserve source information here when we start
2328 // caring about parameter packs.
2329
John McCall0d07eb32009-10-29 18:45:58 +00002330 TemplateArgumentLoc InputArg;
2331 TemplateArgumentLoc OutputArg;
2332 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2333 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002334 return true;
2335
John McCall0d07eb32009-10-29 18:45:58 +00002336 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002337 }
2338 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002339 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002340 true);
John McCall0d07eb32009-10-29 18:45:58 +00002341 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002342 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002343 }
2344 }
Mike Stump11289f42009-09-09 15:08:12 +00002345
Douglas Gregore922c772009-08-04 22:27:00 +00002346 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002347 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002348}
2349
Douglas Gregord6ff3322009-08-04 16:50:30 +00002350//===----------------------------------------------------------------------===//
2351// Type transformation
2352//===----------------------------------------------------------------------===//
2353
2354template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002355QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002356 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002357 if (getDerived().AlreadyTransformed(T))
2358 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002359
John McCall550e0c22009-10-21 00:40:46 +00002360 // Temporary workaround. All of these transformations should
2361 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002362 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002363 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002364
Douglas Gregorfe17d252010-02-16 19:09:40 +00002365 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002366
John McCall550e0c22009-10-21 00:40:46 +00002367 if (!NewDI)
2368 return QualType();
2369
2370 return NewDI->getType();
2371}
2372
2373template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002374TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2375 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002376 if (getDerived().AlreadyTransformed(DI->getType()))
2377 return DI;
2378
2379 TypeLocBuilder TLB;
2380
2381 TypeLoc TL = DI->getTypeLoc();
2382 TLB.reserve(TL.getFullDataSize());
2383
Douglas Gregorfe17d252010-02-16 19:09:40 +00002384 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002385 if (Result.isNull())
2386 return 0;
2387
John McCallbcd03502009-12-07 02:54:59 +00002388 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002389}
2390
2391template<typename Derived>
2392QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002393TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2394 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002395 switch (T.getTypeLocClass()) {
2396#define ABSTRACT_TYPELOC(CLASS, PARENT)
2397#define TYPELOC(CLASS, PARENT) \
2398 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002399 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2400 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002401#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002402 }
Mike Stump11289f42009-09-09 15:08:12 +00002403
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002404 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002405 return QualType();
2406}
2407
2408/// FIXME: By default, this routine adds type qualifiers only to types
2409/// that can have qualifiers, and silently suppresses those qualifiers
2410/// that are not permitted (e.g., qualifiers on reference or function
2411/// types). This is the right thing for template instantiation, but
2412/// probably not for other clients.
2413template<typename Derived>
2414QualType
2415TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002416 QualifiedTypeLoc T,
2417 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002418 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002419
Douglas Gregorfe17d252010-02-16 19:09:40 +00002420 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2421 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002422 if (Result.isNull())
2423 return QualType();
2424
2425 // Silently suppress qualifiers if the result type can't be qualified.
2426 // FIXME: this is the right thing for template instantiation, but
2427 // probably not for other clients.
2428 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002430
John McCallcb0f89a2010-06-05 06:41:15 +00002431 if (!Quals.empty()) {
2432 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2433 TLB.push<QualifiedTypeLoc>(Result);
2434 // No location information to preserve.
2435 }
John McCall550e0c22009-10-21 00:40:46 +00002436
2437 return Result;
2438}
2439
2440template <class TyLoc> static inline
2441QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2442 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2443 NewT.setNameLoc(T.getNameLoc());
2444 return T.getType();
2445}
2446
John McCall550e0c22009-10-21 00:40:46 +00002447template<typename Derived>
2448QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002449 BuiltinTypeLoc T,
2450 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002451 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2452 NewT.setBuiltinLoc(T.getBuiltinLoc());
2453 if (T.needsExtraLocalData())
2454 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2455 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456}
Mike Stump11289f42009-09-09 15:08:12 +00002457
Douglas Gregord6ff3322009-08-04 16:50:30 +00002458template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002459QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002460 ComplexTypeLoc T,
2461 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002462 // FIXME: recurse?
2463 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464}
Mike Stump11289f42009-09-09 15:08:12 +00002465
Douglas Gregord6ff3322009-08-04 16:50:30 +00002466template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002467QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002468 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002469 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002470 QualType PointeeType
2471 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002472 if (PointeeType.isNull())
2473 return QualType();
2474
2475 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002476 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002477 // A dependent pointer type 'T *' has is being transformed such
2478 // that an Objective-C class type is being replaced for 'T'. The
2479 // resulting pointer type is an ObjCObjectPointerType, not a
2480 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002481 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002482
John McCall8b07ec22010-05-15 11:32:37 +00002483 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2484 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002485 return Result;
2486 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002487
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002488 if (getDerived().AlwaysRebuild() ||
2489 PointeeType != TL.getPointeeLoc().getType()) {
2490 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2491 if (Result.isNull())
2492 return QualType();
2493 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002494
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002495 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2496 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002497 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002498}
Mike Stump11289f42009-09-09 15:08:12 +00002499
2500template<typename Derived>
2501QualType
John McCall550e0c22009-10-21 00:40:46 +00002502TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002503 BlockPointerTypeLoc TL,
2504 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002505 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002506 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2507 if (PointeeType.isNull())
2508 return QualType();
2509
2510 QualType Result = TL.getType();
2511 if (getDerived().AlwaysRebuild() ||
2512 PointeeType != TL.getPointeeLoc().getType()) {
2513 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002514 TL.getSigilLoc());
2515 if (Result.isNull())
2516 return QualType();
2517 }
2518
Douglas Gregor049211a2010-04-22 16:50:51 +00002519 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002520 NewT.setSigilLoc(TL.getSigilLoc());
2521 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002522}
2523
John McCall70dd5f62009-10-30 00:06:24 +00002524/// Transforms a reference type. Note that somewhat paradoxically we
2525/// don't care whether the type itself is an l-value type or an r-value
2526/// type; we only care if the type was *written* as an l-value type
2527/// or an r-value type.
2528template<typename Derived>
2529QualType
2530TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002531 ReferenceTypeLoc TL,
2532 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002533 const ReferenceType *T = TL.getTypePtr();
2534
2535 // Note that this works with the pointee-as-written.
2536 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2537 if (PointeeType.isNull())
2538 return QualType();
2539
2540 QualType Result = TL.getType();
2541 if (getDerived().AlwaysRebuild() ||
2542 PointeeType != T->getPointeeTypeAsWritten()) {
2543 Result = getDerived().RebuildReferenceType(PointeeType,
2544 T->isSpelledAsLValue(),
2545 TL.getSigilLoc());
2546 if (Result.isNull())
2547 return QualType();
2548 }
2549
2550 // r-value references can be rebuilt as l-value references.
2551 ReferenceTypeLoc NewTL;
2552 if (isa<LValueReferenceType>(Result))
2553 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2554 else
2555 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2556 NewTL.setSigilLoc(TL.getSigilLoc());
2557
2558 return Result;
2559}
2560
Mike Stump11289f42009-09-09 15:08:12 +00002561template<typename Derived>
2562QualType
John McCall550e0c22009-10-21 00:40:46 +00002563TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002564 LValueReferenceTypeLoc TL,
2565 QualType ObjectType) {
2566 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567}
2568
Mike Stump11289f42009-09-09 15:08:12 +00002569template<typename Derived>
2570QualType
John McCall550e0c22009-10-21 00:40:46 +00002571TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002572 RValueReferenceTypeLoc TL,
2573 QualType ObjectType) {
2574 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002575}
Mike Stump11289f42009-09-09 15:08:12 +00002576
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002578QualType
John McCall550e0c22009-10-21 00:40:46 +00002579TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002580 MemberPointerTypeLoc TL,
2581 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002582 MemberPointerType *T = TL.getTypePtr();
2583
2584 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002585 if (PointeeType.isNull())
2586 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002587
John McCall550e0c22009-10-21 00:40:46 +00002588 // TODO: preserve source information for this.
2589 QualType ClassType
2590 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002591 if (ClassType.isNull())
2592 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002593
John McCall550e0c22009-10-21 00:40:46 +00002594 QualType Result = TL.getType();
2595 if (getDerived().AlwaysRebuild() ||
2596 PointeeType != T->getPointeeType() ||
2597 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002598 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2599 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002600 if (Result.isNull())
2601 return QualType();
2602 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002603
John McCall550e0c22009-10-21 00:40:46 +00002604 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2605 NewTL.setSigilLoc(TL.getSigilLoc());
2606
2607 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608}
2609
Mike Stump11289f42009-09-09 15:08:12 +00002610template<typename Derived>
2611QualType
John McCall550e0c22009-10-21 00:40:46 +00002612TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002613 ConstantArrayTypeLoc TL,
2614 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002615 ConstantArrayType *T = TL.getTypePtr();
2616 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002617 if (ElementType.isNull())
2618 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002619
John McCall550e0c22009-10-21 00:40:46 +00002620 QualType Result = TL.getType();
2621 if (getDerived().AlwaysRebuild() ||
2622 ElementType != T->getElementType()) {
2623 Result = getDerived().RebuildConstantArrayType(ElementType,
2624 T->getSizeModifier(),
2625 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002626 T->getIndexTypeCVRQualifiers(),
2627 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002628 if (Result.isNull())
2629 return QualType();
2630 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002631
John McCall550e0c22009-10-21 00:40:46 +00002632 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2633 NewTL.setLBracketLoc(TL.getLBracketLoc());
2634 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002635
John McCall550e0c22009-10-21 00:40:46 +00002636 Expr *Size = TL.getSizeExpr();
2637 if (Size) {
2638 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2639 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2640 }
2641 NewTL.setSizeExpr(Size);
2642
2643 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002644}
Mike Stump11289f42009-09-09 15:08:12 +00002645
Douglas Gregord6ff3322009-08-04 16:50:30 +00002646template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002647QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002648 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002649 IncompleteArrayTypeLoc TL,
2650 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002651 IncompleteArrayType *T = TL.getTypePtr();
2652 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002653 if (ElementType.isNull())
2654 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002655
John McCall550e0c22009-10-21 00:40:46 +00002656 QualType Result = TL.getType();
2657 if (getDerived().AlwaysRebuild() ||
2658 ElementType != T->getElementType()) {
2659 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002660 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002661 T->getIndexTypeCVRQualifiers(),
2662 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002663 if (Result.isNull())
2664 return QualType();
2665 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002666
John McCall550e0c22009-10-21 00:40:46 +00002667 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2668 NewTL.setLBracketLoc(TL.getLBracketLoc());
2669 NewTL.setRBracketLoc(TL.getRBracketLoc());
2670 NewTL.setSizeExpr(0);
2671
2672 return Result;
2673}
2674
2675template<typename Derived>
2676QualType
2677TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002678 VariableArrayTypeLoc TL,
2679 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002680 VariableArrayType *T = TL.getTypePtr();
2681 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2682 if (ElementType.isNull())
2683 return QualType();
2684
2685 // Array bounds are not potentially evaluated contexts
2686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2687
2688 Sema::OwningExprResult SizeResult
2689 = getDerived().TransformExpr(T->getSizeExpr());
2690 if (SizeResult.isInvalid())
2691 return QualType();
2692
2693 Expr *Size = static_cast<Expr*>(SizeResult.get());
2694
2695 QualType Result = TL.getType();
2696 if (getDerived().AlwaysRebuild() ||
2697 ElementType != T->getElementType() ||
2698 Size != T->getSizeExpr()) {
2699 Result = getDerived().RebuildVariableArrayType(ElementType,
2700 T->getSizeModifier(),
2701 move(SizeResult),
2702 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002703 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002704 if (Result.isNull())
2705 return QualType();
2706 }
2707 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002708
John McCall550e0c22009-10-21 00:40:46 +00002709 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2710 NewTL.setLBracketLoc(TL.getLBracketLoc());
2711 NewTL.setRBracketLoc(TL.getRBracketLoc());
2712 NewTL.setSizeExpr(Size);
2713
2714 return Result;
2715}
2716
2717template<typename Derived>
2718QualType
2719TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002720 DependentSizedArrayTypeLoc TL,
2721 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002722 DependentSizedArrayType *T = TL.getTypePtr();
2723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2724 if (ElementType.isNull())
2725 return QualType();
2726
2727 // Array bounds are not potentially evaluated contexts
2728 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2729
2730 Sema::OwningExprResult SizeResult
2731 = getDerived().TransformExpr(T->getSizeExpr());
2732 if (SizeResult.isInvalid())
2733 return QualType();
2734
2735 Expr *Size = static_cast<Expr*>(SizeResult.get());
2736
2737 QualType Result = TL.getType();
2738 if (getDerived().AlwaysRebuild() ||
2739 ElementType != T->getElementType() ||
2740 Size != T->getSizeExpr()) {
2741 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2742 T->getSizeModifier(),
2743 move(SizeResult),
2744 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002745 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002746 if (Result.isNull())
2747 return QualType();
2748 }
2749 else SizeResult.take();
2750
2751 // We might have any sort of array type now, but fortunately they
2752 // all have the same location layout.
2753 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2754 NewTL.setLBracketLoc(TL.getLBracketLoc());
2755 NewTL.setRBracketLoc(TL.getRBracketLoc());
2756 NewTL.setSizeExpr(Size);
2757
2758 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759}
Mike Stump11289f42009-09-09 15:08:12 +00002760
2761template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002762QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002763 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002764 DependentSizedExtVectorTypeLoc TL,
2765 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002766 DependentSizedExtVectorType *T = TL.getTypePtr();
2767
2768 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002769 QualType ElementType = getDerived().TransformType(T->getElementType());
2770 if (ElementType.isNull())
2771 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002772
Douglas Gregore922c772009-08-04 22:27:00 +00002773 // Vector sizes are not potentially evaluated contexts
2774 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2775
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2777 if (Size.isInvalid())
2778 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002779
John McCall550e0c22009-10-21 00:40:46 +00002780 QualType Result = TL.getType();
2781 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002782 ElementType != T->getElementType() ||
2783 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002784 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002785 move(Size),
2786 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002787 if (Result.isNull())
2788 return QualType();
2789 }
2790 else Size.take();
2791
2792 // Result might be dependent or not.
2793 if (isa<DependentSizedExtVectorType>(Result)) {
2794 DependentSizedExtVectorTypeLoc NewTL
2795 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
2797 } else {
2798 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2799 NewTL.setNameLoc(TL.getNameLoc());
2800 }
2801
2802 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002803}
Mike Stump11289f42009-09-09 15:08:12 +00002804
2805template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002806QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002807 VectorTypeLoc TL,
2808 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002809 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002810 QualType ElementType = getDerived().TransformType(T->getElementType());
2811 if (ElementType.isNull())
2812 return QualType();
2813
John McCall550e0c22009-10-21 00:40:46 +00002814 QualType Result = TL.getType();
2815 if (getDerived().AlwaysRebuild() ||
2816 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002817 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002818 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002819 if (Result.isNull())
2820 return QualType();
2821 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002822
John McCall550e0c22009-10-21 00:40:46 +00002823 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2824 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002825
John McCall550e0c22009-10-21 00:40:46 +00002826 return Result;
2827}
2828
2829template<typename Derived>
2830QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002831 ExtVectorTypeLoc TL,
2832 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002833 VectorType *T = TL.getTypePtr();
2834 QualType ElementType = getDerived().TransformType(T->getElementType());
2835 if (ElementType.isNull())
2836 return QualType();
2837
2838 QualType Result = TL.getType();
2839 if (getDerived().AlwaysRebuild() ||
2840 ElementType != T->getElementType()) {
2841 Result = getDerived().RebuildExtVectorType(ElementType,
2842 T->getNumElements(),
2843 /*FIXME*/ SourceLocation());
2844 if (Result.isNull())
2845 return QualType();
2846 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002847
John McCall550e0c22009-10-21 00:40:46 +00002848 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2849 NewTL.setNameLoc(TL.getNameLoc());
2850
2851 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002852}
Mike Stump11289f42009-09-09 15:08:12 +00002853
2854template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002855ParmVarDecl *
2856TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2857 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2858 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2859 if (!NewDI)
2860 return 0;
2861
2862 if (NewDI == OldDI)
2863 return OldParm;
2864 else
2865 return ParmVarDecl::Create(SemaRef.Context,
2866 OldParm->getDeclContext(),
2867 OldParm->getLocation(),
2868 OldParm->getIdentifier(),
2869 NewDI->getType(),
2870 NewDI,
2871 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002872 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002873 /* DefArg */ NULL);
2874}
2875
2876template<typename Derived>
2877bool TreeTransform<Derived>::
2878 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2879 llvm::SmallVectorImpl<QualType> &PTypes,
2880 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2881 FunctionProtoType *T = TL.getTypePtr();
2882
2883 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2884 ParmVarDecl *OldParm = TL.getArg(i);
2885
2886 QualType NewType;
2887 ParmVarDecl *NewParm;
2888
2889 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002890 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2891 if (!NewParm)
2892 return true;
2893 NewType = NewParm->getType();
2894
2895 // Deal with the possibility that we don't have a parameter
2896 // declaration for this parameter.
2897 } else {
2898 NewParm = 0;
2899
2900 QualType OldType = T->getArgType(i);
2901 NewType = getDerived().TransformType(OldType);
2902 if (NewType.isNull())
2903 return true;
2904 }
2905
2906 PTypes.push_back(NewType);
2907 PVars.push_back(NewParm);
2908 }
2909
2910 return false;
2911}
2912
2913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002914QualType
John McCall550e0c22009-10-21 00:40:46 +00002915TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002916 FunctionProtoTypeLoc TL,
2917 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002918 // Transform the parameters. We do this first for the benefit of template
2919 // instantiations, so that the ParmVarDecls get/ placed into the template
2920 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002921 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002922 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002923 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2924 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002925
Douglas Gregor14cf7522010-04-30 18:55:50 +00002926 FunctionProtoType *T = TL.getTypePtr();
2927 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2928 if (ResultType.isNull())
2929 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002930
John McCall550e0c22009-10-21 00:40:46 +00002931 QualType Result = TL.getType();
2932 if (getDerived().AlwaysRebuild() ||
2933 ResultType != T->getResultType() ||
2934 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2935 Result = getDerived().RebuildFunctionProtoType(ResultType,
2936 ParamTypes.data(),
2937 ParamTypes.size(),
2938 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002939 T->getTypeQuals(),
2940 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002941 if (Result.isNull())
2942 return QualType();
2943 }
Mike Stump11289f42009-09-09 15:08:12 +00002944
John McCall550e0c22009-10-21 00:40:46 +00002945 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2946 NewTL.setLParenLoc(TL.getLParenLoc());
2947 NewTL.setRParenLoc(TL.getRParenLoc());
2948 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2949 NewTL.setArg(i, ParamDecls[i]);
2950
2951 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952}
Mike Stump11289f42009-09-09 15:08:12 +00002953
Douglas Gregord6ff3322009-08-04 16:50:30 +00002954template<typename Derived>
2955QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002956 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002957 FunctionNoProtoTypeLoc TL,
2958 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002959 FunctionNoProtoType *T = TL.getTypePtr();
2960 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2961 if (ResultType.isNull())
2962 return QualType();
2963
2964 QualType Result = TL.getType();
2965 if (getDerived().AlwaysRebuild() ||
2966 ResultType != T->getResultType())
2967 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2968
2969 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2970 NewTL.setLParenLoc(TL.getLParenLoc());
2971 NewTL.setRParenLoc(TL.getRParenLoc());
2972
2973 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002974}
Mike Stump11289f42009-09-09 15:08:12 +00002975
John McCallb96ec562009-12-04 22:46:56 +00002976template<typename Derived> QualType
2977TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002978 UnresolvedUsingTypeLoc TL,
2979 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002980 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002981 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002982 if (!D)
2983 return QualType();
2984
2985 QualType Result = TL.getType();
2986 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2987 Result = getDerived().RebuildUnresolvedUsingType(D);
2988 if (Result.isNull())
2989 return QualType();
2990 }
2991
2992 // We might get an arbitrary type spec type back. We should at
2993 // least always get a type spec type, though.
2994 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2995 NewTL.setNameLoc(TL.getNameLoc());
2996
2997 return Result;
2998}
2999
Douglas Gregord6ff3322009-08-04 16:50:30 +00003000template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003001QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003002 TypedefTypeLoc TL,
3003 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003004 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003005 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003006 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3007 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003008 if (!Typedef)
3009 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003010
John McCall550e0c22009-10-21 00:40:46 +00003011 QualType Result = TL.getType();
3012 if (getDerived().AlwaysRebuild() ||
3013 Typedef != T->getDecl()) {
3014 Result = getDerived().RebuildTypedefType(Typedef);
3015 if (Result.isNull())
3016 return QualType();
3017 }
Mike Stump11289f42009-09-09 15:08:12 +00003018
John McCall550e0c22009-10-21 00:40:46 +00003019 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3020 NewTL.setNameLoc(TL.getNameLoc());
3021
3022 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003023}
Mike Stump11289f42009-09-09 15:08:12 +00003024
Douglas Gregord6ff3322009-08-04 16:50:30 +00003025template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003026QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003027 TypeOfExprTypeLoc TL,
3028 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003029 // typeof expressions are not potentially evaluated contexts
3030 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003031
John McCalle8595032010-01-13 20:03:27 +00003032 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033 if (E.isInvalid())
3034 return QualType();
3035
John McCall550e0c22009-10-21 00:40:46 +00003036 QualType Result = TL.getType();
3037 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003038 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003039 Result = getDerived().RebuildTypeOfExprType(move(E));
3040 if (Result.isNull())
3041 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003042 }
John McCall550e0c22009-10-21 00:40:46 +00003043 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003044
John McCall550e0c22009-10-21 00:40:46 +00003045 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003046 NewTL.setTypeofLoc(TL.getTypeofLoc());
3047 NewTL.setLParenLoc(TL.getLParenLoc());
3048 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003049
3050 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003051}
Mike Stump11289f42009-09-09 15:08:12 +00003052
3053template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003054QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003055 TypeOfTypeLoc TL,
3056 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003057 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3058 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3059 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003060 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003061
John McCall550e0c22009-10-21 00:40:46 +00003062 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003063 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3064 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003065 if (Result.isNull())
3066 return QualType();
3067 }
Mike Stump11289f42009-09-09 15:08:12 +00003068
John McCall550e0c22009-10-21 00:40:46 +00003069 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003070 NewTL.setTypeofLoc(TL.getTypeofLoc());
3071 NewTL.setLParenLoc(TL.getLParenLoc());
3072 NewTL.setRParenLoc(TL.getRParenLoc());
3073 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003074
3075 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076}
Mike Stump11289f42009-09-09 15:08:12 +00003077
3078template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003079QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003080 DecltypeTypeLoc TL,
3081 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003082 DecltypeType *T = TL.getTypePtr();
3083
Douglas Gregore922c772009-08-04 22:27:00 +00003084 // decltype expressions are not potentially evaluated contexts
3085 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003086
Douglas Gregord6ff3322009-08-04 16:50:30 +00003087 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3088 if (E.isInvalid())
3089 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003090
John McCall550e0c22009-10-21 00:40:46 +00003091 QualType Result = TL.getType();
3092 if (getDerived().AlwaysRebuild() ||
3093 E.get() != T->getUnderlyingExpr()) {
3094 Result = getDerived().RebuildDecltypeType(move(E));
3095 if (Result.isNull())
3096 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003097 }
John McCall550e0c22009-10-21 00:40:46 +00003098 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003099
John McCall550e0c22009-10-21 00:40:46 +00003100 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3101 NewTL.setNameLoc(TL.getNameLoc());
3102
3103 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104}
3105
3106template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003107QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003108 RecordTypeLoc TL,
3109 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003110 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003111 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003112 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3113 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003114 if (!Record)
3115 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003116
John McCall550e0c22009-10-21 00:40:46 +00003117 QualType Result = TL.getType();
3118 if (getDerived().AlwaysRebuild() ||
3119 Record != T->getDecl()) {
3120 Result = getDerived().RebuildRecordType(Record);
3121 if (Result.isNull())
3122 return QualType();
3123 }
Mike Stump11289f42009-09-09 15:08:12 +00003124
John McCall550e0c22009-10-21 00:40:46 +00003125 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3126 NewTL.setNameLoc(TL.getNameLoc());
3127
3128 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129}
Mike Stump11289f42009-09-09 15:08:12 +00003130
3131template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003132QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003133 EnumTypeLoc TL,
3134 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003135 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003136 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003137 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3138 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139 if (!Enum)
3140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003141
John McCall550e0c22009-10-21 00:40:46 +00003142 QualType Result = TL.getType();
3143 if (getDerived().AlwaysRebuild() ||
3144 Enum != T->getDecl()) {
3145 Result = getDerived().RebuildEnumType(Enum);
3146 if (Result.isNull())
3147 return QualType();
3148 }
Mike Stump11289f42009-09-09 15:08:12 +00003149
John McCall550e0c22009-10-21 00:40:46 +00003150 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3151 NewTL.setNameLoc(TL.getNameLoc());
3152
3153 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003154}
John McCallfcc33b02009-09-05 00:15:47 +00003155
John McCalle78aac42010-03-10 03:28:59 +00003156template<typename Derived>
3157QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3158 TypeLocBuilder &TLB,
3159 InjectedClassNameTypeLoc TL,
3160 QualType ObjectType) {
3161 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3162 TL.getTypePtr()->getDecl());
3163 if (!D) return QualType();
3164
3165 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3166 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3167 return T;
3168}
3169
Mike Stump11289f42009-09-09 15:08:12 +00003170
Douglas Gregord6ff3322009-08-04 16:50:30 +00003171template<typename Derived>
3172QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003173 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003174 TemplateTypeParmTypeLoc TL,
3175 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003176 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003177}
3178
Mike Stump11289f42009-09-09 15:08:12 +00003179template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003180QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003181 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003182 SubstTemplateTypeParmTypeLoc TL,
3183 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003184 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003185}
3186
3187template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003188QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3189 const TemplateSpecializationType *TST,
3190 QualType ObjectType) {
3191 // FIXME: this entire method is a temporary workaround; callers
3192 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003193
John McCall0ad16662009-10-29 08:12:44 +00003194 // Fake up a TemplateSpecializationTypeLoc.
3195 TypeLocBuilder TLB;
3196 TemplateSpecializationTypeLoc TL
3197 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3198
John McCall0d07eb32009-10-29 18:45:58 +00003199 SourceLocation BaseLoc = getDerived().getBaseLocation();
3200
3201 TL.setTemplateNameLoc(BaseLoc);
3202 TL.setLAngleLoc(BaseLoc);
3203 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003204 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3205 const TemplateArgument &TA = TST->getArg(i);
3206 TemplateArgumentLoc TAL;
3207 getDerived().InventTemplateArgumentLoc(TA, TAL);
3208 TL.setArgLocInfo(i, TAL.getLocInfo());
3209 }
3210
3211 TypeLocBuilder IgnoredTLB;
3212 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003213}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003214
Douglas Gregorc59e5612009-10-19 22:04:39 +00003215template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003216QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003217 TypeLocBuilder &TLB,
3218 TemplateSpecializationTypeLoc TL,
3219 QualType ObjectType) {
3220 const TemplateSpecializationType *T = TL.getTypePtr();
3221
Mike Stump11289f42009-09-09 15:08:12 +00003222 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003223 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003224 if (Template.isNull())
3225 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003226
John McCall6b51f282009-11-23 01:53:49 +00003227 TemplateArgumentListInfo NewTemplateArgs;
3228 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3229 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3230
3231 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3232 TemplateArgumentLoc Loc;
3233 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003234 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003235 NewTemplateArgs.addArgument(Loc);
3236 }
Mike Stump11289f42009-09-09 15:08:12 +00003237
John McCall0ad16662009-10-29 08:12:44 +00003238 // FIXME: maybe don't rebuild if all the template arguments are the same.
3239
3240 QualType Result =
3241 getDerived().RebuildTemplateSpecializationType(Template,
3242 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003243 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003244
3245 if (!Result.isNull()) {
3246 TemplateSpecializationTypeLoc NewTL
3247 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3248 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3249 NewTL.setLAngleLoc(TL.getLAngleLoc());
3250 NewTL.setRAngleLoc(TL.getRAngleLoc());
3251 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3252 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003253 }
Mike Stump11289f42009-09-09 15:08:12 +00003254
John McCall0ad16662009-10-29 08:12:44 +00003255 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003256}
Mike Stump11289f42009-09-09 15:08:12 +00003257
3258template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003259QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003260TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3261 ElaboratedTypeLoc TL,
3262 QualType ObjectType) {
3263 ElaboratedType *T = TL.getTypePtr();
3264
3265 NestedNameSpecifier *NNS = 0;
3266 // NOTE: the qualifier in an ElaboratedType is optional.
3267 if (T->getQualifier() != 0) {
3268 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003269 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003270 ObjectType);
3271 if (!NNS)
3272 return QualType();
3273 }
Mike Stump11289f42009-09-09 15:08:12 +00003274
Abramo Bagnarad7548482010-05-19 21:37:53 +00003275 QualType NamedT;
3276 // FIXME: this test is meant to workaround a problem (failing assertion)
3277 // occurring if directly executing the code in the else branch.
3278 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3279 TemplateSpecializationTypeLoc OldNamedTL
3280 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3281 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003282 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003283 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3284 if (NamedT.isNull())
3285 return QualType();
3286 TemplateSpecializationTypeLoc NewNamedTL
3287 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3288 NewNamedTL.copy(OldNamedTL);
3289 }
3290 else {
3291 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3292 if (NamedT.isNull())
3293 return QualType();
3294 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003295
John McCall550e0c22009-10-21 00:40:46 +00003296 QualType Result = TL.getType();
3297 if (getDerived().AlwaysRebuild() ||
3298 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003299 NamedT != T->getNamedType()) {
3300 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003301 if (Result.isNull())
3302 return QualType();
3303 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304
Abramo Bagnara6150c882010-05-11 21:36:43 +00003305 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003306 NewTL.setKeywordLoc(TL.getKeywordLoc());
3307 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003308
3309 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310}
Mike Stump11289f42009-09-09 15:08:12 +00003311
3312template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003313QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3314 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003315 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003316 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003317
Douglas Gregord6ff3322009-08-04 16:50:30 +00003318 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003319 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3320 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003321 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322 if (!NNS)
3323 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003324
John McCallc392f372010-06-11 00:33:02 +00003325 QualType Result
3326 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3327 T->getIdentifier(),
3328 TL.getKeywordLoc(),
3329 TL.getQualifierRange(),
3330 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003331 if (Result.isNull())
3332 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003333
Abramo Bagnarad7548482010-05-19 21:37:53 +00003334 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3335 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003336 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3337
Abramo Bagnarad7548482010-05-19 21:37:53 +00003338 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3339 NewTL.setKeywordLoc(TL.getKeywordLoc());
3340 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003341 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003342 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3343 NewTL.setKeywordLoc(TL.getKeywordLoc());
3344 NewTL.setQualifierRange(TL.getQualifierRange());
3345 NewTL.setNameLoc(TL.getNameLoc());
3346 }
John McCall550e0c22009-10-21 00:40:46 +00003347 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003348}
Mike Stump11289f42009-09-09 15:08:12 +00003349
Douglas Gregord6ff3322009-08-04 16:50:30 +00003350template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003351QualType TreeTransform<Derived>::
3352 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3353 DependentTemplateSpecializationTypeLoc TL,
3354 QualType ObjectType) {
3355 DependentTemplateSpecializationType *T = TL.getTypePtr();
3356
3357 NestedNameSpecifier *NNS
3358 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3359 TL.getQualifierRange(),
3360 ObjectType);
3361 if (!NNS)
3362 return QualType();
3363
3364 TemplateArgumentListInfo NewTemplateArgs;
3365 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3366 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3367
3368 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3369 TemplateArgumentLoc Loc;
3370 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3371 return QualType();
3372 NewTemplateArgs.addArgument(Loc);
3373 }
3374
3375 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3376 T->getKeyword(),
3377 NNS,
3378 T->getIdentifier(),
3379 TL.getNameLoc(),
3380 NewTemplateArgs);
3381 if (Result.isNull())
3382 return QualType();
3383
3384 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3385 QualType NamedT = ElabT->getNamedType();
3386
3387 // Copy information relevant to the template specialization.
3388 TemplateSpecializationTypeLoc NamedTL
3389 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3390 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3391 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3392 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3393 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3394
3395 // Copy information relevant to the elaborated type.
3396 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3397 NewTL.setKeywordLoc(TL.getKeywordLoc());
3398 NewTL.setQualifierRange(TL.getQualifierRange());
3399 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003400 TypeLoc NewTL(Result, TL.getOpaqueData());
3401 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003402 }
3403 return Result;
3404}
3405
3406template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003407QualType
3408TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003409 ObjCInterfaceTypeLoc TL,
3410 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003411 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003412 TLB.pushFullCopy(TL);
3413 return TL.getType();
3414}
3415
3416template<typename Derived>
3417QualType
3418TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3419 ObjCObjectTypeLoc TL,
3420 QualType ObjectType) {
3421 // ObjCObjectType is never dependent.
3422 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003423 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424}
Mike Stump11289f42009-09-09 15:08:12 +00003425
3426template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003427QualType
3428TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003429 ObjCObjectPointerTypeLoc TL,
3430 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003431 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003432 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003433 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003434}
3435
Douglas Gregord6ff3322009-08-04 16:50:30 +00003436//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003437// Statement transformation
3438//===----------------------------------------------------------------------===//
3439template<typename Derived>
3440Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003441TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3442 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003443}
3444
3445template<typename Derived>
3446Sema::OwningStmtResult
3447TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3448 return getDerived().TransformCompoundStmt(S, false);
3449}
3450
3451template<typename Derived>
3452Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003453TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003454 bool IsStmtExpr) {
3455 bool SubStmtChanged = false;
3456 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3457 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3458 B != BEnd; ++B) {
3459 OwningStmtResult Result = getDerived().TransformStmt(*B);
3460 if (Result.isInvalid())
3461 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003462
Douglas Gregorebe10102009-08-20 07:17:43 +00003463 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3464 Statements.push_back(Result.takeAs<Stmt>());
3465 }
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 if (!getDerived().AlwaysRebuild() &&
3468 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003469 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003470
3471 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3472 move_arg(Statements),
3473 S->getRBracLoc(),
3474 IsStmtExpr);
3475}
Mike Stump11289f42009-09-09 15:08:12 +00003476
Douglas Gregorebe10102009-08-20 07:17:43 +00003477template<typename Derived>
3478Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003479TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003480 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3481 {
3482 // The case value expressions are not potentially evaluated.
3483 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003484
Eli Friedman06577382009-11-19 03:14:00 +00003485 // Transform the left-hand case value.
3486 LHS = getDerived().TransformExpr(S->getLHS());
3487 if (LHS.isInvalid())
3488 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003489
Eli Friedman06577382009-11-19 03:14:00 +00003490 // Transform the right-hand case value (for the GNU case-range extension).
3491 RHS = getDerived().TransformExpr(S->getRHS());
3492 if (RHS.isInvalid())
3493 return SemaRef.StmtError();
3494 }
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // Build the case statement.
3497 // Case statements are always rebuilt so that they will attached to their
3498 // transformed switch statement.
3499 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3500 move(LHS),
3501 S->getEllipsisLoc(),
3502 move(RHS),
3503 S->getColonLoc());
3504 if (Case.isInvalid())
3505 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 // Transform the statement following the case
3508 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3509 if (SubStmt.isInvalid())
3510 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003511
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Attach the body to the case statement
3513 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3514}
3515
3516template<typename Derived>
3517Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 // Transform the statement following the default case
3520 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3521 if (SubStmt.isInvalid())
3522 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 // Default statements are always rebuilt
3525 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3526 move(SubStmt));
3527}
Mike Stump11289f42009-09-09 15:08:12 +00003528
Douglas Gregorebe10102009-08-20 07:17:43 +00003529template<typename Derived>
3530Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003531TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003532 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3533 if (SubStmt.isInvalid())
3534 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // FIXME: Pass the real colon location in.
3537 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3538 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3539 move(SubStmt));
3540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregorebe10102009-08-20 07:17:43 +00003542template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003543Sema::OwningStmtResult
3544TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003546 OwningExprResult Cond(SemaRef);
3547 VarDecl *ConditionVar = 0;
3548 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003549 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003550 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003551 getDerived().TransformDefinition(
3552 S->getConditionVariable()->getLocation(),
3553 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003554 if (!ConditionVar)
3555 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003556 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003557 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003558
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003559 if (Cond.isInvalid())
3560 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003561
3562 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003563 if (S->getCond()) {
3564 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3565 S->getIfLoc(),
3566 move(Cond));
3567 if (CondE.isInvalid())
3568 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003569
Douglas Gregor6d319c62010-05-08 23:34:38 +00003570 Cond = move(CondE);
3571 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003572 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003573
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003574 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3575 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3576 return SemaRef.StmtError();
3577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 // Transform the "then" branch.
3579 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3580 if (Then.isInvalid())
3581 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 // Transform the "else" branch.
3584 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3585 if (Else.isInvalid())
3586 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003589 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003590 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003591 Then.get() == S->getThen() &&
3592 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003593 return SemaRef.Owned(S->Retain());
3594
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003595 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003596 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003597 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003598}
3599
3600template<typename Derived>
3601Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003602TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003603 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003604 OwningExprResult Cond(SemaRef);
3605 VarDecl *ConditionVar = 0;
3606 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003607 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003608 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003609 getDerived().TransformDefinition(
3610 S->getConditionVariable()->getLocation(),
3611 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003612 if (!ConditionVar)
3613 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003614 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003615 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003616
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003617 if (Cond.isInvalid())
3618 return SemaRef.StmtError();
3619 }
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003622 OwningStmtResult Switch
3623 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3624 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 if (Switch.isInvalid())
3626 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 // Transform the body of the switch statement.
3629 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3630 if (Body.isInvalid())
3631 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003632
Douglas Gregorebe10102009-08-20 07:17:43 +00003633 // Complete the switch statement.
3634 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3635 move(Body));
3636}
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregorebe10102009-08-20 07:17:43 +00003638template<typename Derived>
3639Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003640TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003641 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003642 OwningExprResult Cond(SemaRef);
3643 VarDecl *ConditionVar = 0;
3644 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003645 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003646 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003647 getDerived().TransformDefinition(
3648 S->getConditionVariable()->getLocation(),
3649 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003650 if (!ConditionVar)
3651 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003652 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003653 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003654
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003655 if (Cond.isInvalid())
3656 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003657
3658 if (S->getCond()) {
3659 // Convert the condition to a boolean value.
3660 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003661 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003662 move(Cond));
3663 if (CondE.isInvalid())
3664 return getSema().StmtError();
3665 Cond = move(CondE);
3666 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003667 }
Mike Stump11289f42009-09-09 15:08:12 +00003668
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003669 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3670 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3671 return SemaRef.StmtError();
3672
Douglas Gregorebe10102009-08-20 07:17:43 +00003673 // Transform the body
3674 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3675 if (Body.isInvalid())
3676 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003677
Douglas Gregorebe10102009-08-20 07:17:43 +00003678 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003679 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003680 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003682 return SemaRef.Owned(S->Retain());
3683
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003684 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003685 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003686}
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregorebe10102009-08-20 07:17:43 +00003688template<typename Derived>
3689Sema::OwningStmtResult
3690TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 // Transform the body
3692 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3693 if (Body.isInvalid())
3694 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003695
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003696 // Transform the condition
3697 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3698 if (Cond.isInvalid())
3699 return SemaRef.StmtError();
3700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701 if (!getDerived().AlwaysRebuild() &&
3702 Cond.get() == S->getCond() &&
3703 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003704 return SemaRef.Owned(S->Retain());
3705
Douglas Gregorebe10102009-08-20 07:17:43 +00003706 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3707 /*FIXME:*/S->getWhileLoc(), move(Cond),
3708 S->getRParenLoc());
3709}
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregorebe10102009-08-20 07:17:43 +00003711template<typename Derived>
3712Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 // Transform the initialization statement
3715 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3716 if (Init.isInvalid())
3717 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003720 OwningExprResult Cond(SemaRef);
3721 VarDecl *ConditionVar = 0;
3722 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003723 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003724 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003725 getDerived().TransformDefinition(
3726 S->getConditionVariable()->getLocation(),
3727 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003728 if (!ConditionVar)
3729 return SemaRef.StmtError();
3730 } else {
3731 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003732
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003733 if (Cond.isInvalid())
3734 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003735
3736 if (S->getCond()) {
3737 // Convert the condition to a boolean value.
3738 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3739 S->getForLoc(),
3740 move(Cond));
3741 if (CondE.isInvalid())
3742 return getSema().StmtError();
3743
3744 Cond = move(CondE);
3745 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003746 }
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003748 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3749 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3750 return SemaRef.StmtError();
3751
Douglas Gregorebe10102009-08-20 07:17:43 +00003752 // Transform the increment
3753 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3754 if (Inc.isInvalid())
3755 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003757 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3758 if (S->getInc() && !FullInc->get())
3759 return SemaRef.StmtError();
3760
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 // Transform the body
3762 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3763 if (Body.isInvalid())
3764 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003765
Douglas Gregorebe10102009-08-20 07:17:43 +00003766 if (!getDerived().AlwaysRebuild() &&
3767 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003768 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003769 Inc.get() == S->getInc() &&
3770 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003771 return SemaRef.Owned(S->Retain());
3772
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003774 move(Init), FullCond, ConditionVar,
3775 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003776}
3777
3778template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003779Sema::OwningStmtResult
3780TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003781 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003782 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003783 S->getLabel());
3784}
3785
3786template<typename Derived>
3787Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003788TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003789 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3790 if (Target.isInvalid())
3791 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregorebe10102009-08-20 07:17:43 +00003793 if (!getDerived().AlwaysRebuild() &&
3794 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003795 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003796
3797 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3798 move(Target));
3799}
3800
3801template<typename Derived>
3802Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003803TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3804 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003805}
Mike Stump11289f42009-09-09 15:08:12 +00003806
Douglas Gregorebe10102009-08-20 07:17:43 +00003807template<typename Derived>
3808Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003809TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3810 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003811}
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregorebe10102009-08-20 07:17:43 +00003813template<typename Derived>
3814Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003815TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003816 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3817 if (Result.isInvalid())
3818 return SemaRef.StmtError();
3819
Mike Stump11289f42009-09-09 15:08:12 +00003820 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003821 // to tell whether the return type of the function has changed.
3822 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3823}
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregorebe10102009-08-20 07:17:43 +00003825template<typename Derived>
3826Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003827TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003828 bool DeclChanged = false;
3829 llvm::SmallVector<Decl *, 4> Decls;
3830 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3831 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003832 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3833 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003834 if (!Transformed)
3835 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregorebe10102009-08-20 07:17:43 +00003837 if (Transformed != *D)
3838 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003839
Douglas Gregorebe10102009-08-20 07:17:43 +00003840 Decls.push_back(Transformed);
3841 }
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003844 return SemaRef.Owned(S->Retain());
3845
3846 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003847 S->getStartLoc(), S->getEndLoc());
3848}
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregorebe10102009-08-20 07:17:43 +00003850template<typename Derived>
3851Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003852TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003853 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003854 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003855}
3856
3857template<typename Derived>
3858Sema::OwningStmtResult
3859TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003860
Anders Carlssonaaeef072010-01-24 05:50:09 +00003861 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3862 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003863 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003864
Anders Carlssonaaeef072010-01-24 05:50:09 +00003865 OwningExprResult AsmString(SemaRef);
3866 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3867
3868 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003869
Anders Carlssonaaeef072010-01-24 05:50:09 +00003870 // Go through the outputs.
3871 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003872 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003873
Anders Carlssonaaeef072010-01-24 05:50:09 +00003874 // No need to transform the constraint literal.
3875 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003876
Anders Carlssonaaeef072010-01-24 05:50:09 +00003877 // Transform the output expr.
3878 Expr *OutputExpr = S->getOutputExpr(I);
3879 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3880 if (Result.isInvalid())
3881 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003882
Anders Carlssonaaeef072010-01-24 05:50:09 +00003883 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003884
Anders Carlssonaaeef072010-01-24 05:50:09 +00003885 Exprs.push_back(Result.takeAs<Expr>());
3886 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003887
Anders Carlssonaaeef072010-01-24 05:50:09 +00003888 // Go through the inputs.
3889 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003890 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003891
Anders Carlssonaaeef072010-01-24 05:50:09 +00003892 // No need to transform the constraint literal.
3893 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003894
Anders Carlssonaaeef072010-01-24 05:50:09 +00003895 // Transform the input expr.
3896 Expr *InputExpr = S->getInputExpr(I);
3897 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3898 if (Result.isInvalid())
3899 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003900
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003902
Anders Carlssonaaeef072010-01-24 05:50:09 +00003903 Exprs.push_back(Result.takeAs<Expr>());
3904 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003905
Anders Carlssonaaeef072010-01-24 05:50:09 +00003906 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3907 return SemaRef.Owned(S->Retain());
3908
3909 // Go through the clobbers.
3910 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3911 Clobbers.push_back(S->getClobber(I)->Retain());
3912
3913 // No need to transform the asm string literal.
3914 AsmString = SemaRef.Owned(S->getAsmString());
3915
3916 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3917 S->isSimple(),
3918 S->isVolatile(),
3919 S->getNumOutputs(),
3920 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003921 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003922 move_arg(Constraints),
3923 move_arg(Exprs),
3924 move(AsmString),
3925 move_arg(Clobbers),
3926 S->getRParenLoc(),
3927 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003928}
3929
3930
3931template<typename Derived>
3932Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003933TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003934 // Transform the body of the @try.
3935 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3936 if (TryBody.isInvalid())
3937 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003938
Douglas Gregor96c79492010-04-23 22:50:49 +00003939 // Transform the @catch statements (if present).
3940 bool AnyCatchChanged = false;
3941 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3942 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3943 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003944 if (Catch.isInvalid())
3945 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003946 if (Catch.get() != S->getCatchStmt(I))
3947 AnyCatchChanged = true;
3948 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003949 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003950
Douglas Gregor306de2f2010-04-22 23:59:56 +00003951 // Transform the @finally statement (if present).
3952 OwningStmtResult Finally(SemaRef);
3953 if (S->getFinallyStmt()) {
3954 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3955 if (Finally.isInvalid())
3956 return SemaRef.StmtError();
3957 }
3958
3959 // If nothing changed, just retain this statement.
3960 if (!getDerived().AlwaysRebuild() &&
3961 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003962 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003963 Finally.get() == S->getFinallyStmt())
3964 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003965
Douglas Gregor306de2f2010-04-22 23:59:56 +00003966 // Build a new statement.
3967 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003968 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003969}
Mike Stump11289f42009-09-09 15:08:12 +00003970
Douglas Gregorebe10102009-08-20 07:17:43 +00003971template<typename Derived>
3972Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003973TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003974 // Transform the @catch parameter, if there is one.
3975 VarDecl *Var = 0;
3976 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3977 TypeSourceInfo *TSInfo = 0;
3978 if (FromVar->getTypeSourceInfo()) {
3979 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3980 if (!TSInfo)
3981 return SemaRef.StmtError();
3982 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003984 QualType T;
3985 if (TSInfo)
3986 T = TSInfo->getType();
3987 else {
3988 T = getDerived().TransformType(FromVar->getType());
3989 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003991 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003992
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003993 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3994 if (!Var)
3995 return SemaRef.StmtError();
3996 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003997
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003998 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3999 if (Body.isInvalid())
4000 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004001
4002 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004003 S->getRParenLoc(),
4004 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004005}
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregorebe10102009-08-20 07:17:43 +00004007template<typename Derived>
4008Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004009TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004010 // Transform the body.
4011 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4012 if (Body.isInvalid())
4013 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004014
Douglas Gregor306de2f2010-04-22 23:59:56 +00004015 // If nothing changed, just retain this statement.
4016 if (!getDerived().AlwaysRebuild() &&
4017 Body.get() == S->getFinallyBody())
4018 return SemaRef.Owned(S->Retain());
4019
4020 // Build a new statement.
4021 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4022 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004023}
Mike Stump11289f42009-09-09 15:08:12 +00004024
Douglas Gregorebe10102009-08-20 07:17:43 +00004025template<typename Derived>
4026Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004027TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00004028 OwningExprResult Operand(SemaRef);
4029 if (S->getThrowExpr()) {
4030 Operand = getDerived().TransformExpr(S->getThrowExpr());
4031 if (Operand.isInvalid())
4032 return getSema().StmtError();
4033 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004034
Douglas Gregor2900c162010-04-22 21:44:01 +00004035 if (!getDerived().AlwaysRebuild() &&
4036 Operand.get() == S->getThrowExpr())
4037 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004038
Douglas Gregor2900c162010-04-22 21:44:01 +00004039 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00004040}
Mike Stump11289f42009-09-09 15:08:12 +00004041
Douglas Gregorebe10102009-08-20 07:17:43 +00004042template<typename Derived>
4043Sema::OwningStmtResult
4044TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004045 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004046 // Transform the object we are locking.
4047 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4048 if (Object.isInvalid())
4049 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004050
Douglas Gregor6148de72010-04-22 22:01:21 +00004051 // Transform the body.
4052 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4053 if (Body.isInvalid())
4054 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004055
Douglas Gregor6148de72010-04-22 22:01:21 +00004056 // If nothing change, just retain the current statement.
4057 if (!getDerived().AlwaysRebuild() &&
4058 Object.get() == S->getSynchExpr() &&
4059 Body.get() == S->getSynchBody())
4060 return SemaRef.Owned(S->Retain());
4061
4062 // Build a new statement.
4063 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4064 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004065}
4066
4067template<typename Derived>
4068Sema::OwningStmtResult
4069TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004070 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004071 // Transform the element statement.
4072 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4073 if (Element.isInvalid())
4074 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004075
Douglas Gregorf68a5082010-04-22 23:10:45 +00004076 // Transform the collection expression.
4077 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4078 if (Collection.isInvalid())
4079 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004080
Douglas Gregorf68a5082010-04-22 23:10:45 +00004081 // Transform the body.
4082 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4083 if (Body.isInvalid())
4084 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004085
Douglas Gregorf68a5082010-04-22 23:10:45 +00004086 // If nothing changed, just retain this statement.
4087 if (!getDerived().AlwaysRebuild() &&
4088 Element.get() == S->getElement() &&
4089 Collection.get() == S->getCollection() &&
4090 Body.get() == S->getBody())
4091 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004092
Douglas Gregorf68a5082010-04-22 23:10:45 +00004093 // Build a new statement.
4094 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4095 /*FIXME:*/S->getForLoc(),
4096 move(Element),
4097 move(Collection),
4098 S->getRParenLoc(),
4099 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004100}
4101
4102
4103template<typename Derived>
4104Sema::OwningStmtResult
4105TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4106 // Transform the exception declaration, if any.
4107 VarDecl *Var = 0;
4108 if (S->getExceptionDecl()) {
4109 VarDecl *ExceptionDecl = S->getExceptionDecl();
4110 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4111 ExceptionDecl->getDeclName());
4112
4113 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4114 if (T.isNull())
4115 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregorebe10102009-08-20 07:17:43 +00004117 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4118 T,
John McCallbcd03502009-12-07 02:54:59 +00004119 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004120 ExceptionDecl->getIdentifier(),
4121 ExceptionDecl->getLocation(),
4122 /*FIXME: Inaccurate*/
4123 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004124 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004125 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004126 }
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregorebe10102009-08-20 07:17:43 +00004128 // Transform the actual exception handler.
4129 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004130 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004131 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregorebe10102009-08-20 07:17:43 +00004133 if (!getDerived().AlwaysRebuild() &&
4134 !Var &&
4135 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004136 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004137
4138 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4139 Var,
4140 move(Handler));
4141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregorebe10102009-08-20 07:17:43 +00004143template<typename Derived>
4144Sema::OwningStmtResult
4145TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4146 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004147 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004148 = getDerived().TransformCompoundStmt(S->getTryBlock());
4149 if (TryBlock.isInvalid())
4150 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregorebe10102009-08-20 07:17:43 +00004152 // Transform the handlers.
4153 bool HandlerChanged = false;
4154 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4155 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004156 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004157 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4158 if (Handler.isInvalid())
4159 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregorebe10102009-08-20 07:17:43 +00004161 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4162 Handlers.push_back(Handler.takeAs<Stmt>());
4163 }
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregorebe10102009-08-20 07:17:43 +00004165 if (!getDerived().AlwaysRebuild() &&
4166 TryBlock.get() == S->getTryBlock() &&
4167 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004168 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004169
4170 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004171 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregorebe10102009-08-20 07:17:43 +00004174//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004175// Expression transformation
4176//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004177template<typename Derived>
4178Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004179TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004180 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004181}
Mike Stump11289f42009-09-09 15:08:12 +00004182
4183template<typename Derived>
4184Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004185TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004186 NestedNameSpecifier *Qualifier = 0;
4187 if (E->getQualifier()) {
4188 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004189 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004190 if (!Qualifier)
4191 return SemaRef.ExprError();
4192 }
John McCallce546572009-12-08 09:08:17 +00004193
4194 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004195 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4196 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004197 if (!ND)
4198 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004199
Alexis Hunta8136cc2010-05-05 15:23:54 +00004200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004201 Qualifier == E->getQualifier() &&
4202 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004203 !E->hasExplicitTemplateArgumentList()) {
4204
4205 // Mark it referenced in the new context regardless.
4206 // FIXME: this is a bit instantiation-specific.
4207 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4208
Mike Stump11289f42009-09-09 15:08:12 +00004209 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004210 }
John McCallce546572009-12-08 09:08:17 +00004211
4212 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4213 if (E->hasExplicitTemplateArgumentList()) {
4214 TemplateArgs = &TransArgs;
4215 TransArgs.setLAngleLoc(E->getLAngleLoc());
4216 TransArgs.setRAngleLoc(E->getRAngleLoc());
4217 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4218 TemplateArgumentLoc Loc;
4219 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4220 return SemaRef.ExprError();
4221 TransArgs.addArgument(Loc);
4222 }
4223 }
4224
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004225 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004226 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004227}
Mike Stump11289f42009-09-09 15:08:12 +00004228
Douglas Gregora16548e2009-08-11 05:31:07 +00004229template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004230Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004231TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004232 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004233}
Mike Stump11289f42009-09-09 15:08:12 +00004234
Douglas Gregora16548e2009-08-11 05:31:07 +00004235template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004236Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004237TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004238 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004239}
Mike Stump11289f42009-09-09 15:08:12 +00004240
Douglas Gregora16548e2009-08-11 05:31:07 +00004241template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004242Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004243TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004244 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004245}
Mike Stump11289f42009-09-09 15:08:12 +00004246
Douglas Gregora16548e2009-08-11 05:31:07 +00004247template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004248Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004249TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004250 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004251}
Mike Stump11289f42009-09-09 15:08:12 +00004252
Douglas Gregora16548e2009-08-11 05:31:07 +00004253template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004254Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004255TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004256 return SemaRef.Owned(E->Retain());
4257}
4258
4259template<typename Derived>
4260Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004261TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4263 if (SubExpr.isInvalid())
4264 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004265
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004267 return SemaRef.Owned(E->Retain());
4268
4269 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004270 E->getRParen());
4271}
4272
Mike Stump11289f42009-09-09 15:08:12 +00004273template<typename Derived>
4274Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004275TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4276 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 if (SubExpr.isInvalid())
4278 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004281 return SemaRef.Owned(E->Retain());
4282
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4284 E->getOpcode(),
4285 move(SubExpr));
4286}
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004289Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004290TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4291 // Transform the type.
4292 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4293 if (!Type)
4294 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004295
Douglas Gregor882211c2010-04-28 22:16:22 +00004296 // Transform all of the components into components similar to what the
4297 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004298 // FIXME: It would be slightly more efficient in the non-dependent case to
4299 // just map FieldDecls, rather than requiring the rebuilder to look for
4300 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004301 // template code that we don't care.
4302 bool ExprChanged = false;
4303 typedef Action::OffsetOfComponent Component;
4304 typedef OffsetOfExpr::OffsetOfNode Node;
4305 llvm::SmallVector<Component, 4> Components;
4306 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4307 const Node &ON = E->getComponent(I);
4308 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004309 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004310 Comp.LocStart = ON.getRange().getBegin();
4311 Comp.LocEnd = ON.getRange().getEnd();
4312 switch (ON.getKind()) {
4313 case Node::Array: {
4314 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4315 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4316 if (Index.isInvalid())
4317 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004318
Douglas Gregor882211c2010-04-28 22:16:22 +00004319 ExprChanged = ExprChanged || Index.get() != FromIndex;
4320 Comp.isBrackets = true;
4321 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4322 break;
4323 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004324
Douglas Gregor882211c2010-04-28 22:16:22 +00004325 case Node::Field:
4326 case Node::Identifier:
4327 Comp.isBrackets = false;
4328 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004329 if (!Comp.U.IdentInfo)
4330 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004331
Douglas Gregor882211c2010-04-28 22:16:22 +00004332 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004333
Douglas Gregord1702062010-04-29 00:18:15 +00004334 case Node::Base:
4335 // Will be recomputed during the rebuild.
4336 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004337 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004338
Douglas Gregor882211c2010-04-28 22:16:22 +00004339 Components.push_back(Comp);
4340 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004341
Douglas Gregor882211c2010-04-28 22:16:22 +00004342 // If nothing changed, retain the existing expression.
4343 if (!getDerived().AlwaysRebuild() &&
4344 Type == E->getTypeSourceInfo() &&
4345 !ExprChanged)
4346 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004347
Douglas Gregor882211c2010-04-28 22:16:22 +00004348 // Build a new offsetof expression.
4349 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4350 Components.data(), Components.size(),
4351 E->getRParenLoc());
4352}
4353
4354template<typename Derived>
4355Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004358 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004359
John McCallbcd03502009-12-07 02:54:59 +00004360 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004361 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004363
John McCall4c98fd82009-11-04 07:28:41 +00004364 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004366
John McCall4c98fd82009-11-04 07:28:41 +00004367 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004368 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 E->getSourceRange());
4370 }
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004373 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 // C++0x [expr.sizeof]p1:
4375 // The operand is either an expression, which is an unevaluated operand
4376 // [...]
4377 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4380 if (SubExpr.isInvalid())
4381 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4384 return SemaRef.Owned(E->Retain());
4385 }
Mike Stump11289f42009-09-09 15:08:12 +00004386
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4388 E->isSizeOf(),
4389 E->getSourceRange());
4390}
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregora16548e2009-08-11 05:31:07 +00004392template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004393Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004394TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004395 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4396 if (LHS.isInvalid())
4397 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004398
Douglas Gregora16548e2009-08-11 05:31:07 +00004399 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4400 if (RHS.isInvalid())
4401 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004402
4403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 if (!getDerived().AlwaysRebuild() &&
4405 LHS.get() == E->getLHS() &&
4406 RHS.get() == E->getRHS())
4407 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004408
Douglas Gregora16548e2009-08-11 05:31:07 +00004409 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4410 /*FIXME:*/E->getLHS()->getLocStart(),
4411 move(RHS),
4412 E->getRBracketLoc());
4413}
Mike Stump11289f42009-09-09 15:08:12 +00004414
4415template<typename Derived>
4416Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004417TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 // Transform the callee.
4419 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4420 if (Callee.isInvalid())
4421 return SemaRef.ExprError();
4422
4423 // Transform arguments.
4424 bool ArgChanged = false;
4425 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4426 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4427 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4428 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4429 if (Arg.isInvalid())
4430 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 // FIXME: Wrong source location information for the ','.
4433 FakeCommaLocs.push_back(
4434 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004435
4436 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 Args.push_back(Arg.takeAs<Expr>());
4438 }
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 if (!getDerived().AlwaysRebuild() &&
4441 Callee.get() == E->getCallee() &&
4442 !ArgChanged)
4443 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004446 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4448 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4449 move_arg(Args),
4450 FakeCommaLocs.data(),
4451 E->getRParenLoc());
4452}
Mike Stump11289f42009-09-09 15:08:12 +00004453
4454template<typename Derived>
4455Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004456TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004457 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4458 if (Base.isInvalid())
4459 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004460
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004461 NestedNameSpecifier *Qualifier = 0;
4462 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004463 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004464 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004465 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004466 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004467 return SemaRef.ExprError();
4468 }
Mike Stump11289f42009-09-09 15:08:12 +00004469
Eli Friedman2cfcef62009-12-04 06:40:45 +00004470 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004471 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4472 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004473 if (!Member)
4474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004475
John McCall16df1e52010-03-30 21:47:33 +00004476 NamedDecl *FoundDecl = E->getFoundDecl();
4477 if (FoundDecl == E->getMemberDecl()) {
4478 FoundDecl = Member;
4479 } else {
4480 FoundDecl = cast_or_null<NamedDecl>(
4481 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4482 if (!FoundDecl)
4483 return SemaRef.ExprError();
4484 }
4485
Douglas Gregora16548e2009-08-11 05:31:07 +00004486 if (!getDerived().AlwaysRebuild() &&
4487 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004488 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004489 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004490 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004491 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004492
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004493 // Mark it referenced in the new context regardless.
4494 // FIXME: this is a bit instantiation-specific.
4495 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004496 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004497 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004498
John McCall6b51f282009-11-23 01:53:49 +00004499 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004500 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004501 TransArgs.setLAngleLoc(E->getLAngleLoc());
4502 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004503 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004504 TemplateArgumentLoc Loc;
4505 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004506 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004507 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004508 }
4509 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 // FIXME: Bogus source location for the operator
4512 SourceLocation FakeOperatorLoc
4513 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4514
John McCall38836f02010-01-15 08:34:02 +00004515 // FIXME: to do this check properly, we will need to preserve the
4516 // first-qualifier-in-scope here, just in case we had a dependent
4517 // base (and therefore couldn't do the check) and a
4518 // nested-name-qualifier (and therefore could do the lookup).
4519 NamedDecl *FirstQualifierInScope = 0;
4520
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4522 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004523 Qualifier,
4524 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004525 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004526 Member,
John McCall16df1e52010-03-30 21:47:33 +00004527 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004528 (E->hasExplicitTemplateArgumentList()
4529 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004530 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004531}
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregora16548e2009-08-11 05:31:07 +00004533template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004534Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004535TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4537 if (LHS.isInvalid())
4538 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4541 if (RHS.isInvalid())
4542 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 if (!getDerived().AlwaysRebuild() &&
4545 LHS.get() == E->getLHS() &&
4546 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004547 return SemaRef.Owned(E->Retain());
4548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4550 move(LHS), move(RHS));
4551}
4552
Mike Stump11289f42009-09-09 15:08:12 +00004553template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004554Sema::OwningExprResult
4555TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004556 CompoundAssignOperator *E) {
4557 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004558}
Mike Stump11289f42009-09-09 15:08:12 +00004559
Douglas Gregora16548e2009-08-11 05:31:07 +00004560template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004561Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004562TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4564 if (Cond.isInvalid())
4565 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004566
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4568 if (LHS.isInvalid())
4569 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4572 if (RHS.isInvalid())
4573 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575 if (!getDerived().AlwaysRebuild() &&
4576 Cond.get() == E->getCond() &&
4577 LHS.get() == E->getLHS() &&
4578 RHS.get() == E->getRHS())
4579 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004580
4581 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004582 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004583 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004584 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 move(RHS));
4586}
Mike Stump11289f42009-09-09 15:08:12 +00004587
4588template<typename Derived>
4589Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004590TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004591 // Implicit casts are eliminated during transformation, since they
4592 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004593 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004594}
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596template<typename Derived>
4597Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004598TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004599 TypeSourceInfo *OldT;
4600 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 {
4602 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004603 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4605 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004606
John McCall97513962010-01-15 18:39:57 +00004607 OldT = E->getTypeInfoAsWritten();
4608 NewT = getDerived().TransformType(OldT);
4609 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004610 return SemaRef.ExprError();
4611 }
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregor6131b442009-12-12 18:16:41 +00004613 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004614 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 if (SubExpr.isInvalid())
4616 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004619 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004621 return SemaRef.Owned(E->Retain());
4622
John McCall97513962010-01-15 18:39:57 +00004623 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4624 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 E->getRParenLoc(),
4626 move(SubExpr));
4627}
Mike Stump11289f42009-09-09 15:08:12 +00004628
Douglas Gregora16548e2009-08-11 05:31:07 +00004629template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004630Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004631TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004632 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4633 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4634 if (!NewT)
4635 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4638 if (Init.isInvalid())
4639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004642 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004644 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004645
John McCall5d7aa7f2010-01-19 22:33:45 +00004646 // Note: the expression type doesn't necessarily match the
4647 // type-as-written, but that's okay, because it should always be
4648 // derivable from the initializer.
4649
John McCalle15bbff2010-01-18 19:35:47 +00004650 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 /*FIXME:*/E->getInitializer()->getLocEnd(),
4652 move(Init));
4653}
Mike Stump11289f42009-09-09 15:08:12 +00004654
Douglas Gregora16548e2009-08-11 05:31:07 +00004655template<typename Derived>
4656Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004657TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4659 if (Base.isInvalid())
4660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 if (!getDerived().AlwaysRebuild() &&
4663 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004664 return SemaRef.Owned(E->Retain());
4665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004667 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4669 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4670 E->getAccessorLoc(),
4671 E->getAccessor());
4672}
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregora16548e2009-08-11 05:31:07 +00004674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004675Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004676TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregora16548e2009-08-11 05:31:07 +00004679 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4680 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4681 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4682 if (Init.isInvalid())
4683 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 InitChanged = InitChanged || Init.get() != E->getInit(I);
4686 Inits.push_back(Init.takeAs<Expr>());
4687 }
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004690 return SemaRef.Owned(E->Retain());
4691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004693 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004694}
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregora16548e2009-08-11 05:31:07 +00004696template<typename Derived>
4697Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004698TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregorebe10102009-08-20 07:17:43 +00004701 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4703 if (Init.isInvalid())
4704 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregorebe10102009-08-20 07:17:43 +00004706 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4708 bool ExprChanged = false;
4709 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4710 DEnd = E->designators_end();
4711 D != DEnd; ++D) {
4712 if (D->isFieldDesignator()) {
4713 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4714 D->getDotLoc(),
4715 D->getFieldLoc()));
4716 continue;
4717 }
Mike Stump11289f42009-09-09 15:08:12 +00004718
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 if (D->isArrayDesignator()) {
4720 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4721 if (Index.isInvalid())
4722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004723
4724 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4728 ArrayExprs.push_back(Index.release());
4729 continue;
4730 }
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004733 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004734 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4735 if (Start.isInvalid())
4736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4739 if (End.isInvalid())
4740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
4742 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 End.get(),
4744 D->getLBracketLoc(),
4745 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4748 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 ArrayExprs.push_back(Start.release());
4751 ArrayExprs.push_back(End.release());
4752 }
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 if (!getDerived().AlwaysRebuild() &&
4755 Init.get() == E->getInit() &&
4756 !ExprChanged)
4757 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4760 E->getEqualOrColonLoc(),
4761 E->usesGNUSyntax(), move(Init));
4762}
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregora16548e2009-08-11 05:31:07 +00004764template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004765Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004766TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004767 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004768 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004769
Douglas Gregor3da3c062009-10-28 00:29:27 +00004770 // FIXME: Will we ever have proper type location here? Will we actually
4771 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 QualType T = getDerived().TransformType(E->getType());
4773 if (T.isNull())
4774 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 if (!getDerived().AlwaysRebuild() &&
4777 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004778 return SemaRef.Owned(E->Retain());
4779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 return getDerived().RebuildImplicitValueInitExpr(T);
4781}
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregora16548e2009-08-11 05:31:07 +00004783template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004784Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004785TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004786 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4787 if (!TInfo)
4788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4791 if (SubExpr.isInvalid())
4792 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004795 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 SubExpr.get() == E->getSubExpr())
4797 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004800 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004801}
4802
4803template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004804Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004805TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 bool ArgumentChanged = false;
4807 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4808 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4809 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4810 if (Init.isInvalid())
4811 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004812
Douglas Gregora16548e2009-08-11 05:31:07 +00004813 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4814 Inits.push_back(Init.takeAs<Expr>());
4815 }
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4818 move_arg(Inits),
4819 E->getRParenLoc());
4820}
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822/// \brief Transform an address-of-label expression.
4823///
4824/// By default, the transformation of an address-of-label expression always
4825/// rebuilds the expression, so that the label identifier can be resolved to
4826/// the corresponding label statement by semantic analysis.
4827template<typename Derived>
4828Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004829TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4831 E->getLabel());
4832}
Mike Stump11289f42009-09-09 15:08:12 +00004833
4834template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004835Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004836TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004837 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4839 if (SubStmt.isInvalid())
4840 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 if (!getDerived().AlwaysRebuild() &&
4843 SubStmt.get() == E->getSubStmt())
4844 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004845
4846 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 move(SubStmt),
4848 E->getRParenLoc());
4849}
Mike Stump11289f42009-09-09 15:08:12 +00004850
Douglas Gregora16548e2009-08-11 05:31:07 +00004851template<typename Derived>
4852Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004853TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004854 TypeSourceInfo *TInfo1;
4855 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004856
4857 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4858 if (!TInfo1)
4859 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregor7058c262010-08-10 14:27:00 +00004861 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4862 if (!TInfo2)
4863 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004864
4865 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004866 TInfo1 == E->getArgTInfo1() &&
4867 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004868 return SemaRef.Owned(E->Retain());
4869
Douglas Gregora16548e2009-08-11 05:31:07 +00004870 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004871 TInfo1, TInfo2,
4872 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004873}
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875template<typename Derived>
4876Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004877TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4879 if (Cond.isInvalid())
4880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4883 if (LHS.isInvalid())
4884 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregora16548e2009-08-11 05:31:07 +00004886 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4887 if (RHS.isInvalid())
4888 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 if (!getDerived().AlwaysRebuild() &&
4891 Cond.get() == E->getCond() &&
4892 LHS.get() == E->getLHS() &&
4893 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004894 return SemaRef.Owned(E->Retain());
4895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4897 move(Cond), move(LHS), move(RHS),
4898 E->getRParenLoc());
4899}
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregora16548e2009-08-11 05:31:07 +00004901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004902Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004903TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004904 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004905}
4906
4907template<typename Derived>
4908Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004909TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004910 switch (E->getOperator()) {
4911 case OO_New:
4912 case OO_Delete:
4913 case OO_Array_New:
4914 case OO_Array_Delete:
4915 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4916 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004917
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004918 case OO_Call: {
4919 // This is a call to an object's operator().
4920 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4921
4922 // Transform the object itself.
4923 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4924 if (Object.isInvalid())
4925 return SemaRef.ExprError();
4926
4927 // FIXME: Poor location information
4928 SourceLocation FakeLParenLoc
4929 = SemaRef.PP.getLocForEndOfToken(
4930 static_cast<Expr *>(Object.get())->getLocEnd());
4931
4932 // Transform the call arguments.
4933 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4934 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4935 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004936 if (getDerived().DropCallArgument(E->getArg(I)))
4937 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004938
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004939 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4940 if (Arg.isInvalid())
4941 return SemaRef.ExprError();
4942
4943 // FIXME: Poor source location information.
4944 SourceLocation FakeCommaLoc
4945 = SemaRef.PP.getLocForEndOfToken(
4946 static_cast<Expr *>(Arg.get())->getLocEnd());
4947 FakeCommaLocs.push_back(FakeCommaLoc);
4948 Args.push_back(Arg.release());
4949 }
4950
4951 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4952 move_arg(Args),
4953 FakeCommaLocs.data(),
4954 E->getLocEnd());
4955 }
4956
4957#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4958 case OO_##Name:
4959#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4960#include "clang/Basic/OperatorKinds.def"
4961 case OO_Subscript:
4962 // Handled below.
4963 break;
4964
4965 case OO_Conditional:
4966 llvm_unreachable("conditional operator is not actually overloadable");
4967 return SemaRef.ExprError();
4968
4969 case OO_None:
4970 case NUM_OVERLOADED_OPERATORS:
4971 llvm_unreachable("not an overloaded operator?");
4972 return SemaRef.ExprError();
4973 }
4974
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4976 if (Callee.isInvalid())
4977 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004978
John McCall47f29ea2009-12-08 09:21:05 +00004979 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004980 if (First.isInvalid())
4981 return SemaRef.ExprError();
4982
4983 OwningExprResult Second(SemaRef);
4984 if (E->getNumArgs() == 2) {
4985 Second = getDerived().TransformExpr(E->getArg(1));
4986 if (Second.isInvalid())
4987 return SemaRef.ExprError();
4988 }
Mike Stump11289f42009-09-09 15:08:12 +00004989
Douglas Gregora16548e2009-08-11 05:31:07 +00004990 if (!getDerived().AlwaysRebuild() &&
4991 Callee.get() == E->getCallee() &&
4992 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004993 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4994 return SemaRef.Owned(E->Retain());
4995
Douglas Gregora16548e2009-08-11 05:31:07 +00004996 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4997 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004998 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 move(First),
5000 move(Second));
5001}
Mike Stump11289f42009-09-09 15:08:12 +00005002
Douglas Gregora16548e2009-08-11 05:31:07 +00005003template<typename Derived>
5004Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005005TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5006 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005007}
Mike Stump11289f42009-09-09 15:08:12 +00005008
Douglas Gregora16548e2009-08-11 05:31:07 +00005009template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005010Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005011TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005012 TypeSourceInfo *OldT;
5013 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 {
5015 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005016 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5018 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005019
John McCall97513962010-01-15 18:39:57 +00005020 OldT = E->getTypeInfoAsWritten();
5021 NewT = getDerived().TransformType(OldT);
5022 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 return SemaRef.ExprError();
5024 }
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregor6131b442009-12-12 18:16:41 +00005026 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005027 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 if (SubExpr.isInvalid())
5029 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005032 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005034 return SemaRef.Owned(E->Retain());
5035
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005037 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5039 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5040 SourceLocation FakeRParenLoc
5041 = SemaRef.PP.getLocForEndOfToken(
5042 E->getSubExpr()->getSourceRange().getEnd());
5043 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005044 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005046 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 FakeRAngleLoc,
5048 FakeRAngleLoc,
5049 move(SubExpr),
5050 FakeRParenLoc);
5051}
Mike Stump11289f42009-09-09 15:08:12 +00005052
Douglas Gregora16548e2009-08-11 05:31:07 +00005053template<typename Derived>
5054Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005055TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5056 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005057}
Mike Stump11289f42009-09-09 15:08:12 +00005058
5059template<typename Derived>
5060Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005061TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5062 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005063}
5064
Douglas Gregora16548e2009-08-11 05:31:07 +00005065template<typename Derived>
5066Sema::OwningExprResult
5067TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005068 CXXReinterpretCastExpr *E) {
5069 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005070}
Mike Stump11289f42009-09-09 15:08:12 +00005071
Douglas Gregora16548e2009-08-11 05:31:07 +00005072template<typename Derived>
5073Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005074TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5075 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078template<typename Derived>
5079Sema::OwningExprResult
5080TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005081 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005082 TypeSourceInfo *OldT;
5083 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005084 {
5085 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005086
John McCall97513962010-01-15 18:39:57 +00005087 OldT = E->getTypeInfoAsWritten();
5088 NewT = getDerived().TransformType(OldT);
5089 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005090 return SemaRef.ExprError();
5091 }
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregor6131b442009-12-12 18:16:41 +00005093 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005094 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 if (SubExpr.isInvalid())
5096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005099 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005101 return SemaRef.Owned(E->Retain());
5102
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 // FIXME: The end of the type's source range is wrong
5104 return getDerived().RebuildCXXFunctionalCastExpr(
5105 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005106 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 /*FIXME:*/E->getSubExpr()->getLocStart(),
5108 move(SubExpr),
5109 E->getRParenLoc());
5110}
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112template<typename Derived>
5113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005116 TypeSourceInfo *TInfo
5117 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5118 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005122 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005124
Douglas Gregor9da64192010-04-26 22:37:10 +00005125 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5126 E->getLocStart(),
5127 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 E->getLocEnd());
5129 }
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 // We don't know whether the expression is potentially evaluated until
5132 // after we perform semantic analysis, so the expression is potentially
5133 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005134 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5138 if (SubExpr.isInvalid())
5139 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 if (!getDerived().AlwaysRebuild() &&
5142 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005143 return SemaRef.Owned(E->Retain());
5144
Douglas Gregor9da64192010-04-26 22:37:10 +00005145 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5146 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005147 move(SubExpr),
5148 E->getLocEnd());
5149}
5150
5151template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005152Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005153TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005154 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005155}
Mike Stump11289f42009-09-09 15:08:12 +00005156
Douglas Gregora16548e2009-08-11 05:31:07 +00005157template<typename Derived>
5158Sema::OwningExprResult
5159TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005160 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005161 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005162}
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164template<typename Derived>
5165Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005166TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 QualType T = getDerived().TransformType(E->getType());
5170 if (T.isNull())
5171 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 if (!getDerived().AlwaysRebuild() &&
5174 T == E->getType())
5175 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregorb15af892010-01-07 23:12:05 +00005177 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005178}
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180template<typename Derived>
5181Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005182TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5184 if (SubExpr.isInvalid())
5185 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 if (!getDerived().AlwaysRebuild() &&
5188 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005189 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005190
5191 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5192}
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>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005197 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005198 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5199 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 if (!Param)
5201 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005202
Chandler Carruth794da4c2010-02-08 06:42:49 +00005203 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 Param == E->getParam())
5205 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregor033f6752009-12-23 23:03:06 +00005207 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005208}
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregora16548e2009-08-11 05:31:07 +00005210template<typename Derived>
5211Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005212TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005213 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5214
5215 QualType T = getDerived().TransformType(E->getType());
5216 if (T.isNull())
5217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219 if (!getDerived().AlwaysRebuild() &&
5220 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005221 return SemaRef.Owned(E->Retain());
5222
Douglas Gregor747eb782010-07-08 06:14:04 +00005223 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5224 /*FIXME:*/E->getTypeBeginLoc(),
5225 T,
5226 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005227}
Mike Stump11289f42009-09-09 15:08:12 +00005228
Douglas Gregora16548e2009-08-11 05:31:07 +00005229template<typename Derived>
5230Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005232 // Transform the type that we're allocating
5233 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5234 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5235 if (AllocType.isNull())
5236 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregora16548e2009-08-11 05:31:07 +00005238 // Transform the size of the array we're allocating (if any).
5239 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5240 if (ArraySize.isInvalid())
5241 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 // Transform the placement arguments (if any).
5244 bool ArgumentChanged = false;
5245 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5246 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5247 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5248 if (Arg.isInvalid())
5249 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregora16548e2009-08-11 05:31:07 +00005251 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5252 PlacementArgs.push_back(Arg.take());
5253 }
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregorebe10102009-08-20 07:17:43 +00005255 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5257 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005258 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5259 break;
5260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(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->getConstructorArg(I);
5266 ConstructorArgs.push_back(Arg.take());
5267 }
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregord2d9da02010-02-26 00:38:10 +00005269 // Transform constructor, new operator, and delete operator.
5270 CXXConstructorDecl *Constructor = 0;
5271 if (E->getConstructor()) {
5272 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005273 getDerived().TransformDecl(E->getLocStart(),
5274 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005275 if (!Constructor)
5276 return SemaRef.ExprError();
5277 }
5278
5279 FunctionDecl *OperatorNew = 0;
5280 if (E->getOperatorNew()) {
5281 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005282 getDerived().TransformDecl(E->getLocStart(),
5283 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005284 if (!OperatorNew)
5285 return SemaRef.ExprError();
5286 }
5287
5288 FunctionDecl *OperatorDelete = 0;
5289 if (E->getOperatorDelete()) {
5290 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005291 getDerived().TransformDecl(E->getLocStart(),
5292 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005293 if (!OperatorDelete)
5294 return SemaRef.ExprError();
5295 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005296
Douglas Gregora16548e2009-08-11 05:31:07 +00005297 if (!getDerived().AlwaysRebuild() &&
5298 AllocType == E->getAllocatedType() &&
5299 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005300 Constructor == E->getConstructor() &&
5301 OperatorNew == E->getOperatorNew() &&
5302 OperatorDelete == E->getOperatorDelete() &&
5303 !ArgumentChanged) {
5304 // Mark any declarations we need as referenced.
5305 // FIXME: instantiation-specific.
5306 if (Constructor)
5307 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5308 if (OperatorNew)
5309 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5310 if (OperatorDelete)
5311 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005312 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005313 }
Mike Stump11289f42009-09-09 15:08:12 +00005314
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005315 if (!ArraySize.get()) {
5316 // If no array size was specified, but the new expression was
5317 // instantiated with an array type (e.g., "new T" where T is
5318 // instantiated with "int[4]"), extract the outer bound from the
5319 // array type as our array size. We do this with constant and
5320 // dependently-sized array types.
5321 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5322 if (!ArrayT) {
5323 // Do nothing
5324 } else if (const ConstantArrayType *ConsArrayT
5325 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005326 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005327 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005328 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005329 SemaRef.Context.getSizeType(),
5330 /*FIXME:*/E->getLocStart()));
5331 AllocType = ConsArrayT->getElementType();
5332 } else if (const DependentSizedArrayType *DepArrayT
5333 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5334 if (DepArrayT->getSizeExpr()) {
5335 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5336 AllocType = DepArrayT->getElementType();
5337 }
5338 }
5339 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005340 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5341 E->isGlobalNew(),
5342 /*FIXME:*/E->getLocStart(),
5343 move_arg(PlacementArgs),
5344 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005345 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005346 AllocType,
5347 /*FIXME:*/E->getLocStart(),
5348 /*FIXME:*/SourceRange(),
5349 move(ArraySize),
5350 /*FIXME:*/E->getLocStart(),
5351 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005352 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355template<typename Derived>
5356Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5359 if (Operand.isInvalid())
5360 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregord2d9da02010-02-26 00:38:10 +00005362 // Transform the delete operator, if known.
5363 FunctionDecl *OperatorDelete = 0;
5364 if (E->getOperatorDelete()) {
5365 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005366 getDerived().TransformDecl(E->getLocStart(),
5367 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005368 if (!OperatorDelete)
5369 return SemaRef.ExprError();
5370 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005371
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005373 Operand.get() == E->getArgument() &&
5374 OperatorDelete == E->getOperatorDelete()) {
5375 // Mark any declarations we need as referenced.
5376 // FIXME: instantiation-specific.
5377 if (OperatorDelete)
5378 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005379 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005380 }
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5383 E->isGlobalDelete(),
5384 E->isArrayForm(),
5385 move(Operand));
5386}
Mike Stump11289f42009-09-09 15:08:12 +00005387
Douglas Gregora16548e2009-08-11 05:31:07 +00005388template<typename Derived>
5389Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005390TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005391 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005392 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5393 if (Base.isInvalid())
5394 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregor678f90d2010-02-25 01:56:36 +00005396 Sema::TypeTy *ObjectTypePtr = 0;
5397 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005398 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005399 E->getOperatorLoc(),
5400 E->isArrow()? tok::arrow : tok::period,
5401 ObjectTypePtr,
5402 MayBePseudoDestructor);
5403 if (Base.isInvalid())
5404 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005405
Douglas Gregor678f90d2010-02-25 01:56:36 +00005406 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005407 NestedNameSpecifier *Qualifier
5408 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005409 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005410 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005411 if (E->getQualifier() && !Qualifier)
5412 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregor678f90d2010-02-25 01:56:36 +00005414 PseudoDestructorTypeStorage Destroyed;
5415 if (E->getDestroyedTypeInfo()) {
5416 TypeSourceInfo *DestroyedTypeInfo
5417 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5418 if (!DestroyedTypeInfo)
5419 return SemaRef.ExprError();
5420 Destroyed = DestroyedTypeInfo;
5421 } else if (ObjectType->isDependentType()) {
5422 // We aren't likely to be able to resolve the identifier down to a type
5423 // now anyway, so just retain the identifier.
5424 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5425 E->getDestroyedTypeLoc());
5426 } else {
5427 // Look for a destructor known with the given name.
5428 CXXScopeSpec SS;
5429 if (Qualifier) {
5430 SS.setScopeRep(Qualifier);
5431 SS.setRange(E->getQualifierRange());
5432 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005433
Douglas Gregor678f90d2010-02-25 01:56:36 +00005434 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5435 *E->getDestroyedTypeIdentifier(),
5436 E->getDestroyedTypeLoc(),
5437 /*Scope=*/0,
5438 SS, ObjectTypePtr,
5439 false);
5440 if (!T)
5441 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005442
Douglas Gregor678f90d2010-02-25 01:56:36 +00005443 Destroyed
5444 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5445 E->getDestroyedTypeLoc());
5446 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005447
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005448 TypeSourceInfo *ScopeTypeInfo = 0;
5449 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005450 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005451 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005452 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005453 return SemaRef.ExprError();
5454 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005455
Douglas Gregorad8a3362009-09-04 17:36:40 +00005456 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5457 E->getOperatorLoc(),
5458 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005459 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005460 E->getQualifierRange(),
5461 ScopeTypeInfo,
5462 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005463 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005464 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005465}
Mike Stump11289f42009-09-09 15:08:12 +00005466
Douglas Gregorad8a3362009-09-04 17:36:40 +00005467template<typename Derived>
5468Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005469TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005470 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005471 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5472
5473 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5474 Sema::LookupOrdinaryName);
5475
5476 // Transform all the decls.
5477 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5478 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005479 NamedDecl *InstD = static_cast<NamedDecl*>(
5480 getDerived().TransformDecl(Old->getNameLoc(),
5481 *I));
John McCall84d87672009-12-10 09:41:52 +00005482 if (!InstD) {
5483 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5484 // This can happen because of dependent hiding.
5485 if (isa<UsingShadowDecl>(*I))
5486 continue;
5487 else
5488 return SemaRef.ExprError();
5489 }
John McCalle66edc12009-11-24 19:00:30 +00005490
5491 // Expand using declarations.
5492 if (isa<UsingDecl>(InstD)) {
5493 UsingDecl *UD = cast<UsingDecl>(InstD);
5494 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5495 E = UD->shadow_end(); I != E; ++I)
5496 R.addDecl(*I);
5497 continue;
5498 }
5499
5500 R.addDecl(InstD);
5501 }
5502
5503 // Resolve a kind, but don't do any further analysis. If it's
5504 // ambiguous, the callee needs to deal with it.
5505 R.resolveKind();
5506
5507 // Rebuild the nested-name qualifier, if present.
5508 CXXScopeSpec SS;
5509 NestedNameSpecifier *Qualifier = 0;
5510 if (Old->getQualifier()) {
5511 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005512 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005513 if (!Qualifier)
5514 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005515
John McCalle66edc12009-11-24 19:00:30 +00005516 SS.setScopeRep(Qualifier);
5517 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005518 }
5519
Douglas Gregor9262f472010-04-27 18:19:34 +00005520 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005521 CXXRecordDecl *NamingClass
5522 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5523 Old->getNameLoc(),
5524 Old->getNamingClass()));
5525 if (!NamingClass)
5526 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005527
Douglas Gregorda7be082010-04-27 16:10:10 +00005528 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005529 }
5530
5531 // If we have no template arguments, it's a normal declaration name.
5532 if (!Old->hasExplicitTemplateArgs())
5533 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5534
5535 // If we have template arguments, rebuild them, then rebuild the
5536 // templateid expression.
5537 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5538 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5539 TemplateArgumentLoc Loc;
5540 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5541 return SemaRef.ExprError();
5542 TransArgs.addArgument(Loc);
5543 }
5544
5545 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5546 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005547}
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregora16548e2009-08-11 05:31:07 +00005549template<typename Derived>
5550Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005551TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 QualType T = getDerived().TransformType(E->getQueriedType());
5555 if (T.isNull())
5556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 if (!getDerived().AlwaysRebuild() &&
5559 T == E->getQueriedType())
5560 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 // FIXME: Bad location information
5563 SourceLocation FakeLParenLoc
5564 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005565
5566 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005567 E->getLocStart(),
5568 /*FIXME:*/FakeLParenLoc,
5569 T,
5570 E->getLocEnd());
5571}
Mike Stump11289f42009-09-09 15:08:12 +00005572
Douglas Gregora16548e2009-08-11 05:31:07 +00005573template<typename Derived>
5574Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005575TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005576 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005578 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005579 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005580 if (!NNS)
5581 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
5583 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005584 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5585 if (!Name)
5586 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005587
John McCalle66edc12009-11-24 19:00:30 +00005588 if (!E->hasExplicitTemplateArgs()) {
5589 if (!getDerived().AlwaysRebuild() &&
5590 NNS == E->getQualifier() &&
5591 Name == E->getDeclName())
5592 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005593
John McCalle66edc12009-11-24 19:00:30 +00005594 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5595 E->getQualifierRange(),
5596 Name, E->getLocation(),
5597 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005598 }
John McCall6b51f282009-11-23 01:53:49 +00005599
5600 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005602 TemplateArgumentLoc Loc;
5603 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005605 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 }
5607
John McCalle66edc12009-11-24 19:00:30 +00005608 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5609 E->getQualifierRange(),
5610 Name, E->getLocation(),
5611 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005612}
5613
5614template<typename Derived>
5615Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005617 // CXXConstructExprs are always implicit, so when we have a
5618 // 1-argument construction we just transform that argument.
5619 if (E->getNumArgs() == 1 ||
5620 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5621 return getDerived().TransformExpr(E->getArg(0));
5622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5624
5625 QualType T = getDerived().TransformType(E->getType());
5626 if (T.isNull())
5627 return SemaRef.ExprError();
5628
5629 CXXConstructorDecl *Constructor
5630 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005631 getDerived().TransformDecl(E->getLocStart(),
5632 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 if (!Constructor)
5634 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 bool ArgumentChanged = false;
5637 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005638 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 ArgEnd = E->arg_end();
5640 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005641 if (getDerived().DropCallArgument(*Arg)) {
5642 ArgumentChanged = true;
5643 break;
5644 }
5645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5647 if (TransArg.isInvalid())
5648 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5651 Args.push_back(TransArg.takeAs<Expr>());
5652 }
5653
5654 if (!getDerived().AlwaysRebuild() &&
5655 T == E->getType() &&
5656 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005657 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005658 // Mark the constructor as referenced.
5659 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005660 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005662 }
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregordb121ba2009-12-14 16:27:04 +00005664 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5665 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 move_arg(Args));
5667}
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669/// \brief Transform a C++ temporary-binding expression.
5670///
Douglas Gregor363b1512009-12-24 18:51:59 +00005671/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5672/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005673template<typename Derived>
5674Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005675TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005676 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005677}
Mike Stump11289f42009-09-09 15:08:12 +00005678
Anders Carlssonba6c4372010-01-29 02:39:32 +00005679/// \brief Transform a C++ reference-binding expression.
5680///
5681/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5682/// transform the subexpression and return that.
5683template<typename Derived>
5684Sema::OwningExprResult
5685TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5686 return getDerived().TransformExpr(E->getSubExpr());
5687}
5688
Mike Stump11289f42009-09-09 15:08:12 +00005689/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005690/// be destroyed after the expression is evaluated.
5691///
Douglas Gregor363b1512009-12-24 18:51:59 +00005692/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5693/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005694template<typename Derived>
5695Sema::OwningExprResult
5696TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005697 CXXExprWithTemporaries *E) {
5698 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005699}
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701template<typename Derived>
5702Sema::OwningExprResult
5703TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005704 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5706 QualType T = getDerived().TransformType(E->getType());
5707 if (T.isNull())
5708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 CXXConstructorDecl *Constructor
5711 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005712 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005713 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 if (!Constructor)
5715 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregora16548e2009-08-11 05:31:07 +00005717 bool ArgumentChanged = false;
5718 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5719 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005720 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 ArgEnd = E->arg_end();
5722 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005723 if (getDerived().DropCallArgument(*Arg)) {
5724 ArgumentChanged = true;
5725 break;
5726 }
5727
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5729 if (TransArg.isInvalid())
5730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5733 Args.push_back((Expr *)TransArg.release());
5734 }
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 if (!getDerived().AlwaysRebuild() &&
5737 T == E->getType() &&
5738 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005739 !ArgumentChanged) {
5740 // FIXME: Instantiation-specific
5741 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005742 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005743 }
Mike Stump11289f42009-09-09 15:08:12 +00005744
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 // FIXME: Bogus location information
5746 SourceLocation CommaLoc;
5747 if (Args.size() > 1) {
5748 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005749 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5751 }
5752 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5753 T,
5754 /*FIXME:*/E->getTypeBeginLoc(),
5755 move_arg(Args),
5756 &CommaLoc,
5757 E->getLocEnd());
5758}
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760template<typename Derived>
5761Sema::OwningExprResult
5762TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005763 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5765 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5766 if (T.isNull())
5767 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 bool ArgumentChanged = false;
5770 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5771 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5772 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5773 ArgEnd = E->arg_end();
5774 Arg != ArgEnd; ++Arg) {
5775 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5776 if (TransArg.isInvalid())
5777 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005778
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5780 FakeCommaLocs.push_back(
5781 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5782 Args.push_back(TransArg.takeAs<Expr>());
5783 }
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 if (!getDerived().AlwaysRebuild() &&
5786 T == E->getTypeAsWritten() &&
5787 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005788 return SemaRef.Owned(E->Retain());
5789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 // FIXME: we're faking the locations of the commas
5791 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5792 T,
5793 E->getLParenLoc(),
5794 move_arg(Args),
5795 FakeCommaLocs.data(),
5796 E->getRParenLoc());
5797}
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregora16548e2009-08-11 05:31:07 +00005799template<typename Derived>
5800Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005801TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005802 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005804 OwningExprResult Base(SemaRef, (Expr*) 0);
5805 Expr *OldBase;
5806 QualType BaseType;
5807 QualType ObjectType;
5808 if (!E->isImplicitAccess()) {
5809 OldBase = E->getBase();
5810 Base = getDerived().TransformExpr(OldBase);
5811 if (Base.isInvalid())
5812 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005813
John McCall2d74de92009-12-01 22:10:20 +00005814 // Start the member reference and compute the object's type.
5815 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005816 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005817 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5818 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005819 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005820 ObjectTy,
5821 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005822 if (Base.isInvalid())
5823 return SemaRef.ExprError();
5824
5825 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5826 BaseType = ((Expr*) Base.get())->getType();
5827 } else {
5828 OldBase = 0;
5829 BaseType = getDerived().TransformType(E->getBaseType());
5830 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5831 }
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005833 // Transform the first part of the nested-name-specifier that qualifies
5834 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005835 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005836 = getDerived().TransformFirstQualifierInScope(
5837 E->getFirstQualifierFoundInScope(),
5838 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005840 NestedNameSpecifier *Qualifier = 0;
5841 if (E->getQualifier()) {
5842 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5843 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005844 ObjectType,
5845 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005846 if (!Qualifier)
5847 return SemaRef.ExprError();
5848 }
Mike Stump11289f42009-09-09 15:08:12 +00005849
5850 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005851 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005852 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005853 if (!Name)
5854 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005855
John McCall2d74de92009-12-01 22:10:20 +00005856 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005857 // This is a reference to a member without an explicitly-specified
5858 // template argument list. Optimize for this common case.
5859 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005860 Base.get() == OldBase &&
5861 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005862 Qualifier == E->getQualifier() &&
5863 Name == E->getMember() &&
5864 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005865 return SemaRef.Owned(E->Retain());
5866
John McCall8cd78132009-11-19 22:55:06 +00005867 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005868 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005869 E->isArrow(),
5870 E->getOperatorLoc(),
5871 Qualifier,
5872 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005873 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005874 Name,
5875 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005876 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005877 }
5878
John McCall6b51f282009-11-23 01:53:49 +00005879 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005880 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005881 TemplateArgumentLoc Loc;
5882 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005883 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005884 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005885 }
Mike Stump11289f42009-09-09 15:08:12 +00005886
John McCall8cd78132009-11-19 22:55:06 +00005887 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005888 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 E->isArrow(),
5890 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005891 Qualifier,
5892 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005893 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005894 Name,
5895 E->getMemberLoc(),
5896 &TransArgs);
5897}
5898
5899template<typename Derived>
5900Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005901TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005902 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005903 OwningExprResult Base(SemaRef, (Expr*) 0);
5904 QualType BaseType;
5905 if (!Old->isImplicitAccess()) {
5906 Base = getDerived().TransformExpr(Old->getBase());
5907 if (Base.isInvalid())
5908 return SemaRef.ExprError();
5909 BaseType = ((Expr*) Base.get())->getType();
5910 } else {
5911 BaseType = getDerived().TransformType(Old->getBaseType());
5912 }
John McCall10eae182009-11-30 22:42:35 +00005913
5914 NestedNameSpecifier *Qualifier = 0;
5915 if (Old->getQualifier()) {
5916 Qualifier
5917 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005918 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005919 if (Qualifier == 0)
5920 return SemaRef.ExprError();
5921 }
5922
5923 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5924 Sema::LookupOrdinaryName);
5925
5926 // Transform all the decls.
5927 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5928 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005929 NamedDecl *InstD = static_cast<NamedDecl*>(
5930 getDerived().TransformDecl(Old->getMemberLoc(),
5931 *I));
John McCall84d87672009-12-10 09:41:52 +00005932 if (!InstD) {
5933 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5934 // This can happen because of dependent hiding.
5935 if (isa<UsingShadowDecl>(*I))
5936 continue;
5937 else
5938 return SemaRef.ExprError();
5939 }
John McCall10eae182009-11-30 22:42:35 +00005940
5941 // Expand using declarations.
5942 if (isa<UsingDecl>(InstD)) {
5943 UsingDecl *UD = cast<UsingDecl>(InstD);
5944 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5945 E = UD->shadow_end(); I != E; ++I)
5946 R.addDecl(*I);
5947 continue;
5948 }
5949
5950 R.addDecl(InstD);
5951 }
5952
5953 R.resolveKind();
5954
Douglas Gregor9262f472010-04-27 18:19:34 +00005955 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005956 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005957 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005958 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005959 Old->getMemberLoc(),
5960 Old->getNamingClass()));
5961 if (!NamingClass)
5962 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005963
Douglas Gregorda7be082010-04-27 16:10:10 +00005964 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005965 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005966
John McCall10eae182009-11-30 22:42:35 +00005967 TemplateArgumentListInfo TransArgs;
5968 if (Old->hasExplicitTemplateArgs()) {
5969 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5970 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5971 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5972 TemplateArgumentLoc Loc;
5973 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5974 Loc))
5975 return SemaRef.ExprError();
5976 TransArgs.addArgument(Loc);
5977 }
5978 }
John McCall38836f02010-01-15 08:34:02 +00005979
5980 // FIXME: to do this check properly, we will need to preserve the
5981 // first-qualifier-in-scope here, just in case we had a dependent
5982 // base (and therefore couldn't do the check) and a
5983 // nested-name-qualifier (and therefore could do the lookup).
5984 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005985
John McCall10eae182009-11-30 22:42:35 +00005986 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005987 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005988 Old->getOperatorLoc(),
5989 Old->isArrow(),
5990 Qualifier,
5991 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005992 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005993 R,
5994 (Old->hasExplicitTemplateArgs()
5995 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005996}
5997
5998template<typename Derived>
5999Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006000TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006001 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006002}
6003
Mike Stump11289f42009-09-09 15:08:12 +00006004template<typename Derived>
6005Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006006TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006007 TypeSourceInfo *EncodedTypeInfo
6008 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6009 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006011
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006013 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006014 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006015
6016 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006017 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 E->getRParenLoc());
6019}
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021template<typename Derived>
6022Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006023TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006024 // Transform arguments.
6025 bool ArgChanged = false;
6026 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6027 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6028 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6029 if (Arg.isInvalid())
6030 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006031
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006032 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6033 Args.push_back(Arg.takeAs<Expr>());
6034 }
6035
6036 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6037 // Class message: transform the receiver type.
6038 TypeSourceInfo *ReceiverTypeInfo
6039 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6040 if (!ReceiverTypeInfo)
6041 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006042
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006043 // If nothing changed, just retain the existing message send.
6044 if (!getDerived().AlwaysRebuild() &&
6045 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6046 return SemaRef.Owned(E->Retain());
6047
6048 // Build a new class message send.
6049 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6050 E->getSelector(),
6051 E->getMethodDecl(),
6052 E->getLeftLoc(),
6053 move_arg(Args),
6054 E->getRightLoc());
6055 }
6056
6057 // Instance message: transform the receiver
6058 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6059 "Only class and instance messages may be instantiated");
6060 OwningExprResult Receiver
6061 = getDerived().TransformExpr(E->getInstanceReceiver());
6062 if (Receiver.isInvalid())
6063 return SemaRef.ExprError();
6064
6065 // If nothing changed, just retain the existing message send.
6066 if (!getDerived().AlwaysRebuild() &&
6067 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6068 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006069
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006070 // Build a new instance message send.
6071 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6072 E->getSelector(),
6073 E->getMethodDecl(),
6074 E->getLeftLoc(),
6075 move_arg(Args),
6076 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006077}
6078
Mike Stump11289f42009-09-09 15:08:12 +00006079template<typename Derived>
6080Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006081TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006082 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006083}
6084
Mike Stump11289f42009-09-09 15:08:12 +00006085template<typename Derived>
6086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006088 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006089}
6090
Mike Stump11289f42009-09-09 15:08:12 +00006091template<typename Derived>
6092Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006094 // Transform the base expression.
6095 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6096 if (Base.isInvalid())
6097 return SemaRef.ExprError();
6098
6099 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006100
Douglas Gregord51d90d2010-04-26 20:11:03 +00006101 // If nothing changed, just retain the existing expression.
6102 if (!getDerived().AlwaysRebuild() &&
6103 Base.get() == E->getBase())
6104 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006105
Douglas Gregord51d90d2010-04-26 20:11:03 +00006106 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6107 E->getLocation(),
6108 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006109}
6110
Mike Stump11289f42009-09-09 15:08:12 +00006111template<typename Derived>
6112Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006114 // Transform the base expression.
6115 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6116 if (Base.isInvalid())
6117 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006118
Douglas Gregor9faee212010-04-26 20:47:02 +00006119 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006120
Douglas Gregor9faee212010-04-26 20:47:02 +00006121 // If nothing changed, just retain the existing expression.
6122 if (!getDerived().AlwaysRebuild() &&
6123 Base.get() == E->getBase())
6124 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006125
Douglas Gregor9faee212010-04-26 20:47:02 +00006126 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6127 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006128}
6129
Mike Stump11289f42009-09-09 15:08:12 +00006130template<typename Derived>
6131Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006132TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006133 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006134 // If this implicit setter/getter refers to class methods, it cannot have any
6135 // dependent parts. Just retain the existing declaration.
6136 if (E->getInterfaceDecl())
6137 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006138
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006139 // Transform the base expression.
6140 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6141 if (Base.isInvalid())
6142 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006143
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006144 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006145
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006146 // If nothing changed, just retain the existing expression.
6147 if (!getDerived().AlwaysRebuild() &&
6148 Base.get() == E->getBase())
6149 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006150
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006151 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6152 E->getGetterMethod(),
6153 E->getType(),
6154 E->getSetterMethod(),
6155 E->getLocation(),
6156 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006157
Douglas Gregora16548e2009-08-11 05:31:07 +00006158}
6159
Mike Stump11289f42009-09-09 15:08:12 +00006160template<typename Derived>
6161Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006162TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006163 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006164 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165}
6166
Mike Stump11289f42009-09-09 15:08:12 +00006167template<typename Derived>
6168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006170 // Transform the base expression.
6171 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6172 if (Base.isInvalid())
6173 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006174
Douglas Gregord51d90d2010-04-26 20:11:03 +00006175 // If nothing changed, just retain the existing expression.
6176 if (!getDerived().AlwaysRebuild() &&
6177 Base.get() == E->getBase())
6178 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006179
Douglas Gregord51d90d2010-04-26 20:11:03 +00006180 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6181 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006182}
6183
Mike Stump11289f42009-09-09 15:08:12 +00006184template<typename Derived>
6185Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006186TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 bool ArgumentChanged = false;
6188 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6189 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6190 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6191 if (SubExpr.isInvalid())
6192 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006193
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6195 SubExprs.push_back(SubExpr.takeAs<Expr>());
6196 }
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 if (!getDerived().AlwaysRebuild() &&
6199 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006200 return SemaRef.Owned(E->Retain());
6201
Douglas Gregora16548e2009-08-11 05:31:07 +00006202 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6203 move_arg(SubExprs),
6204 E->getRParenLoc());
6205}
6206
Mike Stump11289f42009-09-09 15:08:12 +00006207template<typename Derived>
6208Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006209TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006210 SourceLocation CaretLoc(E->getExprLoc());
6211
6212 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6213 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6214 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6215 llvm::SmallVector<ParmVarDecl*, 4> Params;
6216 llvm::SmallVector<QualType, 4> ParamTypes;
6217
6218 // Parameter substitution.
6219 const BlockDecl *BD = E->getBlockDecl();
6220 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6221 EN = BD->param_end(); P != EN; ++P) {
6222 ParmVarDecl *OldParm = (*P);
6223 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6224 QualType NewType = NewParm->getType();
6225 Params.push_back(NewParm);
6226 ParamTypes.push_back(NewParm->getType());
6227 }
6228
6229 const FunctionType *BExprFunctionType = E->getFunctionType();
6230 QualType BExprResultType = BExprFunctionType->getResultType();
6231 if (!BExprResultType.isNull()) {
6232 if (!BExprResultType->isDependentType())
6233 CurBlock->ReturnType = BExprResultType;
6234 else if (BExprResultType != SemaRef.Context.DependentTy)
6235 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6236 }
6237
6238 // Transform the body
6239 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6240 if (Body.isInvalid())
6241 return SemaRef.ExprError();
6242 // Set the parameters on the block decl.
6243 if (!Params.empty())
6244 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6245
6246 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6247 CurBlock->ReturnType,
6248 ParamTypes.data(),
6249 ParamTypes.size(),
6250 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006251 0,
6252 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006253
6254 CurBlock->FunctionType = FunctionType;
6255 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006256}
6257
Mike Stump11289f42009-09-09 15:08:12 +00006258template<typename Derived>
6259Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006260TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006261 NestedNameSpecifier *Qualifier = 0;
6262
6263 ValueDecl *ND
6264 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6265 E->getDecl()));
6266 if (!ND)
6267 return SemaRef.ExprError();
6268
6269 if (!getDerived().AlwaysRebuild() &&
6270 ND == E->getDecl()) {
6271 // Mark it referenced in the new context regardless.
6272 // FIXME: this is a bit instantiation-specific.
6273 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6274
6275 return SemaRef.Owned(E->Retain());
6276 }
6277
6278 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
6279 ND, E->getLocation(), 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006280}
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006283// Type reconstruction
6284//===----------------------------------------------------------------------===//
6285
Mike Stump11289f42009-09-09 15:08:12 +00006286template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006287QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6288 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006289 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006290 getDerived().getBaseEntity());
6291}
6292
Mike Stump11289f42009-09-09 15:08:12 +00006293template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006294QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6295 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006296 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006297 getDerived().getBaseEntity());
6298}
6299
Mike Stump11289f42009-09-09 15:08:12 +00006300template<typename Derived>
6301QualType
John McCall70dd5f62009-10-30 00:06:24 +00006302TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6303 bool WrittenAsLValue,
6304 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006305 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006306 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006307}
6308
6309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006310QualType
John McCall70dd5f62009-10-30 00:06:24 +00006311TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6312 QualType ClassType,
6313 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006314 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006315 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006316}
6317
6318template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006319QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006320TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6321 ArrayType::ArraySizeModifier SizeMod,
6322 const llvm::APInt *Size,
6323 Expr *SizeExpr,
6324 unsigned IndexTypeQuals,
6325 SourceRange BracketsRange) {
6326 if (SizeExpr || !Size)
6327 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6328 IndexTypeQuals, BracketsRange,
6329 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006330
6331 QualType Types[] = {
6332 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6333 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6334 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006335 };
6336 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6337 QualType SizeType;
6338 for (unsigned I = 0; I != NumTypes; ++I)
6339 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6340 SizeType = Types[I];
6341 break;
6342 }
Mike Stump11289f42009-09-09 15:08:12 +00006343
Douglas Gregord6ff3322009-08-04 16:50:30 +00006344 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006345 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006346 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006347 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006348}
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregord6ff3322009-08-04 16:50:30 +00006350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006351QualType
6352TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353 ArrayType::ArraySizeModifier SizeMod,
6354 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006355 unsigned IndexTypeQuals,
6356 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006357 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006358 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006359}
6360
6361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006362QualType
Mike Stump11289f42009-09-09 15:08:12 +00006363TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006364 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006365 unsigned IndexTypeQuals,
6366 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006367 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006368 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006369}
Mike Stump11289f42009-09-09 15:08:12 +00006370
Douglas Gregord6ff3322009-08-04 16:50:30 +00006371template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006372QualType
6373TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006374 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006375 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006376 unsigned IndexTypeQuals,
6377 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006378 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006379 SizeExpr.takeAs<Expr>(),
6380 IndexTypeQuals, BracketsRange);
6381}
6382
6383template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006384QualType
6385TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006386 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006387 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006388 unsigned IndexTypeQuals,
6389 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006390 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 SizeExpr.takeAs<Expr>(),
6392 IndexTypeQuals, BracketsRange);
6393}
6394
6395template<typename Derived>
6396QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006397 unsigned NumElements,
6398 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006399 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006400 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401}
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregord6ff3322009-08-04 16:50:30 +00006403template<typename Derived>
6404QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6405 unsigned NumElements,
6406 SourceLocation AttributeLoc) {
6407 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6408 NumElements, true);
6409 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006410 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006411 AttributeLoc);
6412 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6413 AttributeLoc);
6414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregord6ff3322009-08-04 16:50:30 +00006416template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006417QualType
6418TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006419 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006420 SourceLocation AttributeLoc) {
6421 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6422}
Mike Stump11289f42009-09-09 15:08:12 +00006423
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424template<typename Derived>
6425QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006426 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006427 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006428 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006429 unsigned Quals,
6430 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006431 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006432 Quals,
6433 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006434 getDerived().getBaseEntity(),
6435 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436}
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006439QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6440 return SemaRef.Context.getFunctionNoProtoType(T);
6441}
6442
6443template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006444QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6445 assert(D && "no decl found");
6446 if (D->isInvalidDecl()) return QualType();
6447
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006448 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006449 TypeDecl *Ty;
6450 if (isa<UsingDecl>(D)) {
6451 UsingDecl *Using = cast<UsingDecl>(D);
6452 assert(Using->isTypeName() &&
6453 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6454
6455 // A valid resolved using typename decl points to exactly one type decl.
6456 assert(++Using->shadow_begin() == Using->shadow_end());
6457 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006458
John McCallb96ec562009-12-04 22:46:56 +00006459 } else {
6460 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6461 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6462 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6463 }
6464
6465 return SemaRef.Context.getTypeDeclType(Ty);
6466}
6467
6468template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006469QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006470 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6471}
6472
6473template<typename Derived>
6474QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6475 return SemaRef.Context.getTypeOfType(Underlying);
6476}
6477
6478template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006479QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006480 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6481}
6482
6483template<typename Derived>
6484QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006485 TemplateName Template,
6486 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006487 const TemplateArgumentListInfo &TemplateArgs) {
6488 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006489}
Mike Stump11289f42009-09-09 15:08:12 +00006490
Douglas Gregor1135c352009-08-06 05:28:30 +00006491template<typename Derived>
6492NestedNameSpecifier *
6493TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6494 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006495 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006496 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006497 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006498 CXXScopeSpec SS;
6499 // FIXME: The source location information is all wrong.
6500 SS.setRange(Range);
6501 SS.setScopeRep(Prefix);
6502 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006503 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006504 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006505 ObjectType,
6506 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006507 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006508}
6509
6510template<typename Derived>
6511NestedNameSpecifier *
6512TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6513 SourceRange Range,
6514 NamespaceDecl *NS) {
6515 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6516}
6517
6518template<typename Derived>
6519NestedNameSpecifier *
6520TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6521 SourceRange Range,
6522 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006523 QualType T) {
6524 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006525 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006526 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006527 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6528 T.getTypePtr());
6529 }
Mike Stump11289f42009-09-09 15:08:12 +00006530
Douglas Gregor1135c352009-08-06 05:28:30 +00006531 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6532 return 0;
6533}
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregor71dc5092009-08-06 06:41:21 +00006535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006536TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006537TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6538 bool TemplateKW,
6539 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006540 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006541 Template);
6542}
6543
6544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006545TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006546TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006547 const IdentifierInfo &II,
6548 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006549 CXXScopeSpec SS;
6550 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006551 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006552 UnqualifiedId Name;
6553 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006554 Sema::TemplateTy Template;
6555 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6556 /*FIXME:*/getDerived().getBaseLocation(),
6557 SS,
6558 Name,
6559 ObjectType.getAsOpaquePtr(),
6560 /*EnteringContext=*/false,
6561 Template);
6562 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006563}
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregora16548e2009-08-11 05:31:07 +00006565template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006566TemplateName
6567TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6568 OverloadedOperatorKind Operator,
6569 QualType ObjectType) {
6570 CXXScopeSpec SS;
6571 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6572 SS.setScopeRep(Qualifier);
6573 UnqualifiedId Name;
6574 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6575 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6576 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006577 Sema::TemplateTy Template;
6578 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006579 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006580 SS,
6581 Name,
6582 ObjectType.getAsOpaquePtr(),
6583 /*EnteringContext=*/false,
6584 Template);
6585 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006586}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006587
Douglas Gregor71395fa2009-11-04 00:56:37 +00006588template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006589Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006590TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6591 SourceLocation OpLoc,
6592 ExprArg Callee,
6593 ExprArg First,
6594 ExprArg Second) {
6595 Expr *FirstExpr = (Expr *)First.get();
6596 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006597 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006598 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregora16548e2009-08-11 05:31:07 +00006600 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006601 if (Op == OO_Subscript) {
6602 if (!FirstExpr->getType()->isOverloadableType() &&
6603 !SecondExpr->getType()->isOverloadableType())
6604 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006605 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006606 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006607 } else if (Op == OO_Arrow) {
6608 // -> is never a builtin operation.
6609 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006610 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 if (!FirstExpr->getType()->isOverloadableType()) {
6612 // The argument is not of overloadable type, so try to create a
6613 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006614 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006616
Douglas Gregora16548e2009-08-11 05:31:07 +00006617 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6618 }
6619 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006620 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 !SecondExpr->getType()->isOverloadableType()) {
6622 // Neither of the arguments is an overloadable type, so try to
6623 // create a built-in binary operation.
6624 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006625 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6627 if (Result.isInvalid())
6628 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006629
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 First.release();
6631 Second.release();
6632 return move(Result);
6633 }
6634 }
Mike Stump11289f42009-09-09 15:08:12 +00006635
6636 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006638 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006639
John McCalld14a8642009-11-21 08:51:07 +00006640 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6641 assert(ULE->requiresADL());
6642
6643 // FIXME: Do we have to check
6644 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006645 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006646 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006647 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006648 }
Mike Stump11289f42009-09-09 15:08:12 +00006649
Douglas Gregora16548e2009-08-11 05:31:07 +00006650 // Add any functions found via argument-dependent lookup.
6651 Expr *Args[2] = { FirstExpr, SecondExpr };
6652 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006653
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 // Create the overloaded operator invocation for unary operators.
6655 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006656 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006657 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6658 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6659 }
Mike Stump11289f42009-09-09 15:08:12 +00006660
Sebastian Redladba46e2009-10-29 20:17:01 +00006661 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006662 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6663 OpLoc,
6664 move(First),
6665 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006666
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006668 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006669 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006670 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006671 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6672 if (Result.isInvalid())
6673 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregora16548e2009-08-11 05:31:07 +00006675 First.release();
6676 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006677 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006678}
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006680template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006681Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006682TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6683 SourceLocation OperatorLoc,
6684 bool isArrow,
6685 NestedNameSpecifier *Qualifier,
6686 SourceRange QualifierRange,
6687 TypeSourceInfo *ScopeType,
6688 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006689 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006690 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006691 CXXScopeSpec SS;
6692 if (Qualifier) {
6693 SS.setRange(QualifierRange);
6694 SS.setScopeRep(Qualifier);
6695 }
6696
6697 Expr *BaseE = (Expr *)Base.get();
6698 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006699 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006700 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006701 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006702 !BaseType->getAs<PointerType>()->getPointeeType()
6703 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006704 // This pseudo-destructor expression is still a pseudo-destructor.
6705 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6706 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006707 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006708 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006709 /*FIXME?*/true);
6710 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006711
Douglas Gregor678f90d2010-02-25 01:56:36 +00006712 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006713 DeclarationName Name
6714 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6715 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006716
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006717 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006718
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006719 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6720 OperatorLoc, isArrow,
6721 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006722 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006723 /*TemplateArgs*/ 0);
6724}
6725
Douglas Gregord6ff3322009-08-04 16:50:30 +00006726} // end namespace clang
6727
6728#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H