blob: a2ace07576c1574f135956dd229dfca3c34b4cbc [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;
99
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 }
184
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.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 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 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 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.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 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 ///
253 /// This specific declaration transformation only applies to the first
254 /// 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.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
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
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 QualType
337 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);
Mike Stump11289f42009-09-09 15:08:12 +0000341
Douglas Gregorebe10102009-08-20 07:17:43 +0000342#define STMT(Node, Parent) \
343 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000344#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000345 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000346#define ABSTRACT_EXPR(Node, Parent)
347#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000348
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 /// \brief Build a new pointer type given its pointee type.
350 ///
351 /// By default, performs semantic analysis when building the pointer type.
352 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000353 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000354
355 /// \brief Build a new block pointer type given its pointee type.
356 ///
Mike Stump11289f42009-09-09 15:08:12 +0000357 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000358 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000359 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000360
John McCall70dd5f62009-10-30 00:06:24 +0000361 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000362 ///
John McCall70dd5f62009-10-30 00:06:24 +0000363 /// By default, performs semantic analysis when building the
364 /// reference type. Subclasses may override this routine to provide
365 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000366 ///
John McCall70dd5f62009-10-30 00:06:24 +0000367 /// \param LValue whether the type was written with an lvalue sigil
368 /// or an rvalue sigil.
369 QualType RebuildReferenceType(QualType ReferentType,
370 bool LValue,
371 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Douglas Gregord6ff3322009-08-04 16:50:30 +0000373 /// \brief Build a new member pointer type given the pointee type and the
374 /// class type it refers into.
375 ///
376 /// By default, performs semantic analysis when building the member pointer
377 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000378 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
379 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000380
John McCall550e0c22009-10-21 00:40:46 +0000381 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000382 QualType RebuildObjCObjectPointerType(QualType PointeeType,
383 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000384
Douglas Gregord6ff3322009-08-04 16:50:30 +0000385 /// \brief Build a new array type given the element type, size
386 /// modifier, size of the array (if known), size expression, and index type
387 /// qualifiers.
388 ///
389 /// By default, performs semantic analysis when building the array type.
390 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000391 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392 QualType RebuildArrayType(QualType ElementType,
393 ArrayType::ArraySizeModifier SizeMod,
394 const llvm::APInt *Size,
395 Expr *SizeExpr,
396 unsigned IndexTypeQuals,
397 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Build a new constant array type given the element type, size
400 /// modifier, (known) size of the array, and index type qualifiers.
401 ///
402 /// By default, performs semantic analysis when building the array type.
403 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000404 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 ArrayType::ArraySizeModifier SizeMod,
406 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000407 unsigned IndexTypeQuals,
408 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000409
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// \brief Build a new incomplete array type given the element type, size
411 /// modifier, and index type qualifiers.
412 ///
413 /// By default, performs semantic analysis when building the array type.
414 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000415 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000417 unsigned IndexTypeQuals,
418 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000419
Mike Stump11289f42009-09-09 15:08:12 +0000420 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 /// size modifier, size expression, and index type qualifiers.
422 ///
423 /// By default, performs semantic analysis when building the array type.
424 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000425 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000426 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000427 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000428 unsigned IndexTypeQuals,
429 SourceRange BracketsRange);
430
Mike Stump11289f42009-09-09 15:08:12 +0000431 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 /// size modifier, size expression, and index type qualifiers.
433 ///
434 /// By default, performs semantic analysis when building the array type.
435 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000436 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000437 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000438 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000439 unsigned IndexTypeQuals,
440 SourceRange BracketsRange);
441
442 /// \brief Build a new vector type given the element type and
443 /// number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000447 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
448 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new extended vector type given the element type and
451 /// number of elements.
452 ///
453 /// By default, performs semantic analysis when building the vector type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
456 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000457
458 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000459 /// given the element type and number of elements.
460 ///
461 /// By default, performs semantic analysis when building the vector type.
462 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000463 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000464 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000465 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000466
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467 /// \brief Build a new function type.
468 ///
469 /// By default, performs semantic analysis when building the function type.
470 /// Subclasses may override this routine to provide different behavior.
471 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000472 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000473 unsigned NumParamTypes,
474 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000475
John McCall550e0c22009-10-21 00:40:46 +0000476 /// \brief Build a new unprototyped function type.
477 QualType RebuildFunctionNoProtoType(QualType ResultType);
478
John McCallb96ec562009-12-04 22:46:56 +0000479 /// \brief Rebuild an unresolved typename type, given the decl that
480 /// the UnresolvedUsingTypenameDecl was transformed to.
481 QualType RebuildUnresolvedUsingType(Decl *D);
482
Douglas Gregord6ff3322009-08-04 16:50:30 +0000483 /// \brief Build a new typedef type.
484 QualType RebuildTypedefType(TypedefDecl *Typedef) {
485 return SemaRef.Context.getTypeDeclType(Typedef);
486 }
487
488 /// \brief Build a new class/struct/union type.
489 QualType RebuildRecordType(RecordDecl *Record) {
490 return SemaRef.Context.getTypeDeclType(Record);
491 }
492
493 /// \brief Build a new Enum type.
494 QualType RebuildEnumType(EnumDecl *Enum) {
495 return SemaRef.Context.getTypeDeclType(Enum);
496 }
John McCallfcc33b02009-09-05 00:15:47 +0000497
498 /// \brief Build a new elaborated type.
499 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
500 return SemaRef.Context.getElaboratedType(T, Tag);
501 }
Mike Stump11289f42009-09-09 15:08:12 +0000502
503 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000504 ///
505 /// By default, performs semantic analysis when building the typeof type.
506 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000507 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508
Mike Stump11289f42009-09-09 15:08:12 +0000509 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000510 ///
511 /// By default, builds a new TypeOfType with the given underlying type.
512 QualType RebuildTypeOfType(QualType Underlying);
513
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000515 ///
516 /// By default, performs semantic analysis when building the decltype type.
517 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000518 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 /// \brief Build a new template specialization type.
521 ///
522 /// By default, performs semantic analysis when building the template
523 /// specialization type. Subclasses may override this routine to provide
524 /// different behavior.
525 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000526 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000527 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000528
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 /// \brief Build a new qualified name type.
530 ///
Mike Stump11289f42009-09-09 15:08:12 +0000531 /// By default, builds a new QualifiedNameType type from the
532 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 /// this routine to provide different behavior.
534 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
535 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000536 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
538 /// \brief Build a new typename type that refers to a template-id.
539 ///
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +0000540 /// By default, builds a new DependentNameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000541 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000543 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
544 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 if (NNS->isDependent()) {
546 CXXScopeSpec SS;
547 SS.setScopeRep(NNS);
548 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000549 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000551 }
Mike Stump11289f42009-09-09 15:08:12 +0000552
Douglas Gregor02085352010-03-31 20:19:30 +0000553 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000555 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556
557 /// \brief Build a new typename type that refers to an identifier.
558 ///
559 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000560 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000561 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000562 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
563 NestedNameSpecifier *NNS,
564 const IdentifierInfo *Id,
565 SourceRange SR) {
566 // FIXME: Handle elaborated-type-specifiers separately.
John McCall0ad16662009-10-29 08:12:44 +0000567 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000568 }
Mike Stump11289f42009-09-09 15:08:12 +0000569
Douglas Gregor1135c352009-08-06 05:28:30 +0000570 /// \brief Build a new nested-name-specifier given the prefix and an
571 /// identifier that names the next step in the nested-name-specifier.
572 ///
573 /// By default, performs semantic analysis when building the new
574 /// nested-name-specifier. Subclasses may override this routine to provide
575 /// different behavior.
576 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
577 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000578 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000579 QualType ObjectType,
580 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000581
582 /// \brief Build a new nested-name-specifier given the prefix and the
583 /// namespace named in the next step in the nested-name-specifier.
584 ///
585 /// By default, performs semantic analysis when building the new
586 /// nested-name-specifier. Subclasses may override this routine to provide
587 /// different behavior.
588 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
589 SourceRange Range,
590 NamespaceDecl *NS);
591
592 /// \brief Build a new nested-name-specifier given the prefix and the
593 /// type named in the next step in the nested-name-specifier.
594 ///
595 /// By default, performs semantic analysis when building the new
596 /// nested-name-specifier. Subclasses may override this routine to provide
597 /// different behavior.
598 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
599 SourceRange Range,
600 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000601 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000602
603 /// \brief Build a new template name given a nested name specifier, a flag
604 /// indicating whether the "template" keyword was provided, and the template
605 /// that the template name refers to.
606 ///
607 /// By default, builds the new template name directly. Subclasses may override
608 /// this routine to provide different behavior.
609 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
610 bool TemplateKW,
611 TemplateDecl *Template);
612
Douglas Gregor71dc5092009-08-06 06:41:21 +0000613 /// \brief Build a new template name given a nested name specifier and the
614 /// name that is referred to as a template.
615 ///
616 /// By default, performs semantic analysis to determine whether the name can
617 /// be resolved to a specific template, then builds the appropriate kind of
618 /// template name. Subclasses may override this routine to provide different
619 /// behavior.
620 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000621 const IdentifierInfo &II,
622 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000623
Douglas Gregor71395fa2009-11-04 00:56:37 +0000624 /// \brief Build a new template name given a nested name specifier and the
625 /// overloaded operator name that is referred to as a template.
626 ///
627 /// By default, performs semantic analysis to determine whether the name can
628 /// be resolved to a specific template, then builds the appropriate kind of
629 /// template name. Subclasses may override this routine to provide different
630 /// behavior.
631 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
632 OverloadedOperatorKind Operator,
633 QualType ObjectType);
634
Douglas Gregorebe10102009-08-20 07:17:43 +0000635 /// \brief Build a new compound statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
639 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
640 MultiStmtArg Statements,
641 SourceLocation RBraceLoc,
642 bool IsStmtExpr) {
643 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
644 IsStmtExpr);
645 }
646
647 /// \brief Build a new case statement.
648 ///
649 /// By default, performs semantic analysis to build the new statement.
650 /// Subclasses may override this routine to provide different behavior.
651 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
652 ExprArg LHS,
653 SourceLocation EllipsisLoc,
654 ExprArg RHS,
655 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000656 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000657 ColonLoc);
658 }
Mike Stump11289f42009-09-09 15:08:12 +0000659
Douglas Gregorebe10102009-08-20 07:17:43 +0000660 /// \brief Attach the body to a new case statement.
661 ///
662 /// By default, performs semantic analysis to build the new statement.
663 /// Subclasses may override this routine to provide different behavior.
664 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
665 getSema().ActOnCaseStmtBody(S.get(), move(Body));
666 return move(S);
667 }
Mike Stump11289f42009-09-09 15:08:12 +0000668
Douglas Gregorebe10102009-08-20 07:17:43 +0000669 /// \brief Build a new default statement.
670 ///
671 /// By default, performs semantic analysis to build the new statement.
672 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000673 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000674 SourceLocation ColonLoc,
675 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000676 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000677 /*CurScope=*/0);
678 }
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregorebe10102009-08-20 07:17:43 +0000680 /// \brief Build a new label statement.
681 ///
682 /// By default, performs semantic analysis to build the new statement.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000684 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000685 IdentifierInfo *Id,
686 SourceLocation ColonLoc,
687 StmtArg SubStmt) {
688 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
689 }
Mike Stump11289f42009-09-09 15:08:12 +0000690
Douglas Gregorebe10102009-08-20 07:17:43 +0000691 /// \brief Build a new "if" statement.
692 ///
693 /// By default, performs semantic analysis to build the new statement.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000695 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000696 VarDecl *CondVar, StmtArg Then,
697 SourceLocation ElseLoc, StmtArg Else) {
698 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
699 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000700 }
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregorebe10102009-08-20 07:17:43 +0000702 /// \brief Start building a new switch statement.
703 ///
704 /// By default, performs semantic analysis to build the new statement.
705 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000706 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
707 VarDecl *CondVar) {
708 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 }
Mike Stump11289f42009-09-09 15:08:12 +0000710
Douglas Gregorebe10102009-08-20 07:17:43 +0000711 /// \brief Attach the body to the switch statement.
712 ///
713 /// By default, performs semantic analysis to build the new statement.
714 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000715 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000716 StmtArg Switch, StmtArg Body) {
717 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
718 move(Body));
719 }
720
721 /// \brief Build a new while statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
725 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
726 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000727 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000729 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
730 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 }
Mike Stump11289f42009-09-09 15:08:12 +0000732
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 /// \brief Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
738 SourceLocation WhileLoc,
739 SourceLocation LParenLoc,
740 ExprArg Cond,
741 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000742 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 move(Cond), RParenLoc);
744 }
745
746 /// \brief Build a new for statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000752 StmtArg Init, Sema::FullExprArg Cond,
753 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000755 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
756 DeclPtrTy::make(CondVar),
757 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 }
Mike Stump11289f42009-09-09 15:08:12 +0000759
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 /// \brief Build a new goto statement.
761 ///
762 /// By default, performs semantic analysis to build the new statement.
763 /// Subclasses may override this routine to provide different behavior.
764 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
765 SourceLocation LabelLoc,
766 LabelStmt *Label) {
767 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
768 }
769
770 /// \brief Build a new indirect goto statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
774 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
775 SourceLocation StarLoc,
776 ExprArg Target) {
777 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
778 }
Mike Stump11289f42009-09-09 15:08:12 +0000779
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 /// \brief Build a new return statement.
781 ///
782 /// By default, performs semantic analysis to build the new statement.
783 /// Subclasses may override this routine to provide different behavior.
784 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
785 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000786
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
788 }
Mike Stump11289f42009-09-09 15:08:12 +0000789
Douglas Gregorebe10102009-08-20 07:17:43 +0000790 /// \brief Build a new declaration statement.
791 ///
792 /// By default, performs semantic analysis to build the new statement.
793 /// Subclasses may override this routine to provide different behavior.
794 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000795 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000796 SourceLocation EndLoc) {
797 return getSema().Owned(
798 new (getSema().Context) DeclStmt(
799 DeclGroupRef::Create(getSema().Context,
800 Decls, NumDecls),
801 StartLoc, EndLoc));
802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Anders Carlssonaaeef072010-01-24 05:50:09 +0000804 /// \brief Build a new inline asm statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
809 bool IsSimple,
810 bool IsVolatile,
811 unsigned NumOutputs,
812 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000813 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000814 MultiExprArg Constraints,
815 MultiExprArg Exprs,
816 ExprArg AsmString,
817 MultiExprArg Clobbers,
818 SourceLocation RParenLoc,
819 bool MSAsm) {
820 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
821 NumInputs, Names, move(Constraints),
822 move(Exprs), move(AsmString), move(Clobbers),
823 RParenLoc, MSAsm);
824 }
825
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 /// \brief Build a new C++ exception declaration.
827 ///
828 /// By default, performs semantic analysis to build the new decaration.
829 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000830 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000831 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 IdentifierInfo *Name,
833 SourceLocation Loc,
834 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000835 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000836 TypeRange);
837 }
838
839 /// \brief Build a new C++ catch statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
843 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
844 VarDecl *ExceptionDecl,
845 StmtArg Handler) {
846 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000847 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000848 Handler.takeAs<Stmt>()));
849 }
Mike Stump11289f42009-09-09 15:08:12 +0000850
Douglas Gregorebe10102009-08-20 07:17:43 +0000851 /// \brief Build a new C++ try statement.
852 ///
853 /// By default, performs semantic analysis to build the new statement.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
856 StmtArg TryBlock,
857 MultiStmtArg Handlers) {
858 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
859 }
Mike Stump11289f42009-09-09 15:08:12 +0000860
Douglas Gregora16548e2009-08-11 05:31:07 +0000861 /// \brief Build a new expression that references a declaration.
862 ///
863 /// By default, performs semantic analysis to build the new expression.
864 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000865 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
866 LookupResult &R,
867 bool RequiresADL) {
868 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
869 }
870
871
872 /// \brief Build a new expression that references a declaration.
873 ///
874 /// By default, performs semantic analysis to build the new expression.
875 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000876 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
877 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000878 ValueDecl *VD, SourceLocation Loc,
879 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000880 CXXScopeSpec SS;
881 SS.setScopeRep(Qualifier);
882 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000883
884 // FIXME: loses template args.
885
886 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000887 }
Mike Stump11289f42009-09-09 15:08:12 +0000888
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000890 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// By default, performs semantic analysis to build the new expression.
892 /// Subclasses may override this routine to provide different behavior.
893 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
894 SourceLocation RParen) {
895 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
896 }
897
Douglas Gregorad8a3362009-09-04 17:36:40 +0000898 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000899 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000900 /// By default, performs semantic analysis to build the new expression.
901 /// Subclasses may override this routine to provide different behavior.
902 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
903 SourceLocation OperatorLoc,
904 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000905 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000906 SourceRange QualifierRange,
907 TypeSourceInfo *ScopeType,
908 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000909 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000910 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000911
Douglas Gregora16548e2009-08-11 05:31:07 +0000912 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000913 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 /// By default, performs semantic analysis to build the new expression.
915 /// Subclasses may override this routine to provide different behavior.
916 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
917 UnaryOperator::Opcode Opc,
918 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000919 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 }
Mike Stump11289f42009-09-09 15:08:12 +0000921
Douglas Gregora16548e2009-08-11 05:31:07 +0000922 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000923 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000924 /// By default, performs semantic analysis to build the new expression.
925 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000926 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000927 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000929 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000930 }
931
Mike Stump11289f42009-09-09 15:08:12 +0000932 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000933 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000934 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000935 /// By default, performs semantic analysis to build the new expression.
936 /// Subclasses may override this routine to provide different behavior.
937 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
938 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000939 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000940 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
941 OpLoc, isSizeOf, R);
942 if (Result.isInvalid())
943 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000944
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 SubExpr.release();
946 return move(Result);
947 }
Mike Stump11289f42009-09-09 15:08:12 +0000948
Douglas Gregora16548e2009-08-11 05:31:07 +0000949 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000950 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000951 /// By default, performs semantic analysis to build the new expression.
952 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000953 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000954 SourceLocation LBracketLoc,
955 ExprArg RHS,
956 SourceLocation RBracketLoc) {
957 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000958 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000959 RBracketLoc);
960 }
961
962 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000963 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000964 /// By default, performs semantic analysis to build the new expression.
965 /// Subclasses may override this routine to provide different behavior.
966 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
967 MultiExprArg Args,
968 SourceLocation *CommaLocs,
969 SourceLocation RParenLoc) {
970 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
971 move(Args), CommaLocs, RParenLoc);
972 }
973
974 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000975 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000976 /// By default, performs semantic analysis to build the new expression.
977 /// Subclasses may override this routine to provide different behavior.
978 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000979 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000980 NestedNameSpecifier *Qualifier,
981 SourceRange QualifierRange,
982 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000983 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +0000984 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +0000985 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000986 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000987 if (!Member->getDeclName()) {
988 // We have a reference to an unnamed field.
989 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000990
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000991 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +0000992 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
993 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000994 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000995
Mike Stump11289f42009-09-09 15:08:12 +0000996 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000997 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000998 Member, MemberLoc,
999 cast<FieldDecl>(Member)->getType());
1000 return getSema().Owned(ME);
1001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001003 CXXScopeSpec SS;
1004 if (Qualifier) {
1005 SS.setRange(QualifierRange);
1006 SS.setScopeRep(Qualifier);
1007 }
1008
John McCall2d74de92009-12-01 22:10:20 +00001009 QualType BaseType = ((Expr*) Base.get())->getType();
1010
John McCall16df1e52010-03-30 21:47:33 +00001011 // FIXME: this involves duplicating earlier analysis in a lot of
1012 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001013 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1014 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001015 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001016 R.resolveKind();
1017
John McCall2d74de92009-12-01 22:10:20 +00001018 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1019 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001020 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001021 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001022 }
Mike Stump11289f42009-09-09 15:08:12 +00001023
Douglas Gregora16548e2009-08-11 05:31:07 +00001024 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001025 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
1028 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1029 BinaryOperator::Opcode Opc,
1030 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001031 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1032 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001033 }
1034
1035 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001036 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
1039 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1040 SourceLocation QuestionLoc,
1041 ExprArg LHS,
1042 SourceLocation ColonLoc,
1043 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001044 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 move(LHS), move(RHS));
1046 }
1047
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001052 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1053 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 SourceLocation RParenLoc,
1055 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001056 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1057 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 }
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001061 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001065 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 SourceLocation RParenLoc,
1067 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001068 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1069 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001073 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001076 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001077 SourceLocation OpLoc,
1078 SourceLocation AccessorLoc,
1079 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001080
John McCall10eae182009-11-30 22:42:35 +00001081 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001082 QualType BaseType = ((Expr*) Base.get())->getType();
1083 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001084 OpLoc, /*IsArrow*/ false,
1085 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001086 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001087 AccessorLoc,
1088 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
1095 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1096 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001097 SourceLocation RBraceLoc,
1098 QualType ResultTy) {
1099 OwningExprResult Result
1100 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1101 if (Result.isInvalid() || ResultTy->isDependentType())
1102 return move(Result);
1103
1104 // Patch in the result type we were given, which may have been computed
1105 // when the initial InitListExpr was built.
1106 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1107 ILE->setType(ResultTy);
1108 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 }
Mike Stump11289f42009-09-09 15:08:12 +00001110
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
1115 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1116 MultiExprArg ArrayExprs,
1117 SourceLocation EqualOrColonLoc,
1118 bool GNUSyntax,
1119 ExprArg Init) {
1120 OwningExprResult Result
1121 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1122 move(Init));
1123 if (Result.isInvalid())
1124 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 ArrayExprs.release();
1127 return move(Result);
1128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001131 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 /// By default, builds the implicit value initialization without performing
1133 /// any semantic analysis. Subclasses may override this routine to provide
1134 /// different behavior.
1135 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1136 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1137 }
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001140 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 /// By default, performs semantic analysis to build the new expression.
1142 /// Subclasses may override this routine to provide different behavior.
1143 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1144 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001145 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 RParenLoc);
1147 }
1148
1149 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001150 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001151 /// By default, performs semantic analysis to build the new expression.
1152 /// Subclasses may override this routine to provide different behavior.
1153 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1154 MultiExprArg SubExprs,
1155 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001156 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1157 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 }
Mike Stump11289f42009-09-09 15:08:12 +00001159
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001161 ///
1162 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001163 /// rather than attempting to map the label statement itself.
1164 /// Subclasses may override this routine to provide different behavior.
1165 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1166 SourceLocation LabelLoc,
1167 LabelStmt *Label) {
1168 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001172 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 /// By default, performs semantic analysis to build the new expression.
1174 /// Subclasses may override this routine to provide different behavior.
1175 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1176 StmtArg SubStmt,
1177 SourceLocation RParenLoc) {
1178 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1179 }
Mike Stump11289f42009-09-09 15:08:12 +00001180
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 /// \brief Build a new __builtin_types_compatible_p expression.
1182 ///
1183 /// By default, performs semantic analysis to build the new expression.
1184 /// Subclasses may override this routine to provide different behavior.
1185 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1186 QualType T1, QualType T2,
1187 SourceLocation RParenLoc) {
1188 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1189 T1.getAsOpaquePtr(),
1190 T2.getAsOpaquePtr(),
1191 RParenLoc);
1192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new __builtin_choose_expr expression.
1195 ///
1196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
1198 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1199 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1200 SourceLocation RParenLoc) {
1201 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1202 move(Cond), move(LHS), move(RHS),
1203 RParenLoc);
1204 }
Mike Stump11289f42009-09-09 15:08:12 +00001205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new overloaded operator call expression.
1207 ///
1208 /// By default, performs semantic analysis to build the new expression.
1209 /// The semantic analysis provides the behavior of template instantiation,
1210 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001211 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 /// argument-dependent lookup, etc. Subclasses may override this routine to
1213 /// provide different behavior.
1214 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1215 SourceLocation OpLoc,
1216 ExprArg Callee,
1217 ExprArg First,
1218 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001219
1220 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// reinterpret_cast.
1222 ///
1223 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001224 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// Subclasses may override this routine to provide different behavior.
1226 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1227 Stmt::StmtClass Class,
1228 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001229 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 SourceLocation RAngleLoc,
1231 SourceLocation LParenLoc,
1232 ExprArg SubExpr,
1233 SourceLocation RParenLoc) {
1234 switch (Class) {
1235 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001236 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001237 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 move(SubExpr), RParenLoc);
1239
1240 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001241 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001242 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001244
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001246 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001247 RAngleLoc, LParenLoc,
1248 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001252 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001253 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001255
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 default:
1257 assert(false && "Invalid C++ named cast");
1258 break;
1259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 return getSema().ExprError();
1262 }
Mike Stump11289f42009-09-09 15:08:12 +00001263
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 /// \brief Build a new C++ static_cast expression.
1265 ///
1266 /// By default, performs semantic analysis to build the new expression.
1267 /// Subclasses may override this routine to provide different behavior.
1268 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1269 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001270 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 SourceLocation RAngleLoc,
1272 SourceLocation LParenLoc,
1273 ExprArg SubExpr,
1274 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001275 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1276 TInfo, move(SubExpr),
1277 SourceRange(LAngleLoc, RAngleLoc),
1278 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 }
1280
1281 /// \brief Build a new C++ dynamic_cast expression.
1282 ///
1283 /// By default, performs semantic analysis to build the new expression.
1284 /// Subclasses may override this routine to provide different behavior.
1285 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1286 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001287 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 SourceLocation RAngleLoc,
1289 SourceLocation LParenLoc,
1290 ExprArg SubExpr,
1291 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001292 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1293 TInfo, move(SubExpr),
1294 SourceRange(LAngleLoc, RAngleLoc),
1295 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 }
1297
1298 /// \brief Build a new C++ reinterpret_cast expression.
1299 ///
1300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1303 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001304 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 SourceLocation RAngleLoc,
1306 SourceLocation LParenLoc,
1307 ExprArg SubExpr,
1308 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001309 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1310 TInfo, move(SubExpr),
1311 SourceRange(LAngleLoc, RAngleLoc),
1312 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 }
1314
1315 /// \brief Build a new C++ const_cast expression.
1316 ///
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1320 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001321 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 SourceLocation RAngleLoc,
1323 SourceLocation LParenLoc,
1324 ExprArg SubExpr,
1325 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001326 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1327 TInfo, move(SubExpr),
1328 SourceRange(LAngleLoc, RAngleLoc),
1329 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new C++ functional-style cast expression.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001337 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation LParenLoc,
1339 ExprArg SubExpr,
1340 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001341 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001343 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001345 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001346 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 RParenLoc);
1348 }
Mike Stump11289f42009-09-09 15:08:12 +00001349
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// \brief Build a new C++ typeid(type) expression.
1351 ///
1352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
1354 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1355 SourceLocation LParenLoc,
1356 QualType T,
1357 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001358 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 T.getAsOpaquePtr(), RParenLoc);
1360 }
Mike Stump11289f42009-09-09 15:08:12 +00001361
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 /// \brief Build a new C++ typeid(expr) expression.
1363 ///
1364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
1366 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1367 SourceLocation LParenLoc,
1368 ExprArg Operand,
1369 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001370 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1372 RParenLoc);
1373 if (Result.isInvalid())
1374 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001375
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1377 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001378 }
1379
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// \brief Build a new C++ "this" expression.
1381 ///
1382 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001383 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001385 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001386 QualType ThisType,
1387 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001389 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1390 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 }
1392
1393 /// \brief Build a new C++ throw expression.
1394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
1397 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1398 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1399 }
1400
1401 /// \brief Build a new C++ default-argument expression.
1402 ///
1403 /// By default, builds a new default-argument expression, which does not
1404 /// require any semantic analysis. Subclasses may override this routine to
1405 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001406 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1407 ParmVarDecl *Param) {
1408 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1409 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 }
1411
1412 /// \brief Build a new C++ zero-initialization expression.
1413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001416 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 SourceLocation LParenLoc,
1418 QualType T,
1419 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001420 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1421 T.getAsOpaquePtr(), LParenLoc,
1422 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 0, RParenLoc);
1424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// \brief Build a new C++ "new" expression.
1427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001430 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 bool UseGlobal,
1432 SourceLocation PlacementLParen,
1433 MultiExprArg PlacementArgs,
1434 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001435 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 QualType AllocType,
1437 SourceLocation TypeLoc,
1438 SourceRange TypeRange,
1439 ExprArg ArraySize,
1440 SourceLocation ConstructorLParen,
1441 MultiExprArg ConstructorArgs,
1442 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001443 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 PlacementLParen,
1445 move(PlacementArgs),
1446 PlacementRParen,
1447 ParenTypeId,
1448 AllocType,
1449 TypeLoc,
1450 TypeRange,
1451 move(ArraySize),
1452 ConstructorLParen,
1453 move(ConstructorArgs),
1454 ConstructorRParen);
1455 }
Mike Stump11289f42009-09-09 15:08:12 +00001456
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 /// \brief Build a new C++ "delete" expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
1461 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1462 bool IsGlobalDelete,
1463 bool IsArrayForm,
1464 ExprArg Operand) {
1465 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1466 move(Operand));
1467 }
Mike Stump11289f42009-09-09 15:08:12 +00001468
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 /// \brief Build a new unary type trait expression.
1470 ///
1471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
1473 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 QualType T,
1477 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001478 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 T.getAsOpaquePtr(), RParenLoc);
1480 }
1481
Mike Stump11289f42009-09-09 15:08:12 +00001482 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 /// expression.
1484 ///
1485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001487 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 SourceRange QualifierRange,
1489 DeclarationName Name,
1490 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001491 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 CXXScopeSpec SS;
1493 SS.setRange(QualifierRange);
1494 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001495
1496 if (TemplateArgs)
1497 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1498 *TemplateArgs);
1499
1500 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 }
1502
1503 /// \brief Build a new template-id expression.
1504 ///
1505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001507 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1508 LookupResult &R,
1509 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001510 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001511 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 }
1513
1514 /// \brief Build a new object-construction expression.
1515 ///
1516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
1518 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001519 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 CXXConstructorDecl *Constructor,
1521 bool IsElidable,
1522 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001523 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1524 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1525 ConvertedArgs))
1526 return getSema().ExprError();
1527
1528 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1529 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
1531
1532 /// \brief Build a new object-construction expression.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
1536 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1537 QualType T,
1538 SourceLocation LParenLoc,
1539 MultiExprArg Args,
1540 SourceLocation *Commas,
1541 SourceLocation RParenLoc) {
1542 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1543 T.getAsOpaquePtr(),
1544 LParenLoc,
1545 move(Args),
1546 Commas,
1547 RParenLoc);
1548 }
1549
1550 /// \brief Build a new object-construction expression.
1551 ///
1552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
1554 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1555 QualType T,
1556 SourceLocation LParenLoc,
1557 MultiExprArg Args,
1558 SourceLocation *Commas,
1559 SourceLocation RParenLoc) {
1560 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1561 /*FIXME*/LParenLoc),
1562 T.getAsOpaquePtr(),
1563 LParenLoc,
1564 move(Args),
1565 Commas,
1566 RParenLoc);
1567 }
Mike Stump11289f42009-09-09 15:08:12 +00001568
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// \brief Build a new member reference expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001573 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001574 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 bool IsArrow,
1576 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001577 NestedNameSpecifier *Qualifier,
1578 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001579 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001581 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001582 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001584 SS.setRange(QualifierRange);
1585 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001586
John McCall2d74de92009-12-01 22:10:20 +00001587 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1588 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001589 SS, FirstQualifierInScope,
1590 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 }
1592
John McCall10eae182009-11-30 22:42:35 +00001593 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001597 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001598 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001599 SourceLocation OperatorLoc,
1600 bool IsArrow,
1601 NestedNameSpecifier *Qualifier,
1602 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001603 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001604 LookupResult &R,
1605 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001606 CXXScopeSpec SS;
1607 SS.setRange(QualifierRange);
1608 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001609
John McCall2d74de92009-12-01 22:10:20 +00001610 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1611 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001612 SS, FirstQualifierInScope,
1613 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001614 }
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 /// \brief Build a new Objective-C @encode expression.
1617 ///
1618 /// By default, performs semantic analysis to build the new expression.
1619 /// Subclasses may override this routine to provide different behavior.
1620 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1621 QualType T,
1622 SourceLocation RParenLoc) {
1623 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1624 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001625 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001626
1627 /// \brief Build a new Objective-C protocol expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
1631 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1632 SourceLocation AtLoc,
1633 SourceLocation ProtoLoc,
1634 SourceLocation LParenLoc,
1635 SourceLocation RParenLoc) {
1636 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1637 Protocol->getIdentifier(),
1638 AtLoc,
1639 ProtoLoc,
1640 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001641 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 }
Mike Stump11289f42009-09-09 15:08:12 +00001643
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 /// \brief Build a new shuffle vector expression.
1645 ///
1646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
1648 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1649 MultiExprArg SubExprs,
1650 SourceLocation RParenLoc) {
1651 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001652 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1654 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1655 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1656 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 // Build a reference to the __builtin_shufflevector builtin
1659 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001660 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001662 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001664
1665 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 unsigned NumSubExprs = SubExprs.size();
1667 Expr **Subs = (Expr **)SubExprs.release();
1668 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1669 Subs, NumSubExprs,
1670 Builtin->getResultType(),
1671 RParenLoc);
1672 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001673
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 // Type-check the __builtin_shufflevector expression.
1675 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1676 if (Result.isInvalid())
1677 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001678
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001680 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001682};
Douglas Gregora16548e2009-08-11 05:31:07 +00001683
Douglas Gregorebe10102009-08-20 07:17:43 +00001684template<typename Derived>
1685Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1686 if (!S)
1687 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001688
Douglas Gregorebe10102009-08-20 07:17:43 +00001689 switch (S->getStmtClass()) {
1690 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001691
Douglas Gregorebe10102009-08-20 07:17:43 +00001692 // Transform individual statement nodes
1693#define STMT(Node, Parent) \
1694 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1695#define EXPR(Node, Parent)
1696#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregorebe10102009-08-20 07:17:43 +00001698 // Transform expressions by calling TransformExpr.
1699#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001700#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001701#define EXPR(Node, Parent) case Stmt::Node##Class:
1702#include "clang/AST/StmtNodes.def"
1703 {
1704 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1705 if (E.isInvalid())
1706 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001707
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001708 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001709 }
Mike Stump11289f42009-09-09 15:08:12 +00001710 }
1711
Douglas Gregorebe10102009-08-20 07:17:43 +00001712 return SemaRef.Owned(S->Retain());
1713}
Mike Stump11289f42009-09-09 15:08:12 +00001714
1715
Douglas Gregore922c772009-08-04 22:27:00 +00001716template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001717Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 if (!E)
1719 return SemaRef.Owned(E);
1720
1721 switch (E->getStmtClass()) {
1722 case Stmt::NoStmtClass: break;
1723#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001724#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001725#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001726 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001727#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001728 }
1729
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001731}
1732
1733template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001734NestedNameSpecifier *
1735TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001736 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001737 QualType ObjectType,
1738 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001739 if (!NNS)
1740 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregorebe10102009-08-20 07:17:43 +00001742 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001743 NestedNameSpecifier *Prefix = NNS->getPrefix();
1744 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001745 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001746 ObjectType,
1747 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001748 if (!Prefix)
1749 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001750
1751 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001752 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001753 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001754 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001755 }
Mike Stump11289f42009-09-09 15:08:12 +00001756
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 switch (NNS->getKind()) {
1758 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001759 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001760 "Identifier nested-name-specifier with no prefix or object type");
1761 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1762 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001763 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001764
1765 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001766 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001767 ObjectType,
1768 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregor1135c352009-08-06 05:28:30 +00001770 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001771 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001772 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001773 getDerived().TransformDecl(Range.getBegin(),
1774 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001775 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001776 Prefix == NNS->getPrefix() &&
1777 NS == NNS->getAsNamespace())
1778 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001779
Douglas Gregor1135c352009-08-06 05:28:30 +00001780 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1781 }
Mike Stump11289f42009-09-09 15:08:12 +00001782
Douglas Gregor1135c352009-08-06 05:28:30 +00001783 case NestedNameSpecifier::Global:
1784 // There is no meaningful transformation that one could perform on the
1785 // global scope.
1786 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001787
Douglas Gregor1135c352009-08-06 05:28:30 +00001788 case NestedNameSpecifier::TypeSpecWithTemplate:
1789 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001790 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001791 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1792 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001793 if (T.isNull())
1794 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001795
Douglas Gregor1135c352009-08-06 05:28:30 +00001796 if (!getDerived().AlwaysRebuild() &&
1797 Prefix == NNS->getPrefix() &&
1798 T == QualType(NNS->getAsType(), 0))
1799 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001800
1801 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1802 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001803 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001804 }
1805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregor1135c352009-08-06 05:28:30 +00001807 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001808 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001809}
1810
1811template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001812DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001813TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001814 SourceLocation Loc,
1815 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001816 if (!Name)
1817 return Name;
1818
1819 switch (Name.getNameKind()) {
1820 case DeclarationName::Identifier:
1821 case DeclarationName::ObjCZeroArgSelector:
1822 case DeclarationName::ObjCOneArgSelector:
1823 case DeclarationName::ObjCMultiArgSelector:
1824 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001825 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001826 case DeclarationName::CXXUsingDirective:
1827 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregorf816bd72009-09-03 22:13:48 +00001829 case DeclarationName::CXXConstructorName:
1830 case DeclarationName::CXXDestructorName:
1831 case DeclarationName::CXXConversionFunctionName: {
1832 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001833 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1834 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001835 if (T.isNull())
1836 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregorf816bd72009-09-03 22:13:48 +00001838 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001839 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001840 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001841 }
Mike Stump11289f42009-09-09 15:08:12 +00001842 }
1843
Douglas Gregorf816bd72009-09-03 22:13:48 +00001844 return DeclarationName();
1845}
1846
1847template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001848TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001849TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1850 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001851 SourceLocation Loc = getDerived().getBaseLocation();
1852
Douglas Gregor71dc5092009-08-06 06:41:21 +00001853 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001854 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001855 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001856 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1857 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 if (!NNS)
1859 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001860
Douglas Gregor71dc5092009-08-06 06:41:21 +00001861 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001862 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001863 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 if (!TransTemplate)
1865 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001866
Douglas Gregor71dc5092009-08-06 06:41:21 +00001867 if (!getDerived().AlwaysRebuild() &&
1868 NNS == QTN->getQualifier() &&
1869 TransTemplate == Template)
1870 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001871
Douglas Gregor71dc5092009-08-06 06:41:21 +00001872 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1873 TransTemplate);
1874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
John McCalle66edc12009-11-24 19:00:30 +00001876 // These should be getting filtered out before they make it into the AST.
1877 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 }
Mike Stump11289f42009-09-09 15:08:12 +00001879
Douglas Gregor71dc5092009-08-06 06:41:21 +00001880 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001881 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001882 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001883 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1884 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001885 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001886 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregor71dc5092009-08-06 06:41:21 +00001888 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001889 NNS == DTN->getQualifier() &&
1890 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001891 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001892
Douglas Gregor71395fa2009-11-04 00:56:37 +00001893 if (DTN->isIdentifier())
1894 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1895 ObjectType);
1896
1897 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1898 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001899 }
Mike Stump11289f42009-09-09 15:08:12 +00001900
Douglas Gregor71dc5092009-08-06 06:41:21 +00001901 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001902 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001903 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001904 if (!TransTemplate)
1905 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001906
Douglas Gregor71dc5092009-08-06 06:41:21 +00001907 if (!getDerived().AlwaysRebuild() &&
1908 TransTemplate == Template)
1909 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001910
Douglas Gregor71dc5092009-08-06 06:41:21 +00001911 return TemplateName(TransTemplate);
1912 }
Mike Stump11289f42009-09-09 15:08:12 +00001913
John McCalle66edc12009-11-24 19:00:30 +00001914 // These should be getting filtered out before they reach the AST.
1915 assert(false && "overloaded function decl survived to here");
1916 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001917}
1918
1919template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001920void TreeTransform<Derived>::InventTemplateArgumentLoc(
1921 const TemplateArgument &Arg,
1922 TemplateArgumentLoc &Output) {
1923 SourceLocation Loc = getDerived().getBaseLocation();
1924 switch (Arg.getKind()) {
1925 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001926 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001927 break;
1928
1929 case TemplateArgument::Type:
1930 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001931 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001932
1933 break;
1934
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001935 case TemplateArgument::Template:
1936 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1937 break;
1938
John McCall0ad16662009-10-29 08:12:44 +00001939 case TemplateArgument::Expression:
1940 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1941 break;
1942
1943 case TemplateArgument::Declaration:
1944 case TemplateArgument::Integral:
1945 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001946 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001947 break;
1948 }
1949}
1950
1951template<typename Derived>
1952bool TreeTransform<Derived>::TransformTemplateArgument(
1953 const TemplateArgumentLoc &Input,
1954 TemplateArgumentLoc &Output) {
1955 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001956 switch (Arg.getKind()) {
1957 case TemplateArgument::Null:
1958 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001959 Output = Input;
1960 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregore922c772009-08-04 22:27:00 +00001962 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001963 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001964 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001965 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001966
1967 DI = getDerived().TransformType(DI);
1968 if (!DI) return true;
1969
1970 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1971 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001972 }
Mike Stump11289f42009-09-09 15:08:12 +00001973
Douglas Gregore922c772009-08-04 22:27:00 +00001974 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001975 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001976 DeclarationName Name;
1977 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1978 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001979 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001980 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001981 if (!D) return true;
1982
John McCall0d07eb32009-10-29 18:45:58 +00001983 Expr *SourceExpr = Input.getSourceDeclExpression();
1984 if (SourceExpr) {
1985 EnterExpressionEvaluationContext Unevaluated(getSema(),
1986 Action::Unevaluated);
1987 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1988 if (E.isInvalid())
1989 SourceExpr = NULL;
1990 else {
1991 SourceExpr = E.takeAs<Expr>();
1992 SourceExpr->Retain();
1993 }
1994 }
1995
1996 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001997 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002000 case TemplateArgument::Template: {
2001 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2002 TemplateName Template
2003 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2004 if (Template.isNull())
2005 return true;
2006
2007 Output = TemplateArgumentLoc(TemplateArgument(Template),
2008 Input.getTemplateQualifierRange(),
2009 Input.getTemplateNameLoc());
2010 return false;
2011 }
2012
Douglas Gregore922c772009-08-04 22:27:00 +00002013 case TemplateArgument::Expression: {
2014 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002015 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002016 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002017
John McCall0ad16662009-10-29 08:12:44 +00002018 Expr *InputExpr = Input.getSourceExpression();
2019 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2020
2021 Sema::OwningExprResult E
2022 = getDerived().TransformExpr(InputExpr);
2023 if (E.isInvalid()) return true;
2024
2025 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002026 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002027 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2028 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002029 }
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregore922c772009-08-04 22:27:00 +00002031 case TemplateArgument::Pack: {
2032 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2033 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002034 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002035 AEnd = Arg.pack_end();
2036 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002037
John McCall0ad16662009-10-29 08:12:44 +00002038 // FIXME: preserve source information here when we start
2039 // caring about parameter packs.
2040
John McCall0d07eb32009-10-29 18:45:58 +00002041 TemplateArgumentLoc InputArg;
2042 TemplateArgumentLoc OutputArg;
2043 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2044 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002045 return true;
2046
John McCall0d07eb32009-10-29 18:45:58 +00002047 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002048 }
2049 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002050 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002051 true);
John McCall0d07eb32009-10-29 18:45:58 +00002052 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002053 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002054 }
2055 }
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregore922c772009-08-04 22:27:00 +00002057 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002058 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002059}
2060
Douglas Gregord6ff3322009-08-04 16:50:30 +00002061//===----------------------------------------------------------------------===//
2062// Type transformation
2063//===----------------------------------------------------------------------===//
2064
2065template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002066QualType TreeTransform<Derived>::TransformType(QualType T,
2067 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002068 if (getDerived().AlreadyTransformed(T))
2069 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002070
John McCall550e0c22009-10-21 00:40:46 +00002071 // Temporary workaround. All of these transformations should
2072 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002073 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002074 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002075
Douglas Gregorfe17d252010-02-16 19:09:40 +00002076 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002077
John McCall550e0c22009-10-21 00:40:46 +00002078 if (!NewDI)
2079 return QualType();
2080
2081 return NewDI->getType();
2082}
2083
2084template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002085TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2086 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002087 if (getDerived().AlreadyTransformed(DI->getType()))
2088 return DI;
2089
2090 TypeLocBuilder TLB;
2091
2092 TypeLoc TL = DI->getTypeLoc();
2093 TLB.reserve(TL.getFullDataSize());
2094
Douglas Gregorfe17d252010-02-16 19:09:40 +00002095 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002096 if (Result.isNull())
2097 return 0;
2098
John McCallbcd03502009-12-07 02:54:59 +00002099 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002100}
2101
2102template<typename Derived>
2103QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002104TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2105 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002106 switch (T.getTypeLocClass()) {
2107#define ABSTRACT_TYPELOC(CLASS, PARENT)
2108#define TYPELOC(CLASS, PARENT) \
2109 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002110 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2111 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002112#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002113 }
Mike Stump11289f42009-09-09 15:08:12 +00002114
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002115 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002116 return QualType();
2117}
2118
2119/// FIXME: By default, this routine adds type qualifiers only to types
2120/// that can have qualifiers, and silently suppresses those qualifiers
2121/// that are not permitted (e.g., qualifiers on reference or function
2122/// types). This is the right thing for template instantiation, but
2123/// probably not for other clients.
2124template<typename Derived>
2125QualType
2126TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002127 QualifiedTypeLoc T,
2128 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002129 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002130
Douglas Gregorfe17d252010-02-16 19:09:40 +00002131 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2132 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002133 if (Result.isNull())
2134 return QualType();
2135
2136 // Silently suppress qualifiers if the result type can't be qualified.
2137 // FIXME: this is the right thing for template instantiation, but
2138 // probably not for other clients.
2139 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002140 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002141
John McCall550e0c22009-10-21 00:40:46 +00002142 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2143
2144 TLB.push<QualifiedTypeLoc>(Result);
2145
2146 // No location information to preserve.
2147
2148 return Result;
2149}
2150
2151template <class TyLoc> static inline
2152QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2153 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2154 NewT.setNameLoc(T.getNameLoc());
2155 return T.getType();
2156}
2157
2158// Ugly metaprogramming macros because I couldn't be bothered to make
2159// the equivalent template version work.
2160#define TransformPointerLikeType(TypeClass) do { \
2161 QualType PointeeType \
2162 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2163 if (PointeeType.isNull()) \
2164 return QualType(); \
2165 \
2166 QualType Result = TL.getType(); \
2167 if (getDerived().AlwaysRebuild() || \
2168 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002169 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2170 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002171 if (Result.isNull()) \
2172 return QualType(); \
2173 } \
2174 \
2175 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2176 NewT.setSigilLoc(TL.getSigilLoc()); \
2177 \
2178 return Result; \
2179} while(0)
2180
John McCall550e0c22009-10-21 00:40:46 +00002181template<typename Derived>
2182QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002183 BuiltinTypeLoc T,
2184 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002185 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2186 NewT.setBuiltinLoc(T.getBuiltinLoc());
2187 if (T.needsExtraLocalData())
2188 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2189 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002190}
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregord6ff3322009-08-04 16:50:30 +00002192template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002193QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002194 ComplexTypeLoc T,
2195 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002196 // FIXME: recurse?
2197 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002198}
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregord6ff3322009-08-04 16:50:30 +00002200template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002201QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002202 PointerTypeLoc TL,
2203 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002204 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002205}
Mike Stump11289f42009-09-09 15:08:12 +00002206
2207template<typename Derived>
2208QualType
John McCall550e0c22009-10-21 00:40:46 +00002209TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002210 BlockPointerTypeLoc TL,
2211 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002212 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002213}
2214
John McCall70dd5f62009-10-30 00:06:24 +00002215/// Transforms a reference type. Note that somewhat paradoxically we
2216/// don't care whether the type itself is an l-value type or an r-value
2217/// type; we only care if the type was *written* as an l-value type
2218/// or an r-value type.
2219template<typename Derived>
2220QualType
2221TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002222 ReferenceTypeLoc TL,
2223 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002224 const ReferenceType *T = TL.getTypePtr();
2225
2226 // Note that this works with the pointee-as-written.
2227 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2228 if (PointeeType.isNull())
2229 return QualType();
2230
2231 QualType Result = TL.getType();
2232 if (getDerived().AlwaysRebuild() ||
2233 PointeeType != T->getPointeeTypeAsWritten()) {
2234 Result = getDerived().RebuildReferenceType(PointeeType,
2235 T->isSpelledAsLValue(),
2236 TL.getSigilLoc());
2237 if (Result.isNull())
2238 return QualType();
2239 }
2240
2241 // r-value references can be rebuilt as l-value references.
2242 ReferenceTypeLoc NewTL;
2243 if (isa<LValueReferenceType>(Result))
2244 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2245 else
2246 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2247 NewTL.setSigilLoc(TL.getSigilLoc());
2248
2249 return Result;
2250}
2251
Mike Stump11289f42009-09-09 15:08:12 +00002252template<typename Derived>
2253QualType
John McCall550e0c22009-10-21 00:40:46 +00002254TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002255 LValueReferenceTypeLoc TL,
2256 QualType ObjectType) {
2257 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002258}
2259
Mike Stump11289f42009-09-09 15:08:12 +00002260template<typename Derived>
2261QualType
John McCall550e0c22009-10-21 00:40:46 +00002262TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002263 RValueReferenceTypeLoc TL,
2264 QualType ObjectType) {
2265 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002266}
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregord6ff3322009-08-04 16:50:30 +00002268template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002269QualType
John McCall550e0c22009-10-21 00:40:46 +00002270TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002271 MemberPointerTypeLoc TL,
2272 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002273 MemberPointerType *T = TL.getTypePtr();
2274
2275 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002276 if (PointeeType.isNull())
2277 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002278
John McCall550e0c22009-10-21 00:40:46 +00002279 // TODO: preserve source information for this.
2280 QualType ClassType
2281 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002282 if (ClassType.isNull())
2283 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002284
John McCall550e0c22009-10-21 00:40:46 +00002285 QualType Result = TL.getType();
2286 if (getDerived().AlwaysRebuild() ||
2287 PointeeType != T->getPointeeType() ||
2288 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002289 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2290 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002291 if (Result.isNull())
2292 return QualType();
2293 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002294
John McCall550e0c22009-10-21 00:40:46 +00002295 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2296 NewTL.setSigilLoc(TL.getSigilLoc());
2297
2298 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002299}
2300
Mike Stump11289f42009-09-09 15:08:12 +00002301template<typename Derived>
2302QualType
John McCall550e0c22009-10-21 00:40:46 +00002303TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002304 ConstantArrayTypeLoc TL,
2305 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002306 ConstantArrayType *T = TL.getTypePtr();
2307 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002308 if (ElementType.isNull())
2309 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002310
John McCall550e0c22009-10-21 00:40:46 +00002311 QualType Result = TL.getType();
2312 if (getDerived().AlwaysRebuild() ||
2313 ElementType != T->getElementType()) {
2314 Result = getDerived().RebuildConstantArrayType(ElementType,
2315 T->getSizeModifier(),
2316 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002317 T->getIndexTypeCVRQualifiers(),
2318 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002319 if (Result.isNull())
2320 return QualType();
2321 }
2322
2323 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2324 NewTL.setLBracketLoc(TL.getLBracketLoc());
2325 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002326
John McCall550e0c22009-10-21 00:40:46 +00002327 Expr *Size = TL.getSizeExpr();
2328 if (Size) {
2329 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2330 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2331 }
2332 NewTL.setSizeExpr(Size);
2333
2334 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002335}
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregord6ff3322009-08-04 16:50:30 +00002337template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002338QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002339 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002340 IncompleteArrayTypeLoc TL,
2341 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002342 IncompleteArrayType *T = TL.getTypePtr();
2343 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002344 if (ElementType.isNull())
2345 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002346
John McCall550e0c22009-10-21 00:40:46 +00002347 QualType Result = TL.getType();
2348 if (getDerived().AlwaysRebuild() ||
2349 ElementType != T->getElementType()) {
2350 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002351 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002352 T->getIndexTypeCVRQualifiers(),
2353 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002354 if (Result.isNull())
2355 return QualType();
2356 }
2357
2358 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2359 NewTL.setLBracketLoc(TL.getLBracketLoc());
2360 NewTL.setRBracketLoc(TL.getRBracketLoc());
2361 NewTL.setSizeExpr(0);
2362
2363 return Result;
2364}
2365
2366template<typename Derived>
2367QualType
2368TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002369 VariableArrayTypeLoc TL,
2370 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002371 VariableArrayType *T = TL.getTypePtr();
2372 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2373 if (ElementType.isNull())
2374 return QualType();
2375
2376 // Array bounds are not potentially evaluated contexts
2377 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2378
2379 Sema::OwningExprResult SizeResult
2380 = getDerived().TransformExpr(T->getSizeExpr());
2381 if (SizeResult.isInvalid())
2382 return QualType();
2383
2384 Expr *Size = static_cast<Expr*>(SizeResult.get());
2385
2386 QualType Result = TL.getType();
2387 if (getDerived().AlwaysRebuild() ||
2388 ElementType != T->getElementType() ||
2389 Size != T->getSizeExpr()) {
2390 Result = getDerived().RebuildVariableArrayType(ElementType,
2391 T->getSizeModifier(),
2392 move(SizeResult),
2393 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002394 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002395 if (Result.isNull())
2396 return QualType();
2397 }
2398 else SizeResult.take();
2399
2400 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2401 NewTL.setLBracketLoc(TL.getLBracketLoc());
2402 NewTL.setRBracketLoc(TL.getRBracketLoc());
2403 NewTL.setSizeExpr(Size);
2404
2405 return Result;
2406}
2407
2408template<typename Derived>
2409QualType
2410TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002411 DependentSizedArrayTypeLoc TL,
2412 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002413 DependentSizedArrayType *T = TL.getTypePtr();
2414 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2415 if (ElementType.isNull())
2416 return QualType();
2417
2418 // Array bounds are not potentially evaluated contexts
2419 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2420
2421 Sema::OwningExprResult SizeResult
2422 = getDerived().TransformExpr(T->getSizeExpr());
2423 if (SizeResult.isInvalid())
2424 return QualType();
2425
2426 Expr *Size = static_cast<Expr*>(SizeResult.get());
2427
2428 QualType Result = TL.getType();
2429 if (getDerived().AlwaysRebuild() ||
2430 ElementType != T->getElementType() ||
2431 Size != T->getSizeExpr()) {
2432 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2433 T->getSizeModifier(),
2434 move(SizeResult),
2435 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002436 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002437 if (Result.isNull())
2438 return QualType();
2439 }
2440 else SizeResult.take();
2441
2442 // We might have any sort of array type now, but fortunately they
2443 // all have the same location layout.
2444 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2445 NewTL.setLBracketLoc(TL.getLBracketLoc());
2446 NewTL.setRBracketLoc(TL.getRBracketLoc());
2447 NewTL.setSizeExpr(Size);
2448
2449 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002450}
Mike Stump11289f42009-09-09 15:08:12 +00002451
2452template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002453QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002454 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002455 DependentSizedExtVectorTypeLoc TL,
2456 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002457 DependentSizedExtVectorType *T = TL.getTypePtr();
2458
2459 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002460 QualType ElementType = getDerived().TransformType(T->getElementType());
2461 if (ElementType.isNull())
2462 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregore922c772009-08-04 22:27:00 +00002464 // Vector sizes are not potentially evaluated contexts
2465 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2466
Douglas Gregord6ff3322009-08-04 16:50:30 +00002467 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2468 if (Size.isInvalid())
2469 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002470
John McCall550e0c22009-10-21 00:40:46 +00002471 QualType Result = TL.getType();
2472 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002473 ElementType != T->getElementType() ||
2474 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002475 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002476 move(Size),
2477 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002478 if (Result.isNull())
2479 return QualType();
2480 }
2481 else Size.take();
2482
2483 // Result might be dependent or not.
2484 if (isa<DependentSizedExtVectorType>(Result)) {
2485 DependentSizedExtVectorTypeLoc NewTL
2486 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2487 NewTL.setNameLoc(TL.getNameLoc());
2488 } else {
2489 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2490 NewTL.setNameLoc(TL.getNameLoc());
2491 }
2492
2493 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002494}
Mike Stump11289f42009-09-09 15:08:12 +00002495
2496template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002497QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002498 VectorTypeLoc TL,
2499 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002500 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002501 QualType ElementType = getDerived().TransformType(T->getElementType());
2502 if (ElementType.isNull())
2503 return QualType();
2504
John McCall550e0c22009-10-21 00:40:46 +00002505 QualType Result = TL.getType();
2506 if (getDerived().AlwaysRebuild() ||
2507 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002508 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2509 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002510 if (Result.isNull())
2511 return QualType();
2512 }
2513
2514 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2515 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002516
John McCall550e0c22009-10-21 00:40:46 +00002517 return Result;
2518}
2519
2520template<typename Derived>
2521QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002522 ExtVectorTypeLoc TL,
2523 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002524 VectorType *T = TL.getTypePtr();
2525 QualType ElementType = getDerived().TransformType(T->getElementType());
2526 if (ElementType.isNull())
2527 return QualType();
2528
2529 QualType Result = TL.getType();
2530 if (getDerived().AlwaysRebuild() ||
2531 ElementType != T->getElementType()) {
2532 Result = getDerived().RebuildExtVectorType(ElementType,
2533 T->getNumElements(),
2534 /*FIXME*/ SourceLocation());
2535 if (Result.isNull())
2536 return QualType();
2537 }
2538
2539 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2540 NewTL.setNameLoc(TL.getNameLoc());
2541
2542 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002543}
Mike Stump11289f42009-09-09 15:08:12 +00002544
2545template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002546ParmVarDecl *
2547TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2548 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2549 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2550 if (!NewDI)
2551 return 0;
2552
2553 if (NewDI == OldDI)
2554 return OldParm;
2555 else
2556 return ParmVarDecl::Create(SemaRef.Context,
2557 OldParm->getDeclContext(),
2558 OldParm->getLocation(),
2559 OldParm->getIdentifier(),
2560 NewDI->getType(),
2561 NewDI,
2562 OldParm->getStorageClass(),
2563 /* DefArg */ NULL);
2564}
2565
2566template<typename Derived>
2567bool TreeTransform<Derived>::
2568 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2569 llvm::SmallVectorImpl<QualType> &PTypes,
2570 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2571 FunctionProtoType *T = TL.getTypePtr();
2572
2573 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2574 ParmVarDecl *OldParm = TL.getArg(i);
2575
2576 QualType NewType;
2577 ParmVarDecl *NewParm;
2578
2579 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002580 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2581 if (!NewParm)
2582 return true;
2583 NewType = NewParm->getType();
2584
2585 // Deal with the possibility that we don't have a parameter
2586 // declaration for this parameter.
2587 } else {
2588 NewParm = 0;
2589
2590 QualType OldType = T->getArgType(i);
2591 NewType = getDerived().TransformType(OldType);
2592 if (NewType.isNull())
2593 return true;
2594 }
2595
2596 PTypes.push_back(NewType);
2597 PVars.push_back(NewParm);
2598 }
2599
2600 return false;
2601}
2602
2603template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002604QualType
John McCall550e0c22009-10-21 00:40:46 +00002605TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002606 FunctionProtoTypeLoc TL,
2607 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002608 FunctionProtoType *T = TL.getTypePtr();
2609 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610 if (ResultType.isNull())
2611 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002612
John McCall550e0c22009-10-21 00:40:46 +00002613 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002614 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002615 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002616 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2617 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002618
John McCall550e0c22009-10-21 00:40:46 +00002619 QualType Result = TL.getType();
2620 if (getDerived().AlwaysRebuild() ||
2621 ResultType != T->getResultType() ||
2622 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2623 Result = getDerived().RebuildFunctionProtoType(ResultType,
2624 ParamTypes.data(),
2625 ParamTypes.size(),
2626 T->isVariadic(),
2627 T->getTypeQuals());
2628 if (Result.isNull())
2629 return QualType();
2630 }
Mike Stump11289f42009-09-09 15:08:12 +00002631
John McCall550e0c22009-10-21 00:40:46 +00002632 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2633 NewTL.setLParenLoc(TL.getLParenLoc());
2634 NewTL.setRParenLoc(TL.getRParenLoc());
2635 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2636 NewTL.setArg(i, ParamDecls[i]);
2637
2638 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639}
Mike Stump11289f42009-09-09 15:08:12 +00002640
Douglas Gregord6ff3322009-08-04 16:50:30 +00002641template<typename Derived>
2642QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002643 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002644 FunctionNoProtoTypeLoc TL,
2645 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002646 FunctionNoProtoType *T = TL.getTypePtr();
2647 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2648 if (ResultType.isNull())
2649 return QualType();
2650
2651 QualType Result = TL.getType();
2652 if (getDerived().AlwaysRebuild() ||
2653 ResultType != T->getResultType())
2654 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2655
2656 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2657 NewTL.setLParenLoc(TL.getLParenLoc());
2658 NewTL.setRParenLoc(TL.getRParenLoc());
2659
2660 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002661}
Mike Stump11289f42009-09-09 15:08:12 +00002662
John McCallb96ec562009-12-04 22:46:56 +00002663template<typename Derived> QualType
2664TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002665 UnresolvedUsingTypeLoc TL,
2666 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002667 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002668 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002669 if (!D)
2670 return QualType();
2671
2672 QualType Result = TL.getType();
2673 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2674 Result = getDerived().RebuildUnresolvedUsingType(D);
2675 if (Result.isNull())
2676 return QualType();
2677 }
2678
2679 // We might get an arbitrary type spec type back. We should at
2680 // least always get a type spec type, though.
2681 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2682 NewTL.setNameLoc(TL.getNameLoc());
2683
2684 return Result;
2685}
2686
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002688QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002689 TypedefTypeLoc TL,
2690 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002691 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002692 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002693 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2694 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002695 if (!Typedef)
2696 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002697
John McCall550e0c22009-10-21 00:40:46 +00002698 QualType Result = TL.getType();
2699 if (getDerived().AlwaysRebuild() ||
2700 Typedef != T->getDecl()) {
2701 Result = getDerived().RebuildTypedefType(Typedef);
2702 if (Result.isNull())
2703 return QualType();
2704 }
Mike Stump11289f42009-09-09 15:08:12 +00002705
John McCall550e0c22009-10-21 00:40:46 +00002706 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2707 NewTL.setNameLoc(TL.getNameLoc());
2708
2709 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002710}
Mike Stump11289f42009-09-09 15:08:12 +00002711
Douglas Gregord6ff3322009-08-04 16:50:30 +00002712template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002713QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002714 TypeOfExprTypeLoc TL,
2715 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002716 // typeof expressions are not potentially evaluated contexts
2717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002718
John McCalle8595032010-01-13 20:03:27 +00002719 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002720 if (E.isInvalid())
2721 return QualType();
2722
John McCall550e0c22009-10-21 00:40:46 +00002723 QualType Result = TL.getType();
2724 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002725 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002726 Result = getDerived().RebuildTypeOfExprType(move(E));
2727 if (Result.isNull())
2728 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002729 }
John McCall550e0c22009-10-21 00:40:46 +00002730 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002731
John McCall550e0c22009-10-21 00:40:46 +00002732 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002733 NewTL.setTypeofLoc(TL.getTypeofLoc());
2734 NewTL.setLParenLoc(TL.getLParenLoc());
2735 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002736
2737 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002738}
Mike Stump11289f42009-09-09 15:08:12 +00002739
2740template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002741QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002742 TypeOfTypeLoc TL,
2743 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002744 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2745 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2746 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002747 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002748
John McCall550e0c22009-10-21 00:40:46 +00002749 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002750 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2751 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002752 if (Result.isNull())
2753 return QualType();
2754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
John McCall550e0c22009-10-21 00:40:46 +00002756 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002757 NewTL.setTypeofLoc(TL.getTypeofLoc());
2758 NewTL.setLParenLoc(TL.getLParenLoc());
2759 NewTL.setRParenLoc(TL.getRParenLoc());
2760 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002761
2762 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002763}
Mike Stump11289f42009-09-09 15:08:12 +00002764
2765template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002766QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002767 DecltypeTypeLoc TL,
2768 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002769 DecltypeType *T = TL.getTypePtr();
2770
Douglas Gregore922c772009-08-04 22:27:00 +00002771 // decltype expressions are not potentially evaluated contexts
2772 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002773
Douglas Gregord6ff3322009-08-04 16:50:30 +00002774 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2775 if (E.isInvalid())
2776 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002777
John McCall550e0c22009-10-21 00:40:46 +00002778 QualType Result = TL.getType();
2779 if (getDerived().AlwaysRebuild() ||
2780 E.get() != T->getUnderlyingExpr()) {
2781 Result = getDerived().RebuildDecltypeType(move(E));
2782 if (Result.isNull())
2783 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784 }
John McCall550e0c22009-10-21 00:40:46 +00002785 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002786
John McCall550e0c22009-10-21 00:40:46 +00002787 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2788 NewTL.setNameLoc(TL.getNameLoc());
2789
2790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791}
2792
2793template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002795 RecordTypeLoc TL,
2796 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002797 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002798 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002799 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2800 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002801 if (!Record)
2802 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002803
John McCall550e0c22009-10-21 00:40:46 +00002804 QualType Result = TL.getType();
2805 if (getDerived().AlwaysRebuild() ||
2806 Record != T->getDecl()) {
2807 Result = getDerived().RebuildRecordType(Record);
2808 if (Result.isNull())
2809 return QualType();
2810 }
Mike Stump11289f42009-09-09 15:08:12 +00002811
John McCall550e0c22009-10-21 00:40:46 +00002812 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2813 NewTL.setNameLoc(TL.getNameLoc());
2814
2815 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002816}
Mike Stump11289f42009-09-09 15:08:12 +00002817
2818template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002819QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002820 EnumTypeLoc TL,
2821 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002822 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002823 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002824 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2825 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002826 if (!Enum)
2827 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002828
John McCall550e0c22009-10-21 00:40:46 +00002829 QualType Result = TL.getType();
2830 if (getDerived().AlwaysRebuild() ||
2831 Enum != T->getDecl()) {
2832 Result = getDerived().RebuildEnumType(Enum);
2833 if (Result.isNull())
2834 return QualType();
2835 }
Mike Stump11289f42009-09-09 15:08:12 +00002836
John McCall550e0c22009-10-21 00:40:46 +00002837 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2838 NewTL.setNameLoc(TL.getNameLoc());
2839
2840 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002841}
John McCallfcc33b02009-09-05 00:15:47 +00002842
2843template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002844QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002845 ElaboratedTypeLoc TL,
2846 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002847 ElaboratedType *T = TL.getTypePtr();
2848
2849 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002850 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2851 if (Underlying.isNull())
2852 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002853
John McCall550e0c22009-10-21 00:40:46 +00002854 QualType Result = TL.getType();
2855 if (getDerived().AlwaysRebuild() ||
2856 Underlying != T->getUnderlyingType()) {
2857 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2858 if (Result.isNull())
2859 return QualType();
2860 }
Mike Stump11289f42009-09-09 15:08:12 +00002861
John McCall550e0c22009-10-21 00:40:46 +00002862 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2863 NewTL.setNameLoc(TL.getNameLoc());
2864
2865 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002866}
Mike Stump11289f42009-09-09 15:08:12 +00002867
John McCalle78aac42010-03-10 03:28:59 +00002868template<typename Derived>
2869QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2870 TypeLocBuilder &TLB,
2871 InjectedClassNameTypeLoc TL,
2872 QualType ObjectType) {
2873 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2874 TL.getTypePtr()->getDecl());
2875 if (!D) return QualType();
2876
2877 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2878 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2879 return T;
2880}
2881
Mike Stump11289f42009-09-09 15:08:12 +00002882
Douglas Gregord6ff3322009-08-04 16:50:30 +00002883template<typename Derived>
2884QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002885 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002886 TemplateTypeParmTypeLoc TL,
2887 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002888 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002889}
2890
Mike Stump11289f42009-09-09 15:08:12 +00002891template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002892QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002893 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002894 SubstTemplateTypeParmTypeLoc TL,
2895 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002896 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002897}
2898
2899template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002900QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2901 const TemplateSpecializationType *TST,
2902 QualType ObjectType) {
2903 // FIXME: this entire method is a temporary workaround; callers
2904 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002905
John McCall0ad16662009-10-29 08:12:44 +00002906 // Fake up a TemplateSpecializationTypeLoc.
2907 TypeLocBuilder TLB;
2908 TemplateSpecializationTypeLoc TL
2909 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2910
John McCall0d07eb32009-10-29 18:45:58 +00002911 SourceLocation BaseLoc = getDerived().getBaseLocation();
2912
2913 TL.setTemplateNameLoc(BaseLoc);
2914 TL.setLAngleLoc(BaseLoc);
2915 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002916 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2917 const TemplateArgument &TA = TST->getArg(i);
2918 TemplateArgumentLoc TAL;
2919 getDerived().InventTemplateArgumentLoc(TA, TAL);
2920 TL.setArgLocInfo(i, TAL.getLocInfo());
2921 }
2922
2923 TypeLocBuilder IgnoredTLB;
2924 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002925}
2926
2927template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002929 TypeLocBuilder &TLB,
2930 TemplateSpecializationTypeLoc TL,
2931 QualType ObjectType) {
2932 const TemplateSpecializationType *T = TL.getTypePtr();
2933
Mike Stump11289f42009-09-09 15:08:12 +00002934 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002935 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002936 if (Template.isNull())
2937 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002938
John McCall6b51f282009-11-23 01:53:49 +00002939 TemplateArgumentListInfo NewTemplateArgs;
2940 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2941 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2942
2943 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2944 TemplateArgumentLoc Loc;
2945 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002946 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002947 NewTemplateArgs.addArgument(Loc);
2948 }
Mike Stump11289f42009-09-09 15:08:12 +00002949
John McCall0ad16662009-10-29 08:12:44 +00002950 // FIXME: maybe don't rebuild if all the template arguments are the same.
2951
2952 QualType Result =
2953 getDerived().RebuildTemplateSpecializationType(Template,
2954 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002955 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002956
2957 if (!Result.isNull()) {
2958 TemplateSpecializationTypeLoc NewTL
2959 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2960 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2961 NewTL.setLAngleLoc(TL.getLAngleLoc());
2962 NewTL.setRAngleLoc(TL.getRAngleLoc());
2963 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2964 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002965 }
Mike Stump11289f42009-09-09 15:08:12 +00002966
John McCall0ad16662009-10-29 08:12:44 +00002967 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002968}
Mike Stump11289f42009-09-09 15:08:12 +00002969
2970template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002971QualType
2972TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002973 QualifiedNameTypeLoc TL,
2974 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002975 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976 NestedNameSpecifier *NNS
2977 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002978 SourceRange(),
2979 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002980 if (!NNS)
2981 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregord6ff3322009-08-04 16:50:30 +00002983 QualType Named = getDerived().TransformType(T->getNamedType());
2984 if (Named.isNull())
2985 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002986
John McCall550e0c22009-10-21 00:40:46 +00002987 QualType Result = TL.getType();
2988 if (getDerived().AlwaysRebuild() ||
2989 NNS != T->getQualifier() ||
2990 Named != T->getNamedType()) {
2991 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2992 if (Result.isNull())
2993 return QualType();
2994 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995
John McCall550e0c22009-10-21 00:40:46 +00002996 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2997 NewTL.setNameLoc(TL.getNameLoc());
2998
2999 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003000}
Mike Stump11289f42009-09-09 15:08:12 +00003001
3002template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003003QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3004 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003005 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003006 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003007
3008 /* FIXME: preserve source information better than this */
3009 SourceRange SR(TL.getNameLoc());
3010
Douglas Gregord6ff3322009-08-04 16:50:30 +00003011 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003012 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003013 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003014 if (!NNS)
3015 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003016
John McCall550e0c22009-10-21 00:40:46 +00003017 QualType Result;
3018
Douglas Gregord6ff3322009-08-04 16:50:30 +00003019 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003020 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 = getDerived().TransformType(QualType(TemplateId, 0));
3022 if (NewTemplateId.isNull())
3023 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003024
Douglas Gregord6ff3322009-08-04 16:50:30 +00003025 if (!getDerived().AlwaysRebuild() &&
3026 NNS == T->getQualifier() &&
3027 NewTemplateId == QualType(TemplateId, 0))
3028 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003029
Douglas Gregor02085352010-03-31 20:19:30 +00003030 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3031 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003032 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003033 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3034 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003035 }
John McCall550e0c22009-10-21 00:40:46 +00003036 if (Result.isNull())
3037 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003039 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003040 NewTL.setNameLoc(TL.getNameLoc());
3041
3042 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003043}
Mike Stump11289f42009-09-09 15:08:12 +00003044
Douglas Gregord6ff3322009-08-04 16:50:30 +00003045template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003046QualType
3047TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003048 ObjCInterfaceTypeLoc TL,
3049 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003050 assert(false && "TransformObjCInterfaceType unimplemented");
3051 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003052}
Mike Stump11289f42009-09-09 15:08:12 +00003053
3054template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003055QualType
3056TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003057 ObjCObjectPointerTypeLoc TL,
3058 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003059 assert(false && "TransformObjCObjectPointerType unimplemented");
3060 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003061}
3062
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003064// Statement transformation
3065//===----------------------------------------------------------------------===//
3066template<typename Derived>
3067Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003068TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3069 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003070}
3071
3072template<typename Derived>
3073Sema::OwningStmtResult
3074TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3075 return getDerived().TransformCompoundStmt(S, false);
3076}
3077
3078template<typename Derived>
3079Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003080TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003081 bool IsStmtExpr) {
3082 bool SubStmtChanged = false;
3083 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3084 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3085 B != BEnd; ++B) {
3086 OwningStmtResult Result = getDerived().TransformStmt(*B);
3087 if (Result.isInvalid())
3088 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003089
Douglas Gregorebe10102009-08-20 07:17:43 +00003090 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3091 Statements.push_back(Result.takeAs<Stmt>());
3092 }
Mike Stump11289f42009-09-09 15:08:12 +00003093
Douglas Gregorebe10102009-08-20 07:17:43 +00003094 if (!getDerived().AlwaysRebuild() &&
3095 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003096 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003097
3098 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3099 move_arg(Statements),
3100 S->getRBracLoc(),
3101 IsStmtExpr);
3102}
Mike Stump11289f42009-09-09 15:08:12 +00003103
Douglas Gregorebe10102009-08-20 07:17:43 +00003104template<typename Derived>
3105Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003106TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003107 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3108 {
3109 // The case value expressions are not potentially evaluated.
3110 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003111
Eli Friedman06577382009-11-19 03:14:00 +00003112 // Transform the left-hand case value.
3113 LHS = getDerived().TransformExpr(S->getLHS());
3114 if (LHS.isInvalid())
3115 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003116
Eli Friedman06577382009-11-19 03:14:00 +00003117 // Transform the right-hand case value (for the GNU case-range extension).
3118 RHS = getDerived().TransformExpr(S->getRHS());
3119 if (RHS.isInvalid())
3120 return SemaRef.StmtError();
3121 }
Mike Stump11289f42009-09-09 15:08:12 +00003122
Douglas Gregorebe10102009-08-20 07:17:43 +00003123 // Build the case statement.
3124 // Case statements are always rebuilt so that they will attached to their
3125 // transformed switch statement.
3126 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3127 move(LHS),
3128 S->getEllipsisLoc(),
3129 move(RHS),
3130 S->getColonLoc());
3131 if (Case.isInvalid())
3132 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003133
Douglas Gregorebe10102009-08-20 07:17:43 +00003134 // Transform the statement following the case
3135 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3136 if (SubStmt.isInvalid())
3137 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003138
Douglas Gregorebe10102009-08-20 07:17:43 +00003139 // Attach the body to the case statement
3140 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3141}
3142
3143template<typename Derived>
3144Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003145TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003146 // Transform the statement following the default case
3147 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3148 if (SubStmt.isInvalid())
3149 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003150
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 // Default statements are always rebuilt
3152 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3153 move(SubStmt));
3154}
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregorebe10102009-08-20 07:17:43 +00003156template<typename Derived>
3157Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003158TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3160 if (SubStmt.isInvalid())
3161 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003162
Douglas Gregorebe10102009-08-20 07:17:43 +00003163 // FIXME: Pass the real colon location in.
3164 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3165 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3166 move(SubStmt));
3167}
Mike Stump11289f42009-09-09 15:08:12 +00003168
Douglas Gregorebe10102009-08-20 07:17:43 +00003169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003170Sema::OwningStmtResult
3171TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003172 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003173 OwningExprResult Cond(SemaRef);
3174 VarDecl *ConditionVar = 0;
3175 if (S->getConditionVariable()) {
3176 ConditionVar
3177 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003178 getDerived().TransformDefinition(
3179 S->getConditionVariable()->getLocation(),
3180 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003181 if (!ConditionVar)
3182 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003183 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003184 Cond = getDerived().TransformExpr(S->getCond());
3185
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003186 if (Cond.isInvalid())
3187 return SemaRef.StmtError();
3188 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003189
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003190 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003191
Douglas Gregorebe10102009-08-20 07:17:43 +00003192 // Transform the "then" branch.
3193 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3194 if (Then.isInvalid())
3195 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003196
Douglas Gregorebe10102009-08-20 07:17:43 +00003197 // Transform the "else" branch.
3198 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3199 if (Else.isInvalid())
3200 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregorebe10102009-08-20 07:17:43 +00003202 if (!getDerived().AlwaysRebuild() &&
3203 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003204 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003205 Then.get() == S->getThen() &&
3206 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003207 return SemaRef.Owned(S->Retain());
3208
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003209 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3210 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003211 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003212}
3213
3214template<typename Derived>
3215Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003216TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003217 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003218 OwningExprResult Cond(SemaRef);
3219 VarDecl *ConditionVar = 0;
3220 if (S->getConditionVariable()) {
3221 ConditionVar
3222 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003223 getDerived().TransformDefinition(
3224 S->getConditionVariable()->getLocation(),
3225 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003226 if (!ConditionVar)
3227 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003228 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003229 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003230
3231 if (Cond.isInvalid())
3232 return SemaRef.StmtError();
3233 }
Mike Stump11289f42009-09-09 15:08:12 +00003234
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003235 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003238 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3239 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003240 if (Switch.isInvalid())
3241 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003242
Douglas Gregorebe10102009-08-20 07:17:43 +00003243 // Transform the body of the switch statement.
3244 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3245 if (Body.isInvalid())
3246 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 // Complete the switch statement.
3249 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3250 move(Body));
3251}
Mike Stump11289f42009-09-09 15:08:12 +00003252
Douglas Gregorebe10102009-08-20 07:17:43 +00003253template<typename Derived>
3254Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003255TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003256 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003257 OwningExprResult Cond(SemaRef);
3258 VarDecl *ConditionVar = 0;
3259 if (S->getConditionVariable()) {
3260 ConditionVar
3261 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003262 getDerived().TransformDefinition(
3263 S->getConditionVariable()->getLocation(),
3264 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003265 if (!ConditionVar)
3266 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003267 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003268 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003269
3270 if (Cond.isInvalid())
3271 return SemaRef.StmtError();
3272 }
Mike Stump11289f42009-09-09 15:08:12 +00003273
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003274 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 // Transform the body
3277 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3278 if (Body.isInvalid())
3279 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003280
Douglas Gregorebe10102009-08-20 07:17:43 +00003281 if (!getDerived().AlwaysRebuild() &&
3282 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003283 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003284 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003285 return SemaRef.Owned(S->Retain());
3286
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003287 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3288 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003289}
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregorebe10102009-08-20 07:17:43 +00003291template<typename Derived>
3292Sema::OwningStmtResult
3293TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3294 // Transform the condition
3295 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3296 if (Cond.isInvalid())
3297 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003298
Douglas Gregorebe10102009-08-20 07:17:43 +00003299 // Transform the body
3300 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3301 if (Body.isInvalid())
3302 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003303
Douglas Gregorebe10102009-08-20 07:17:43 +00003304 if (!getDerived().AlwaysRebuild() &&
3305 Cond.get() == S->getCond() &&
3306 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003307 return SemaRef.Owned(S->Retain());
3308
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3310 /*FIXME:*/S->getWhileLoc(), move(Cond),
3311 S->getRParenLoc());
3312}
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregorebe10102009-08-20 07:17:43 +00003314template<typename Derived>
3315Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003316TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 // Transform the initialization statement
3318 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3319 if (Init.isInvalid())
3320 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregorebe10102009-08-20 07:17:43 +00003322 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003323 OwningExprResult Cond(SemaRef);
3324 VarDecl *ConditionVar = 0;
3325 if (S->getConditionVariable()) {
3326 ConditionVar
3327 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003328 getDerived().TransformDefinition(
3329 S->getConditionVariable()->getLocation(),
3330 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003331 if (!ConditionVar)
3332 return SemaRef.StmtError();
3333 } else {
3334 Cond = getDerived().TransformExpr(S->getCond());
3335
3336 if (Cond.isInvalid())
3337 return SemaRef.StmtError();
3338 }
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregorebe10102009-08-20 07:17:43 +00003340 // Transform the increment
3341 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3342 if (Inc.isInvalid())
3343 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003344
Douglas Gregorebe10102009-08-20 07:17:43 +00003345 // Transform the body
3346 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3347 if (Body.isInvalid())
3348 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003349
Douglas Gregorebe10102009-08-20 07:17:43 +00003350 if (!getDerived().AlwaysRebuild() &&
3351 Init.get() == S->getInit() &&
3352 Cond.get() == S->getCond() &&
3353 Inc.get() == S->getInc() &&
3354 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003355 return SemaRef.Owned(S->Retain());
3356
Douglas Gregorebe10102009-08-20 07:17:43 +00003357 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003358 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003359 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003360 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 S->getRParenLoc(), move(Body));
3362}
3363
3364template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003365Sema::OwningStmtResult
3366TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003367 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003368 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 S->getLabel());
3370}
3371
3372template<typename Derived>
3373Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003374TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003375 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3376 if (Target.isInvalid())
3377 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003378
Douglas Gregorebe10102009-08-20 07:17:43 +00003379 if (!getDerived().AlwaysRebuild() &&
3380 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003381 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003382
3383 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3384 move(Target));
3385}
3386
3387template<typename Derived>
3388Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003389TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3390 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003391}
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregorebe10102009-08-20 07:17:43 +00003393template<typename Derived>
3394Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003395TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3396 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003397}
Mike Stump11289f42009-09-09 15:08:12 +00003398
Douglas Gregorebe10102009-08-20 07:17:43 +00003399template<typename Derived>
3400Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003401TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003402 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3403 if (Result.isInvalid())
3404 return SemaRef.StmtError();
3405
Mike Stump11289f42009-09-09 15:08:12 +00003406 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003407 // to tell whether the return type of the function has changed.
3408 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3409}
Mike Stump11289f42009-09-09 15:08:12 +00003410
Douglas Gregorebe10102009-08-20 07:17:43 +00003411template<typename Derived>
3412Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003413TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003414 bool DeclChanged = false;
3415 llvm::SmallVector<Decl *, 4> Decls;
3416 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3417 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003418 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3419 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003420 if (!Transformed)
3421 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423 if (Transformed != *D)
3424 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003425
Douglas Gregorebe10102009-08-20 07:17:43 +00003426 Decls.push_back(Transformed);
3427 }
Mike Stump11289f42009-09-09 15:08:12 +00003428
Douglas Gregorebe10102009-08-20 07:17:43 +00003429 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003430 return SemaRef.Owned(S->Retain());
3431
3432 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003433 S->getStartLoc(), S->getEndLoc());
3434}
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregorebe10102009-08-20 07:17:43 +00003436template<typename Derived>
3437Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003438TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003439 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003440 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003441}
3442
3443template<typename Derived>
3444Sema::OwningStmtResult
3445TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003446
3447 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3448 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003449 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003450
Anders Carlssonaaeef072010-01-24 05:50:09 +00003451 OwningExprResult AsmString(SemaRef);
3452 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3453
3454 bool ExprsChanged = false;
3455
3456 // Go through the outputs.
3457 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003458 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003459
Anders Carlssonaaeef072010-01-24 05:50:09 +00003460 // No need to transform the constraint literal.
3461 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3462
3463 // Transform the output expr.
3464 Expr *OutputExpr = S->getOutputExpr(I);
3465 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3466 if (Result.isInvalid())
3467 return SemaRef.StmtError();
3468
3469 ExprsChanged |= Result.get() != OutputExpr;
3470
3471 Exprs.push_back(Result.takeAs<Expr>());
3472 }
3473
3474 // Go through the inputs.
3475 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003476 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003477
Anders Carlssonaaeef072010-01-24 05:50:09 +00003478 // No need to transform the constraint literal.
3479 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3480
3481 // Transform the input expr.
3482 Expr *InputExpr = S->getInputExpr(I);
3483 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3484 if (Result.isInvalid())
3485 return SemaRef.StmtError();
3486
3487 ExprsChanged |= Result.get() != InputExpr;
3488
3489 Exprs.push_back(Result.takeAs<Expr>());
3490 }
3491
3492 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3493 return SemaRef.Owned(S->Retain());
3494
3495 // Go through the clobbers.
3496 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3497 Clobbers.push_back(S->getClobber(I)->Retain());
3498
3499 // No need to transform the asm string literal.
3500 AsmString = SemaRef.Owned(S->getAsmString());
3501
3502 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3503 S->isSimple(),
3504 S->isVolatile(),
3505 S->getNumOutputs(),
3506 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003507 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003508 move_arg(Constraints),
3509 move_arg(Exprs),
3510 move(AsmString),
3511 move_arg(Clobbers),
3512 S->getRParenLoc(),
3513 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003514}
3515
3516
3517template<typename Derived>
3518Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003519TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003520 // FIXME: Implement this
3521 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003522 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003523}
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregorebe10102009-08-20 07:17:43 +00003525template<typename Derived>
3526Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003527TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003528 // FIXME: Implement this
3529 assert(false && "Cannot transform an Objective-C @catch statement");
3530 return SemaRef.Owned(S->Retain());
3531}
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorebe10102009-08-20 07:17:43 +00003533template<typename Derived>
3534Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // FIXME: Implement this
3537 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003538 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003539}
Mike Stump11289f42009-09-09 15:08:12 +00003540
Douglas Gregorebe10102009-08-20 07:17:43 +00003541template<typename Derived>
3542Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003543TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003544 // FIXME: Implement this
3545 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003546 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003547}
Mike Stump11289f42009-09-09 15:08:12 +00003548
Douglas Gregorebe10102009-08-20 07:17:43 +00003549template<typename Derived>
3550Sema::OwningStmtResult
3551TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003552 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003553 // FIXME: Implement this
3554 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003555 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003556}
3557
3558template<typename Derived>
3559Sema::OwningStmtResult
3560TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003561 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003562 // FIXME: Implement this
3563 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003564 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003565}
3566
3567
3568template<typename Derived>
3569Sema::OwningStmtResult
3570TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3571 // Transform the exception declaration, if any.
3572 VarDecl *Var = 0;
3573 if (S->getExceptionDecl()) {
3574 VarDecl *ExceptionDecl = S->getExceptionDecl();
3575 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3576 ExceptionDecl->getDeclName());
3577
3578 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3579 if (T.isNull())
3580 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003581
Douglas Gregorebe10102009-08-20 07:17:43 +00003582 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3583 T,
John McCallbcd03502009-12-07 02:54:59 +00003584 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003585 ExceptionDecl->getIdentifier(),
3586 ExceptionDecl->getLocation(),
3587 /*FIXME: Inaccurate*/
3588 SourceRange(ExceptionDecl->getLocation()));
3589 if (!Var || Var->isInvalidDecl()) {
3590 if (Var)
3591 Var->Destroy(SemaRef.Context);
3592 return SemaRef.StmtError();
3593 }
3594 }
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregorebe10102009-08-20 07:17:43 +00003596 // Transform the actual exception handler.
3597 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3598 if (Handler.isInvalid()) {
3599 if (Var)
3600 Var->Destroy(SemaRef.Context);
3601 return SemaRef.StmtError();
3602 }
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 if (!getDerived().AlwaysRebuild() &&
3605 !Var &&
3606 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003607 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003608
3609 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3610 Var,
3611 move(Handler));
3612}
Mike Stump11289f42009-09-09 15:08:12 +00003613
Douglas Gregorebe10102009-08-20 07:17:43 +00003614template<typename Derived>
3615Sema::OwningStmtResult
3616TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3617 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003618 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003619 = getDerived().TransformCompoundStmt(S->getTryBlock());
3620 if (TryBlock.isInvalid())
3621 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregorebe10102009-08-20 07:17:43 +00003623 // Transform the handlers.
3624 bool HandlerChanged = false;
3625 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3626 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003627 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3629 if (Handler.isInvalid())
3630 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003631
Douglas Gregorebe10102009-08-20 07:17:43 +00003632 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3633 Handlers.push_back(Handler.takeAs<Stmt>());
3634 }
Mike Stump11289f42009-09-09 15:08:12 +00003635
Douglas Gregorebe10102009-08-20 07:17:43 +00003636 if (!getDerived().AlwaysRebuild() &&
3637 TryBlock.get() == S->getTryBlock() &&
3638 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003639 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003640
3641 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003642 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003643}
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregorebe10102009-08-20 07:17:43 +00003645//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003646// Expression transformation
3647//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003648template<typename Derived>
3649Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003650TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003651 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003652}
Mike Stump11289f42009-09-09 15:08:12 +00003653
3654template<typename Derived>
3655Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003656TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003657 NestedNameSpecifier *Qualifier = 0;
3658 if (E->getQualifier()) {
3659 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003660 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003661 if (!Qualifier)
3662 return SemaRef.ExprError();
3663 }
John McCallce546572009-12-08 09:08:17 +00003664
3665 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003666 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3667 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003668 if (!ND)
3669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003670
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003671 if (!getDerived().AlwaysRebuild() &&
3672 Qualifier == E->getQualifier() &&
3673 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003674 !E->hasExplicitTemplateArgumentList()) {
3675
3676 // Mark it referenced in the new context regardless.
3677 // FIXME: this is a bit instantiation-specific.
3678 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3679
Mike Stump11289f42009-09-09 15:08:12 +00003680 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003681 }
John McCallce546572009-12-08 09:08:17 +00003682
3683 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3684 if (E->hasExplicitTemplateArgumentList()) {
3685 TemplateArgs = &TransArgs;
3686 TransArgs.setLAngleLoc(E->getLAngleLoc());
3687 TransArgs.setRAngleLoc(E->getRAngleLoc());
3688 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3689 TemplateArgumentLoc Loc;
3690 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3691 return SemaRef.ExprError();
3692 TransArgs.addArgument(Loc);
3693 }
3694 }
3695
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003696 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003697 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003698}
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregora16548e2009-08-11 05:31:07 +00003700template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003701Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003702TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003703 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003704}
Mike Stump11289f42009-09-09 15:08:12 +00003705
Douglas Gregora16548e2009-08-11 05:31:07 +00003706template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003707Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003708TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003709 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003710}
Mike Stump11289f42009-09-09 15:08:12 +00003711
Douglas Gregora16548e2009-08-11 05:31:07 +00003712template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003713Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003714TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003715 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003716}
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregora16548e2009-08-11 05:31:07 +00003718template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003719Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003720TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003721 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003722}
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregora16548e2009-08-11 05:31:07 +00003724template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003725Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003726TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003727 return SemaRef.Owned(E->Retain());
3728}
3729
3730template<typename Derived>
3731Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003732TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3734 if (SubExpr.isInvalid())
3735 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregora16548e2009-08-11 05:31:07 +00003737 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003738 return SemaRef.Owned(E->Retain());
3739
3740 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003741 E->getRParen());
3742}
3743
Mike Stump11289f42009-09-09 15:08:12 +00003744template<typename Derived>
3745Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003746TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3747 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003748 if (SubExpr.isInvalid())
3749 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003750
Douglas Gregora16548e2009-08-11 05:31:07 +00003751 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003752 return SemaRef.Owned(E->Retain());
3753
Douglas Gregora16548e2009-08-11 05:31:07 +00003754 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3755 E->getOpcode(),
3756 move(SubExpr));
3757}
Mike Stump11289f42009-09-09 15:08:12 +00003758
Douglas Gregora16548e2009-08-11 05:31:07 +00003759template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003760Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003761TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003762 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003763 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003764
John McCallbcd03502009-12-07 02:54:59 +00003765 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003766 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003767 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003768
John McCall4c98fd82009-11-04 07:28:41 +00003769 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003770 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003771
John McCall4c98fd82009-11-04 07:28:41 +00003772 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003773 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003774 E->getSourceRange());
3775 }
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregora16548e2009-08-11 05:31:07 +00003777 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003778 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003779 // C++0x [expr.sizeof]p1:
3780 // The operand is either an expression, which is an unevaluated operand
3781 // [...]
3782 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003783
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3785 if (SubExpr.isInvalid())
3786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregora16548e2009-08-11 05:31:07 +00003788 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3789 return SemaRef.Owned(E->Retain());
3790 }
Mike Stump11289f42009-09-09 15:08:12 +00003791
Douglas Gregora16548e2009-08-11 05:31:07 +00003792 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3793 E->isSizeOf(),
3794 E->getSourceRange());
3795}
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregora16548e2009-08-11 05:31:07 +00003797template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003798Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003799TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003800 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3801 if (LHS.isInvalid())
3802 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003803
Douglas Gregora16548e2009-08-11 05:31:07 +00003804 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3805 if (RHS.isInvalid())
3806 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003807
3808
Douglas Gregora16548e2009-08-11 05:31:07 +00003809 if (!getDerived().AlwaysRebuild() &&
3810 LHS.get() == E->getLHS() &&
3811 RHS.get() == E->getRHS())
3812 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregora16548e2009-08-11 05:31:07 +00003814 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3815 /*FIXME:*/E->getLHS()->getLocStart(),
3816 move(RHS),
3817 E->getRBracketLoc());
3818}
Mike Stump11289f42009-09-09 15:08:12 +00003819
3820template<typename Derived>
3821Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003822TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003823 // Transform the callee.
3824 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3825 if (Callee.isInvalid())
3826 return SemaRef.ExprError();
3827
3828 // Transform arguments.
3829 bool ArgChanged = false;
3830 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3831 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3832 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3833 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3834 if (Arg.isInvalid())
3835 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 // FIXME: Wrong source location information for the ','.
3838 FakeCommaLocs.push_back(
3839 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003840
3841 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003842 Args.push_back(Arg.takeAs<Expr>());
3843 }
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregora16548e2009-08-11 05:31:07 +00003845 if (!getDerived().AlwaysRebuild() &&
3846 Callee.get() == E->getCallee() &&
3847 !ArgChanged)
3848 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregora16548e2009-08-11 05:31:07 +00003850 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003851 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003852 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3853 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3854 move_arg(Args),
3855 FakeCommaLocs.data(),
3856 E->getRParenLoc());
3857}
Mike Stump11289f42009-09-09 15:08:12 +00003858
3859template<typename Derived>
3860Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003861TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003862 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3863 if (Base.isInvalid())
3864 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003866 NestedNameSpecifier *Qualifier = 0;
3867 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003868 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003869 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003870 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003871 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003872 return SemaRef.ExprError();
3873 }
Mike Stump11289f42009-09-09 15:08:12 +00003874
Eli Friedman2cfcef62009-12-04 06:40:45 +00003875 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003876 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3877 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003878 if (!Member)
3879 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003880
John McCall16df1e52010-03-30 21:47:33 +00003881 NamedDecl *FoundDecl = E->getFoundDecl();
3882 if (FoundDecl == E->getMemberDecl()) {
3883 FoundDecl = Member;
3884 } else {
3885 FoundDecl = cast_or_null<NamedDecl>(
3886 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
3887 if (!FoundDecl)
3888 return SemaRef.ExprError();
3889 }
3890
Douglas Gregora16548e2009-08-11 05:31:07 +00003891 if (!getDerived().AlwaysRebuild() &&
3892 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003893 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003894 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00003895 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003896 !E->hasExplicitTemplateArgumentList()) {
3897
3898 // Mark it referenced in the new context regardless.
3899 // FIXME: this is a bit instantiation-specific.
3900 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003901 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003902 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003903
John McCall6b51f282009-11-23 01:53:49 +00003904 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003905 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003906 TransArgs.setLAngleLoc(E->getLAngleLoc());
3907 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003908 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003909 TemplateArgumentLoc Loc;
3910 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003911 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003912 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003913 }
3914 }
3915
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 // FIXME: Bogus source location for the operator
3917 SourceLocation FakeOperatorLoc
3918 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3919
John McCall38836f02010-01-15 08:34:02 +00003920 // FIXME: to do this check properly, we will need to preserve the
3921 // first-qualifier-in-scope here, just in case we had a dependent
3922 // base (and therefore couldn't do the check) and a
3923 // nested-name-qualifier (and therefore could do the lookup).
3924 NamedDecl *FirstQualifierInScope = 0;
3925
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3927 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003928 Qualifier,
3929 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003930 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003931 Member,
John McCall16df1e52010-03-30 21:47:33 +00003932 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00003933 (E->hasExplicitTemplateArgumentList()
3934 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003935 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003936}
Mike Stump11289f42009-09-09 15:08:12 +00003937
Douglas Gregora16548e2009-08-11 05:31:07 +00003938template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003939Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003940TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003941 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3942 if (LHS.isInvalid())
3943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3946 if (RHS.isInvalid())
3947 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003948
Douglas Gregora16548e2009-08-11 05:31:07 +00003949 if (!getDerived().AlwaysRebuild() &&
3950 LHS.get() == E->getLHS() &&
3951 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003952 return SemaRef.Owned(E->Retain());
3953
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3955 move(LHS), move(RHS));
3956}
3957
Mike Stump11289f42009-09-09 15:08:12 +00003958template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003959Sema::OwningExprResult
3960TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003961 CompoundAssignOperator *E) {
3962 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003963}
Mike Stump11289f42009-09-09 15:08:12 +00003964
Douglas Gregora16548e2009-08-11 05:31:07 +00003965template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003966Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003967TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3969 if (Cond.isInvalid())
3970 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003971
Douglas Gregora16548e2009-08-11 05:31:07 +00003972 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3973 if (LHS.isInvalid())
3974 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003975
Douglas Gregora16548e2009-08-11 05:31:07 +00003976 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3977 if (RHS.isInvalid())
3978 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregora16548e2009-08-11 05:31:07 +00003980 if (!getDerived().AlwaysRebuild() &&
3981 Cond.get() == E->getCond() &&
3982 LHS.get() == E->getLHS() &&
3983 RHS.get() == E->getRHS())
3984 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003985
3986 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003987 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003988 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003989 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 move(RHS));
3991}
Mike Stump11289f42009-09-09 15:08:12 +00003992
3993template<typename Derived>
3994Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003995TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003996 // Implicit casts are eliminated during transformation, since they
3997 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003998 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003999}
Mike Stump11289f42009-09-09 15:08:12 +00004000
Douglas Gregora16548e2009-08-11 05:31:07 +00004001template<typename Derived>
4002Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004003TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004004 TypeSourceInfo *OldT;
4005 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 {
4007 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004008 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004009 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4010 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004011
John McCall97513962010-01-15 18:39:57 +00004012 OldT = E->getTypeInfoAsWritten();
4013 NewT = getDerived().TransformType(OldT);
4014 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 return SemaRef.ExprError();
4016 }
Mike Stump11289f42009-09-09 15:08:12 +00004017
Douglas Gregor6131b442009-12-12 18:16:41 +00004018 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004019 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004020 if (SubExpr.isInvalid())
4021 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregora16548e2009-08-11 05:31:07 +00004023 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004024 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004025 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004026 return SemaRef.Owned(E->Retain());
4027
John McCall97513962010-01-15 18:39:57 +00004028 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4029 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004030 E->getRParenLoc(),
4031 move(SubExpr));
4032}
Mike Stump11289f42009-09-09 15:08:12 +00004033
Douglas Gregora16548e2009-08-11 05:31:07 +00004034template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004035Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004036TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004037 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4038 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4039 if (!NewT)
4040 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004041
Douglas Gregora16548e2009-08-11 05:31:07 +00004042 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4043 if (Init.isInvalid())
4044 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004047 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004048 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004049 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004050
John McCall5d7aa7f2010-01-19 22:33:45 +00004051 // Note: the expression type doesn't necessarily match the
4052 // type-as-written, but that's okay, because it should always be
4053 // derivable from the initializer.
4054
John McCalle15bbff2010-01-18 19:35:47 +00004055 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004056 /*FIXME:*/E->getInitializer()->getLocEnd(),
4057 move(Init));
4058}
Mike Stump11289f42009-09-09 15:08:12 +00004059
Douglas Gregora16548e2009-08-11 05:31:07 +00004060template<typename Derived>
4061Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004062TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004063 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4064 if (Base.isInvalid())
4065 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004066
Douglas Gregora16548e2009-08-11 05:31:07 +00004067 if (!getDerived().AlwaysRebuild() &&
4068 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004069 return SemaRef.Owned(E->Retain());
4070
Douglas Gregora16548e2009-08-11 05:31:07 +00004071 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004072 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004073 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4074 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4075 E->getAccessorLoc(),
4076 E->getAccessor());
4077}
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004080Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004081TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004082 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004083
Douglas Gregora16548e2009-08-11 05:31:07 +00004084 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4085 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4086 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4087 if (Init.isInvalid())
4088 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004089
Douglas Gregora16548e2009-08-11 05:31:07 +00004090 InitChanged = InitChanged || Init.get() != E->getInit(I);
4091 Inits.push_back(Init.takeAs<Expr>());
4092 }
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregora16548e2009-08-11 05:31:07 +00004094 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004095 return SemaRef.Owned(E->Retain());
4096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004098 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004099}
Mike Stump11289f42009-09-09 15:08:12 +00004100
Douglas Gregora16548e2009-08-11 05:31:07 +00004101template<typename Derived>
4102Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004103TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004104 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregorebe10102009-08-20 07:17:43 +00004106 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4108 if (Init.isInvalid())
4109 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004110
Douglas Gregorebe10102009-08-20 07:17:43 +00004111 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4113 bool ExprChanged = false;
4114 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4115 DEnd = E->designators_end();
4116 D != DEnd; ++D) {
4117 if (D->isFieldDesignator()) {
4118 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4119 D->getDotLoc(),
4120 D->getFieldLoc()));
4121 continue;
4122 }
Mike Stump11289f42009-09-09 15:08:12 +00004123
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 if (D->isArrayDesignator()) {
4125 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4126 if (Index.isInvalid())
4127 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004128
4129 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004130 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4133 ArrayExprs.push_back(Index.release());
4134 continue;
4135 }
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregora16548e2009-08-11 05:31:07 +00004137 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004138 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004139 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4140 if (Start.isInvalid())
4141 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregora16548e2009-08-11 05:31:07 +00004143 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4144 if (End.isInvalid())
4145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
4147 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004148 End.get(),
4149 D->getLBracketLoc(),
4150 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregora16548e2009-08-11 05:31:07 +00004152 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4153 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004154
Douglas Gregora16548e2009-08-11 05:31:07 +00004155 ArrayExprs.push_back(Start.release());
4156 ArrayExprs.push_back(End.release());
4157 }
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregora16548e2009-08-11 05:31:07 +00004159 if (!getDerived().AlwaysRebuild() &&
4160 Init.get() == E->getInit() &&
4161 !ExprChanged)
4162 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4165 E->getEqualOrColonLoc(),
4166 E->usesGNUSyntax(), move(Init));
4167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregora16548e2009-08-11 05:31:07 +00004169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004170Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004171TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004172 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004173 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4174
4175 // FIXME: Will we ever have proper type location here? Will we actually
4176 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 QualType T = getDerived().TransformType(E->getType());
4178 if (T.isNull())
4179 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 if (!getDerived().AlwaysRebuild() &&
4182 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004183 return SemaRef.Owned(E->Retain());
4184
Douglas Gregora16548e2009-08-11 05:31:07 +00004185 return getDerived().RebuildImplicitValueInitExpr(T);
4186}
Mike Stump11289f42009-09-09 15:08:12 +00004187
Douglas Gregora16548e2009-08-11 05:31:07 +00004188template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004189Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004190TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004191 // FIXME: Do we want the type as written?
4192 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004193
Douglas Gregora16548e2009-08-11 05:31:07 +00004194 {
4195 // FIXME: Source location isn't quite accurate.
4196 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4197 T = getDerived().TransformType(E->getType());
4198 if (T.isNull())
4199 return SemaRef.ExprError();
4200 }
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4203 if (SubExpr.isInvalid())
4204 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206 if (!getDerived().AlwaysRebuild() &&
4207 T == E->getType() &&
4208 SubExpr.get() == E->getSubExpr())
4209 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4212 T, E->getRParenLoc());
4213}
4214
4215template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004216Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004217TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004218 bool ArgumentChanged = false;
4219 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4220 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4221 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4222 if (Init.isInvalid())
4223 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004224
Douglas Gregora16548e2009-08-11 05:31:07 +00004225 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4226 Inits.push_back(Init.takeAs<Expr>());
4227 }
Mike Stump11289f42009-09-09 15:08:12 +00004228
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4230 move_arg(Inits),
4231 E->getRParenLoc());
4232}
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregora16548e2009-08-11 05:31:07 +00004234/// \brief Transform an address-of-label expression.
4235///
4236/// By default, the transformation of an address-of-label expression always
4237/// rebuilds the expression, so that the label identifier can be resolved to
4238/// the corresponding label statement by semantic analysis.
4239template<typename Derived>
4240Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004241TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004242 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4243 E->getLabel());
4244}
Mike Stump11289f42009-09-09 15:08:12 +00004245
4246template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004247Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004248TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004249 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004250 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4251 if (SubStmt.isInvalid())
4252 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004253
Douglas Gregora16548e2009-08-11 05:31:07 +00004254 if (!getDerived().AlwaysRebuild() &&
4255 SubStmt.get() == E->getSubStmt())
4256 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004257
4258 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004259 move(SubStmt),
4260 E->getRParenLoc());
4261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263template<typename Derived>
4264Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004265TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 QualType T1, T2;
4267 {
4268 // FIXME: Source location isn't quite accurate.
4269 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004270
Douglas Gregora16548e2009-08-11 05:31:07 +00004271 T1 = getDerived().TransformType(E->getArgType1());
4272 if (T1.isNull())
4273 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004274
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 T2 = getDerived().TransformType(E->getArgType2());
4276 if (T2.isNull())
4277 return SemaRef.ExprError();
4278 }
4279
4280 if (!getDerived().AlwaysRebuild() &&
4281 T1 == E->getArgType1() &&
4282 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004283 return SemaRef.Owned(E->Retain());
4284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4286 T1, T2, E->getRParenLoc());
4287}
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregora16548e2009-08-11 05:31:07 +00004289template<typename Derived>
4290Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004291TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004292 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4293 if (Cond.isInvalid())
4294 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004295
Douglas Gregora16548e2009-08-11 05:31:07 +00004296 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4297 if (LHS.isInvalid())
4298 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004299
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4301 if (RHS.isInvalid())
4302 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004303
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 if (!getDerived().AlwaysRebuild() &&
4305 Cond.get() == E->getCond() &&
4306 LHS.get() == E->getLHS() &&
4307 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004308 return SemaRef.Owned(E->Retain());
4309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4311 move(Cond), move(LHS), move(RHS),
4312 E->getRParenLoc());
4313}
Mike Stump11289f42009-09-09 15:08:12 +00004314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004316Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004317TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004318 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004319}
4320
4321template<typename Derived>
4322Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004323TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004324 switch (E->getOperator()) {
4325 case OO_New:
4326 case OO_Delete:
4327 case OO_Array_New:
4328 case OO_Array_Delete:
4329 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4330 return SemaRef.ExprError();
4331
4332 case OO_Call: {
4333 // This is a call to an object's operator().
4334 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4335
4336 // Transform the object itself.
4337 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4338 if (Object.isInvalid())
4339 return SemaRef.ExprError();
4340
4341 // FIXME: Poor location information
4342 SourceLocation FakeLParenLoc
4343 = SemaRef.PP.getLocForEndOfToken(
4344 static_cast<Expr *>(Object.get())->getLocEnd());
4345
4346 // Transform the call arguments.
4347 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4348 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4349 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004350 if (getDerived().DropCallArgument(E->getArg(I)))
4351 break;
4352
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004353 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4354 if (Arg.isInvalid())
4355 return SemaRef.ExprError();
4356
4357 // FIXME: Poor source location information.
4358 SourceLocation FakeCommaLoc
4359 = SemaRef.PP.getLocForEndOfToken(
4360 static_cast<Expr *>(Arg.get())->getLocEnd());
4361 FakeCommaLocs.push_back(FakeCommaLoc);
4362 Args.push_back(Arg.release());
4363 }
4364
4365 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4366 move_arg(Args),
4367 FakeCommaLocs.data(),
4368 E->getLocEnd());
4369 }
4370
4371#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4372 case OO_##Name:
4373#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4374#include "clang/Basic/OperatorKinds.def"
4375 case OO_Subscript:
4376 // Handled below.
4377 break;
4378
4379 case OO_Conditional:
4380 llvm_unreachable("conditional operator is not actually overloadable");
4381 return SemaRef.ExprError();
4382
4383 case OO_None:
4384 case NUM_OVERLOADED_OPERATORS:
4385 llvm_unreachable("not an overloaded operator?");
4386 return SemaRef.ExprError();
4387 }
4388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4390 if (Callee.isInvalid())
4391 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004392
John McCall47f29ea2009-12-08 09:21:05 +00004393 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 if (First.isInvalid())
4395 return SemaRef.ExprError();
4396
4397 OwningExprResult Second(SemaRef);
4398 if (E->getNumArgs() == 2) {
4399 Second = getDerived().TransformExpr(E->getArg(1));
4400 if (Second.isInvalid())
4401 return SemaRef.ExprError();
4402 }
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 if (!getDerived().AlwaysRebuild() &&
4405 Callee.get() == E->getCallee() &&
4406 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004407 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4408 return SemaRef.Owned(E->Retain());
4409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4411 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004412 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 move(First),
4414 move(Second));
4415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
4418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4420 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004421}
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004424Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004425TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004426 TypeSourceInfo *OldT;
4427 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 {
4429 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004430 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4432 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004433
John McCall97513962010-01-15 18:39:57 +00004434 OldT = E->getTypeInfoAsWritten();
4435 NewT = getDerived().TransformType(OldT);
4436 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 return SemaRef.ExprError();
4438 }
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregor6131b442009-12-12 18:16:41 +00004440 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004441 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 if (SubExpr.isInvalid())
4443 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004446 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004448 return SemaRef.Owned(E->Retain());
4449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004451 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4453 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4454 SourceLocation FakeRParenLoc
4455 = SemaRef.PP.getLocForEndOfToken(
4456 E->getSubExpr()->getSourceRange().getEnd());
4457 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004458 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004460 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 FakeRAngleLoc,
4462 FakeRAngleLoc,
4463 move(SubExpr),
4464 FakeRParenLoc);
4465}
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467template<typename Derived>
4468Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004469TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4470 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004471}
Mike Stump11289f42009-09-09 15:08:12 +00004472
4473template<typename Derived>
4474Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004475TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4476 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004477}
4478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479template<typename Derived>
4480Sema::OwningExprResult
4481TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004482 CXXReinterpretCastExpr *E) {
4483 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004484}
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregora16548e2009-08-11 05:31:07 +00004486template<typename Derived>
4487Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004488TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4489 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004490}
Mike Stump11289f42009-09-09 15:08:12 +00004491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492template<typename Derived>
4493Sema::OwningExprResult
4494TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004495 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004496 TypeSourceInfo *OldT;
4497 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 {
4499 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004500
John McCall97513962010-01-15 18:39:57 +00004501 OldT = E->getTypeInfoAsWritten();
4502 NewT = getDerived().TransformType(OldT);
4503 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 return SemaRef.ExprError();
4505 }
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregor6131b442009-12-12 18:16:41 +00004507 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004508 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 if (SubExpr.isInvalid())
4510 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregora16548e2009-08-11 05:31:07 +00004512 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004513 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004515 return SemaRef.Owned(E->Retain());
4516
Douglas Gregora16548e2009-08-11 05:31:07 +00004517 // FIXME: The end of the type's source range is wrong
4518 return getDerived().RebuildCXXFunctionalCastExpr(
4519 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004520 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 /*FIXME:*/E->getSubExpr()->getLocStart(),
4522 move(SubExpr),
4523 E->getRParenLoc());
4524}
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526template<typename Derived>
4527Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004528TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 if (E->isTypeOperand()) {
4530 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 QualType T = getDerived().TransformType(E->getTypeOperand());
4533 if (T.isNull())
4534 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004535
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 if (!getDerived().AlwaysRebuild() &&
4537 T == E->getTypeOperand())
4538 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4541 /*FIXME:*/E->getLocStart(),
4542 T,
4543 E->getLocEnd());
4544 }
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 // We don't know whether the expression is potentially evaluated until
4547 // after we perform semantic analysis, so the expression is potentially
4548 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004549 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004550 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004551
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4553 if (SubExpr.isInvalid())
4554 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004555
Douglas Gregora16548e2009-08-11 05:31:07 +00004556 if (!getDerived().AlwaysRebuild() &&
4557 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004558 return SemaRef.Owned(E->Retain());
4559
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4561 /*FIXME:*/E->getLocStart(),
4562 move(SubExpr),
4563 E->getLocEnd());
4564}
4565
4566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004567Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004568TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004569 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004570}
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572template<typename Derived>
4573Sema::OwningExprResult
4574TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004575 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004576 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004577}
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregora16548e2009-08-11 05:31:07 +00004579template<typename Derived>
4580Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004581TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004583
Douglas Gregora16548e2009-08-11 05:31:07 +00004584 QualType T = getDerived().TransformType(E->getType());
4585 if (T.isNull())
4586 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004587
Douglas Gregora16548e2009-08-11 05:31:07 +00004588 if (!getDerived().AlwaysRebuild() &&
4589 T == E->getType())
4590 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregorb15af892010-01-07 23:12:05 +00004592 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004593}
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregora16548e2009-08-11 05:31:07 +00004595template<typename Derived>
4596Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004597TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004598 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4599 if (SubExpr.isInvalid())
4600 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 if (!getDerived().AlwaysRebuild() &&
4603 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004604 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004605
4606 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4607}
Mike Stump11289f42009-09-09 15:08:12 +00004608
Douglas Gregora16548e2009-08-11 05:31:07 +00004609template<typename Derived>
4610Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004611TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004612 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004613 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4614 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 if (!Param)
4616 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004617
Chandler Carruth794da4c2010-02-08 06:42:49 +00004618 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004619 Param == E->getParam())
4620 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregor033f6752009-12-23 23:03:06 +00004622 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004623}
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625template<typename Derived>
4626Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004627TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4629
4630 QualType T = getDerived().TransformType(E->getType());
4631 if (T.isNull())
4632 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 if (!getDerived().AlwaysRebuild() &&
4635 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004636 return SemaRef.Owned(E->Retain());
4637
4638 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 /*FIXME:*/E->getTypeBeginLoc(),
4640 T,
4641 E->getRParenLoc());
4642}
Mike Stump11289f42009-09-09 15:08:12 +00004643
Douglas Gregora16548e2009-08-11 05:31:07 +00004644template<typename Derived>
4645Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004646TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 // Transform the type that we're allocating
4648 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4649 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4650 if (AllocType.isNull())
4651 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 // Transform the size of the array we're allocating (if any).
4654 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4655 if (ArraySize.isInvalid())
4656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 // Transform the placement arguments (if any).
4659 bool ArgumentChanged = false;
4660 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4661 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4662 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4663 if (Arg.isInvalid())
4664 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4667 PlacementArgs.push_back(Arg.take());
4668 }
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregorebe10102009-08-20 07:17:43 +00004670 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4672 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4673 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4674 if (Arg.isInvalid())
4675 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4678 ConstructorArgs.push_back(Arg.take());
4679 }
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregord2d9da02010-02-26 00:38:10 +00004681 // Transform constructor, new operator, and delete operator.
4682 CXXConstructorDecl *Constructor = 0;
4683 if (E->getConstructor()) {
4684 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004685 getDerived().TransformDecl(E->getLocStart(),
4686 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004687 if (!Constructor)
4688 return SemaRef.ExprError();
4689 }
4690
4691 FunctionDecl *OperatorNew = 0;
4692 if (E->getOperatorNew()) {
4693 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004694 getDerived().TransformDecl(E->getLocStart(),
4695 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004696 if (!OperatorNew)
4697 return SemaRef.ExprError();
4698 }
4699
4700 FunctionDecl *OperatorDelete = 0;
4701 if (E->getOperatorDelete()) {
4702 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004703 getDerived().TransformDecl(E->getLocStart(),
4704 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004705 if (!OperatorDelete)
4706 return SemaRef.ExprError();
4707 }
4708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 if (!getDerived().AlwaysRebuild() &&
4710 AllocType == E->getAllocatedType() &&
4711 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004712 Constructor == E->getConstructor() &&
4713 OperatorNew == E->getOperatorNew() &&
4714 OperatorDelete == E->getOperatorDelete() &&
4715 !ArgumentChanged) {
4716 // Mark any declarations we need as referenced.
4717 // FIXME: instantiation-specific.
4718 if (Constructor)
4719 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4720 if (OperatorNew)
4721 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4722 if (OperatorDelete)
4723 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004724 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004725 }
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004727 if (!ArraySize.get()) {
4728 // If no array size was specified, but the new expression was
4729 // instantiated with an array type (e.g., "new T" where T is
4730 // instantiated with "int[4]"), extract the outer bound from the
4731 // array type as our array size. We do this with constant and
4732 // dependently-sized array types.
4733 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4734 if (!ArrayT) {
4735 // Do nothing
4736 } else if (const ConstantArrayType *ConsArrayT
4737 = dyn_cast<ConstantArrayType>(ArrayT)) {
4738 ArraySize
4739 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4740 ConsArrayT->getSize(),
4741 SemaRef.Context.getSizeType(),
4742 /*FIXME:*/E->getLocStart()));
4743 AllocType = ConsArrayT->getElementType();
4744 } else if (const DependentSizedArrayType *DepArrayT
4745 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4746 if (DepArrayT->getSizeExpr()) {
4747 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4748 AllocType = DepArrayT->getElementType();
4749 }
4750 }
4751 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4753 E->isGlobalNew(),
4754 /*FIXME:*/E->getLocStart(),
4755 move_arg(PlacementArgs),
4756 /*FIXME:*/E->getLocStart(),
4757 E->isParenTypeId(),
4758 AllocType,
4759 /*FIXME:*/E->getLocStart(),
4760 /*FIXME:*/SourceRange(),
4761 move(ArraySize),
4762 /*FIXME:*/E->getLocStart(),
4763 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004764 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767template<typename Derived>
4768Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004769TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4771 if (Operand.isInvalid())
4772 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregord2d9da02010-02-26 00:38:10 +00004774 // Transform the delete operator, if known.
4775 FunctionDecl *OperatorDelete = 0;
4776 if (E->getOperatorDelete()) {
4777 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004778 getDerived().TransformDecl(E->getLocStart(),
4779 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004780 if (!OperatorDelete)
4781 return SemaRef.ExprError();
4782 }
4783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004785 Operand.get() == E->getArgument() &&
4786 OperatorDelete == E->getOperatorDelete()) {
4787 // Mark any declarations we need as referenced.
4788 // FIXME: instantiation-specific.
4789 if (OperatorDelete)
4790 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004791 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004792 }
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4795 E->isGlobalDelete(),
4796 E->isArrayForm(),
4797 move(Operand));
4798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800template<typename Derived>
4801Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004802TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004803 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004804 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4805 if (Base.isInvalid())
4806 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregor678f90d2010-02-25 01:56:36 +00004808 Sema::TypeTy *ObjectTypePtr = 0;
4809 bool MayBePseudoDestructor = false;
4810 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4811 E->getOperatorLoc(),
4812 E->isArrow()? tok::arrow : tok::period,
4813 ObjectTypePtr,
4814 MayBePseudoDestructor);
4815 if (Base.isInvalid())
4816 return SemaRef.ExprError();
4817
4818 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004819 NestedNameSpecifier *Qualifier
4820 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004821 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004822 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004823 if (E->getQualifier() && !Qualifier)
4824 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregor678f90d2010-02-25 01:56:36 +00004826 PseudoDestructorTypeStorage Destroyed;
4827 if (E->getDestroyedTypeInfo()) {
4828 TypeSourceInfo *DestroyedTypeInfo
4829 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4830 if (!DestroyedTypeInfo)
4831 return SemaRef.ExprError();
4832 Destroyed = DestroyedTypeInfo;
4833 } else if (ObjectType->isDependentType()) {
4834 // We aren't likely to be able to resolve the identifier down to a type
4835 // now anyway, so just retain the identifier.
4836 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4837 E->getDestroyedTypeLoc());
4838 } else {
4839 // Look for a destructor known with the given name.
4840 CXXScopeSpec SS;
4841 if (Qualifier) {
4842 SS.setScopeRep(Qualifier);
4843 SS.setRange(E->getQualifierRange());
4844 }
4845
4846 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4847 *E->getDestroyedTypeIdentifier(),
4848 E->getDestroyedTypeLoc(),
4849 /*Scope=*/0,
4850 SS, ObjectTypePtr,
4851 false);
4852 if (!T)
4853 return SemaRef.ExprError();
4854
4855 Destroyed
4856 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4857 E->getDestroyedTypeLoc());
4858 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004859
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004860 TypeSourceInfo *ScopeTypeInfo = 0;
4861 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004862 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4863 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004864 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004865 return SemaRef.ExprError();
4866 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004867
Douglas Gregorad8a3362009-09-04 17:36:40 +00004868 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4869 E->getOperatorLoc(),
4870 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004871 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004872 E->getQualifierRange(),
4873 ScopeTypeInfo,
4874 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00004875 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004876 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004877}
Mike Stump11289f42009-09-09 15:08:12 +00004878
Douglas Gregorad8a3362009-09-04 17:36:40 +00004879template<typename Derived>
4880Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004881TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004882 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004883 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4884
4885 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4886 Sema::LookupOrdinaryName);
4887
4888 // Transform all the decls.
4889 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4890 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004891 NamedDecl *InstD = static_cast<NamedDecl*>(
4892 getDerived().TransformDecl(Old->getNameLoc(),
4893 *I));
John McCall84d87672009-12-10 09:41:52 +00004894 if (!InstD) {
4895 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4896 // This can happen because of dependent hiding.
4897 if (isa<UsingShadowDecl>(*I))
4898 continue;
4899 else
4900 return SemaRef.ExprError();
4901 }
John McCalle66edc12009-11-24 19:00:30 +00004902
4903 // Expand using declarations.
4904 if (isa<UsingDecl>(InstD)) {
4905 UsingDecl *UD = cast<UsingDecl>(InstD);
4906 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4907 E = UD->shadow_end(); I != E; ++I)
4908 R.addDecl(*I);
4909 continue;
4910 }
4911
4912 R.addDecl(InstD);
4913 }
4914
4915 // Resolve a kind, but don't do any further analysis. If it's
4916 // ambiguous, the callee needs to deal with it.
4917 R.resolveKind();
4918
4919 // Rebuild the nested-name qualifier, if present.
4920 CXXScopeSpec SS;
4921 NestedNameSpecifier *Qualifier = 0;
4922 if (Old->getQualifier()) {
4923 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004924 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00004925 if (!Qualifier)
4926 return SemaRef.ExprError();
4927
4928 SS.setScopeRep(Qualifier);
4929 SS.setRange(Old->getQualifierRange());
4930 }
4931
4932 // If we have no template arguments, it's a normal declaration name.
4933 if (!Old->hasExplicitTemplateArgs())
4934 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4935
4936 // If we have template arguments, rebuild them, then rebuild the
4937 // templateid expression.
4938 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4939 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4940 TemplateArgumentLoc Loc;
4941 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4942 return SemaRef.ExprError();
4943 TransArgs.addArgument(Loc);
4944 }
4945
4946 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4947 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004948}
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregora16548e2009-08-11 05:31:07 +00004950template<typename Derived>
4951Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004952TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004953 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregora16548e2009-08-11 05:31:07 +00004955 QualType T = getDerived().TransformType(E->getQueriedType());
4956 if (T.isNull())
4957 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004958
Douglas Gregora16548e2009-08-11 05:31:07 +00004959 if (!getDerived().AlwaysRebuild() &&
4960 T == E->getQueriedType())
4961 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 // FIXME: Bad location information
4964 SourceLocation FakeLParenLoc
4965 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004966
4967 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004968 E->getLocStart(),
4969 /*FIXME:*/FakeLParenLoc,
4970 T,
4971 E->getLocEnd());
4972}
Mike Stump11289f42009-09-09 15:08:12 +00004973
Douglas Gregora16548e2009-08-11 05:31:07 +00004974template<typename Derived>
4975Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004976TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004977 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004979 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004980 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004981 if (!NNS)
4982 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004983
4984 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004985 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4986 if (!Name)
4987 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004988
John McCalle66edc12009-11-24 19:00:30 +00004989 if (!E->hasExplicitTemplateArgs()) {
4990 if (!getDerived().AlwaysRebuild() &&
4991 NNS == E->getQualifier() &&
4992 Name == E->getDeclName())
4993 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004994
John McCalle66edc12009-11-24 19:00:30 +00004995 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4996 E->getQualifierRange(),
4997 Name, E->getLocation(),
4998 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004999 }
John McCall6b51f282009-11-23 01:53:49 +00005000
5001 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005002 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005003 TemplateArgumentLoc Loc;
5004 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005006 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 }
5008
John McCalle66edc12009-11-24 19:00:30 +00005009 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5010 E->getQualifierRange(),
5011 Name, E->getLocation(),
5012 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005013}
5014
5015template<typename Derived>
5016Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005017TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005018 // CXXConstructExprs are always implicit, so when we have a
5019 // 1-argument construction we just transform that argument.
5020 if (E->getNumArgs() == 1 ||
5021 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5022 return getDerived().TransformExpr(E->getArg(0));
5023
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5025
5026 QualType T = getDerived().TransformType(E->getType());
5027 if (T.isNull())
5028 return SemaRef.ExprError();
5029
5030 CXXConstructorDecl *Constructor
5031 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005032 getDerived().TransformDecl(E->getLocStart(),
5033 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 if (!Constructor)
5035 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 bool ArgumentChanged = false;
5038 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005039 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 ArgEnd = E->arg_end();
5041 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005042 if (getDerived().DropCallArgument(*Arg)) {
5043 ArgumentChanged = true;
5044 break;
5045 }
5046
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5048 if (TransArg.isInvalid())
5049 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregora16548e2009-08-11 05:31:07 +00005051 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5052 Args.push_back(TransArg.takeAs<Expr>());
5053 }
5054
5055 if (!getDerived().AlwaysRebuild() &&
5056 T == E->getType() &&
5057 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005058 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005059 // Mark the constructor as referenced.
5060 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005061 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005063 }
Mike Stump11289f42009-09-09 15:08:12 +00005064
Douglas Gregordb121ba2009-12-14 16:27:04 +00005065 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5066 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 move_arg(Args));
5068}
Mike Stump11289f42009-09-09 15:08:12 +00005069
Douglas Gregora16548e2009-08-11 05:31:07 +00005070/// \brief Transform a C++ temporary-binding expression.
5071///
Douglas Gregor363b1512009-12-24 18:51:59 +00005072/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5073/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005074template<typename Derived>
5075Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005076TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005077 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005078}
Mike Stump11289f42009-09-09 15:08:12 +00005079
Anders Carlssonba6c4372010-01-29 02:39:32 +00005080/// \brief Transform a C++ reference-binding expression.
5081///
5082/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5083/// transform the subexpression and return that.
5084template<typename Derived>
5085Sema::OwningExprResult
5086TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5087 return getDerived().TransformExpr(E->getSubExpr());
5088}
5089
Mike Stump11289f42009-09-09 15:08:12 +00005090/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005091/// be destroyed after the expression is evaluated.
5092///
Douglas Gregor363b1512009-12-24 18:51:59 +00005093/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5094/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005095template<typename Derived>
5096Sema::OwningExprResult
5097TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005098 CXXExprWithTemporaries *E) {
5099 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005100}
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregora16548e2009-08-11 05:31:07 +00005102template<typename Derived>
5103Sema::OwningExprResult
5104TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005105 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5107 QualType T = getDerived().TransformType(E->getType());
5108 if (T.isNull())
5109 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005110
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 CXXConstructorDecl *Constructor
5112 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005113 getDerived().TransformDecl(E->getLocStart(),
5114 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 if (!Constructor)
5116 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 bool ArgumentChanged = false;
5119 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5120 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005121 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 ArgEnd = E->arg_end();
5123 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005124 if (getDerived().DropCallArgument(*Arg)) {
5125 ArgumentChanged = true;
5126 break;
5127 }
5128
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5130 if (TransArg.isInvalid())
5131 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5134 Args.push_back((Expr *)TransArg.release());
5135 }
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 T == E->getType() &&
5139 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005140 !ArgumentChanged) {
5141 // FIXME: Instantiation-specific
5142 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005143 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005144 }
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 // FIXME: Bogus location information
5147 SourceLocation CommaLoc;
5148 if (Args.size() > 1) {
5149 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005150 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5152 }
5153 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5154 T,
5155 /*FIXME:*/E->getTypeBeginLoc(),
5156 move_arg(Args),
5157 &CommaLoc,
5158 E->getLocEnd());
5159}
Mike Stump11289f42009-09-09 15:08:12 +00005160
Douglas Gregora16548e2009-08-11 05:31:07 +00005161template<typename Derived>
5162Sema::OwningExprResult
5163TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005164 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5166 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5167 if (T.isNull())
5168 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 bool ArgumentChanged = false;
5171 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5172 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5173 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5174 ArgEnd = E->arg_end();
5175 Arg != ArgEnd; ++Arg) {
5176 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5177 if (TransArg.isInvalid())
5178 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5181 FakeCommaLocs.push_back(
5182 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5183 Args.push_back(TransArg.takeAs<Expr>());
5184 }
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregora16548e2009-08-11 05:31:07 +00005186 if (!getDerived().AlwaysRebuild() &&
5187 T == E->getTypeAsWritten() &&
5188 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005189 return SemaRef.Owned(E->Retain());
5190
Douglas Gregora16548e2009-08-11 05:31:07 +00005191 // FIXME: we're faking the locations of the commas
5192 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5193 T,
5194 E->getLParenLoc(),
5195 move_arg(Args),
5196 FakeCommaLocs.data(),
5197 E->getRParenLoc());
5198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200template<typename Derived>
5201Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005202TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005203 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005205 OwningExprResult Base(SemaRef, (Expr*) 0);
5206 Expr *OldBase;
5207 QualType BaseType;
5208 QualType ObjectType;
5209 if (!E->isImplicitAccess()) {
5210 OldBase = E->getBase();
5211 Base = getDerived().TransformExpr(OldBase);
5212 if (Base.isInvalid())
5213 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005214
John McCall2d74de92009-12-01 22:10:20 +00005215 // Start the member reference and compute the object's type.
5216 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005217 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005218 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5219 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005220 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005221 ObjectTy,
5222 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005223 if (Base.isInvalid())
5224 return SemaRef.ExprError();
5225
5226 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5227 BaseType = ((Expr*) Base.get())->getType();
5228 } else {
5229 OldBase = 0;
5230 BaseType = getDerived().TransformType(E->getBaseType());
5231 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5232 }
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005234 // Transform the first part of the nested-name-specifier that qualifies
5235 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005236 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005237 = getDerived().TransformFirstQualifierInScope(
5238 E->getFirstQualifierFoundInScope(),
5239 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005240
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005241 NestedNameSpecifier *Qualifier = 0;
5242 if (E->getQualifier()) {
5243 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5244 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005245 ObjectType,
5246 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005247 if (!Qualifier)
5248 return SemaRef.ExprError();
5249 }
Mike Stump11289f42009-09-09 15:08:12 +00005250
5251 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005252 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005253 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005254 if (!Name)
5255 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005256
John McCall2d74de92009-12-01 22:10:20 +00005257 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005258 // This is a reference to a member without an explicitly-specified
5259 // template argument list. Optimize for this common case.
5260 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005261 Base.get() == OldBase &&
5262 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005263 Qualifier == E->getQualifier() &&
5264 Name == E->getMember() &&
5265 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005266 return SemaRef.Owned(E->Retain());
5267
John McCall8cd78132009-11-19 22:55:06 +00005268 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005269 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005270 E->isArrow(),
5271 E->getOperatorLoc(),
5272 Qualifier,
5273 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005274 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005275 Name,
5276 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005277 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005278 }
5279
John McCall6b51f282009-11-23 01:53:49 +00005280 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005281 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005282 TemplateArgumentLoc Loc;
5283 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005284 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005285 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005286 }
Mike Stump11289f42009-09-09 15:08:12 +00005287
John McCall8cd78132009-11-19 22:55:06 +00005288 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005289 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 E->isArrow(),
5291 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005292 Qualifier,
5293 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005294 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005295 Name,
5296 E->getMemberLoc(),
5297 &TransArgs);
5298}
5299
5300template<typename Derived>
5301Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005302TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005303 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005304 OwningExprResult Base(SemaRef, (Expr*) 0);
5305 QualType BaseType;
5306 if (!Old->isImplicitAccess()) {
5307 Base = getDerived().TransformExpr(Old->getBase());
5308 if (Base.isInvalid())
5309 return SemaRef.ExprError();
5310 BaseType = ((Expr*) Base.get())->getType();
5311 } else {
5312 BaseType = getDerived().TransformType(Old->getBaseType());
5313 }
John McCall10eae182009-11-30 22:42:35 +00005314
5315 NestedNameSpecifier *Qualifier = 0;
5316 if (Old->getQualifier()) {
5317 Qualifier
5318 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005319 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005320 if (Qualifier == 0)
5321 return SemaRef.ExprError();
5322 }
5323
5324 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5325 Sema::LookupOrdinaryName);
5326
5327 // Transform all the decls.
5328 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5329 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005330 NamedDecl *InstD = static_cast<NamedDecl*>(
5331 getDerived().TransformDecl(Old->getMemberLoc(),
5332 *I));
John McCall84d87672009-12-10 09:41:52 +00005333 if (!InstD) {
5334 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5335 // This can happen because of dependent hiding.
5336 if (isa<UsingShadowDecl>(*I))
5337 continue;
5338 else
5339 return SemaRef.ExprError();
5340 }
John McCall10eae182009-11-30 22:42:35 +00005341
5342 // Expand using declarations.
5343 if (isa<UsingDecl>(InstD)) {
5344 UsingDecl *UD = cast<UsingDecl>(InstD);
5345 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5346 E = UD->shadow_end(); I != E; ++I)
5347 R.addDecl(*I);
5348 continue;
5349 }
5350
5351 R.addDecl(InstD);
5352 }
5353
5354 R.resolveKind();
5355
5356 TemplateArgumentListInfo TransArgs;
5357 if (Old->hasExplicitTemplateArgs()) {
5358 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5359 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5360 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5361 TemplateArgumentLoc Loc;
5362 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5363 Loc))
5364 return SemaRef.ExprError();
5365 TransArgs.addArgument(Loc);
5366 }
5367 }
John McCall38836f02010-01-15 08:34:02 +00005368
5369 // FIXME: to do this check properly, we will need to preserve the
5370 // first-qualifier-in-scope here, just in case we had a dependent
5371 // base (and therefore couldn't do the check) and a
5372 // nested-name-qualifier (and therefore could do the lookup).
5373 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005374
5375 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005376 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005377 Old->getOperatorLoc(),
5378 Old->isArrow(),
5379 Qualifier,
5380 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005381 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005382 R,
5383 (Old->hasExplicitTemplateArgs()
5384 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005385}
5386
5387template<typename Derived>
5388Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005389TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005390 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005391}
5392
Mike Stump11289f42009-09-09 15:08:12 +00005393template<typename Derived>
5394Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 // FIXME: poor source location
5397 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5398 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5399 if (EncodedType.isNull())
5400 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregora16548e2009-08-11 05:31:07 +00005402 if (!getDerived().AlwaysRebuild() &&
5403 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005404 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005405
5406 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5407 EncodedType,
5408 E->getRParenLoc());
5409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregora16548e2009-08-11 05:31:07 +00005411template<typename Derived>
5412Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005413TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 // FIXME: Implement this!
5415 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005416 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005417}
5418
Mike Stump11289f42009-09-09 15:08:12 +00005419template<typename Derived>
5420Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005421TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005422 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005423}
5424
Mike Stump11289f42009-09-09 15:08:12 +00005425template<typename Derived>
5426Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005427TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005428 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005429 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005430 getDerived().TransformDecl(E->getLocStart(),
5431 E->getProtocol()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005432 if (!Protocol)
5433 return SemaRef.ExprError();
5434
5435 if (!getDerived().AlwaysRebuild() &&
5436 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005437 return SemaRef.Owned(E->Retain());
5438
Douglas Gregora16548e2009-08-11 05:31:07 +00005439 return getDerived().RebuildObjCProtocolExpr(Protocol,
5440 E->getAtLoc(),
5441 /*FIXME:*/E->getAtLoc(),
5442 /*FIXME:*/E->getAtLoc(),
5443 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregora16548e2009-08-11 05:31:07 +00005445}
5446
Mike Stump11289f42009-09-09 15:08:12 +00005447template<typename Derived>
5448Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005449TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 // FIXME: Implement this!
5451 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005452 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005453}
5454
Mike Stump11289f42009-09-09 15:08:12 +00005455template<typename Derived>
5456Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005457TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005458 // FIXME: Implement this!
5459 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005460 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005461}
5462
Mike Stump11289f42009-09-09 15:08:12 +00005463template<typename Derived>
5464Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005465TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005466 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005467 // FIXME: Implement this!
5468 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005469 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005470}
5471
Mike Stump11289f42009-09-09 15:08:12 +00005472template<typename Derived>
5473Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005474TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005475 // FIXME: Implement this!
5476 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005477 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005478}
5479
Mike Stump11289f42009-09-09 15:08:12 +00005480template<typename Derived>
5481Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005482TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005483 // FIXME: Implement this!
5484 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005485 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005486}
5487
Mike Stump11289f42009-09-09 15:08:12 +00005488template<typename Derived>
5489Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005490TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 bool ArgumentChanged = false;
5492 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5493 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5494 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5495 if (SubExpr.isInvalid())
5496 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregora16548e2009-08-11 05:31:07 +00005498 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5499 SubExprs.push_back(SubExpr.takeAs<Expr>());
5500 }
Mike Stump11289f42009-09-09 15:08:12 +00005501
Douglas Gregora16548e2009-08-11 05:31:07 +00005502 if (!getDerived().AlwaysRebuild() &&
5503 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005504 return SemaRef.Owned(E->Retain());
5505
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5507 move_arg(SubExprs),
5508 E->getRParenLoc());
5509}
5510
Mike Stump11289f42009-09-09 15:08:12 +00005511template<typename Derived>
5512Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005513TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 // FIXME: Implement this!
5515 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005516 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005517}
5518
Mike Stump11289f42009-09-09 15:08:12 +00005519template<typename Derived>
5520Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005521TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 // FIXME: Implement this!
5523 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005524 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005525}
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005528// Type reconstruction
5529//===----------------------------------------------------------------------===//
5530
Mike Stump11289f42009-09-09 15:08:12 +00005531template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005532QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5533 SourceLocation Star) {
5534 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005535 getDerived().getBaseEntity());
5536}
5537
Mike Stump11289f42009-09-09 15:08:12 +00005538template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005539QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5540 SourceLocation Star) {
5541 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005542 getDerived().getBaseEntity());
5543}
5544
Mike Stump11289f42009-09-09 15:08:12 +00005545template<typename Derived>
5546QualType
John McCall70dd5f62009-10-30 00:06:24 +00005547TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5548 bool WrittenAsLValue,
5549 SourceLocation Sigil) {
5550 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5551 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005552}
5553
5554template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005555QualType
John McCall70dd5f62009-10-30 00:06:24 +00005556TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5557 QualType ClassType,
5558 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005559 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005560 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005561}
5562
5563template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005564QualType
John McCall70dd5f62009-10-30 00:06:24 +00005565TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5566 SourceLocation Sigil) {
5567 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005568 getDerived().getBaseEntity());
5569}
5570
5571template<typename Derived>
5572QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005573TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5574 ArrayType::ArraySizeModifier SizeMod,
5575 const llvm::APInt *Size,
5576 Expr *SizeExpr,
5577 unsigned IndexTypeQuals,
5578 SourceRange BracketsRange) {
5579 if (SizeExpr || !Size)
5580 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5581 IndexTypeQuals, BracketsRange,
5582 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005583
5584 QualType Types[] = {
5585 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5586 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5587 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005588 };
5589 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5590 QualType SizeType;
5591 for (unsigned I = 0; I != NumTypes; ++I)
5592 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5593 SizeType = Types[I];
5594 break;
5595 }
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregord6ff3322009-08-04 16:50:30 +00005597 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005598 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005599 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005600 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005601}
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregord6ff3322009-08-04 16:50:30 +00005603template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005604QualType
5605TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005606 ArrayType::ArraySizeModifier SizeMod,
5607 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005608 unsigned IndexTypeQuals,
5609 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005610 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005611 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612}
5613
5614template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005615QualType
Mike Stump11289f42009-09-09 15:08:12 +00005616TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005617 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005618 unsigned IndexTypeQuals,
5619 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005620 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005621 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622}
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregord6ff3322009-08-04 16:50:30 +00005624template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005625QualType
5626TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005627 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005629 unsigned IndexTypeQuals,
5630 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005631 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005632 SizeExpr.takeAs<Expr>(),
5633 IndexTypeQuals, BracketsRange);
5634}
5635
5636template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005637QualType
5638TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005639 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005641 unsigned IndexTypeQuals,
5642 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005643 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005644 SizeExpr.takeAs<Expr>(),
5645 IndexTypeQuals, BracketsRange);
5646}
5647
5648template<typename Derived>
5649QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005650 unsigned NumElements,
5651 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005652 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005653 return SemaRef.Context.getVectorType(ElementType, NumElements,
5654 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005655}
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregord6ff3322009-08-04 16:50:30 +00005657template<typename Derived>
5658QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5659 unsigned NumElements,
5660 SourceLocation AttributeLoc) {
5661 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5662 NumElements, true);
5663 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005664 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005665 AttributeLoc);
5666 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5667 AttributeLoc);
5668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregord6ff3322009-08-04 16:50:30 +00005670template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005671QualType
5672TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005674 SourceLocation AttributeLoc) {
5675 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5676}
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregord6ff3322009-08-04 16:50:30 +00005678template<typename Derived>
5679QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005680 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005681 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005682 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005683 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005684 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005685 Quals,
5686 getDerived().getBaseLocation(),
5687 getDerived().getBaseEntity());
5688}
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregord6ff3322009-08-04 16:50:30 +00005690template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005691QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5692 return SemaRef.Context.getFunctionNoProtoType(T);
5693}
5694
5695template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005696QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5697 assert(D && "no decl found");
5698 if (D->isInvalidDecl()) return QualType();
5699
5700 TypeDecl *Ty;
5701 if (isa<UsingDecl>(D)) {
5702 UsingDecl *Using = cast<UsingDecl>(D);
5703 assert(Using->isTypeName() &&
5704 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5705
5706 // A valid resolved using typename decl points to exactly one type decl.
5707 assert(++Using->shadow_begin() == Using->shadow_end());
5708 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5709
5710 } else {
5711 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5712 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5713 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5714 }
5715
5716 return SemaRef.Context.getTypeDeclType(Ty);
5717}
5718
5719template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005720QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005721 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5722}
5723
5724template<typename Derived>
5725QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5726 return SemaRef.Context.getTypeOfType(Underlying);
5727}
5728
5729template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005730QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005731 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5732}
5733
5734template<typename Derived>
5735QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005736 TemplateName Template,
5737 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005738 const TemplateArgumentListInfo &TemplateArgs) {
5739 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005740}
Mike Stump11289f42009-09-09 15:08:12 +00005741
Douglas Gregor1135c352009-08-06 05:28:30 +00005742template<typename Derived>
5743NestedNameSpecifier *
5744TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5745 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005746 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005747 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005748 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005749 CXXScopeSpec SS;
5750 // FIXME: The source location information is all wrong.
5751 SS.setRange(Range);
5752 SS.setScopeRep(Prefix);
5753 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005754 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005755 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005756 ObjectType,
5757 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005758 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005759}
5760
5761template<typename Derived>
5762NestedNameSpecifier *
5763TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5764 SourceRange Range,
5765 NamespaceDecl *NS) {
5766 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5767}
5768
5769template<typename Derived>
5770NestedNameSpecifier *
5771TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5772 SourceRange Range,
5773 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005774 QualType T) {
5775 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005776 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005777 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005778 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5779 T.getTypePtr());
5780 }
Mike Stump11289f42009-09-09 15:08:12 +00005781
Douglas Gregor1135c352009-08-06 05:28:30 +00005782 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5783 return 0;
5784}
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregor71dc5092009-08-06 06:41:21 +00005786template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005787TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005788TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5789 bool TemplateKW,
5790 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005791 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005792 Template);
5793}
5794
5795template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005796TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005797TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005798 const IdentifierInfo &II,
5799 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005800 CXXScopeSpec SS;
5801 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005802 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005803 UnqualifiedId Name;
5804 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005805 return getSema().ActOnDependentTemplateName(
5806 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005807 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005808 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005809 ObjectType.getAsOpaquePtr(),
5810 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005811 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005812}
Mike Stump11289f42009-09-09 15:08:12 +00005813
Douglas Gregora16548e2009-08-11 05:31:07 +00005814template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005815TemplateName
5816TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5817 OverloadedOperatorKind Operator,
5818 QualType ObjectType) {
5819 CXXScopeSpec SS;
5820 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5821 SS.setScopeRep(Qualifier);
5822 UnqualifiedId Name;
5823 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5824 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5825 Operator, SymbolLocations);
5826 return getSema().ActOnDependentTemplateName(
5827 /*FIXME:*/getDerived().getBaseLocation(),
5828 SS,
5829 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005830 ObjectType.getAsOpaquePtr(),
5831 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005832 .template getAsVal<TemplateName>();
5833}
5834
5835template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005836Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005837TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5838 SourceLocation OpLoc,
5839 ExprArg Callee,
5840 ExprArg First,
5841 ExprArg Second) {
5842 Expr *FirstExpr = (Expr *)First.get();
5843 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005844 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005845 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005846
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005848 if (Op == OO_Subscript) {
5849 if (!FirstExpr->getType()->isOverloadableType() &&
5850 !SecondExpr->getType()->isOverloadableType())
5851 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005852 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005853 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005854 } else if (Op == OO_Arrow) {
5855 // -> is never a builtin operation.
5856 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005857 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 if (!FirstExpr->getType()->isOverloadableType()) {
5859 // The argument is not of overloadable type, so try to create a
5860 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005861 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5865 }
5866 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005867 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 !SecondExpr->getType()->isOverloadableType()) {
5869 // Neither of the arguments is an overloadable type, so try to
5870 // create a built-in binary operation.
5871 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005872 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5874 if (Result.isInvalid())
5875 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 First.release();
5878 Second.release();
5879 return move(Result);
5880 }
5881 }
Mike Stump11289f42009-09-09 15:08:12 +00005882
5883 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005885 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005886
John McCalld14a8642009-11-21 08:51:07 +00005887 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5888 assert(ULE->requiresADL());
5889
5890 // FIXME: Do we have to check
5891 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005892 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005893 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005894 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005895 }
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 // Add any functions found via argument-dependent lookup.
5898 Expr *Args[2] = { FirstExpr, SecondExpr };
5899 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005900
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 // Create the overloaded operator invocation for unary operators.
5902 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005903 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5905 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5906 }
Mike Stump11289f42009-09-09 15:08:12 +00005907
Sebastian Redladba46e2009-10-29 20:17:01 +00005908 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005909 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5910 OpLoc,
5911 move(First),
5912 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005913
Douglas Gregora16548e2009-08-11 05:31:07 +00005914 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005915 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005917 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005918 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5919 if (Result.isInvalid())
5920 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 First.release();
5923 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005924 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005925}
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005927template<typename Derived>
5928Sema::OwningExprResult
5929TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5930 SourceLocation OperatorLoc,
5931 bool isArrow,
5932 NestedNameSpecifier *Qualifier,
5933 SourceRange QualifierRange,
5934 TypeSourceInfo *ScopeType,
5935 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005936 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005937 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005938 CXXScopeSpec SS;
5939 if (Qualifier) {
5940 SS.setRange(QualifierRange);
5941 SS.setScopeRep(Qualifier);
5942 }
5943
5944 Expr *BaseE = (Expr *)Base.get();
5945 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005946 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005947 (!isArrow && !BaseType->getAs<RecordType>()) ||
5948 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00005949 !BaseType->getAs<PointerType>()->getPointeeType()
5950 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005951 // This pseudo-destructor expression is still a pseudo-destructor.
5952 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5953 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005954 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005955 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005956 /*FIXME?*/true);
5957 }
5958
Douglas Gregor678f90d2010-02-25 01:56:36 +00005959 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005960 DeclarationName Name
5961 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5962 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5963
5964 // FIXME: the ScopeType should be tacked onto SS.
5965
5966 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5967 OperatorLoc, isArrow,
5968 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005969 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005970 /*TemplateArgs*/ 0);
5971}
5972
Douglas Gregord6ff3322009-08-04 16:50:30 +00005973} // end namespace clang
5974
5975#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H