blob: 1ff6d5335d1be77f44c8455b27f3daa92ca3b53f [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) {
Abramo Bagnara27db2392010-08-10 10:06:15 +00004786 TypeSourceInfo *TInfo;
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 {
4788 // FIXME: Source location isn't quite accurate.
4789 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Abramo Bagnara27db2392010-08-10 10:06:15 +00004790 TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4791 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 return SemaRef.ExprError();
4793 }
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4796 if (SubExpr.isInvalid())
4797 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004800 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 SubExpr.get() == E->getSubExpr())
4802 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004805 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004806}
4807
4808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004809Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004810TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 bool ArgumentChanged = false;
4812 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4813 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4814 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4815 if (Init.isInvalid())
4816 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4819 Inits.push_back(Init.takeAs<Expr>());
4820 }
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4823 move_arg(Inits),
4824 E->getRParenLoc());
4825}
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregora16548e2009-08-11 05:31:07 +00004827/// \brief Transform an address-of-label expression.
4828///
4829/// By default, the transformation of an address-of-label expression always
4830/// rebuilds the expression, so that the label identifier can be resolved to
4831/// the corresponding label statement by semantic analysis.
4832template<typename Derived>
4833Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004834TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4836 E->getLabel());
4837}
Mike Stump11289f42009-09-09 15:08:12 +00004838
4839template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004840Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004841TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004842 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004843 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4844 if (SubStmt.isInvalid())
4845 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 if (!getDerived().AlwaysRebuild() &&
4848 SubStmt.get() == E->getSubStmt())
4849 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004850
4851 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 move(SubStmt),
4853 E->getRParenLoc());
4854}
Mike Stump11289f42009-09-09 15:08:12 +00004855
Douglas Gregora16548e2009-08-11 05:31:07 +00004856template<typename Derived>
4857Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004859 TypeSourceInfo *TInfo1;
4860 TypeSourceInfo *TInfo2;
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 {
4862 // FIXME: Source location isn't quite accurate.
4863 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004864
Abramo Bagnara092990a2010-08-10 08:50:03 +00004865 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4866 if (!TInfo1)
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004868
Abramo Bagnara092990a2010-08-10 08:50:03 +00004869 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4870 if (!TInfo2)
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 return SemaRef.ExprError();
4872 }
4873
4874 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004875 TInfo1 == E->getArgTInfo1() &&
4876 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004877 return SemaRef.Owned(E->Retain());
4878
Douglas Gregora16548e2009-08-11 05:31:07 +00004879 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004880 TInfo1, TInfo2,
4881 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004882}
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregora16548e2009-08-11 05:31:07 +00004884template<typename Derived>
4885Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004886TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004887 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4888 if (Cond.isInvalid())
4889 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4892 if (LHS.isInvalid())
4893 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004894
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4896 if (RHS.isInvalid())
4897 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 if (!getDerived().AlwaysRebuild() &&
4900 Cond.get() == E->getCond() &&
4901 LHS.get() == E->getLHS() &&
4902 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004903 return SemaRef.Owned(E->Retain());
4904
Douglas Gregora16548e2009-08-11 05:31:07 +00004905 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4906 move(Cond), move(LHS), move(RHS),
4907 E->getRParenLoc());
4908}
Mike Stump11289f42009-09-09 15:08:12 +00004909
Douglas Gregora16548e2009-08-11 05:31:07 +00004910template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004911Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004912TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004913 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004914}
4915
4916template<typename Derived>
4917Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004918TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004919 switch (E->getOperator()) {
4920 case OO_New:
4921 case OO_Delete:
4922 case OO_Array_New:
4923 case OO_Array_Delete:
4924 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4925 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004926
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004927 case OO_Call: {
4928 // This is a call to an object's operator().
4929 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4930
4931 // Transform the object itself.
4932 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4933 if (Object.isInvalid())
4934 return SemaRef.ExprError();
4935
4936 // FIXME: Poor location information
4937 SourceLocation FakeLParenLoc
4938 = SemaRef.PP.getLocForEndOfToken(
4939 static_cast<Expr *>(Object.get())->getLocEnd());
4940
4941 // Transform the call arguments.
4942 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4943 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4944 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004945 if (getDerived().DropCallArgument(E->getArg(I)))
4946 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004947
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004948 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4949 if (Arg.isInvalid())
4950 return SemaRef.ExprError();
4951
4952 // FIXME: Poor source location information.
4953 SourceLocation FakeCommaLoc
4954 = SemaRef.PP.getLocForEndOfToken(
4955 static_cast<Expr *>(Arg.get())->getLocEnd());
4956 FakeCommaLocs.push_back(FakeCommaLoc);
4957 Args.push_back(Arg.release());
4958 }
4959
4960 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4961 move_arg(Args),
4962 FakeCommaLocs.data(),
4963 E->getLocEnd());
4964 }
4965
4966#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4967 case OO_##Name:
4968#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4969#include "clang/Basic/OperatorKinds.def"
4970 case OO_Subscript:
4971 // Handled below.
4972 break;
4973
4974 case OO_Conditional:
4975 llvm_unreachable("conditional operator is not actually overloadable");
4976 return SemaRef.ExprError();
4977
4978 case OO_None:
4979 case NUM_OVERLOADED_OPERATORS:
4980 llvm_unreachable("not an overloaded operator?");
4981 return SemaRef.ExprError();
4982 }
4983
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4985 if (Callee.isInvalid())
4986 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004987
John McCall47f29ea2009-12-08 09:21:05 +00004988 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 if (First.isInvalid())
4990 return SemaRef.ExprError();
4991
4992 OwningExprResult Second(SemaRef);
4993 if (E->getNumArgs() == 2) {
4994 Second = getDerived().TransformExpr(E->getArg(1));
4995 if (Second.isInvalid())
4996 return SemaRef.ExprError();
4997 }
Mike Stump11289f42009-09-09 15:08:12 +00004998
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 if (!getDerived().AlwaysRebuild() &&
5000 Callee.get() == E->getCallee() &&
5001 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005002 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5003 return SemaRef.Owned(E->Retain());
5004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5006 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005007 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00005008 move(First),
5009 move(Second));
5010}
Mike Stump11289f42009-09-09 15:08:12 +00005011
Douglas Gregora16548e2009-08-11 05:31:07 +00005012template<typename Derived>
5013Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005014TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5015 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005019Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005020TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005021 TypeSourceInfo *OldT;
5022 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 {
5024 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005025 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5027 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005028
John McCall97513962010-01-15 18:39:57 +00005029 OldT = E->getTypeInfoAsWritten();
5030 NewT = getDerived().TransformType(OldT);
5031 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 return SemaRef.ExprError();
5033 }
Mike Stump11289f42009-09-09 15:08:12 +00005034
Douglas Gregor6131b442009-12-12 18:16:41 +00005035 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005036 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 if (SubExpr.isInvalid())
5038 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005039
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005041 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005043 return SemaRef.Owned(E->Retain());
5044
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005046 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5048 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5049 SourceLocation FakeRParenLoc
5050 = SemaRef.PP.getLocForEndOfToken(
5051 E->getSubExpr()->getSourceRange().getEnd());
5052 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005053 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005054 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005055 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 FakeRAngleLoc,
5057 FakeRAngleLoc,
5058 move(SubExpr),
5059 FakeRParenLoc);
5060}
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062template<typename Derived>
5063Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005064TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5065 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005066}
Mike Stump11289f42009-09-09 15:08:12 +00005067
5068template<typename Derived>
5069Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5071 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005072}
5073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074template<typename Derived>
5075Sema::OwningExprResult
5076TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005077 CXXReinterpretCastExpr *E) {
5078 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005079}
Mike Stump11289f42009-09-09 15:08:12 +00005080
Douglas Gregora16548e2009-08-11 05:31:07 +00005081template<typename Derived>
5082Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005083TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5084 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005085}
Mike Stump11289f42009-09-09 15:08:12 +00005086
Douglas Gregora16548e2009-08-11 05:31:07 +00005087template<typename Derived>
5088Sema::OwningExprResult
5089TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005090 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005091 TypeSourceInfo *OldT;
5092 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 {
5094 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005095
John McCall97513962010-01-15 18:39:57 +00005096 OldT = E->getTypeInfoAsWritten();
5097 NewT = getDerived().TransformType(OldT);
5098 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005099 return SemaRef.ExprError();
5100 }
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregor6131b442009-12-12 18:16:41 +00005102 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005103 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 if (SubExpr.isInvalid())
5105 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005108 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005110 return SemaRef.Owned(E->Retain());
5111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 // FIXME: The end of the type's source range is wrong
5113 return getDerived().RebuildCXXFunctionalCastExpr(
5114 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005115 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 /*FIXME:*/E->getSubExpr()->getLocStart(),
5117 move(SubExpr),
5118 E->getRParenLoc());
5119}
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregora16548e2009-08-11 05:31:07 +00005121template<typename Derived>
5122Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005123TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005125 TypeSourceInfo *TInfo
5126 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5127 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005129
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005131 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregor9da64192010-04-26 22:37:10 +00005134 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5135 E->getLocStart(),
5136 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 E->getLocEnd());
5138 }
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 // We don't know whether the expression is potentially evaluated until
5141 // after we perform semantic analysis, so the expression is potentially
5142 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005143 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5147 if (SubExpr.isInvalid())
5148 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 if (!getDerived().AlwaysRebuild() &&
5151 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005152 return SemaRef.Owned(E->Retain());
5153
Douglas Gregor9da64192010-04-26 22:37:10 +00005154 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5155 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 move(SubExpr),
5157 E->getLocEnd());
5158}
5159
5160template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005161Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005162TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005163 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005164}
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregora16548e2009-08-11 05:31:07 +00005166template<typename Derived>
5167Sema::OwningExprResult
5168TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005169 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005170 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005171}
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173template<typename Derived>
5174Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005175TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005176 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178 QualType T = getDerived().TransformType(E->getType());
5179 if (T.isNull())
5180 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005181
Douglas Gregora16548e2009-08-11 05:31:07 +00005182 if (!getDerived().AlwaysRebuild() &&
5183 T == E->getType())
5184 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregorb15af892010-01-07 23:12:05 +00005186 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005187}
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregora16548e2009-08-11 05:31:07 +00005189template<typename Derived>
5190Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005191TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5193 if (SubExpr.isInvalid())
5194 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005195
Douglas Gregora16548e2009-08-11 05:31:07 +00005196 if (!getDerived().AlwaysRebuild() &&
5197 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005198 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005199
5200 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5201}
Mike Stump11289f42009-09-09 15:08:12 +00005202
Douglas Gregora16548e2009-08-11 05:31:07 +00005203template<typename Derived>
5204Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005205TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005206 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005207 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5208 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005209 if (!Param)
5210 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005211
Chandler Carruth794da4c2010-02-08 06:42:49 +00005212 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005213 Param == E->getParam())
5214 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregor033f6752009-12-23 23:03:06 +00005216 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219template<typename Derived>
5220Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005221TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005222 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5223
5224 QualType T = getDerived().TransformType(E->getType());
5225 if (T.isNull())
5226 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregora16548e2009-08-11 05:31:07 +00005228 if (!getDerived().AlwaysRebuild() &&
5229 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005230 return SemaRef.Owned(E->Retain());
5231
Douglas Gregor747eb782010-07-08 06:14:04 +00005232 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5233 /*FIXME:*/E->getTypeBeginLoc(),
5234 T,
5235 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005236}
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregora16548e2009-08-11 05:31:07 +00005238template<typename Derived>
5239Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005240TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 // Transform the type that we're allocating
5242 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5243 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5244 if (AllocType.isNull())
5245 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 // Transform the size of the array we're allocating (if any).
5248 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5249 if (ArraySize.isInvalid())
5250 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregora16548e2009-08-11 05:31:07 +00005252 // Transform the placement arguments (if any).
5253 bool ArgumentChanged = false;
5254 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5255 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5256 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5257 if (Arg.isInvalid())
5258 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5261 PlacementArgs.push_back(Arg.take());
5262 }
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregorebe10102009-08-20 07:17:43 +00005264 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5266 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005267 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5268 break;
5269
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5271 if (Arg.isInvalid())
5272 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5275 ConstructorArgs.push_back(Arg.take());
5276 }
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregord2d9da02010-02-26 00:38:10 +00005278 // Transform constructor, new operator, and delete operator.
5279 CXXConstructorDecl *Constructor = 0;
5280 if (E->getConstructor()) {
5281 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005282 getDerived().TransformDecl(E->getLocStart(),
5283 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005284 if (!Constructor)
5285 return SemaRef.ExprError();
5286 }
5287
5288 FunctionDecl *OperatorNew = 0;
5289 if (E->getOperatorNew()) {
5290 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005291 getDerived().TransformDecl(E->getLocStart(),
5292 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005293 if (!OperatorNew)
5294 return SemaRef.ExprError();
5295 }
5296
5297 FunctionDecl *OperatorDelete = 0;
5298 if (E->getOperatorDelete()) {
5299 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005300 getDerived().TransformDecl(E->getLocStart(),
5301 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005302 if (!OperatorDelete)
5303 return SemaRef.ExprError();
5304 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005305
Douglas Gregora16548e2009-08-11 05:31:07 +00005306 if (!getDerived().AlwaysRebuild() &&
5307 AllocType == E->getAllocatedType() &&
5308 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005309 Constructor == E->getConstructor() &&
5310 OperatorNew == E->getOperatorNew() &&
5311 OperatorDelete == E->getOperatorDelete() &&
5312 !ArgumentChanged) {
5313 // Mark any declarations we need as referenced.
5314 // FIXME: instantiation-specific.
5315 if (Constructor)
5316 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5317 if (OperatorNew)
5318 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5319 if (OperatorDelete)
5320 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005321 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005322 }
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005324 if (!ArraySize.get()) {
5325 // If no array size was specified, but the new expression was
5326 // instantiated with an array type (e.g., "new T" where T is
5327 // instantiated with "int[4]"), extract the outer bound from the
5328 // array type as our array size. We do this with constant and
5329 // dependently-sized array types.
5330 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5331 if (!ArrayT) {
5332 // Do nothing
5333 } else if (const ConstantArrayType *ConsArrayT
5334 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005335 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005336 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005337 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005338 SemaRef.Context.getSizeType(),
5339 /*FIXME:*/E->getLocStart()));
5340 AllocType = ConsArrayT->getElementType();
5341 } else if (const DependentSizedArrayType *DepArrayT
5342 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5343 if (DepArrayT->getSizeExpr()) {
5344 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5345 AllocType = DepArrayT->getElementType();
5346 }
5347 }
5348 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005349 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5350 E->isGlobalNew(),
5351 /*FIXME:*/E->getLocStart(),
5352 move_arg(PlacementArgs),
5353 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005354 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 AllocType,
5356 /*FIXME:*/E->getLocStart(),
5357 /*FIXME:*/SourceRange(),
5358 move(ArraySize),
5359 /*FIXME:*/E->getLocStart(),
5360 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005361 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005362}
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregora16548e2009-08-11 05:31:07 +00005364template<typename Derived>
5365Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005366TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5368 if (Operand.isInvalid())
5369 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregord2d9da02010-02-26 00:38:10 +00005371 // Transform the delete operator, if known.
5372 FunctionDecl *OperatorDelete = 0;
5373 if (E->getOperatorDelete()) {
5374 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005375 getDerived().TransformDecl(E->getLocStart(),
5376 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005377 if (!OperatorDelete)
5378 return SemaRef.ExprError();
5379 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005380
Douglas Gregora16548e2009-08-11 05:31:07 +00005381 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005382 Operand.get() == E->getArgument() &&
5383 OperatorDelete == E->getOperatorDelete()) {
5384 // Mark any declarations we need as referenced.
5385 // FIXME: instantiation-specific.
5386 if (OperatorDelete)
5387 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005388 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005389 }
Mike Stump11289f42009-09-09 15:08:12 +00005390
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5392 E->isGlobalDelete(),
5393 E->isArrayForm(),
5394 move(Operand));
5395}
Mike Stump11289f42009-09-09 15:08:12 +00005396
Douglas Gregora16548e2009-08-11 05:31:07 +00005397template<typename Derived>
5398Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005399TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005400 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005401 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5402 if (Base.isInvalid())
5403 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005404
Douglas Gregor678f90d2010-02-25 01:56:36 +00005405 Sema::TypeTy *ObjectTypePtr = 0;
5406 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005407 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005408 E->getOperatorLoc(),
5409 E->isArrow()? tok::arrow : tok::period,
5410 ObjectTypePtr,
5411 MayBePseudoDestructor);
5412 if (Base.isInvalid())
5413 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
Douglas Gregor678f90d2010-02-25 01:56:36 +00005415 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005416 NestedNameSpecifier *Qualifier
5417 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005418 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005419 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005420 if (E->getQualifier() && !Qualifier)
5421 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregor678f90d2010-02-25 01:56:36 +00005423 PseudoDestructorTypeStorage Destroyed;
5424 if (E->getDestroyedTypeInfo()) {
5425 TypeSourceInfo *DestroyedTypeInfo
5426 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5427 if (!DestroyedTypeInfo)
5428 return SemaRef.ExprError();
5429 Destroyed = DestroyedTypeInfo;
5430 } else if (ObjectType->isDependentType()) {
5431 // We aren't likely to be able to resolve the identifier down to a type
5432 // now anyway, so just retain the identifier.
5433 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5434 E->getDestroyedTypeLoc());
5435 } else {
5436 // Look for a destructor known with the given name.
5437 CXXScopeSpec SS;
5438 if (Qualifier) {
5439 SS.setScopeRep(Qualifier);
5440 SS.setRange(E->getQualifierRange());
5441 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005442
Douglas Gregor678f90d2010-02-25 01:56:36 +00005443 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5444 *E->getDestroyedTypeIdentifier(),
5445 E->getDestroyedTypeLoc(),
5446 /*Scope=*/0,
5447 SS, ObjectTypePtr,
5448 false);
5449 if (!T)
5450 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005451
Douglas Gregor678f90d2010-02-25 01:56:36 +00005452 Destroyed
5453 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5454 E->getDestroyedTypeLoc());
5455 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005456
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005457 TypeSourceInfo *ScopeTypeInfo = 0;
5458 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005459 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005460 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005461 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005462 return SemaRef.ExprError();
5463 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464
Douglas Gregorad8a3362009-09-04 17:36:40 +00005465 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5466 E->getOperatorLoc(),
5467 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005468 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005469 E->getQualifierRange(),
5470 ScopeTypeInfo,
5471 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005472 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005473 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregorad8a3362009-09-04 17:36:40 +00005476template<typename Derived>
5477Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005478TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005479 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005480 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5481
5482 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5483 Sema::LookupOrdinaryName);
5484
5485 // Transform all the decls.
5486 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5487 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005488 NamedDecl *InstD = static_cast<NamedDecl*>(
5489 getDerived().TransformDecl(Old->getNameLoc(),
5490 *I));
John McCall84d87672009-12-10 09:41:52 +00005491 if (!InstD) {
5492 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5493 // This can happen because of dependent hiding.
5494 if (isa<UsingShadowDecl>(*I))
5495 continue;
5496 else
5497 return SemaRef.ExprError();
5498 }
John McCalle66edc12009-11-24 19:00:30 +00005499
5500 // Expand using declarations.
5501 if (isa<UsingDecl>(InstD)) {
5502 UsingDecl *UD = cast<UsingDecl>(InstD);
5503 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5504 E = UD->shadow_end(); I != E; ++I)
5505 R.addDecl(*I);
5506 continue;
5507 }
5508
5509 R.addDecl(InstD);
5510 }
5511
5512 // Resolve a kind, but don't do any further analysis. If it's
5513 // ambiguous, the callee needs to deal with it.
5514 R.resolveKind();
5515
5516 // Rebuild the nested-name qualifier, if present.
5517 CXXScopeSpec SS;
5518 NestedNameSpecifier *Qualifier = 0;
5519 if (Old->getQualifier()) {
5520 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005521 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005522 if (!Qualifier)
5523 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005524
John McCalle66edc12009-11-24 19:00:30 +00005525 SS.setScopeRep(Qualifier);
5526 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005527 }
5528
Douglas Gregor9262f472010-04-27 18:19:34 +00005529 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005530 CXXRecordDecl *NamingClass
5531 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5532 Old->getNameLoc(),
5533 Old->getNamingClass()));
5534 if (!NamingClass)
5535 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005536
Douglas Gregorda7be082010-04-27 16:10:10 +00005537 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005538 }
5539
5540 // If we have no template arguments, it's a normal declaration name.
5541 if (!Old->hasExplicitTemplateArgs())
5542 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5543
5544 // If we have template arguments, rebuild them, then rebuild the
5545 // templateid expression.
5546 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5547 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5548 TemplateArgumentLoc Loc;
5549 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5550 return SemaRef.ExprError();
5551 TransArgs.addArgument(Loc);
5552 }
5553
5554 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5555 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005556}
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558template<typename Derived>
5559Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005560TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregora16548e2009-08-11 05:31:07 +00005563 QualType T = getDerived().TransformType(E->getQueriedType());
5564 if (T.isNull())
5565 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005566
Douglas Gregora16548e2009-08-11 05:31:07 +00005567 if (!getDerived().AlwaysRebuild() &&
5568 T == E->getQueriedType())
5569 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 // FIXME: Bad location information
5572 SourceLocation FakeLParenLoc
5573 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005574
5575 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 E->getLocStart(),
5577 /*FIXME:*/FakeLParenLoc,
5578 T,
5579 E->getLocEnd());
5580}
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregora16548e2009-08-11 05:31:07 +00005582template<typename Derived>
5583Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005584TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005585 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005586 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005587 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005588 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 if (!NNS)
5590 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005591
5592 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005593 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5594 if (!Name)
5595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005596
John McCalle66edc12009-11-24 19:00:30 +00005597 if (!E->hasExplicitTemplateArgs()) {
5598 if (!getDerived().AlwaysRebuild() &&
5599 NNS == E->getQualifier() &&
5600 Name == E->getDeclName())
5601 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005602
John McCalle66edc12009-11-24 19:00:30 +00005603 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5604 E->getQualifierRange(),
5605 Name, E->getLocation(),
5606 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005607 }
John McCall6b51f282009-11-23 01:53:49 +00005608
5609 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005610 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005611 TemplateArgumentLoc Loc;
5612 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005614 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 }
5616
John McCalle66edc12009-11-24 19:00:30 +00005617 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5618 E->getQualifierRange(),
5619 Name, E->getLocation(),
5620 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005621}
5622
5623template<typename Derived>
5624Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005625TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005626 // CXXConstructExprs are always implicit, so when we have a
5627 // 1-argument construction we just transform that argument.
5628 if (E->getNumArgs() == 1 ||
5629 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5630 return getDerived().TransformExpr(E->getArg(0));
5631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5633
5634 QualType T = getDerived().TransformType(E->getType());
5635 if (T.isNull())
5636 return SemaRef.ExprError();
5637
5638 CXXConstructorDecl *Constructor
5639 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005640 getDerived().TransformDecl(E->getLocStart(),
5641 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 if (!Constructor)
5643 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005644
Douglas Gregora16548e2009-08-11 05:31:07 +00005645 bool ArgumentChanged = false;
5646 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005647 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 ArgEnd = E->arg_end();
5649 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005650 if (getDerived().DropCallArgument(*Arg)) {
5651 ArgumentChanged = true;
5652 break;
5653 }
5654
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5656 if (TransArg.isInvalid())
5657 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5660 Args.push_back(TransArg.takeAs<Expr>());
5661 }
5662
5663 if (!getDerived().AlwaysRebuild() &&
5664 T == E->getType() &&
5665 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005666 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005667 // Mark the constructor as referenced.
5668 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005669 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005671 }
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregordb121ba2009-12-14 16:27:04 +00005673 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5674 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 move_arg(Args));
5676}
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregora16548e2009-08-11 05:31:07 +00005678/// \brief Transform a C++ temporary-binding expression.
5679///
Douglas Gregor363b1512009-12-24 18:51:59 +00005680/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5681/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005682template<typename Derived>
5683Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005684TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005685 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005686}
Mike Stump11289f42009-09-09 15:08:12 +00005687
Anders Carlssonba6c4372010-01-29 02:39:32 +00005688/// \brief Transform a C++ reference-binding expression.
5689///
5690/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5691/// transform the subexpression and return that.
5692template<typename Derived>
5693Sema::OwningExprResult
5694TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5695 return getDerived().TransformExpr(E->getSubExpr());
5696}
5697
Mike Stump11289f42009-09-09 15:08:12 +00005698/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005699/// be destroyed after the expression is evaluated.
5700///
Douglas Gregor363b1512009-12-24 18:51:59 +00005701/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5702/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005703template<typename Derived>
5704Sema::OwningExprResult
5705TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005706 CXXExprWithTemporaries *E) {
5707 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005708}
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710template<typename Derived>
5711Sema::OwningExprResult
5712TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005713 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5715 QualType T = getDerived().TransformType(E->getType());
5716 if (T.isNull())
5717 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 CXXConstructorDecl *Constructor
5720 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005721 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005722 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 if (!Constructor)
5724 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 bool ArgumentChanged = false;
5727 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5728 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005729 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 ArgEnd = E->arg_end();
5731 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005732 if (getDerived().DropCallArgument(*Arg)) {
5733 ArgumentChanged = true;
5734 break;
5735 }
5736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5738 if (TransArg.isInvalid())
5739 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5742 Args.push_back((Expr *)TransArg.release());
5743 }
Mike Stump11289f42009-09-09 15:08:12 +00005744
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 if (!getDerived().AlwaysRebuild() &&
5746 T == E->getType() &&
5747 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005748 !ArgumentChanged) {
5749 // FIXME: Instantiation-specific
5750 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005751 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005752 }
Mike Stump11289f42009-09-09 15:08:12 +00005753
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 // FIXME: Bogus location information
5755 SourceLocation CommaLoc;
5756 if (Args.size() > 1) {
5757 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005758 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5760 }
5761 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5762 T,
5763 /*FIXME:*/E->getTypeBeginLoc(),
5764 move_arg(Args),
5765 &CommaLoc,
5766 E->getLocEnd());
5767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769template<typename Derived>
5770Sema::OwningExprResult
5771TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005772 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5774 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5775 if (T.isNull())
5776 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005777
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 bool ArgumentChanged = false;
5779 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5780 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5781 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5782 ArgEnd = E->arg_end();
5783 Arg != ArgEnd; ++Arg) {
5784 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5785 if (TransArg.isInvalid())
5786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005787
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5789 FakeCommaLocs.push_back(
5790 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5791 Args.push_back(TransArg.takeAs<Expr>());
5792 }
Mike Stump11289f42009-09-09 15:08:12 +00005793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 if (!getDerived().AlwaysRebuild() &&
5795 T == E->getTypeAsWritten() &&
5796 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005797 return SemaRef.Owned(E->Retain());
5798
Douglas Gregora16548e2009-08-11 05:31:07 +00005799 // FIXME: we're faking the locations of the commas
5800 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5801 T,
5802 E->getLParenLoc(),
5803 move_arg(Args),
5804 FakeCommaLocs.data(),
5805 E->getRParenLoc());
5806}
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808template<typename Derived>
5809Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005810TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005811 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005813 OwningExprResult Base(SemaRef, (Expr*) 0);
5814 Expr *OldBase;
5815 QualType BaseType;
5816 QualType ObjectType;
5817 if (!E->isImplicitAccess()) {
5818 OldBase = E->getBase();
5819 Base = getDerived().TransformExpr(OldBase);
5820 if (Base.isInvalid())
5821 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005822
John McCall2d74de92009-12-01 22:10:20 +00005823 // Start the member reference and compute the object's type.
5824 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005825 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005826 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5827 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005828 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005829 ObjectTy,
5830 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005831 if (Base.isInvalid())
5832 return SemaRef.ExprError();
5833
5834 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5835 BaseType = ((Expr*) Base.get())->getType();
5836 } else {
5837 OldBase = 0;
5838 BaseType = getDerived().TransformType(E->getBaseType());
5839 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5840 }
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005842 // Transform the first part of the nested-name-specifier that qualifies
5843 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005844 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005845 = getDerived().TransformFirstQualifierInScope(
5846 E->getFirstQualifierFoundInScope(),
5847 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005848
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005849 NestedNameSpecifier *Qualifier = 0;
5850 if (E->getQualifier()) {
5851 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5852 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005853 ObjectType,
5854 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005855 if (!Qualifier)
5856 return SemaRef.ExprError();
5857 }
Mike Stump11289f42009-09-09 15:08:12 +00005858
5859 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005860 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005861 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005862 if (!Name)
5863 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005864
John McCall2d74de92009-12-01 22:10:20 +00005865 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005866 // This is a reference to a member without an explicitly-specified
5867 // template argument list. Optimize for this common case.
5868 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005869 Base.get() == OldBase &&
5870 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005871 Qualifier == E->getQualifier() &&
5872 Name == E->getMember() &&
5873 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005874 return SemaRef.Owned(E->Retain());
5875
John McCall8cd78132009-11-19 22:55:06 +00005876 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005877 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005878 E->isArrow(),
5879 E->getOperatorLoc(),
5880 Qualifier,
5881 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005882 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005883 Name,
5884 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005885 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005886 }
5887
John McCall6b51f282009-11-23 01:53:49 +00005888 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005889 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005890 TemplateArgumentLoc Loc;
5891 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005892 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005893 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005894 }
Mike Stump11289f42009-09-09 15:08:12 +00005895
John McCall8cd78132009-11-19 22:55:06 +00005896 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005897 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 E->isArrow(),
5899 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005900 Qualifier,
5901 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005902 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005903 Name,
5904 E->getMemberLoc(),
5905 &TransArgs);
5906}
5907
5908template<typename Derived>
5909Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005910TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005911 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005912 OwningExprResult Base(SemaRef, (Expr*) 0);
5913 QualType BaseType;
5914 if (!Old->isImplicitAccess()) {
5915 Base = getDerived().TransformExpr(Old->getBase());
5916 if (Base.isInvalid())
5917 return SemaRef.ExprError();
5918 BaseType = ((Expr*) Base.get())->getType();
5919 } else {
5920 BaseType = getDerived().TransformType(Old->getBaseType());
5921 }
John McCall10eae182009-11-30 22:42:35 +00005922
5923 NestedNameSpecifier *Qualifier = 0;
5924 if (Old->getQualifier()) {
5925 Qualifier
5926 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005927 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005928 if (Qualifier == 0)
5929 return SemaRef.ExprError();
5930 }
5931
5932 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5933 Sema::LookupOrdinaryName);
5934
5935 // Transform all the decls.
5936 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5937 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005938 NamedDecl *InstD = static_cast<NamedDecl*>(
5939 getDerived().TransformDecl(Old->getMemberLoc(),
5940 *I));
John McCall84d87672009-12-10 09:41:52 +00005941 if (!InstD) {
5942 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5943 // This can happen because of dependent hiding.
5944 if (isa<UsingShadowDecl>(*I))
5945 continue;
5946 else
5947 return SemaRef.ExprError();
5948 }
John McCall10eae182009-11-30 22:42:35 +00005949
5950 // Expand using declarations.
5951 if (isa<UsingDecl>(InstD)) {
5952 UsingDecl *UD = cast<UsingDecl>(InstD);
5953 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5954 E = UD->shadow_end(); I != E; ++I)
5955 R.addDecl(*I);
5956 continue;
5957 }
5958
5959 R.addDecl(InstD);
5960 }
5961
5962 R.resolveKind();
5963
Douglas Gregor9262f472010-04-27 18:19:34 +00005964 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005965 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005966 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005967 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005968 Old->getMemberLoc(),
5969 Old->getNamingClass()));
5970 if (!NamingClass)
5971 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005972
Douglas Gregorda7be082010-04-27 16:10:10 +00005973 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005974 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005975
John McCall10eae182009-11-30 22:42:35 +00005976 TemplateArgumentListInfo TransArgs;
5977 if (Old->hasExplicitTemplateArgs()) {
5978 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5979 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5980 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5981 TemplateArgumentLoc Loc;
5982 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5983 Loc))
5984 return SemaRef.ExprError();
5985 TransArgs.addArgument(Loc);
5986 }
5987 }
John McCall38836f02010-01-15 08:34:02 +00005988
5989 // FIXME: to do this check properly, we will need to preserve the
5990 // first-qualifier-in-scope here, just in case we had a dependent
5991 // base (and therefore couldn't do the check) and a
5992 // nested-name-qualifier (and therefore could do the lookup).
5993 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005994
John McCall10eae182009-11-30 22:42:35 +00005995 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005996 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005997 Old->getOperatorLoc(),
5998 Old->isArrow(),
5999 Qualifier,
6000 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006001 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006002 R,
6003 (Old->hasExplicitTemplateArgs()
6004 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006005}
6006
6007template<typename Derived>
6008Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006010 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006011}
6012
Mike Stump11289f42009-09-09 15:08:12 +00006013template<typename Derived>
6014Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006015TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006016 TypeSourceInfo *EncodedTypeInfo
6017 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6018 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006022 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006023 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006024
6025 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006026 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 E->getRParenLoc());
6028}
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030template<typename Derived>
6031Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006032TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006033 // Transform arguments.
6034 bool ArgChanged = false;
6035 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6036 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6037 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6038 if (Arg.isInvalid())
6039 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006040
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006041 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6042 Args.push_back(Arg.takeAs<Expr>());
6043 }
6044
6045 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6046 // Class message: transform the receiver type.
6047 TypeSourceInfo *ReceiverTypeInfo
6048 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6049 if (!ReceiverTypeInfo)
6050 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006051
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006052 // If nothing changed, just retain the existing message send.
6053 if (!getDerived().AlwaysRebuild() &&
6054 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6055 return SemaRef.Owned(E->Retain());
6056
6057 // Build a new class message send.
6058 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6059 E->getSelector(),
6060 E->getMethodDecl(),
6061 E->getLeftLoc(),
6062 move_arg(Args),
6063 E->getRightLoc());
6064 }
6065
6066 // Instance message: transform the receiver
6067 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6068 "Only class and instance messages may be instantiated");
6069 OwningExprResult Receiver
6070 = getDerived().TransformExpr(E->getInstanceReceiver());
6071 if (Receiver.isInvalid())
6072 return SemaRef.ExprError();
6073
6074 // If nothing changed, just retain the existing message send.
6075 if (!getDerived().AlwaysRebuild() &&
6076 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6077 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006078
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006079 // Build a new instance message send.
6080 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6081 E->getSelector(),
6082 E->getMethodDecl(),
6083 E->getLeftLoc(),
6084 move_arg(Args),
6085 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006086}
6087
Mike Stump11289f42009-09-09 15:08:12 +00006088template<typename Derived>
6089Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006090TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006091 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006092}
6093
Mike Stump11289f42009-09-09 15:08:12 +00006094template<typename Derived>
6095Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006096TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006097 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006098}
6099
Mike Stump11289f42009-09-09 15:08:12 +00006100template<typename Derived>
6101Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006102TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006103 // Transform the base expression.
6104 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6105 if (Base.isInvalid())
6106 return SemaRef.ExprError();
6107
6108 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006109
Douglas Gregord51d90d2010-04-26 20:11:03 +00006110 // If nothing changed, just retain the existing expression.
6111 if (!getDerived().AlwaysRebuild() &&
6112 Base.get() == E->getBase())
6113 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006114
Douglas Gregord51d90d2010-04-26 20:11:03 +00006115 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6116 E->getLocation(),
6117 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006118}
6119
Mike Stump11289f42009-09-09 15:08:12 +00006120template<typename Derived>
6121Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006123 // Transform the base expression.
6124 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6125 if (Base.isInvalid())
6126 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006127
Douglas Gregor9faee212010-04-26 20:47:02 +00006128 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006129
Douglas Gregor9faee212010-04-26 20:47:02 +00006130 // If nothing changed, just retain the existing expression.
6131 if (!getDerived().AlwaysRebuild() &&
6132 Base.get() == E->getBase())
6133 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006134
Douglas Gregor9faee212010-04-26 20:47:02 +00006135 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6136 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006137}
6138
Mike Stump11289f42009-09-09 15:08:12 +00006139template<typename Derived>
6140Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006141TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006142 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006143 // If this implicit setter/getter refers to class methods, it cannot have any
6144 // dependent parts. Just retain the existing declaration.
6145 if (E->getInterfaceDecl())
6146 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006147
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006148 // Transform the base expression.
6149 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6150 if (Base.isInvalid())
6151 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006152
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006153 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006154
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006155 // If nothing changed, just retain the existing expression.
6156 if (!getDerived().AlwaysRebuild() &&
6157 Base.get() == E->getBase())
6158 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006159
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006160 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6161 E->getGetterMethod(),
6162 E->getType(),
6163 E->getSetterMethod(),
6164 E->getLocation(),
6165 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006166
Douglas Gregora16548e2009-08-11 05:31:07 +00006167}
6168
Mike Stump11289f42009-09-09 15:08:12 +00006169template<typename Derived>
6170Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006172 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006173 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006174}
6175
Mike Stump11289f42009-09-09 15:08:12 +00006176template<typename Derived>
6177Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006178TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006179 // Transform the base expression.
6180 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6181 if (Base.isInvalid())
6182 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006183
Douglas Gregord51d90d2010-04-26 20:11:03 +00006184 // If nothing changed, just retain the existing expression.
6185 if (!getDerived().AlwaysRebuild() &&
6186 Base.get() == E->getBase())
6187 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006188
Douglas Gregord51d90d2010-04-26 20:11:03 +00006189 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6190 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006191}
6192
Mike Stump11289f42009-09-09 15:08:12 +00006193template<typename Derived>
6194Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 bool ArgumentChanged = false;
6197 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6198 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6199 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6200 if (SubExpr.isInvalid())
6201 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6204 SubExprs.push_back(SubExpr.takeAs<Expr>());
6205 }
Mike Stump11289f42009-09-09 15:08:12 +00006206
Douglas Gregora16548e2009-08-11 05:31:07 +00006207 if (!getDerived().AlwaysRebuild() &&
6208 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006209 return SemaRef.Owned(E->Retain());
6210
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6212 move_arg(SubExprs),
6213 E->getRParenLoc());
6214}
6215
Mike Stump11289f42009-09-09 15:08:12 +00006216template<typename Derived>
6217Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006218TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006219 SourceLocation CaretLoc(E->getExprLoc());
6220
6221 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6222 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6223 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6224 llvm::SmallVector<ParmVarDecl*, 4> Params;
6225 llvm::SmallVector<QualType, 4> ParamTypes;
6226
6227 // Parameter substitution.
6228 const BlockDecl *BD = E->getBlockDecl();
6229 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6230 EN = BD->param_end(); P != EN; ++P) {
6231 ParmVarDecl *OldParm = (*P);
6232 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6233 QualType NewType = NewParm->getType();
6234 Params.push_back(NewParm);
6235 ParamTypes.push_back(NewParm->getType());
6236 }
6237
6238 const FunctionType *BExprFunctionType = E->getFunctionType();
6239 QualType BExprResultType = BExprFunctionType->getResultType();
6240 if (!BExprResultType.isNull()) {
6241 if (!BExprResultType->isDependentType())
6242 CurBlock->ReturnType = BExprResultType;
6243 else if (BExprResultType != SemaRef.Context.DependentTy)
6244 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6245 }
6246
6247 // Transform the body
6248 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6249 if (Body.isInvalid())
6250 return SemaRef.ExprError();
6251 // Set the parameters on the block decl.
6252 if (!Params.empty())
6253 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6254
6255 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6256 CurBlock->ReturnType,
6257 ParamTypes.data(),
6258 ParamTypes.size(),
6259 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006260 0,
6261 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006262
6263 CurBlock->FunctionType = FunctionType;
6264 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006265}
6266
Mike Stump11289f42009-09-09 15:08:12 +00006267template<typename Derived>
6268Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006269TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006270 NestedNameSpecifier *Qualifier = 0;
6271
6272 ValueDecl *ND
6273 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6274 E->getDecl()));
6275 if (!ND)
6276 return SemaRef.ExprError();
6277
6278 if (!getDerived().AlwaysRebuild() &&
6279 ND == E->getDecl()) {
6280 // Mark it referenced in the new context regardless.
6281 // FIXME: this is a bit instantiation-specific.
6282 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6283
6284 return SemaRef.Owned(E->Retain());
6285 }
6286
6287 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
6288 ND, E->getLocation(), 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006289}
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006292// Type reconstruction
6293//===----------------------------------------------------------------------===//
6294
Mike Stump11289f42009-09-09 15:08:12 +00006295template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006296QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6297 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006298 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006299 getDerived().getBaseEntity());
6300}
6301
Mike Stump11289f42009-09-09 15:08:12 +00006302template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006303QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6304 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006305 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006306 getDerived().getBaseEntity());
6307}
6308
Mike Stump11289f42009-09-09 15:08:12 +00006309template<typename Derived>
6310QualType
John McCall70dd5f62009-10-30 00:06:24 +00006311TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6312 bool WrittenAsLValue,
6313 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006314 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
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
John McCall70dd5f62009-10-30 00:06:24 +00006320TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6321 QualType ClassType,
6322 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006323 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006324 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006325}
6326
6327template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006328QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006329TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6330 ArrayType::ArraySizeModifier SizeMod,
6331 const llvm::APInt *Size,
6332 Expr *SizeExpr,
6333 unsigned IndexTypeQuals,
6334 SourceRange BracketsRange) {
6335 if (SizeExpr || !Size)
6336 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6337 IndexTypeQuals, BracketsRange,
6338 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006339
6340 QualType Types[] = {
6341 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6342 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6343 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006344 };
6345 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6346 QualType SizeType;
6347 for (unsigned I = 0; I != NumTypes; ++I)
6348 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6349 SizeType = Types[I];
6350 break;
6351 }
Mike Stump11289f42009-09-09 15:08:12 +00006352
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006354 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006355 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006356 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006357}
Mike Stump11289f42009-09-09 15:08:12 +00006358
Douglas Gregord6ff3322009-08-04 16:50:30 +00006359template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006360QualType
6361TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006362 ArrayType::ArraySizeModifier SizeMod,
6363 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006364 unsigned IndexTypeQuals,
6365 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006366 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006367 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006368}
6369
6370template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006371QualType
Mike Stump11289f42009-09-09 15:08:12 +00006372TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006373 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006374 unsigned IndexTypeQuals,
6375 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006376 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006377 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006378}
Mike Stump11289f42009-09-09 15:08:12 +00006379
Douglas Gregord6ff3322009-08-04 16:50:30 +00006380template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006381QualType
6382TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006383 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006384 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006385 unsigned IndexTypeQuals,
6386 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006387 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006388 SizeExpr.takeAs<Expr>(),
6389 IndexTypeQuals, BracketsRange);
6390}
6391
6392template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006393QualType
6394TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006395 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006397 unsigned IndexTypeQuals,
6398 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006399 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006400 SizeExpr.takeAs<Expr>(),
6401 IndexTypeQuals, BracketsRange);
6402}
6403
6404template<typename Derived>
6405QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006406 unsigned NumElements,
6407 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006408 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006409 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410}
Mike Stump11289f42009-09-09 15:08:12 +00006411
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412template<typename Derived>
6413QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6414 unsigned NumElements,
6415 SourceLocation AttributeLoc) {
6416 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6417 NumElements, true);
6418 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006419 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006420 AttributeLoc);
6421 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6422 AttributeLoc);
6423}
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregord6ff3322009-08-04 16:50:30 +00006425template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006426QualType
6427TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429 SourceLocation AttributeLoc) {
6430 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6431}
Mike Stump11289f42009-09-09 15:08:12 +00006432
Douglas Gregord6ff3322009-08-04 16:50:30 +00006433template<typename Derived>
6434QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006435 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006437 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006438 unsigned Quals,
6439 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006440 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006441 Quals,
6442 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006443 getDerived().getBaseEntity(),
6444 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006445}
Mike Stump11289f42009-09-09 15:08:12 +00006446
Douglas Gregord6ff3322009-08-04 16:50:30 +00006447template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006448QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6449 return SemaRef.Context.getFunctionNoProtoType(T);
6450}
6451
6452template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006453QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6454 assert(D && "no decl found");
6455 if (D->isInvalidDecl()) return QualType();
6456
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006457 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006458 TypeDecl *Ty;
6459 if (isa<UsingDecl>(D)) {
6460 UsingDecl *Using = cast<UsingDecl>(D);
6461 assert(Using->isTypeName() &&
6462 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6463
6464 // A valid resolved using typename decl points to exactly one type decl.
6465 assert(++Using->shadow_begin() == Using->shadow_end());
6466 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006467
John McCallb96ec562009-12-04 22:46:56 +00006468 } else {
6469 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6470 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6471 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6472 }
6473
6474 return SemaRef.Context.getTypeDeclType(Ty);
6475}
6476
6477template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006478QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006479 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6480}
6481
6482template<typename Derived>
6483QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6484 return SemaRef.Context.getTypeOfType(Underlying);
6485}
6486
6487template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006488QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006489 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6490}
6491
6492template<typename Derived>
6493QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006494 TemplateName Template,
6495 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006496 const TemplateArgumentListInfo &TemplateArgs) {
6497 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006498}
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregor1135c352009-08-06 05:28:30 +00006500template<typename Derived>
6501NestedNameSpecifier *
6502TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6503 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006504 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006505 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006506 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006507 CXXScopeSpec SS;
6508 // FIXME: The source location information is all wrong.
6509 SS.setRange(Range);
6510 SS.setScopeRep(Prefix);
6511 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006512 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006513 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006514 ObjectType,
6515 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006516 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006517}
6518
6519template<typename Derived>
6520NestedNameSpecifier *
6521TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6522 SourceRange Range,
6523 NamespaceDecl *NS) {
6524 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6525}
6526
6527template<typename Derived>
6528NestedNameSpecifier *
6529TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6530 SourceRange Range,
6531 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006532 QualType T) {
6533 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006534 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006535 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006536 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6537 T.getTypePtr());
6538 }
Mike Stump11289f42009-09-09 15:08:12 +00006539
Douglas Gregor1135c352009-08-06 05:28:30 +00006540 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6541 return 0;
6542}
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregor71dc5092009-08-06 06:41:21 +00006544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006545TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006546TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6547 bool TemplateKW,
6548 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006549 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006550 Template);
6551}
6552
6553template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006554TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006555TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006556 const IdentifierInfo &II,
6557 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006558 CXXScopeSpec SS;
6559 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006560 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006561 UnqualifiedId Name;
6562 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006563 Sema::TemplateTy Template;
6564 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6565 /*FIXME:*/getDerived().getBaseLocation(),
6566 SS,
6567 Name,
6568 ObjectType.getAsOpaquePtr(),
6569 /*EnteringContext=*/false,
6570 Template);
6571 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006572}
Mike Stump11289f42009-09-09 15:08:12 +00006573
Douglas Gregora16548e2009-08-11 05:31:07 +00006574template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006575TemplateName
6576TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6577 OverloadedOperatorKind Operator,
6578 QualType ObjectType) {
6579 CXXScopeSpec SS;
6580 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6581 SS.setScopeRep(Qualifier);
6582 UnqualifiedId Name;
6583 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6584 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6585 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006586 Sema::TemplateTy Template;
6587 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006588 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006589 SS,
6590 Name,
6591 ObjectType.getAsOpaquePtr(),
6592 /*EnteringContext=*/false,
6593 Template);
6594 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006595}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006596
Douglas Gregor71395fa2009-11-04 00:56:37 +00006597template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006598Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006599TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6600 SourceLocation OpLoc,
6601 ExprArg Callee,
6602 ExprArg First,
6603 ExprArg Second) {
6604 Expr *FirstExpr = (Expr *)First.get();
6605 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006606 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006607 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006608
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006610 if (Op == OO_Subscript) {
6611 if (!FirstExpr->getType()->isOverloadableType() &&
6612 !SecondExpr->getType()->isOverloadableType())
6613 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006614 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006615 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006616 } else if (Op == OO_Arrow) {
6617 // -> is never a builtin operation.
6618 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006619 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 if (!FirstExpr->getType()->isOverloadableType()) {
6621 // The argument is not of overloadable type, so try to create a
6622 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006623 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6627 }
6628 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006629 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 !SecondExpr->getType()->isOverloadableType()) {
6631 // Neither of the arguments is an overloadable type, so try to
6632 // create a built-in binary operation.
6633 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006634 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006635 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6636 if (Result.isInvalid())
6637 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregora16548e2009-08-11 05:31:07 +00006639 First.release();
6640 Second.release();
6641 return move(Result);
6642 }
6643 }
Mike Stump11289f42009-09-09 15:08:12 +00006644
6645 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006646 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006647 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006648
John McCalld14a8642009-11-21 08:51:07 +00006649 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6650 assert(ULE->requiresADL());
6651
6652 // FIXME: Do we have to check
6653 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006654 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006655 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006656 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006657 }
Mike Stump11289f42009-09-09 15:08:12 +00006658
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 // Add any functions found via argument-dependent lookup.
6660 Expr *Args[2] = { FirstExpr, SecondExpr };
6661 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 // Create the overloaded operator invocation for unary operators.
6664 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006665 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6667 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6668 }
Mike Stump11289f42009-09-09 15:08:12 +00006669
Sebastian Redladba46e2009-10-29 20:17:01 +00006670 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006671 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6672 OpLoc,
6673 move(First),
6674 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006675
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006677 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006679 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6681 if (Result.isInvalid())
6682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006683
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 First.release();
6685 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006686 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006687}
Mike Stump11289f42009-09-09 15:08:12 +00006688
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006689template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006690Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006691TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6692 SourceLocation OperatorLoc,
6693 bool isArrow,
6694 NestedNameSpecifier *Qualifier,
6695 SourceRange QualifierRange,
6696 TypeSourceInfo *ScopeType,
6697 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006698 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006699 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006700 CXXScopeSpec SS;
6701 if (Qualifier) {
6702 SS.setRange(QualifierRange);
6703 SS.setScopeRep(Qualifier);
6704 }
6705
6706 Expr *BaseE = (Expr *)Base.get();
6707 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006708 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006709 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006710 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006711 !BaseType->getAs<PointerType>()->getPointeeType()
6712 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006713 // This pseudo-destructor expression is still a pseudo-destructor.
6714 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6715 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006716 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006717 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006718 /*FIXME?*/true);
6719 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006720
Douglas Gregor678f90d2010-02-25 01:56:36 +00006721 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006722 DeclarationName Name
6723 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6724 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006725
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006726 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006727
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006728 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6729 OperatorLoc, isArrow,
6730 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006731 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006732 /*TemplateArgs*/ 0);
6733}
6734
Douglas Gregord6ff3322009-08-04 16:50:30 +00006735} // end namespace clang
6736
6737#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H