blob: 361ab2e78c9af427af45c7f15d5a0bd4e3968bed [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 Gregorc1d2d8a2010-03-31 17:34:00 +0000543 QualType RebuildDependentNameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000544 if (NNS->isDependent()) {
545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +0000548 return SemaRef.Context.getDependentNameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Mike Stump11289f42009-09-09 15:08:12 +0000551
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000553 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554
555 /// \brief Build a new typename type that refers to an identifier.
556 ///
557 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000558 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000559 /// different behavior.
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +0000560 QualType RebuildDependentNameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000561 const IdentifierInfo *Id,
562 SourceRange SR) {
563 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
Douglas Gregor1135c352009-08-06 05:28:30 +0000566 /// \brief Build a new nested-name-specifier given the prefix and an
567 /// identifier that names the next step in the nested-name-specifier.
568 ///
569 /// By default, performs semantic analysis when building the new
570 /// nested-name-specifier. Subclasses may override this routine to provide
571 /// different behavior.
572 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
573 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000574 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000575 QualType ObjectType,
576 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000577
578 /// \brief Build a new nested-name-specifier given the prefix and the
579 /// namespace named in the next step in the nested-name-specifier.
580 ///
581 /// By default, performs semantic analysis when building the new
582 /// nested-name-specifier. Subclasses may override this routine to provide
583 /// different behavior.
584 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
585 SourceRange Range,
586 NamespaceDecl *NS);
587
588 /// \brief Build a new nested-name-specifier given the prefix and the
589 /// type named in the next step in the nested-name-specifier.
590 ///
591 /// By default, performs semantic analysis when building the new
592 /// nested-name-specifier. Subclasses may override this routine to provide
593 /// different behavior.
594 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
595 SourceRange Range,
596 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000597 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000598
599 /// \brief Build a new template name given a nested name specifier, a flag
600 /// indicating whether the "template" keyword was provided, and the template
601 /// that the template name refers to.
602 ///
603 /// By default, builds the new template name directly. Subclasses may override
604 /// this routine to provide different behavior.
605 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
606 bool TemplateKW,
607 TemplateDecl *Template);
608
Douglas Gregor71dc5092009-08-06 06:41:21 +0000609 /// \brief Build a new template name given a nested name specifier and the
610 /// name that is referred to as a template.
611 ///
612 /// By default, performs semantic analysis to determine whether the name can
613 /// be resolved to a specific template, then builds the appropriate kind of
614 /// template name. Subclasses may override this routine to provide different
615 /// behavior.
616 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000617 const IdentifierInfo &II,
618 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000619
Douglas Gregor71395fa2009-11-04 00:56:37 +0000620 /// \brief Build a new template name given a nested name specifier and the
621 /// overloaded operator name that is referred to as a template.
622 ///
623 /// By default, performs semantic analysis to determine whether the name can
624 /// be resolved to a specific template, then builds the appropriate kind of
625 /// template name. Subclasses may override this routine to provide different
626 /// behavior.
627 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
628 OverloadedOperatorKind Operator,
629 QualType ObjectType);
630
Douglas Gregorebe10102009-08-20 07:17:43 +0000631 /// \brief Build a new compound statement.
632 ///
633 /// By default, performs semantic analysis to build the new statement.
634 /// Subclasses may override this routine to provide different behavior.
635 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
636 MultiStmtArg Statements,
637 SourceLocation RBraceLoc,
638 bool IsStmtExpr) {
639 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
640 IsStmtExpr);
641 }
642
643 /// \brief Build a new case statement.
644 ///
645 /// By default, performs semantic analysis to build the new statement.
646 /// Subclasses may override this routine to provide different behavior.
647 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
648 ExprArg LHS,
649 SourceLocation EllipsisLoc,
650 ExprArg RHS,
651 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000652 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000653 ColonLoc);
654 }
Mike Stump11289f42009-09-09 15:08:12 +0000655
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 /// \brief Attach the body to a new case statement.
657 ///
658 /// By default, performs semantic analysis to build the new statement.
659 /// Subclasses may override this routine to provide different behavior.
660 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
661 getSema().ActOnCaseStmtBody(S.get(), move(Body));
662 return move(S);
663 }
Mike Stump11289f42009-09-09 15:08:12 +0000664
Douglas Gregorebe10102009-08-20 07:17:43 +0000665 /// \brief Build a new default statement.
666 ///
667 /// By default, performs semantic analysis to build the new statement.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000669 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000670 SourceLocation ColonLoc,
671 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000672 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000673 /*CurScope=*/0);
674 }
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregorebe10102009-08-20 07:17:43 +0000676 /// \brief Build a new label statement.
677 ///
678 /// By default, performs semantic analysis to build the new statement.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000680 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000681 IdentifierInfo *Id,
682 SourceLocation ColonLoc,
683 StmtArg SubStmt) {
684 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
685 }
Mike Stump11289f42009-09-09 15:08:12 +0000686
Douglas Gregorebe10102009-08-20 07:17:43 +0000687 /// \brief Build a new "if" statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000691 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000692 VarDecl *CondVar, StmtArg Then,
693 SourceLocation ElseLoc, StmtArg Else) {
694 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
695 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000696 }
Mike Stump11289f42009-09-09 15:08:12 +0000697
Douglas Gregorebe10102009-08-20 07:17:43 +0000698 /// \brief Start building a new switch statement.
699 ///
700 /// By default, performs semantic analysis to build the new statement.
701 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000702 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
703 VarDecl *CondVar) {
704 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000705 }
Mike Stump11289f42009-09-09 15:08:12 +0000706
Douglas Gregorebe10102009-08-20 07:17:43 +0000707 /// \brief Attach the body to the switch statement.
708 ///
709 /// By default, performs semantic analysis to build the new statement.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000711 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 StmtArg Switch, StmtArg Body) {
713 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
714 move(Body));
715 }
716
717 /// \brief Build a new while statement.
718 ///
719 /// By default, performs semantic analysis to build the new statement.
720 /// Subclasses may override this routine to provide different behavior.
721 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
722 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000723 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000725 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
726 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 }
Mike Stump11289f42009-09-09 15:08:12 +0000728
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 /// \brief Build a new do-while statement.
730 ///
731 /// By default, performs semantic analysis to build the new statement.
732 /// Subclasses may override this routine to provide different behavior.
733 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
734 SourceLocation WhileLoc,
735 SourceLocation LParenLoc,
736 ExprArg Cond,
737 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000738 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 move(Cond), RParenLoc);
740 }
741
742 /// \brief Build a new for statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000746 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000748 StmtArg Init, Sema::FullExprArg Cond,
749 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000750 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000751 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
752 DeclPtrTy::make(CondVar),
753 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 }
Mike Stump11289f42009-09-09 15:08:12 +0000755
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 /// \brief Build a new goto statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
760 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
761 SourceLocation LabelLoc,
762 LabelStmt *Label) {
763 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
764 }
765
766 /// \brief Build a new indirect goto statement.
767 ///
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
770 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
771 SourceLocation StarLoc,
772 ExprArg Target) {
773 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
774 }
Mike Stump11289f42009-09-09 15:08:12 +0000775
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 /// \brief Build a new return statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
780 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
781 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000782
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 /// \brief Build a new declaration statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
790 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000791 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000792 SourceLocation EndLoc) {
793 return getSema().Owned(
794 new (getSema().Context) DeclStmt(
795 DeclGroupRef::Create(getSema().Context,
796 Decls, NumDecls),
797 StartLoc, EndLoc));
798 }
Mike Stump11289f42009-09-09 15:08:12 +0000799
Anders Carlssonaaeef072010-01-24 05:50:09 +0000800 /// \brief Build a new inline asm statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
804 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
805 bool IsSimple,
806 bool IsVolatile,
807 unsigned NumOutputs,
808 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000809 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000810 MultiExprArg Constraints,
811 MultiExprArg Exprs,
812 ExprArg AsmString,
813 MultiExprArg Clobbers,
814 SourceLocation RParenLoc,
815 bool MSAsm) {
816 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
817 NumInputs, Names, move(Constraints),
818 move(Exprs), move(AsmString), move(Clobbers),
819 RParenLoc, MSAsm);
820 }
821
Douglas Gregorebe10102009-08-20 07:17:43 +0000822 /// \brief Build a new C++ exception declaration.
823 ///
824 /// By default, performs semantic analysis to build the new decaration.
825 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000826 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000827 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 IdentifierInfo *Name,
829 SourceLocation Loc,
830 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000831 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 TypeRange);
833 }
834
835 /// \brief Build a new C++ catch statement.
836 ///
837 /// By default, performs semantic analysis to build the new statement.
838 /// Subclasses may override this routine to provide different behavior.
839 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
840 VarDecl *ExceptionDecl,
841 StmtArg Handler) {
842 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000843 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 Handler.takeAs<Stmt>()));
845 }
Mike Stump11289f42009-09-09 15:08:12 +0000846
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 /// \brief Build a new C++ try statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
851 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
852 StmtArg TryBlock,
853 MultiStmtArg Handlers) {
854 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregora16548e2009-08-11 05:31:07 +0000857 /// \brief Build a new expression that references a declaration.
858 ///
859 /// By default, performs semantic analysis to build the new expression.
860 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000861 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
862 LookupResult &R,
863 bool RequiresADL) {
864 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
865 }
866
867
868 /// \brief Build a new expression that references a declaration.
869 ///
870 /// By default, performs semantic analysis to build the new expression.
871 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000872 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
873 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000874 ValueDecl *VD, SourceLocation Loc,
875 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000876 CXXScopeSpec SS;
877 SS.setScopeRep(Qualifier);
878 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000879
880 // FIXME: loses template args.
881
882 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 }
Mike Stump11289f42009-09-09 15:08:12 +0000884
Douglas Gregora16548e2009-08-11 05:31:07 +0000885 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000886 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000887 /// By default, performs semantic analysis to build the new expression.
888 /// Subclasses may override this routine to provide different behavior.
889 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
890 SourceLocation RParen) {
891 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
892 }
893
Douglas Gregorad8a3362009-09-04 17:36:40 +0000894 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000895 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000896 /// By default, performs semantic analysis to build the new expression.
897 /// Subclasses may override this routine to provide different behavior.
898 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
899 SourceLocation OperatorLoc,
900 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000901 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000902 SourceRange QualifierRange,
903 TypeSourceInfo *ScopeType,
904 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000905 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000906 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000907
Douglas Gregora16548e2009-08-11 05:31:07 +0000908 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000909 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000910 /// By default, performs semantic analysis to build the new expression.
911 /// Subclasses may override this routine to provide different behavior.
912 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
913 UnaryOperator::Opcode Opc,
914 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000915 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000922 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000923 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000924 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000925 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 }
927
Mike Stump11289f42009-09-09 15:08:12 +0000928 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000929 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000930 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000931 /// By default, performs semantic analysis to build the new expression.
932 /// Subclasses may override this routine to provide different behavior.
933 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
934 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000935 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000936 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
937 OpLoc, isSizeOf, R);
938 if (Result.isInvalid())
939 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000940
Douglas Gregora16548e2009-08-11 05:31:07 +0000941 SubExpr.release();
942 return move(Result);
943 }
Mike Stump11289f42009-09-09 15:08:12 +0000944
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000946 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000947 /// By default, performs semantic analysis to build the new expression.
948 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000949 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000950 SourceLocation LBracketLoc,
951 ExprArg RHS,
952 SourceLocation RBracketLoc) {
953 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000954 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000955 RBracketLoc);
956 }
957
958 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000960 /// By default, performs semantic analysis to build the new expression.
961 /// Subclasses may override this routine to provide different behavior.
962 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
963 MultiExprArg Args,
964 SourceLocation *CommaLocs,
965 SourceLocation RParenLoc) {
966 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
967 move(Args), CommaLocs, RParenLoc);
968 }
969
970 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000971 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000972 /// By default, performs semantic analysis to build the new expression.
973 /// Subclasses may override this routine to provide different behavior.
974 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000975 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000976 NestedNameSpecifier *Qualifier,
977 SourceRange QualifierRange,
978 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000979 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +0000980 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +0000981 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000982 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000983 if (!Member->getDeclName()) {
984 // We have a reference to an unnamed field.
985 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000986
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000987 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +0000988 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
989 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000990 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000991
Mike Stump11289f42009-09-09 15:08:12 +0000992 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000993 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000994 Member, MemberLoc,
995 cast<FieldDecl>(Member)->getType());
996 return getSema().Owned(ME);
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000999 CXXScopeSpec SS;
1000 if (Qualifier) {
1001 SS.setRange(QualifierRange);
1002 SS.setScopeRep(Qualifier);
1003 }
1004
John McCall2d74de92009-12-01 22:10:20 +00001005 QualType BaseType = ((Expr*) Base.get())->getType();
1006
John McCall16df1e52010-03-30 21:47:33 +00001007 // FIXME: this involves duplicating earlier analysis in a lot of
1008 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001009 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1010 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001011 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001012 R.resolveKind();
1013
John McCall2d74de92009-12-01 22:10:20 +00001014 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1015 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001016 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001017 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 }
Mike Stump11289f42009-09-09 15:08:12 +00001019
Douglas Gregora16548e2009-08-11 05:31:07 +00001020 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001021 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001022 /// By default, performs semantic analysis to build the new expression.
1023 /// Subclasses may override this routine to provide different behavior.
1024 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1025 BinaryOperator::Opcode Opc,
1026 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001027 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1028 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001029 }
1030
1031 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001032 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001033 /// By default, performs semantic analysis to build the new expression.
1034 /// Subclasses may override this routine to provide different behavior.
1035 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1036 SourceLocation QuestionLoc,
1037 ExprArg LHS,
1038 SourceLocation ColonLoc,
1039 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001040 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 move(LHS), move(RHS));
1042 }
1043
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001045 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 /// By default, performs semantic analysis to build the new expression.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001048 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1049 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 SourceLocation RParenLoc,
1051 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001052 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1053 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 }
Mike Stump11289f42009-09-09 15:08:12 +00001055
Douglas Gregora16548e2009-08-11 05:31:07 +00001056 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001057 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 /// By default, performs semantic analysis to build the new expression.
1059 /// Subclasses may override this routine to provide different behavior.
1060 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001061 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 SourceLocation RParenLoc,
1063 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001064 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1065 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 }
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001072 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 SourceLocation OpLoc,
1074 SourceLocation AccessorLoc,
1075 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001076
John McCall10eae182009-11-30 22:42:35 +00001077 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001078 QualType BaseType = ((Expr*) Base.get())->getType();
1079 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001080 OpLoc, /*IsArrow*/ false,
1081 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001082 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001083 AccessorLoc,
1084 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 }
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
1091 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1092 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001093 SourceLocation RBraceLoc,
1094 QualType ResultTy) {
1095 OwningExprResult Result
1096 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1097 if (Result.isInvalid() || ResultTy->isDependentType())
1098 return move(Result);
1099
1100 // Patch in the result type we were given, which may have been computed
1101 // when the initial InitListExpr was built.
1102 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1103 ILE->setType(ResultTy);
1104 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 }
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001108 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 /// By default, performs semantic analysis to build the new expression.
1110 /// Subclasses may override this routine to provide different behavior.
1111 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1112 MultiExprArg ArrayExprs,
1113 SourceLocation EqualOrColonLoc,
1114 bool GNUSyntax,
1115 ExprArg Init) {
1116 OwningExprResult Result
1117 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1118 move(Init));
1119 if (Result.isInvalid())
1120 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001121
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 ArrayExprs.release();
1123 return move(Result);
1124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// By default, builds the implicit value initialization without performing
1129 /// any semantic analysis. Subclasses may override this routine to provide
1130 /// different behavior.
1131 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1132 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1133 }
Mike Stump11289f42009-09-09 15:08:12 +00001134
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
1139 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1140 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001141 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 RParenLoc);
1143 }
1144
1145 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001146 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001147 /// By default, performs semantic analysis to build the new expression.
1148 /// Subclasses may override this routine to provide different behavior.
1149 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1150 MultiExprArg SubExprs,
1151 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001152 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1153 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001154 }
Mike Stump11289f42009-09-09 15:08:12 +00001155
Douglas Gregora16548e2009-08-11 05:31:07 +00001156 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001157 ///
1158 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001159 /// rather than attempting to map the label statement itself.
1160 /// Subclasses may override this routine to provide different behavior.
1161 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1162 SourceLocation LabelLoc,
1163 LabelStmt *Label) {
1164 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregora16548e2009-08-11 05:31:07 +00001167 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001168 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001169 /// By default, performs semantic analysis to build the new expression.
1170 /// Subclasses may override this routine to provide different behavior.
1171 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1172 StmtArg SubStmt,
1173 SourceLocation RParenLoc) {
1174 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1175 }
Mike Stump11289f42009-09-09 15:08:12 +00001176
Douglas Gregora16548e2009-08-11 05:31:07 +00001177 /// \brief Build a new __builtin_types_compatible_p expression.
1178 ///
1179 /// By default, performs semantic analysis to build the new expression.
1180 /// Subclasses may override this routine to provide different behavior.
1181 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1182 QualType T1, QualType T2,
1183 SourceLocation RParenLoc) {
1184 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1185 T1.getAsOpaquePtr(),
1186 T2.getAsOpaquePtr(),
1187 RParenLoc);
1188 }
Mike Stump11289f42009-09-09 15:08:12 +00001189
Douglas Gregora16548e2009-08-11 05:31:07 +00001190 /// \brief Build a new __builtin_choose_expr expression.
1191 ///
1192 /// By default, performs semantic analysis to build the new expression.
1193 /// Subclasses may override this routine to provide different behavior.
1194 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1195 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1196 SourceLocation RParenLoc) {
1197 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1198 move(Cond), move(LHS), move(RHS),
1199 RParenLoc);
1200 }
Mike Stump11289f42009-09-09 15:08:12 +00001201
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 /// \brief Build a new overloaded operator call expression.
1203 ///
1204 /// By default, performs semantic analysis to build the new expression.
1205 /// The semantic analysis provides the behavior of template instantiation,
1206 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001207 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// argument-dependent lookup, etc. Subclasses may override this routine to
1209 /// provide different behavior.
1210 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1211 SourceLocation OpLoc,
1212 ExprArg Callee,
1213 ExprArg First,
1214 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001215
1216 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// reinterpret_cast.
1218 ///
1219 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001220 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// Subclasses may override this routine to provide different behavior.
1222 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1223 Stmt::StmtClass Class,
1224 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001225 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation RAngleLoc,
1227 SourceLocation LParenLoc,
1228 ExprArg SubExpr,
1229 SourceLocation RParenLoc) {
1230 switch (Class) {
1231 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001232 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001233 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 move(SubExpr), RParenLoc);
1235
1236 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001237 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001238 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001240
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001242 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001243 RAngleLoc, LParenLoc,
1244 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001246
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001248 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001249 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 default:
1253 assert(false && "Invalid C++ named cast");
1254 break;
1255 }
Mike Stump11289f42009-09-09 15:08:12 +00001256
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 return getSema().ExprError();
1258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// \brief Build a new C++ static_cast expression.
1261 ///
1262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
1264 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1265 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001266 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 SourceLocation RAngleLoc,
1268 SourceLocation LParenLoc,
1269 ExprArg SubExpr,
1270 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001271 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1272 TInfo, move(SubExpr),
1273 SourceRange(LAngleLoc, RAngleLoc),
1274 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 }
1276
1277 /// \brief Build a new C++ dynamic_cast expression.
1278 ///
1279 /// By default, performs semantic analysis to build the new expression.
1280 /// Subclasses may override this routine to provide different behavior.
1281 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1282 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001283 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 SourceLocation RAngleLoc,
1285 SourceLocation LParenLoc,
1286 ExprArg SubExpr,
1287 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001288 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1289 TInfo, move(SubExpr),
1290 SourceRange(LAngleLoc, RAngleLoc),
1291 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 }
1293
1294 /// \brief Build a new C++ reinterpret_cast expression.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
1298 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1299 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001300 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 SourceLocation RAngleLoc,
1302 SourceLocation LParenLoc,
1303 ExprArg SubExpr,
1304 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001305 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1306 TInfo, move(SubExpr),
1307 SourceRange(LAngleLoc, RAngleLoc),
1308 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 }
1310
1311 /// \brief Build a new C++ const_cast expression.
1312 ///
1313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
1315 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1316 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001317 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 SourceLocation RAngleLoc,
1319 SourceLocation LParenLoc,
1320 ExprArg SubExpr,
1321 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001322 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1323 TInfo, move(SubExpr),
1324 SourceRange(LAngleLoc, RAngleLoc),
1325 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 }
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// \brief Build a new C++ functional-style cast expression.
1329 ///
1330 /// By default, performs semantic analysis to build the new expression.
1331 /// Subclasses may override this routine to provide different behavior.
1332 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001333 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 SourceLocation LParenLoc,
1335 ExprArg SubExpr,
1336 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001337 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001339 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001341 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001342 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 RParenLoc);
1344 }
Mike Stump11289f42009-09-09 15:08:12 +00001345
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// \brief Build a new C++ typeid(type) expression.
1347 ///
1348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
1350 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1351 SourceLocation LParenLoc,
1352 QualType T,
1353 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001354 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 T.getAsOpaquePtr(), RParenLoc);
1356 }
Mike Stump11289f42009-09-09 15:08:12 +00001357
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// \brief Build a new C++ typeid(expr) expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
1362 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1363 SourceLocation LParenLoc,
1364 ExprArg Operand,
1365 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001366 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1368 RParenLoc);
1369 if (Result.isInvalid())
1370 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001371
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1373 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001374 }
1375
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// \brief Build a new C++ "this" expression.
1377 ///
1378 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001379 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001381 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001382 QualType ThisType,
1383 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001385 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1386 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 }
1388
1389 /// \brief Build a new C++ throw expression.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
1393 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1394 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1395 }
1396
1397 /// \brief Build a new C++ default-argument expression.
1398 ///
1399 /// By default, builds a new default-argument expression, which does not
1400 /// require any semantic analysis. Subclasses may override this routine to
1401 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001402 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1403 ParmVarDecl *Param) {
1404 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1405 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 }
1407
1408 /// \brief Build a new C++ zero-initialization expression.
1409 ///
1410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001412 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 SourceLocation LParenLoc,
1414 QualType T,
1415 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001416 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1417 T.getAsOpaquePtr(), LParenLoc,
1418 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 0, RParenLoc);
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 /// \brief Build a new C++ "new" expression.
1423 ///
1424 /// By default, performs semantic analysis to build the new expression.
1425 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001426 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 bool UseGlobal,
1428 SourceLocation PlacementLParen,
1429 MultiExprArg PlacementArgs,
1430 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001431 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 QualType AllocType,
1433 SourceLocation TypeLoc,
1434 SourceRange TypeRange,
1435 ExprArg ArraySize,
1436 SourceLocation ConstructorLParen,
1437 MultiExprArg ConstructorArgs,
1438 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001439 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 PlacementLParen,
1441 move(PlacementArgs),
1442 PlacementRParen,
1443 ParenTypeId,
1444 AllocType,
1445 TypeLoc,
1446 TypeRange,
1447 move(ArraySize),
1448 ConstructorLParen,
1449 move(ConstructorArgs),
1450 ConstructorRParen);
1451 }
Mike Stump11289f42009-09-09 15:08:12 +00001452
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 /// \brief Build a new C++ "delete" expression.
1454 ///
1455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1458 bool IsGlobalDelete,
1459 bool IsArrayForm,
1460 ExprArg Operand) {
1461 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1462 move(Operand));
1463 }
Mike Stump11289f42009-09-09 15:08:12 +00001464
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 /// \brief Build a new unary type trait expression.
1466 ///
1467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
1469 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 QualType T,
1473 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001474 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 T.getAsOpaquePtr(), RParenLoc);
1476 }
1477
Mike Stump11289f42009-09-09 15:08:12 +00001478 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 /// expression.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001483 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceRange QualifierRange,
1485 DeclarationName Name,
1486 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001487 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 CXXScopeSpec SS;
1489 SS.setRange(QualifierRange);
1490 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001491
1492 if (TemplateArgs)
1493 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1494 *TemplateArgs);
1495
1496 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 }
1498
1499 /// \brief Build a new template-id expression.
1500 ///
1501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001503 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1504 LookupResult &R,
1505 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001506 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001507 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 }
1509
1510 /// \brief Build a new object-construction expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
1514 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001515 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 CXXConstructorDecl *Constructor,
1517 bool IsElidable,
1518 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001519 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1520 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1521 ConvertedArgs))
1522 return getSema().ExprError();
1523
1524 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1525 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 }
1527
1528 /// \brief Build a new object-construction expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
1532 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1533 QualType T,
1534 SourceLocation LParenLoc,
1535 MultiExprArg Args,
1536 SourceLocation *Commas,
1537 SourceLocation RParenLoc) {
1538 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1539 T.getAsOpaquePtr(),
1540 LParenLoc,
1541 move(Args),
1542 Commas,
1543 RParenLoc);
1544 }
1545
1546 /// \brief Build a new object-construction expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
1550 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1551 QualType T,
1552 SourceLocation LParenLoc,
1553 MultiExprArg Args,
1554 SourceLocation *Commas,
1555 SourceLocation RParenLoc) {
1556 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1557 /*FIXME*/LParenLoc),
1558 T.getAsOpaquePtr(),
1559 LParenLoc,
1560 move(Args),
1561 Commas,
1562 RParenLoc);
1563 }
Mike Stump11289f42009-09-09 15:08:12 +00001564
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// \brief Build a new member reference expression.
1566 ///
1567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001569 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001570 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 bool IsArrow,
1572 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001573 NestedNameSpecifier *Qualifier,
1574 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001575 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001577 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001578 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001580 SS.setRange(QualifierRange);
1581 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001582
John McCall2d74de92009-12-01 22:10:20 +00001583 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1584 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001585 SS, FirstQualifierInScope,
1586 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 }
1588
John McCall10eae182009-11-30 22:42:35 +00001589 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001590 ///
1591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001593 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001594 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001595 SourceLocation OperatorLoc,
1596 bool IsArrow,
1597 NestedNameSpecifier *Qualifier,
1598 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001599 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001600 LookupResult &R,
1601 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001602 CXXScopeSpec SS;
1603 SS.setRange(QualifierRange);
1604 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001605
John McCall2d74de92009-12-01 22:10:20 +00001606 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1607 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001608 SS, FirstQualifierInScope,
1609 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001610 }
Mike Stump11289f42009-09-09 15:08:12 +00001611
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// \brief Build a new Objective-C @encode expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1617 QualType T,
1618 SourceLocation RParenLoc) {
1619 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1620 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001621 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001622
1623 /// \brief Build a new Objective-C protocol expression.
1624 ///
1625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
1627 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1628 SourceLocation AtLoc,
1629 SourceLocation ProtoLoc,
1630 SourceLocation LParenLoc,
1631 SourceLocation RParenLoc) {
1632 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1633 Protocol->getIdentifier(),
1634 AtLoc,
1635 ProtoLoc,
1636 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001637 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 }
Mike Stump11289f42009-09-09 15:08:12 +00001639
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 /// \brief Build a new shuffle vector expression.
1641 ///
1642 /// By default, performs semantic analysis to build the new expression.
1643 /// Subclasses may override this routine to provide different behavior.
1644 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1645 MultiExprArg SubExprs,
1646 SourceLocation RParenLoc) {
1647 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001648 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1650 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1651 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1652 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001653
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 // Build a reference to the __builtin_shufflevector builtin
1655 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001656 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001658 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001660
1661 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 unsigned NumSubExprs = SubExprs.size();
1663 Expr **Subs = (Expr **)SubExprs.release();
1664 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1665 Subs, NumSubExprs,
1666 Builtin->getResultType(),
1667 RParenLoc);
1668 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001669
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 // Type-check the __builtin_shufflevector expression.
1671 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1672 if (Result.isInvalid())
1673 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001674
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001676 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001678};
Douglas Gregora16548e2009-08-11 05:31:07 +00001679
Douglas Gregorebe10102009-08-20 07:17:43 +00001680template<typename Derived>
1681Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1682 if (!S)
1683 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001684
Douglas Gregorebe10102009-08-20 07:17:43 +00001685 switch (S->getStmtClass()) {
1686 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001687
Douglas Gregorebe10102009-08-20 07:17:43 +00001688 // Transform individual statement nodes
1689#define STMT(Node, Parent) \
1690 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1691#define EXPR(Node, Parent)
1692#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001693
Douglas Gregorebe10102009-08-20 07:17:43 +00001694 // Transform expressions by calling TransformExpr.
1695#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001696#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001697#define EXPR(Node, Parent) case Stmt::Node##Class:
1698#include "clang/AST/StmtNodes.def"
1699 {
1700 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1701 if (E.isInvalid())
1702 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001703
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001704 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001705 }
Mike Stump11289f42009-09-09 15:08:12 +00001706 }
1707
Douglas Gregorebe10102009-08-20 07:17:43 +00001708 return SemaRef.Owned(S->Retain());
1709}
Mike Stump11289f42009-09-09 15:08:12 +00001710
1711
Douglas Gregore922c772009-08-04 22:27:00 +00001712template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001713Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 if (!E)
1715 return SemaRef.Owned(E);
1716
1717 switch (E->getStmtClass()) {
1718 case Stmt::NoStmtClass: break;
1719#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001720#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001721#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001722 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001723#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001724 }
1725
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001727}
1728
1729template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001730NestedNameSpecifier *
1731TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001733 QualType ObjectType,
1734 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001735 if (!NNS)
1736 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001737
Douglas Gregorebe10102009-08-20 07:17:43 +00001738 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 NestedNameSpecifier *Prefix = NNS->getPrefix();
1740 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001741 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001742 ObjectType,
1743 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001744 if (!Prefix)
1745 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001746
1747 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001748 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001749 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001750 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregor1135c352009-08-06 05:28:30 +00001753 switch (NNS->getKind()) {
1754 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001755 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001756 "Identifier nested-name-specifier with no prefix or object type");
1757 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1758 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001759 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001760
1761 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001762 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001763 ObjectType,
1764 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregor1135c352009-08-06 05:28:30 +00001766 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001767 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001768 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001769 getDerived().TransformDecl(Range.getBegin(),
1770 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001771 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001772 Prefix == NNS->getPrefix() &&
1773 NS == NNS->getAsNamespace())
1774 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregor1135c352009-08-06 05:28:30 +00001776 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1777 }
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregor1135c352009-08-06 05:28:30 +00001779 case NestedNameSpecifier::Global:
1780 // There is no meaningful transformation that one could perform on the
1781 // global scope.
1782 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregor1135c352009-08-06 05:28:30 +00001784 case NestedNameSpecifier::TypeSpecWithTemplate:
1785 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001786 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001787 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1788 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001789 if (T.isNull())
1790 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001791
Douglas Gregor1135c352009-08-06 05:28:30 +00001792 if (!getDerived().AlwaysRebuild() &&
1793 Prefix == NNS->getPrefix() &&
1794 T == QualType(NNS->getAsType(), 0))
1795 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001796
1797 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1798 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001799 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001800 }
1801 }
Mike Stump11289f42009-09-09 15:08:12 +00001802
Douglas Gregor1135c352009-08-06 05:28:30 +00001803 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001804 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001805}
1806
1807template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001808DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001809TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001810 SourceLocation Loc,
1811 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001812 if (!Name)
1813 return Name;
1814
1815 switch (Name.getNameKind()) {
1816 case DeclarationName::Identifier:
1817 case DeclarationName::ObjCZeroArgSelector:
1818 case DeclarationName::ObjCOneArgSelector:
1819 case DeclarationName::ObjCMultiArgSelector:
1820 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001821 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001822 case DeclarationName::CXXUsingDirective:
1823 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregorf816bd72009-09-03 22:13:48 +00001825 case DeclarationName::CXXConstructorName:
1826 case DeclarationName::CXXDestructorName:
1827 case DeclarationName::CXXConversionFunctionName: {
1828 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001829 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1830 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001831 if (T.isNull())
1832 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001833
Douglas Gregorf816bd72009-09-03 22:13:48 +00001834 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001835 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001836 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001837 }
Mike Stump11289f42009-09-09 15:08:12 +00001838 }
1839
Douglas Gregorf816bd72009-09-03 22:13:48 +00001840 return DeclarationName();
1841}
1842
1843template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001844TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001845TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1846 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001847 SourceLocation Loc = getDerived().getBaseLocation();
1848
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001850 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001852 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1853 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001854 if (!NNS)
1855 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregor71dc5092009-08-06 06:41:21 +00001857 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001858 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001859 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 if (!TransTemplate)
1861 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 if (!getDerived().AlwaysRebuild() &&
1864 NNS == QTN->getQualifier() &&
1865 TransTemplate == Template)
1866 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1869 TransTemplate);
1870 }
Mike Stump11289f42009-09-09 15:08:12 +00001871
John McCalle66edc12009-11-24 19:00:30 +00001872 // These should be getting filtered out before they make it into the AST.
1873 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor71dc5092009-08-06 06:41:21 +00001876 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001877 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001879 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1880 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001881 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001882 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregor71dc5092009-08-06 06:41:21 +00001884 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001885 NNS == DTN->getQualifier() &&
1886 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001887 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001888
Douglas Gregor71395fa2009-11-04 00:56:37 +00001889 if (DTN->isIdentifier())
1890 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1891 ObjectType);
1892
1893 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1894 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001895 }
Mike Stump11289f42009-09-09 15:08:12 +00001896
Douglas Gregor71dc5092009-08-06 06:41:21 +00001897 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001898 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001899 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001900 if (!TransTemplate)
1901 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001902
Douglas Gregor71dc5092009-08-06 06:41:21 +00001903 if (!getDerived().AlwaysRebuild() &&
1904 TransTemplate == Template)
1905 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001906
Douglas Gregor71dc5092009-08-06 06:41:21 +00001907 return TemplateName(TransTemplate);
1908 }
Mike Stump11289f42009-09-09 15:08:12 +00001909
John McCalle66edc12009-11-24 19:00:30 +00001910 // These should be getting filtered out before they reach the AST.
1911 assert(false && "overloaded function decl survived to here");
1912 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001913}
1914
1915template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001916void TreeTransform<Derived>::InventTemplateArgumentLoc(
1917 const TemplateArgument &Arg,
1918 TemplateArgumentLoc &Output) {
1919 SourceLocation Loc = getDerived().getBaseLocation();
1920 switch (Arg.getKind()) {
1921 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001922 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001923 break;
1924
1925 case TemplateArgument::Type:
1926 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001927 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001928
1929 break;
1930
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001931 case TemplateArgument::Template:
1932 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1933 break;
1934
John McCall0ad16662009-10-29 08:12:44 +00001935 case TemplateArgument::Expression:
1936 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1937 break;
1938
1939 case TemplateArgument::Declaration:
1940 case TemplateArgument::Integral:
1941 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001942 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001943 break;
1944 }
1945}
1946
1947template<typename Derived>
1948bool TreeTransform<Derived>::TransformTemplateArgument(
1949 const TemplateArgumentLoc &Input,
1950 TemplateArgumentLoc &Output) {
1951 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001952 switch (Arg.getKind()) {
1953 case TemplateArgument::Null:
1954 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001955 Output = Input;
1956 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregore922c772009-08-04 22:27:00 +00001958 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001959 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001960 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001961 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001962
1963 DI = getDerived().TransformType(DI);
1964 if (!DI) return true;
1965
1966 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1967 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001968 }
Mike Stump11289f42009-09-09 15:08:12 +00001969
Douglas Gregore922c772009-08-04 22:27:00 +00001970 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001971 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001972 DeclarationName Name;
1973 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1974 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001975 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001976 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001977 if (!D) return true;
1978
John McCall0d07eb32009-10-29 18:45:58 +00001979 Expr *SourceExpr = Input.getSourceDeclExpression();
1980 if (SourceExpr) {
1981 EnterExpressionEvaluationContext Unevaluated(getSema(),
1982 Action::Unevaluated);
1983 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1984 if (E.isInvalid())
1985 SourceExpr = NULL;
1986 else {
1987 SourceExpr = E.takeAs<Expr>();
1988 SourceExpr->Retain();
1989 }
1990 }
1991
1992 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001993 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001996 case TemplateArgument::Template: {
1997 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1998 TemplateName Template
1999 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2000 if (Template.isNull())
2001 return true;
2002
2003 Output = TemplateArgumentLoc(TemplateArgument(Template),
2004 Input.getTemplateQualifierRange(),
2005 Input.getTemplateNameLoc());
2006 return false;
2007 }
2008
Douglas Gregore922c772009-08-04 22:27:00 +00002009 case TemplateArgument::Expression: {
2010 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002011 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002012 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002013
John McCall0ad16662009-10-29 08:12:44 +00002014 Expr *InputExpr = Input.getSourceExpression();
2015 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2016
2017 Sema::OwningExprResult E
2018 = getDerived().TransformExpr(InputExpr);
2019 if (E.isInvalid()) return true;
2020
2021 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002022 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002023 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2024 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregore922c772009-08-04 22:27:00 +00002027 case TemplateArgument::Pack: {
2028 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2029 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002030 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002031 AEnd = Arg.pack_end();
2032 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002033
John McCall0ad16662009-10-29 08:12:44 +00002034 // FIXME: preserve source information here when we start
2035 // caring about parameter packs.
2036
John McCall0d07eb32009-10-29 18:45:58 +00002037 TemplateArgumentLoc InputArg;
2038 TemplateArgumentLoc OutputArg;
2039 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2040 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002041 return true;
2042
John McCall0d07eb32009-10-29 18:45:58 +00002043 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002044 }
2045 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002046 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002047 true);
John McCall0d07eb32009-10-29 18:45:58 +00002048 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002049 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002050 }
2051 }
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregore922c772009-08-04 22:27:00 +00002053 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002054 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002055}
2056
Douglas Gregord6ff3322009-08-04 16:50:30 +00002057//===----------------------------------------------------------------------===//
2058// Type transformation
2059//===----------------------------------------------------------------------===//
2060
2061template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002062QualType TreeTransform<Derived>::TransformType(QualType T,
2063 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002064 if (getDerived().AlreadyTransformed(T))
2065 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002066
John McCall550e0c22009-10-21 00:40:46 +00002067 // Temporary workaround. All of these transformations should
2068 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002069 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002070 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002071
Douglas Gregorfe17d252010-02-16 19:09:40 +00002072 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002073
John McCall550e0c22009-10-21 00:40:46 +00002074 if (!NewDI)
2075 return QualType();
2076
2077 return NewDI->getType();
2078}
2079
2080template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002081TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2082 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002083 if (getDerived().AlreadyTransformed(DI->getType()))
2084 return DI;
2085
2086 TypeLocBuilder TLB;
2087
2088 TypeLoc TL = DI->getTypeLoc();
2089 TLB.reserve(TL.getFullDataSize());
2090
Douglas Gregorfe17d252010-02-16 19:09:40 +00002091 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002092 if (Result.isNull())
2093 return 0;
2094
John McCallbcd03502009-12-07 02:54:59 +00002095 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002096}
2097
2098template<typename Derived>
2099QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002100TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2101 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002102 switch (T.getTypeLocClass()) {
2103#define ABSTRACT_TYPELOC(CLASS, PARENT)
2104#define TYPELOC(CLASS, PARENT) \
2105 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002106 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2107 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002108#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002109 }
Mike Stump11289f42009-09-09 15:08:12 +00002110
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002111 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002112 return QualType();
2113}
2114
2115/// FIXME: By default, this routine adds type qualifiers only to types
2116/// that can have qualifiers, and silently suppresses those qualifiers
2117/// that are not permitted (e.g., qualifiers on reference or function
2118/// types). This is the right thing for template instantiation, but
2119/// probably not for other clients.
2120template<typename Derived>
2121QualType
2122TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002123 QualifiedTypeLoc T,
2124 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002125 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002126
Douglas Gregorfe17d252010-02-16 19:09:40 +00002127 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2128 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002129 if (Result.isNull())
2130 return QualType();
2131
2132 // Silently suppress qualifiers if the result type can't be qualified.
2133 // FIXME: this is the right thing for template instantiation, but
2134 // probably not for other clients.
2135 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002136 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002137
John McCall550e0c22009-10-21 00:40:46 +00002138 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2139
2140 TLB.push<QualifiedTypeLoc>(Result);
2141
2142 // No location information to preserve.
2143
2144 return Result;
2145}
2146
2147template <class TyLoc> static inline
2148QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2149 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2150 NewT.setNameLoc(T.getNameLoc());
2151 return T.getType();
2152}
2153
2154// Ugly metaprogramming macros because I couldn't be bothered to make
2155// the equivalent template version work.
2156#define TransformPointerLikeType(TypeClass) do { \
2157 QualType PointeeType \
2158 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2159 if (PointeeType.isNull()) \
2160 return QualType(); \
2161 \
2162 QualType Result = TL.getType(); \
2163 if (getDerived().AlwaysRebuild() || \
2164 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002165 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2166 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002167 if (Result.isNull()) \
2168 return QualType(); \
2169 } \
2170 \
2171 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2172 NewT.setSigilLoc(TL.getSigilLoc()); \
2173 \
2174 return Result; \
2175} while(0)
2176
John McCall550e0c22009-10-21 00:40:46 +00002177template<typename Derived>
2178QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002179 BuiltinTypeLoc T,
2180 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002181 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2182 NewT.setBuiltinLoc(T.getBuiltinLoc());
2183 if (T.needsExtraLocalData())
2184 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2185 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002186}
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregord6ff3322009-08-04 16:50:30 +00002188template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002189QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002190 ComplexTypeLoc T,
2191 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002192 // FIXME: recurse?
2193 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002194}
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregord6ff3322009-08-04 16:50:30 +00002196template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002197QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002198 PointerTypeLoc TL,
2199 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002200 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002201}
Mike Stump11289f42009-09-09 15:08:12 +00002202
2203template<typename Derived>
2204QualType
John McCall550e0c22009-10-21 00:40:46 +00002205TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002206 BlockPointerTypeLoc TL,
2207 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002208 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002209}
2210
John McCall70dd5f62009-10-30 00:06:24 +00002211/// Transforms a reference type. Note that somewhat paradoxically we
2212/// don't care whether the type itself is an l-value type or an r-value
2213/// type; we only care if the type was *written* as an l-value type
2214/// or an r-value type.
2215template<typename Derived>
2216QualType
2217TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002218 ReferenceTypeLoc TL,
2219 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002220 const ReferenceType *T = TL.getTypePtr();
2221
2222 // Note that this works with the pointee-as-written.
2223 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2224 if (PointeeType.isNull())
2225 return QualType();
2226
2227 QualType Result = TL.getType();
2228 if (getDerived().AlwaysRebuild() ||
2229 PointeeType != T->getPointeeTypeAsWritten()) {
2230 Result = getDerived().RebuildReferenceType(PointeeType,
2231 T->isSpelledAsLValue(),
2232 TL.getSigilLoc());
2233 if (Result.isNull())
2234 return QualType();
2235 }
2236
2237 // r-value references can be rebuilt as l-value references.
2238 ReferenceTypeLoc NewTL;
2239 if (isa<LValueReferenceType>(Result))
2240 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2241 else
2242 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2243 NewTL.setSigilLoc(TL.getSigilLoc());
2244
2245 return Result;
2246}
2247
Mike Stump11289f42009-09-09 15:08:12 +00002248template<typename Derived>
2249QualType
John McCall550e0c22009-10-21 00:40:46 +00002250TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002251 LValueReferenceTypeLoc TL,
2252 QualType ObjectType) {
2253 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002254}
2255
Mike Stump11289f42009-09-09 15:08:12 +00002256template<typename Derived>
2257QualType
John McCall550e0c22009-10-21 00:40:46 +00002258TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002259 RValueReferenceTypeLoc TL,
2260 QualType ObjectType) {
2261 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002262}
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregord6ff3322009-08-04 16:50:30 +00002264template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002265QualType
John McCall550e0c22009-10-21 00:40:46 +00002266TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002267 MemberPointerTypeLoc TL,
2268 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002269 MemberPointerType *T = TL.getTypePtr();
2270
2271 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002272 if (PointeeType.isNull())
2273 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002274
John McCall550e0c22009-10-21 00:40:46 +00002275 // TODO: preserve source information for this.
2276 QualType ClassType
2277 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002278 if (ClassType.isNull())
2279 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002280
John McCall550e0c22009-10-21 00:40:46 +00002281 QualType Result = TL.getType();
2282 if (getDerived().AlwaysRebuild() ||
2283 PointeeType != T->getPointeeType() ||
2284 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002285 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2286 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002287 if (Result.isNull())
2288 return QualType();
2289 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002290
John McCall550e0c22009-10-21 00:40:46 +00002291 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2292 NewTL.setSigilLoc(TL.getSigilLoc());
2293
2294 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002295}
2296
Mike Stump11289f42009-09-09 15:08:12 +00002297template<typename Derived>
2298QualType
John McCall550e0c22009-10-21 00:40:46 +00002299TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002300 ConstantArrayTypeLoc TL,
2301 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002302 ConstantArrayType *T = TL.getTypePtr();
2303 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002304 if (ElementType.isNull())
2305 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002306
John McCall550e0c22009-10-21 00:40:46 +00002307 QualType Result = TL.getType();
2308 if (getDerived().AlwaysRebuild() ||
2309 ElementType != T->getElementType()) {
2310 Result = getDerived().RebuildConstantArrayType(ElementType,
2311 T->getSizeModifier(),
2312 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002313 T->getIndexTypeCVRQualifiers(),
2314 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002315 if (Result.isNull())
2316 return QualType();
2317 }
2318
2319 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2320 NewTL.setLBracketLoc(TL.getLBracketLoc());
2321 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002322
John McCall550e0c22009-10-21 00:40:46 +00002323 Expr *Size = TL.getSizeExpr();
2324 if (Size) {
2325 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2326 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2327 }
2328 NewTL.setSizeExpr(Size);
2329
2330 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002331}
Mike Stump11289f42009-09-09 15:08:12 +00002332
Douglas Gregord6ff3322009-08-04 16:50:30 +00002333template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002334QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002335 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002336 IncompleteArrayTypeLoc TL,
2337 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002338 IncompleteArrayType *T = TL.getTypePtr();
2339 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002340 if (ElementType.isNull())
2341 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002342
John McCall550e0c22009-10-21 00:40:46 +00002343 QualType Result = TL.getType();
2344 if (getDerived().AlwaysRebuild() ||
2345 ElementType != T->getElementType()) {
2346 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002347 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002348 T->getIndexTypeCVRQualifiers(),
2349 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002350 if (Result.isNull())
2351 return QualType();
2352 }
2353
2354 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2355 NewTL.setLBracketLoc(TL.getLBracketLoc());
2356 NewTL.setRBracketLoc(TL.getRBracketLoc());
2357 NewTL.setSizeExpr(0);
2358
2359 return Result;
2360}
2361
2362template<typename Derived>
2363QualType
2364TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002365 VariableArrayTypeLoc TL,
2366 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002367 VariableArrayType *T = TL.getTypePtr();
2368 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2369 if (ElementType.isNull())
2370 return QualType();
2371
2372 // Array bounds are not potentially evaluated contexts
2373 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2374
2375 Sema::OwningExprResult SizeResult
2376 = getDerived().TransformExpr(T->getSizeExpr());
2377 if (SizeResult.isInvalid())
2378 return QualType();
2379
2380 Expr *Size = static_cast<Expr*>(SizeResult.get());
2381
2382 QualType Result = TL.getType();
2383 if (getDerived().AlwaysRebuild() ||
2384 ElementType != T->getElementType() ||
2385 Size != T->getSizeExpr()) {
2386 Result = getDerived().RebuildVariableArrayType(ElementType,
2387 T->getSizeModifier(),
2388 move(SizeResult),
2389 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002390 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002391 if (Result.isNull())
2392 return QualType();
2393 }
2394 else SizeResult.take();
2395
2396 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2397 NewTL.setLBracketLoc(TL.getLBracketLoc());
2398 NewTL.setRBracketLoc(TL.getRBracketLoc());
2399 NewTL.setSizeExpr(Size);
2400
2401 return Result;
2402}
2403
2404template<typename Derived>
2405QualType
2406TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002407 DependentSizedArrayTypeLoc TL,
2408 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002409 DependentSizedArrayType *T = TL.getTypePtr();
2410 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2411 if (ElementType.isNull())
2412 return QualType();
2413
2414 // Array bounds are not potentially evaluated contexts
2415 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2416
2417 Sema::OwningExprResult SizeResult
2418 = getDerived().TransformExpr(T->getSizeExpr());
2419 if (SizeResult.isInvalid())
2420 return QualType();
2421
2422 Expr *Size = static_cast<Expr*>(SizeResult.get());
2423
2424 QualType Result = TL.getType();
2425 if (getDerived().AlwaysRebuild() ||
2426 ElementType != T->getElementType() ||
2427 Size != T->getSizeExpr()) {
2428 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2429 T->getSizeModifier(),
2430 move(SizeResult),
2431 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002432 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002433 if (Result.isNull())
2434 return QualType();
2435 }
2436 else SizeResult.take();
2437
2438 // We might have any sort of array type now, but fortunately they
2439 // all have the same location layout.
2440 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2441 NewTL.setLBracketLoc(TL.getLBracketLoc());
2442 NewTL.setRBracketLoc(TL.getRBracketLoc());
2443 NewTL.setSizeExpr(Size);
2444
2445 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002446}
Mike Stump11289f42009-09-09 15:08:12 +00002447
2448template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002449QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002450 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002451 DependentSizedExtVectorTypeLoc TL,
2452 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002453 DependentSizedExtVectorType *T = TL.getTypePtr();
2454
2455 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456 QualType ElementType = getDerived().TransformType(T->getElementType());
2457 if (ElementType.isNull())
2458 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002459
Douglas Gregore922c772009-08-04 22:27:00 +00002460 // Vector sizes are not potentially evaluated contexts
2461 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2462
Douglas Gregord6ff3322009-08-04 16:50:30 +00002463 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2464 if (Size.isInvalid())
2465 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002466
John McCall550e0c22009-10-21 00:40:46 +00002467 QualType Result = TL.getType();
2468 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002469 ElementType != T->getElementType() ||
2470 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002471 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472 move(Size),
2473 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002474 if (Result.isNull())
2475 return QualType();
2476 }
2477 else Size.take();
2478
2479 // Result might be dependent or not.
2480 if (isa<DependentSizedExtVectorType>(Result)) {
2481 DependentSizedExtVectorTypeLoc NewTL
2482 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2483 NewTL.setNameLoc(TL.getNameLoc());
2484 } else {
2485 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2486 NewTL.setNameLoc(TL.getNameLoc());
2487 }
2488
2489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002490}
Mike Stump11289f42009-09-09 15:08:12 +00002491
2492template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002493QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002494 VectorTypeLoc TL,
2495 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002496 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002497 QualType ElementType = getDerived().TransformType(T->getElementType());
2498 if (ElementType.isNull())
2499 return QualType();
2500
John McCall550e0c22009-10-21 00:40:46 +00002501 QualType Result = TL.getType();
2502 if (getDerived().AlwaysRebuild() ||
2503 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002504 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2505 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002506 if (Result.isNull())
2507 return QualType();
2508 }
2509
2510 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2511 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002512
John McCall550e0c22009-10-21 00:40:46 +00002513 return Result;
2514}
2515
2516template<typename Derived>
2517QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002518 ExtVectorTypeLoc TL,
2519 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002520 VectorType *T = TL.getTypePtr();
2521 QualType ElementType = getDerived().TransformType(T->getElementType());
2522 if (ElementType.isNull())
2523 return QualType();
2524
2525 QualType Result = TL.getType();
2526 if (getDerived().AlwaysRebuild() ||
2527 ElementType != T->getElementType()) {
2528 Result = getDerived().RebuildExtVectorType(ElementType,
2529 T->getNumElements(),
2530 /*FIXME*/ SourceLocation());
2531 if (Result.isNull())
2532 return QualType();
2533 }
2534
2535 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2536 NewTL.setNameLoc(TL.getNameLoc());
2537
2538 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002539}
Mike Stump11289f42009-09-09 15:08:12 +00002540
2541template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002542ParmVarDecl *
2543TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2544 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2545 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2546 if (!NewDI)
2547 return 0;
2548
2549 if (NewDI == OldDI)
2550 return OldParm;
2551 else
2552 return ParmVarDecl::Create(SemaRef.Context,
2553 OldParm->getDeclContext(),
2554 OldParm->getLocation(),
2555 OldParm->getIdentifier(),
2556 NewDI->getType(),
2557 NewDI,
2558 OldParm->getStorageClass(),
2559 /* DefArg */ NULL);
2560}
2561
2562template<typename Derived>
2563bool TreeTransform<Derived>::
2564 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2565 llvm::SmallVectorImpl<QualType> &PTypes,
2566 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2567 FunctionProtoType *T = TL.getTypePtr();
2568
2569 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2570 ParmVarDecl *OldParm = TL.getArg(i);
2571
2572 QualType NewType;
2573 ParmVarDecl *NewParm;
2574
2575 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002576 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2577 if (!NewParm)
2578 return true;
2579 NewType = NewParm->getType();
2580
2581 // Deal with the possibility that we don't have a parameter
2582 // declaration for this parameter.
2583 } else {
2584 NewParm = 0;
2585
2586 QualType OldType = T->getArgType(i);
2587 NewType = getDerived().TransformType(OldType);
2588 if (NewType.isNull())
2589 return true;
2590 }
2591
2592 PTypes.push_back(NewType);
2593 PVars.push_back(NewParm);
2594 }
2595
2596 return false;
2597}
2598
2599template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002600QualType
John McCall550e0c22009-10-21 00:40:46 +00002601TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002602 FunctionProtoTypeLoc TL,
2603 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002604 FunctionProtoType *T = TL.getTypePtr();
2605 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002606 if (ResultType.isNull())
2607 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002608
John McCall550e0c22009-10-21 00:40:46 +00002609 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002611 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002612 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002614
John McCall550e0c22009-10-21 00:40:46 +00002615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
2617 ResultType != T->getResultType() ||
2618 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2619 Result = getDerived().RebuildFunctionProtoType(ResultType,
2620 ParamTypes.data(),
2621 ParamTypes.size(),
2622 T->isVariadic(),
2623 T->getTypeQuals());
2624 if (Result.isNull())
2625 return QualType();
2626 }
Mike Stump11289f42009-09-09 15:08:12 +00002627
John McCall550e0c22009-10-21 00:40:46 +00002628 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2629 NewTL.setLParenLoc(TL.getLParenLoc());
2630 NewTL.setRParenLoc(TL.getRParenLoc());
2631 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2632 NewTL.setArg(i, ParamDecls[i]);
2633
2634 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635}
Mike Stump11289f42009-09-09 15:08:12 +00002636
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637template<typename Derived>
2638QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002639 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002640 FunctionNoProtoTypeLoc TL,
2641 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002642 FunctionNoProtoType *T = TL.getTypePtr();
2643 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2644 if (ResultType.isNull())
2645 return QualType();
2646
2647 QualType Result = TL.getType();
2648 if (getDerived().AlwaysRebuild() ||
2649 ResultType != T->getResultType())
2650 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2651
2652 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2653 NewTL.setLParenLoc(TL.getLParenLoc());
2654 NewTL.setRParenLoc(TL.getRParenLoc());
2655
2656 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002657}
Mike Stump11289f42009-09-09 15:08:12 +00002658
John McCallb96ec562009-12-04 22:46:56 +00002659template<typename Derived> QualType
2660TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002661 UnresolvedUsingTypeLoc TL,
2662 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002663 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002664 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002665 if (!D)
2666 return QualType();
2667
2668 QualType Result = TL.getType();
2669 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2670 Result = getDerived().RebuildUnresolvedUsingType(D);
2671 if (Result.isNull())
2672 return QualType();
2673 }
2674
2675 // We might get an arbitrary type spec type back. We should at
2676 // least always get a type spec type, though.
2677 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2678 NewTL.setNameLoc(TL.getNameLoc());
2679
2680 return Result;
2681}
2682
Douglas Gregord6ff3322009-08-04 16:50:30 +00002683template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002684QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002685 TypedefTypeLoc TL,
2686 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002687 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002688 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002689 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2690 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002691 if (!Typedef)
2692 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002693
John McCall550e0c22009-10-21 00:40:46 +00002694 QualType Result = TL.getType();
2695 if (getDerived().AlwaysRebuild() ||
2696 Typedef != T->getDecl()) {
2697 Result = getDerived().RebuildTypedefType(Typedef);
2698 if (Result.isNull())
2699 return QualType();
2700 }
Mike Stump11289f42009-09-09 15:08:12 +00002701
John McCall550e0c22009-10-21 00:40:46 +00002702 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2703 NewTL.setNameLoc(TL.getNameLoc());
2704
2705 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002706}
Mike Stump11289f42009-09-09 15:08:12 +00002707
Douglas Gregord6ff3322009-08-04 16:50:30 +00002708template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002709QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002710 TypeOfExprTypeLoc TL,
2711 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002712 // typeof expressions are not potentially evaluated contexts
2713 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002714
John McCalle8595032010-01-13 20:03:27 +00002715 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002716 if (E.isInvalid())
2717 return QualType();
2718
John McCall550e0c22009-10-21 00:40:46 +00002719 QualType Result = TL.getType();
2720 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002721 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002722 Result = getDerived().RebuildTypeOfExprType(move(E));
2723 if (Result.isNull())
2724 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002725 }
John McCall550e0c22009-10-21 00:40:46 +00002726 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002727
John McCall550e0c22009-10-21 00:40:46 +00002728 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002729 NewTL.setTypeofLoc(TL.getTypeofLoc());
2730 NewTL.setLParenLoc(TL.getLParenLoc());
2731 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002732
2733 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734}
Mike Stump11289f42009-09-09 15:08:12 +00002735
2736template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002737QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002738 TypeOfTypeLoc TL,
2739 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002740 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2741 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2742 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002744
John McCall550e0c22009-10-21 00:40:46 +00002745 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002746 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2747 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002748 if (Result.isNull())
2749 return QualType();
2750 }
Mike Stump11289f42009-09-09 15:08:12 +00002751
John McCall550e0c22009-10-21 00:40:46 +00002752 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002753 NewTL.setTypeofLoc(TL.getTypeofLoc());
2754 NewTL.setLParenLoc(TL.getLParenLoc());
2755 NewTL.setRParenLoc(TL.getRParenLoc());
2756 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002757
2758 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759}
Mike Stump11289f42009-09-09 15:08:12 +00002760
2761template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002762QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002763 DecltypeTypeLoc TL,
2764 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002765 DecltypeType *T = TL.getTypePtr();
2766
Douglas Gregore922c772009-08-04 22:27:00 +00002767 // decltype expressions are not potentially evaluated contexts
2768 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002769
Douglas Gregord6ff3322009-08-04 16:50:30 +00002770 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2771 if (E.isInvalid())
2772 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002773
John McCall550e0c22009-10-21 00:40:46 +00002774 QualType Result = TL.getType();
2775 if (getDerived().AlwaysRebuild() ||
2776 E.get() != T->getUnderlyingExpr()) {
2777 Result = getDerived().RebuildDecltypeType(move(E));
2778 if (Result.isNull())
2779 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002780 }
John McCall550e0c22009-10-21 00:40:46 +00002781 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002782
John McCall550e0c22009-10-21 00:40:46 +00002783 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785
2786 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002787}
2788
2789template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002790QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002791 RecordTypeLoc TL,
2792 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002793 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002794 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002795 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2796 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002797 if (!Record)
2798 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002799
John McCall550e0c22009-10-21 00:40:46 +00002800 QualType Result = TL.getType();
2801 if (getDerived().AlwaysRebuild() ||
2802 Record != T->getDecl()) {
2803 Result = getDerived().RebuildRecordType(Record);
2804 if (Result.isNull())
2805 return QualType();
2806 }
Mike Stump11289f42009-09-09 15:08:12 +00002807
John McCall550e0c22009-10-21 00:40:46 +00002808 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2809 NewTL.setNameLoc(TL.getNameLoc());
2810
2811 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002812}
Mike Stump11289f42009-09-09 15:08:12 +00002813
2814template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002815QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002816 EnumTypeLoc TL,
2817 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002818 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002819 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002820 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2821 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002822 if (!Enum)
2823 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002824
John McCall550e0c22009-10-21 00:40:46 +00002825 QualType Result = TL.getType();
2826 if (getDerived().AlwaysRebuild() ||
2827 Enum != T->getDecl()) {
2828 Result = getDerived().RebuildEnumType(Enum);
2829 if (Result.isNull())
2830 return QualType();
2831 }
Mike Stump11289f42009-09-09 15:08:12 +00002832
John McCall550e0c22009-10-21 00:40:46 +00002833 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2834 NewTL.setNameLoc(TL.getNameLoc());
2835
2836 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837}
John McCallfcc33b02009-09-05 00:15:47 +00002838
2839template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002840QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002841 ElaboratedTypeLoc TL,
2842 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002843 ElaboratedType *T = TL.getTypePtr();
2844
2845 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002846 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2847 if (Underlying.isNull())
2848 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002849
John McCall550e0c22009-10-21 00:40:46 +00002850 QualType Result = TL.getType();
2851 if (getDerived().AlwaysRebuild() ||
2852 Underlying != T->getUnderlyingType()) {
2853 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2854 if (Result.isNull())
2855 return QualType();
2856 }
Mike Stump11289f42009-09-09 15:08:12 +00002857
John McCall550e0c22009-10-21 00:40:46 +00002858 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2859 NewTL.setNameLoc(TL.getNameLoc());
2860
2861 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002862}
Mike Stump11289f42009-09-09 15:08:12 +00002863
John McCalle78aac42010-03-10 03:28:59 +00002864template<typename Derived>
2865QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2866 TypeLocBuilder &TLB,
2867 InjectedClassNameTypeLoc TL,
2868 QualType ObjectType) {
2869 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2870 TL.getTypePtr()->getDecl());
2871 if (!D) return QualType();
2872
2873 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2874 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2875 return T;
2876}
2877
Mike Stump11289f42009-09-09 15:08:12 +00002878
Douglas Gregord6ff3322009-08-04 16:50:30 +00002879template<typename Derived>
2880QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002881 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002882 TemplateTypeParmTypeLoc TL,
2883 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002884 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002885}
2886
Mike Stump11289f42009-09-09 15:08:12 +00002887template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002888QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002889 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002890 SubstTemplateTypeParmTypeLoc TL,
2891 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002892 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002893}
2894
2895template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002896QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2897 const TemplateSpecializationType *TST,
2898 QualType ObjectType) {
2899 // FIXME: this entire method is a temporary workaround; callers
2900 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002901
John McCall0ad16662009-10-29 08:12:44 +00002902 // Fake up a TemplateSpecializationTypeLoc.
2903 TypeLocBuilder TLB;
2904 TemplateSpecializationTypeLoc TL
2905 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2906
John McCall0d07eb32009-10-29 18:45:58 +00002907 SourceLocation BaseLoc = getDerived().getBaseLocation();
2908
2909 TL.setTemplateNameLoc(BaseLoc);
2910 TL.setLAngleLoc(BaseLoc);
2911 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002912 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2913 const TemplateArgument &TA = TST->getArg(i);
2914 TemplateArgumentLoc TAL;
2915 getDerived().InventTemplateArgumentLoc(TA, TAL);
2916 TL.setArgLocInfo(i, TAL.getLocInfo());
2917 }
2918
2919 TypeLocBuilder IgnoredTLB;
2920 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002921}
2922
2923template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002924QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002925 TypeLocBuilder &TLB,
2926 TemplateSpecializationTypeLoc TL,
2927 QualType ObjectType) {
2928 const TemplateSpecializationType *T = TL.getTypePtr();
2929
Mike Stump11289f42009-09-09 15:08:12 +00002930 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002931 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002932 if (Template.isNull())
2933 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002934
John McCall6b51f282009-11-23 01:53:49 +00002935 TemplateArgumentListInfo NewTemplateArgs;
2936 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2937 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2938
2939 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2940 TemplateArgumentLoc Loc;
2941 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002943 NewTemplateArgs.addArgument(Loc);
2944 }
Mike Stump11289f42009-09-09 15:08:12 +00002945
John McCall0ad16662009-10-29 08:12:44 +00002946 // FIXME: maybe don't rebuild if all the template arguments are the same.
2947
2948 QualType Result =
2949 getDerived().RebuildTemplateSpecializationType(Template,
2950 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002951 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002952
2953 if (!Result.isNull()) {
2954 TemplateSpecializationTypeLoc NewTL
2955 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2956 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2957 NewTL.setLAngleLoc(TL.getLAngleLoc());
2958 NewTL.setRAngleLoc(TL.getRAngleLoc());
2959 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2960 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961 }
Mike Stump11289f42009-09-09 15:08:12 +00002962
John McCall0ad16662009-10-29 08:12:44 +00002963 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002964}
Mike Stump11289f42009-09-09 15:08:12 +00002965
2966template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002967QualType
2968TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002969 QualifiedNameTypeLoc TL,
2970 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002971 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002972 NestedNameSpecifier *NNS
2973 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002974 SourceRange(),
2975 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976 if (!NNS)
2977 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002978
Douglas Gregord6ff3322009-08-04 16:50:30 +00002979 QualType Named = getDerived().TransformType(T->getNamedType());
2980 if (Named.isNull())
2981 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002982
John McCall550e0c22009-10-21 00:40:46 +00002983 QualType Result = TL.getType();
2984 if (getDerived().AlwaysRebuild() ||
2985 NNS != T->getQualifier() ||
2986 Named != T->getNamedType()) {
2987 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2988 if (Result.isNull())
2989 return QualType();
2990 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991
John McCall550e0c22009-10-21 00:40:46 +00002992 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2993 NewTL.setNameLoc(TL.getNameLoc());
2994
2995 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996}
Mike Stump11289f42009-09-09 15:08:12 +00002997
2998template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00002999QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3000 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003001 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003002 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003003
3004 /* FIXME: preserve source information better than this */
3005 SourceRange SR(TL.getNameLoc());
3006
Douglas Gregord6ff3322009-08-04 16:50:30 +00003007 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003008 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003009 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003010 if (!NNS)
3011 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003012
John McCall550e0c22009-10-21 00:40:46 +00003013 QualType Result;
3014
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003016 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003017 = getDerived().TransformType(QualType(TemplateId, 0));
3018 if (NewTemplateId.isNull())
3019 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003020
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 if (!getDerived().AlwaysRebuild() &&
3022 NNS == T->getQualifier() &&
3023 NewTemplateId == QualType(TemplateId, 0))
3024 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003025
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003026 Result = getDerived().RebuildDependentNameType(NNS, NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003027 } else {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003028 Result = getDerived().RebuildDependentNameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029 }
John McCall550e0c22009-10-21 00:40:46 +00003030 if (Result.isNull())
3031 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003032
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003033 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003034 NewTL.setNameLoc(TL.getNameLoc());
3035
3036 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003037}
Mike Stump11289f42009-09-09 15:08:12 +00003038
Douglas Gregord6ff3322009-08-04 16:50:30 +00003039template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003040QualType
3041TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003042 ObjCInterfaceTypeLoc TL,
3043 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003044 assert(false && "TransformObjCInterfaceType unimplemented");
3045 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003046}
Mike Stump11289f42009-09-09 15:08:12 +00003047
3048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003049QualType
3050TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003051 ObjCObjectPointerTypeLoc TL,
3052 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003053 assert(false && "TransformObjCObjectPointerType unimplemented");
3054 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003055}
3056
Douglas Gregord6ff3322009-08-04 16:50:30 +00003057//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003058// Statement transformation
3059//===----------------------------------------------------------------------===//
3060template<typename Derived>
3061Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003062TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3063 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003064}
3065
3066template<typename Derived>
3067Sema::OwningStmtResult
3068TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3069 return getDerived().TransformCompoundStmt(S, false);
3070}
3071
3072template<typename Derived>
3073Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003074TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003075 bool IsStmtExpr) {
3076 bool SubStmtChanged = false;
3077 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3078 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3079 B != BEnd; ++B) {
3080 OwningStmtResult Result = getDerived().TransformStmt(*B);
3081 if (Result.isInvalid())
3082 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003083
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3085 Statements.push_back(Result.takeAs<Stmt>());
3086 }
Mike Stump11289f42009-09-09 15:08:12 +00003087
Douglas Gregorebe10102009-08-20 07:17:43 +00003088 if (!getDerived().AlwaysRebuild() &&
3089 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003090 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003091
3092 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3093 move_arg(Statements),
3094 S->getRBracLoc(),
3095 IsStmtExpr);
3096}
Mike Stump11289f42009-09-09 15:08:12 +00003097
Douglas Gregorebe10102009-08-20 07:17:43 +00003098template<typename Derived>
3099Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003100TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003101 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3102 {
3103 // The case value expressions are not potentially evaluated.
3104 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003105
Eli Friedman06577382009-11-19 03:14:00 +00003106 // Transform the left-hand case value.
3107 LHS = getDerived().TransformExpr(S->getLHS());
3108 if (LHS.isInvalid())
3109 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003110
Eli Friedman06577382009-11-19 03:14:00 +00003111 // Transform the right-hand case value (for the GNU case-range extension).
3112 RHS = getDerived().TransformExpr(S->getRHS());
3113 if (RHS.isInvalid())
3114 return SemaRef.StmtError();
3115 }
Mike Stump11289f42009-09-09 15:08:12 +00003116
Douglas Gregorebe10102009-08-20 07:17:43 +00003117 // Build the case statement.
3118 // Case statements are always rebuilt so that they will attached to their
3119 // transformed switch statement.
3120 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3121 move(LHS),
3122 S->getEllipsisLoc(),
3123 move(RHS),
3124 S->getColonLoc());
3125 if (Case.isInvalid())
3126 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003127
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 // Transform the statement following the case
3129 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3130 if (SubStmt.isInvalid())
3131 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003132
Douglas Gregorebe10102009-08-20 07:17:43 +00003133 // Attach the body to the case statement
3134 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3135}
3136
3137template<typename Derived>
3138Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003139TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003140 // Transform the statement following the default case
3141 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3142 if (SubStmt.isInvalid())
3143 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003144
Douglas Gregorebe10102009-08-20 07:17:43 +00003145 // Default statements are always rebuilt
3146 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3147 move(SubStmt));
3148}
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregorebe10102009-08-20 07:17:43 +00003150template<typename Derived>
3151Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003152TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3154 if (SubStmt.isInvalid())
3155 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003156
Douglas Gregorebe10102009-08-20 07:17:43 +00003157 // FIXME: Pass the real colon location in.
3158 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3159 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3160 move(SubStmt));
3161}
Mike Stump11289f42009-09-09 15:08:12 +00003162
Douglas Gregorebe10102009-08-20 07:17:43 +00003163template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003164Sema::OwningStmtResult
3165TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003166 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003167 OwningExprResult Cond(SemaRef);
3168 VarDecl *ConditionVar = 0;
3169 if (S->getConditionVariable()) {
3170 ConditionVar
3171 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003172 getDerived().TransformDefinition(
3173 S->getConditionVariable()->getLocation(),
3174 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003175 if (!ConditionVar)
3176 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003177 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003178 Cond = getDerived().TransformExpr(S->getCond());
3179
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003180 if (Cond.isInvalid())
3181 return SemaRef.StmtError();
3182 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003183
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003184 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003185
Douglas Gregorebe10102009-08-20 07:17:43 +00003186 // Transform the "then" branch.
3187 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3188 if (Then.isInvalid())
3189 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003190
Douglas Gregorebe10102009-08-20 07:17:43 +00003191 // Transform the "else" branch.
3192 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3193 if (Else.isInvalid())
3194 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003195
Douglas Gregorebe10102009-08-20 07:17:43 +00003196 if (!getDerived().AlwaysRebuild() &&
3197 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003198 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003199 Then.get() == S->getThen() &&
3200 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003201 return SemaRef.Owned(S->Retain());
3202
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003203 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3204 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003205 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003206}
3207
3208template<typename Derived>
3209Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003210TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003211 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003212 OwningExprResult Cond(SemaRef);
3213 VarDecl *ConditionVar = 0;
3214 if (S->getConditionVariable()) {
3215 ConditionVar
3216 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003217 getDerived().TransformDefinition(
3218 S->getConditionVariable()->getLocation(),
3219 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003220 if (!ConditionVar)
3221 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003222 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003223 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003224
3225 if (Cond.isInvalid())
3226 return SemaRef.StmtError();
3227 }
Mike Stump11289f42009-09-09 15:08:12 +00003228
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003229 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003230
Douglas Gregorebe10102009-08-20 07:17:43 +00003231 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003232 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3233 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003234 if (Switch.isInvalid())
3235 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 // Transform the body of the switch statement.
3238 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3239 if (Body.isInvalid())
3240 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003241
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 // Complete the switch statement.
3243 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3244 move(Body));
3245}
Mike Stump11289f42009-09-09 15:08:12 +00003246
Douglas Gregorebe10102009-08-20 07:17:43 +00003247template<typename Derived>
3248Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003249TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003250 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003251 OwningExprResult Cond(SemaRef);
3252 VarDecl *ConditionVar = 0;
3253 if (S->getConditionVariable()) {
3254 ConditionVar
3255 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003256 getDerived().TransformDefinition(
3257 S->getConditionVariable()->getLocation(),
3258 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003259 if (!ConditionVar)
3260 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003261 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003262 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003263
3264 if (Cond.isInvalid())
3265 return SemaRef.StmtError();
3266 }
Mike Stump11289f42009-09-09 15:08:12 +00003267
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003268 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003269
Douglas Gregorebe10102009-08-20 07:17:43 +00003270 // Transform the body
3271 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3272 if (Body.isInvalid())
3273 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003274
Douglas Gregorebe10102009-08-20 07:17:43 +00003275 if (!getDerived().AlwaysRebuild() &&
3276 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003277 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003278 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003279 return SemaRef.Owned(S->Retain());
3280
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003281 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3282 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003283}
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregorebe10102009-08-20 07:17:43 +00003285template<typename Derived>
3286Sema::OwningStmtResult
3287TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3288 // Transform the condition
3289 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3290 if (Cond.isInvalid())
3291 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003292
Douglas Gregorebe10102009-08-20 07:17:43 +00003293 // Transform the body
3294 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3295 if (Body.isInvalid())
3296 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregorebe10102009-08-20 07:17:43 +00003298 if (!getDerived().AlwaysRebuild() &&
3299 Cond.get() == S->getCond() &&
3300 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003301 return SemaRef.Owned(S->Retain());
3302
Douglas Gregorebe10102009-08-20 07:17:43 +00003303 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3304 /*FIXME:*/S->getWhileLoc(), move(Cond),
3305 S->getRParenLoc());
3306}
Mike Stump11289f42009-09-09 15:08:12 +00003307
Douglas Gregorebe10102009-08-20 07:17:43 +00003308template<typename Derived>
3309Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003310TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003311 // Transform the initialization statement
3312 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3313 if (Init.isInvalid())
3314 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003315
Douglas Gregorebe10102009-08-20 07:17:43 +00003316 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003317 OwningExprResult Cond(SemaRef);
3318 VarDecl *ConditionVar = 0;
3319 if (S->getConditionVariable()) {
3320 ConditionVar
3321 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003322 getDerived().TransformDefinition(
3323 S->getConditionVariable()->getLocation(),
3324 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003325 if (!ConditionVar)
3326 return SemaRef.StmtError();
3327 } else {
3328 Cond = getDerived().TransformExpr(S->getCond());
3329
3330 if (Cond.isInvalid())
3331 return SemaRef.StmtError();
3332 }
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregorebe10102009-08-20 07:17:43 +00003334 // Transform the increment
3335 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3336 if (Inc.isInvalid())
3337 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003338
Douglas Gregorebe10102009-08-20 07:17:43 +00003339 // Transform the body
3340 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3341 if (Body.isInvalid())
3342 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003343
Douglas Gregorebe10102009-08-20 07:17:43 +00003344 if (!getDerived().AlwaysRebuild() &&
3345 Init.get() == S->getInit() &&
3346 Cond.get() == S->getCond() &&
3347 Inc.get() == S->getInc() &&
3348 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003349 return SemaRef.Owned(S->Retain());
3350
Douglas Gregorebe10102009-08-20 07:17:43 +00003351 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003352 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003353 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003354 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003355 S->getRParenLoc(), move(Body));
3356}
3357
3358template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003359Sema::OwningStmtResult
3360TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003362 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003363 S->getLabel());
3364}
3365
3366template<typename Derived>
3367Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003368TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3370 if (Target.isInvalid())
3371 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003372
Douglas Gregorebe10102009-08-20 07:17:43 +00003373 if (!getDerived().AlwaysRebuild() &&
3374 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003375 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003376
3377 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3378 move(Target));
3379}
3380
3381template<typename Derived>
3382Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003383TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3384 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003385}
Mike Stump11289f42009-09-09 15:08:12 +00003386
Douglas Gregorebe10102009-08-20 07:17:43 +00003387template<typename Derived>
3388Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003389TreeTransform<Derived>::TransformBreakStmt(BreakStmt *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>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3397 if (Result.isInvalid())
3398 return SemaRef.StmtError();
3399
Mike Stump11289f42009-09-09 15:08:12 +00003400 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003401 // to tell whether the return type of the function has changed.
3402 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3403}
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregorebe10102009-08-20 07:17:43 +00003405template<typename Derived>
3406Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003407TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003408 bool DeclChanged = false;
3409 llvm::SmallVector<Decl *, 4> Decls;
3410 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3411 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003412 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3413 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003414 if (!Transformed)
3415 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003416
Douglas Gregorebe10102009-08-20 07:17:43 +00003417 if (Transformed != *D)
3418 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003419
Douglas Gregorebe10102009-08-20 07:17:43 +00003420 Decls.push_back(Transformed);
3421 }
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003424 return SemaRef.Owned(S->Retain());
3425
3426 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003427 S->getStartLoc(), S->getEndLoc());
3428}
Mike Stump11289f42009-09-09 15:08:12 +00003429
Douglas Gregorebe10102009-08-20 07:17:43 +00003430template<typename Derived>
3431Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003432TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003433 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003434 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003435}
3436
3437template<typename Derived>
3438Sema::OwningStmtResult
3439TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003440
3441 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3442 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003443 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003444
Anders Carlssonaaeef072010-01-24 05:50:09 +00003445 OwningExprResult AsmString(SemaRef);
3446 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3447
3448 bool ExprsChanged = false;
3449
3450 // Go through the outputs.
3451 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003452 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003453
Anders Carlssonaaeef072010-01-24 05:50:09 +00003454 // No need to transform the constraint literal.
3455 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3456
3457 // Transform the output expr.
3458 Expr *OutputExpr = S->getOutputExpr(I);
3459 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3460 if (Result.isInvalid())
3461 return SemaRef.StmtError();
3462
3463 ExprsChanged |= Result.get() != OutputExpr;
3464
3465 Exprs.push_back(Result.takeAs<Expr>());
3466 }
3467
3468 // Go through the inputs.
3469 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003470 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003471
Anders Carlssonaaeef072010-01-24 05:50:09 +00003472 // No need to transform the constraint literal.
3473 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3474
3475 // Transform the input expr.
3476 Expr *InputExpr = S->getInputExpr(I);
3477 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3478 if (Result.isInvalid())
3479 return SemaRef.StmtError();
3480
3481 ExprsChanged |= Result.get() != InputExpr;
3482
3483 Exprs.push_back(Result.takeAs<Expr>());
3484 }
3485
3486 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3487 return SemaRef.Owned(S->Retain());
3488
3489 // Go through the clobbers.
3490 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3491 Clobbers.push_back(S->getClobber(I)->Retain());
3492
3493 // No need to transform the asm string literal.
3494 AsmString = SemaRef.Owned(S->getAsmString());
3495
3496 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3497 S->isSimple(),
3498 S->isVolatile(),
3499 S->getNumOutputs(),
3500 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003501 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003502 move_arg(Constraints),
3503 move_arg(Exprs),
3504 move(AsmString),
3505 move_arg(Clobbers),
3506 S->getRParenLoc(),
3507 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003508}
3509
3510
3511template<typename Derived>
3512Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003513TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003514 // FIXME: Implement this
3515 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003516 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003517}
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregorebe10102009-08-20 07:17:43 +00003519template<typename Derived>
3520Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003521TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 // FIXME: Implement this
3523 assert(false && "Cannot transform an Objective-C @catch statement");
3524 return SemaRef.Owned(S->Retain());
3525}
Mike Stump11289f42009-09-09 15:08:12 +00003526
Douglas Gregorebe10102009-08-20 07:17:43 +00003527template<typename Derived>
3528Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003529TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003530 // FIXME: Implement this
3531 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003532 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003533}
Mike Stump11289f42009-09-09 15:08:12 +00003534
Douglas Gregorebe10102009-08-20 07:17:43 +00003535template<typename Derived>
3536Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003537TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 // FIXME: Implement this
3539 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003540 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003541}
Mike Stump11289f42009-09-09 15:08:12 +00003542
Douglas Gregorebe10102009-08-20 07:17:43 +00003543template<typename Derived>
3544Sema::OwningStmtResult
3545TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003546 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 // FIXME: Implement this
3548 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003549 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003550}
3551
3552template<typename Derived>
3553Sema::OwningStmtResult
3554TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003555 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003556 // FIXME: Implement this
3557 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003558 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003559}
3560
3561
3562template<typename Derived>
3563Sema::OwningStmtResult
3564TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3565 // Transform the exception declaration, if any.
3566 VarDecl *Var = 0;
3567 if (S->getExceptionDecl()) {
3568 VarDecl *ExceptionDecl = S->getExceptionDecl();
3569 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3570 ExceptionDecl->getDeclName());
3571
3572 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3573 if (T.isNull())
3574 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregorebe10102009-08-20 07:17:43 +00003576 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3577 T,
John McCallbcd03502009-12-07 02:54:59 +00003578 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 ExceptionDecl->getIdentifier(),
3580 ExceptionDecl->getLocation(),
3581 /*FIXME: Inaccurate*/
3582 SourceRange(ExceptionDecl->getLocation()));
3583 if (!Var || Var->isInvalidDecl()) {
3584 if (Var)
3585 Var->Destroy(SemaRef.Context);
3586 return SemaRef.StmtError();
3587 }
3588 }
Mike Stump11289f42009-09-09 15:08:12 +00003589
Douglas Gregorebe10102009-08-20 07:17:43 +00003590 // Transform the actual exception handler.
3591 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3592 if (Handler.isInvalid()) {
3593 if (Var)
3594 Var->Destroy(SemaRef.Context);
3595 return SemaRef.StmtError();
3596 }
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 if (!getDerived().AlwaysRebuild() &&
3599 !Var &&
3600 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003601 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003602
3603 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3604 Var,
3605 move(Handler));
3606}
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregorebe10102009-08-20 07:17:43 +00003608template<typename Derived>
3609Sema::OwningStmtResult
3610TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3611 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003612 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003613 = getDerived().TransformCompoundStmt(S->getTryBlock());
3614 if (TryBlock.isInvalid())
3615 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregorebe10102009-08-20 07:17:43 +00003617 // Transform the handlers.
3618 bool HandlerChanged = false;
3619 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3620 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003621 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003622 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3623 if (Handler.isInvalid())
3624 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003625
Douglas Gregorebe10102009-08-20 07:17:43 +00003626 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3627 Handlers.push_back(Handler.takeAs<Stmt>());
3628 }
Mike Stump11289f42009-09-09 15:08:12 +00003629
Douglas Gregorebe10102009-08-20 07:17:43 +00003630 if (!getDerived().AlwaysRebuild() &&
3631 TryBlock.get() == S->getTryBlock() &&
3632 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003633 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003634
3635 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003636 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003637}
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregorebe10102009-08-20 07:17:43 +00003639//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003640// Expression transformation
3641//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003642template<typename Derived>
3643Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003644TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003645 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003646}
Mike Stump11289f42009-09-09 15:08:12 +00003647
3648template<typename Derived>
3649Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003650TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003651 NestedNameSpecifier *Qualifier = 0;
3652 if (E->getQualifier()) {
3653 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003654 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003655 if (!Qualifier)
3656 return SemaRef.ExprError();
3657 }
John McCallce546572009-12-08 09:08:17 +00003658
3659 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003660 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3661 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003662 if (!ND)
3663 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003664
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003665 if (!getDerived().AlwaysRebuild() &&
3666 Qualifier == E->getQualifier() &&
3667 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003668 !E->hasExplicitTemplateArgumentList()) {
3669
3670 // Mark it referenced in the new context regardless.
3671 // FIXME: this is a bit instantiation-specific.
3672 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3673
Mike Stump11289f42009-09-09 15:08:12 +00003674 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003675 }
John McCallce546572009-12-08 09:08:17 +00003676
3677 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3678 if (E->hasExplicitTemplateArgumentList()) {
3679 TemplateArgs = &TransArgs;
3680 TransArgs.setLAngleLoc(E->getLAngleLoc());
3681 TransArgs.setRAngleLoc(E->getRAngleLoc());
3682 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3683 TemplateArgumentLoc Loc;
3684 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3685 return SemaRef.ExprError();
3686 TransArgs.addArgument(Loc);
3687 }
3688 }
3689
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003690 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003691 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003692}
Mike Stump11289f42009-09-09 15:08:12 +00003693
Douglas Gregora16548e2009-08-11 05:31:07 +00003694template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003695Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003696TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003697 return SemaRef.Owned(E->Retain());
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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003721 return SemaRef.Owned(E->Retain());
3722}
3723
3724template<typename Derived>
3725Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003726TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003727 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3728 if (SubExpr.isInvalid())
3729 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregora16548e2009-08-11 05:31:07 +00003731 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003732 return SemaRef.Owned(E->Retain());
3733
3734 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003735 E->getRParen());
3736}
3737
Mike Stump11289f42009-09-09 15:08:12 +00003738template<typename Derived>
3739Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003740TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3741 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003742 if (SubExpr.isInvalid())
3743 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003744
Douglas Gregora16548e2009-08-11 05:31:07 +00003745 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003746 return SemaRef.Owned(E->Retain());
3747
Douglas Gregora16548e2009-08-11 05:31:07 +00003748 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3749 E->getOpcode(),
3750 move(SubExpr));
3751}
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregora16548e2009-08-11 05:31:07 +00003753template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003754Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003755TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003756 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003757 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003758
John McCallbcd03502009-12-07 02:54:59 +00003759 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003760 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003761 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003762
John McCall4c98fd82009-11-04 07:28:41 +00003763 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003764 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003765
John McCall4c98fd82009-11-04 07:28:41 +00003766 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003767 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003768 E->getSourceRange());
3769 }
Mike Stump11289f42009-09-09 15:08:12 +00003770
Douglas Gregora16548e2009-08-11 05:31:07 +00003771 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003772 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003773 // C++0x [expr.sizeof]p1:
3774 // The operand is either an expression, which is an unevaluated operand
3775 // [...]
3776 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003777
Douglas Gregora16548e2009-08-11 05:31:07 +00003778 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3779 if (SubExpr.isInvalid())
3780 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003781
Douglas Gregora16548e2009-08-11 05:31:07 +00003782 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3783 return SemaRef.Owned(E->Retain());
3784 }
Mike Stump11289f42009-09-09 15:08:12 +00003785
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3787 E->isSizeOf(),
3788 E->getSourceRange());
3789}
Mike Stump11289f42009-09-09 15:08:12 +00003790
Douglas Gregora16548e2009-08-11 05:31:07 +00003791template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003792Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003793TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003794 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3795 if (LHS.isInvalid())
3796 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003797
Douglas Gregora16548e2009-08-11 05:31:07 +00003798 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3799 if (RHS.isInvalid())
3800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003801
3802
Douglas Gregora16548e2009-08-11 05:31:07 +00003803 if (!getDerived().AlwaysRebuild() &&
3804 LHS.get() == E->getLHS() &&
3805 RHS.get() == E->getRHS())
3806 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregora16548e2009-08-11 05:31:07 +00003808 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3809 /*FIXME:*/E->getLHS()->getLocStart(),
3810 move(RHS),
3811 E->getRBracketLoc());
3812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
3814template<typename Derived>
3815Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003816TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003817 // Transform the callee.
3818 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3819 if (Callee.isInvalid())
3820 return SemaRef.ExprError();
3821
3822 // Transform arguments.
3823 bool ArgChanged = false;
3824 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3825 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3826 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3827 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3828 if (Arg.isInvalid())
3829 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003830
Douglas Gregora16548e2009-08-11 05:31:07 +00003831 // FIXME: Wrong source location information for the ','.
3832 FakeCommaLocs.push_back(
3833 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003834
3835 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003836 Args.push_back(Arg.takeAs<Expr>());
3837 }
Mike Stump11289f42009-09-09 15:08:12 +00003838
Douglas Gregora16548e2009-08-11 05:31:07 +00003839 if (!getDerived().AlwaysRebuild() &&
3840 Callee.get() == E->getCallee() &&
3841 !ArgChanged)
3842 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003845 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003846 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3847 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3848 move_arg(Args),
3849 FakeCommaLocs.data(),
3850 E->getRParenLoc());
3851}
Mike Stump11289f42009-09-09 15:08:12 +00003852
3853template<typename Derived>
3854Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003855TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3857 if (Base.isInvalid())
3858 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003860 NestedNameSpecifier *Qualifier = 0;
3861 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003862 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003863 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003864 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003865 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003866 return SemaRef.ExprError();
3867 }
Mike Stump11289f42009-09-09 15:08:12 +00003868
Eli Friedman2cfcef62009-12-04 06:40:45 +00003869 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003870 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3871 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003872 if (!Member)
3873 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003874
John McCall16df1e52010-03-30 21:47:33 +00003875 NamedDecl *FoundDecl = E->getFoundDecl();
3876 if (FoundDecl == E->getMemberDecl()) {
3877 FoundDecl = Member;
3878 } else {
3879 FoundDecl = cast_or_null<NamedDecl>(
3880 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
3881 if (!FoundDecl)
3882 return SemaRef.ExprError();
3883 }
3884
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 if (!getDerived().AlwaysRebuild() &&
3886 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003887 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003888 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00003889 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003890 !E->hasExplicitTemplateArgumentList()) {
3891
3892 // Mark it referenced in the new context regardless.
3893 // FIXME: this is a bit instantiation-specific.
3894 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003895 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003896 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003897
John McCall6b51f282009-11-23 01:53:49 +00003898 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003899 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003900 TransArgs.setLAngleLoc(E->getLAngleLoc());
3901 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003902 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003903 TemplateArgumentLoc Loc;
3904 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003905 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003906 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003907 }
3908 }
3909
Douglas Gregora16548e2009-08-11 05:31:07 +00003910 // FIXME: Bogus source location for the operator
3911 SourceLocation FakeOperatorLoc
3912 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3913
John McCall38836f02010-01-15 08:34:02 +00003914 // FIXME: to do this check properly, we will need to preserve the
3915 // first-qualifier-in-scope here, just in case we had a dependent
3916 // base (and therefore couldn't do the check) and a
3917 // nested-name-qualifier (and therefore could do the lookup).
3918 NamedDecl *FirstQualifierInScope = 0;
3919
Douglas Gregora16548e2009-08-11 05:31:07 +00003920 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3921 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003922 Qualifier,
3923 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003924 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003925 Member,
John McCall16df1e52010-03-30 21:47:33 +00003926 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00003927 (E->hasExplicitTemplateArgumentList()
3928 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003929 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003930}
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregora16548e2009-08-11 05:31:07 +00003932template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003933Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003934TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003935 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3936 if (LHS.isInvalid())
3937 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregora16548e2009-08-11 05:31:07 +00003939 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3940 if (RHS.isInvalid())
3941 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003942
Douglas Gregora16548e2009-08-11 05:31:07 +00003943 if (!getDerived().AlwaysRebuild() &&
3944 LHS.get() == E->getLHS() &&
3945 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003946 return SemaRef.Owned(E->Retain());
3947
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3949 move(LHS), move(RHS));
3950}
3951
Mike Stump11289f42009-09-09 15:08:12 +00003952template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003953Sema::OwningExprResult
3954TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003955 CompoundAssignOperator *E) {
3956 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003957}
Mike Stump11289f42009-09-09 15:08:12 +00003958
Douglas Gregora16548e2009-08-11 05:31:07 +00003959template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003960Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003961TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003962 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3963 if (Cond.isInvalid())
3964 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregora16548e2009-08-11 05:31:07 +00003966 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3967 if (LHS.isInvalid())
3968 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003969
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3971 if (RHS.isInvalid())
3972 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003973
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 if (!getDerived().AlwaysRebuild() &&
3975 Cond.get() == E->getCond() &&
3976 LHS.get() == E->getLHS() &&
3977 RHS.get() == E->getRHS())
3978 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003979
3980 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003981 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003982 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003983 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 move(RHS));
3985}
Mike Stump11289f42009-09-09 15:08:12 +00003986
3987template<typename Derived>
3988Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003989TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003990 // Implicit casts are eliminated during transformation, since they
3991 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003992 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003993}
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregora16548e2009-08-11 05:31:07 +00003995template<typename Derived>
3996Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003997TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003998 TypeSourceInfo *OldT;
3999 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 {
4001 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004002 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4004 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004005
John McCall97513962010-01-15 18:39:57 +00004006 OldT = E->getTypeInfoAsWritten();
4007 NewT = getDerived().TransformType(OldT);
4008 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004009 return SemaRef.ExprError();
4010 }
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregor6131b442009-12-12 18:16:41 +00004012 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004013 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004014 if (SubExpr.isInvalid())
4015 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004018 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004019 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004020 return SemaRef.Owned(E->Retain());
4021
John McCall97513962010-01-15 18:39:57 +00004022 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4023 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004024 E->getRParenLoc(),
4025 move(SubExpr));
4026}
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregora16548e2009-08-11 05:31:07 +00004028template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004029Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004030TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004031 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4032 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4033 if (!NewT)
4034 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004035
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4037 if (Init.isInvalid())
4038 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004041 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004042 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004043 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004044
John McCall5d7aa7f2010-01-19 22:33:45 +00004045 // Note: the expression type doesn't necessarily match the
4046 // type-as-written, but that's okay, because it should always be
4047 // derivable from the initializer.
4048
John McCalle15bbff2010-01-18 19:35:47 +00004049 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004050 /*FIXME:*/E->getInitializer()->getLocEnd(),
4051 move(Init));
4052}
Mike Stump11289f42009-09-09 15:08:12 +00004053
Douglas Gregora16548e2009-08-11 05:31:07 +00004054template<typename Derived>
4055Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004056TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4058 if (Base.isInvalid())
4059 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004060
Douglas Gregora16548e2009-08-11 05:31:07 +00004061 if (!getDerived().AlwaysRebuild() &&
4062 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004063 return SemaRef.Owned(E->Retain());
4064
Douglas Gregora16548e2009-08-11 05:31:07 +00004065 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004066 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004067 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4068 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4069 E->getAccessorLoc(),
4070 E->getAccessor());
4071}
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregora16548e2009-08-11 05:31:07 +00004073template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004074Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004075TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004076 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregora16548e2009-08-11 05:31:07 +00004078 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4079 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4080 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4081 if (Init.isInvalid())
4082 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004083
Douglas Gregora16548e2009-08-11 05:31:07 +00004084 InitChanged = InitChanged || Init.get() != E->getInit(I);
4085 Inits.push_back(Init.takeAs<Expr>());
4086 }
Mike Stump11289f42009-09-09 15:08:12 +00004087
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004089 return SemaRef.Owned(E->Retain());
4090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004092 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004093}
Mike Stump11289f42009-09-09 15:08:12 +00004094
Douglas Gregora16548e2009-08-11 05:31:07 +00004095template<typename Derived>
4096Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004097TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004099
Douglas Gregorebe10102009-08-20 07:17:43 +00004100 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004101 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4102 if (Init.isInvalid())
4103 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004104
Douglas Gregorebe10102009-08-20 07:17:43 +00004105 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004106 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4107 bool ExprChanged = false;
4108 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4109 DEnd = E->designators_end();
4110 D != DEnd; ++D) {
4111 if (D->isFieldDesignator()) {
4112 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4113 D->getDotLoc(),
4114 D->getFieldLoc()));
4115 continue;
4116 }
Mike Stump11289f42009-09-09 15:08:12 +00004117
Douglas Gregora16548e2009-08-11 05:31:07 +00004118 if (D->isArrayDesignator()) {
4119 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4120 if (Index.isInvalid())
4121 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004122
4123 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregora16548e2009-08-11 05:31:07 +00004126 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4127 ArrayExprs.push_back(Index.release());
4128 continue;
4129 }
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregora16548e2009-08-11 05:31:07 +00004131 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004132 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4134 if (Start.isInvalid())
4135 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregora16548e2009-08-11 05:31:07 +00004137 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4138 if (End.isInvalid())
4139 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004140
4141 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004142 End.get(),
4143 D->getLBracketLoc(),
4144 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregora16548e2009-08-11 05:31:07 +00004146 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4147 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregora16548e2009-08-11 05:31:07 +00004149 ArrayExprs.push_back(Start.release());
4150 ArrayExprs.push_back(End.release());
4151 }
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregora16548e2009-08-11 05:31:07 +00004153 if (!getDerived().AlwaysRebuild() &&
4154 Init.get() == E->getInit() &&
4155 !ExprChanged)
4156 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4159 E->getEqualOrColonLoc(),
4160 E->usesGNUSyntax(), move(Init));
4161}
Mike Stump11289f42009-09-09 15:08:12 +00004162
Douglas Gregora16548e2009-08-11 05:31:07 +00004163template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004164Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004165TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004166 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004167 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4168
4169 // FIXME: Will we ever have proper type location here? Will we actually
4170 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 QualType T = getDerived().TransformType(E->getType());
4172 if (T.isNull())
4173 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004174
Douglas Gregora16548e2009-08-11 05:31:07 +00004175 if (!getDerived().AlwaysRebuild() &&
4176 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
4178
Douglas Gregora16548e2009-08-11 05:31:07 +00004179 return getDerived().RebuildImplicitValueInitExpr(T);
4180}
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregora16548e2009-08-11 05:31:07 +00004182template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004183Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004184TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004185 // FIXME: Do we want the type as written?
4186 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004187
Douglas Gregora16548e2009-08-11 05:31:07 +00004188 {
4189 // FIXME: Source location isn't quite accurate.
4190 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4191 T = getDerived().TransformType(E->getType());
4192 if (T.isNull())
4193 return SemaRef.ExprError();
4194 }
Mike Stump11289f42009-09-09 15:08:12 +00004195
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4197 if (SubExpr.isInvalid())
4198 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregora16548e2009-08-11 05:31:07 +00004200 if (!getDerived().AlwaysRebuild() &&
4201 T == E->getType() &&
4202 SubExpr.get() == E->getSubExpr())
4203 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004204
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4206 T, E->getRParenLoc());
4207}
4208
4209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004210Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004211TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 bool ArgumentChanged = false;
4213 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4214 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4215 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4216 if (Init.isInvalid())
4217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4220 Inits.push_back(Init.takeAs<Expr>());
4221 }
Mike Stump11289f42009-09-09 15:08:12 +00004222
Douglas Gregora16548e2009-08-11 05:31:07 +00004223 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4224 move_arg(Inits),
4225 E->getRParenLoc());
4226}
Mike Stump11289f42009-09-09 15:08:12 +00004227
Douglas Gregora16548e2009-08-11 05:31:07 +00004228/// \brief Transform an address-of-label expression.
4229///
4230/// By default, the transformation of an address-of-label expression always
4231/// rebuilds the expression, so that the label identifier can be resolved to
4232/// the corresponding label statement by semantic analysis.
4233template<typename Derived>
4234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004235TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004236 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4237 E->getLabel());
4238}
Mike Stump11289f42009-09-09 15:08:12 +00004239
4240template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004241Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004242TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004243 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004244 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4245 if (SubStmt.isInvalid())
4246 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248 if (!getDerived().AlwaysRebuild() &&
4249 SubStmt.get() == E->getSubStmt())
4250 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004251
4252 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 move(SubStmt),
4254 E->getRParenLoc());
4255}
Mike Stump11289f42009-09-09 15:08:12 +00004256
Douglas Gregora16548e2009-08-11 05:31:07 +00004257template<typename Derived>
4258Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004259TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 QualType T1, T2;
4261 {
4262 // FIXME: Source location isn't quite accurate.
4263 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004264
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 T1 = getDerived().TransformType(E->getArgType1());
4266 if (T1.isNull())
4267 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregora16548e2009-08-11 05:31:07 +00004269 T2 = getDerived().TransformType(E->getArgType2());
4270 if (T2.isNull())
4271 return SemaRef.ExprError();
4272 }
4273
4274 if (!getDerived().AlwaysRebuild() &&
4275 T1 == E->getArgType1() &&
4276 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004277 return SemaRef.Owned(E->Retain());
4278
Douglas Gregora16548e2009-08-11 05:31:07 +00004279 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4280 T1, T2, E->getRParenLoc());
4281}
Mike Stump11289f42009-09-09 15:08:12 +00004282
Douglas Gregora16548e2009-08-11 05:31:07 +00004283template<typename Derived>
4284Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004285TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4287 if (Cond.isInvalid())
4288 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004289
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4291 if (LHS.isInvalid())
4292 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregora16548e2009-08-11 05:31:07 +00004294 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4295 if (RHS.isInvalid())
4296 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004297
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 if (!getDerived().AlwaysRebuild() &&
4299 Cond.get() == E->getCond() &&
4300 LHS.get() == E->getLHS() &&
4301 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004302 return SemaRef.Owned(E->Retain());
4303
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4305 move(Cond), move(LHS), move(RHS),
4306 E->getRParenLoc());
4307}
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004310Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004311TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004312 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004313}
4314
4315template<typename Derived>
4316Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004317TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004318 switch (E->getOperator()) {
4319 case OO_New:
4320 case OO_Delete:
4321 case OO_Array_New:
4322 case OO_Array_Delete:
4323 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4324 return SemaRef.ExprError();
4325
4326 case OO_Call: {
4327 // This is a call to an object's operator().
4328 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4329
4330 // Transform the object itself.
4331 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4332 if (Object.isInvalid())
4333 return SemaRef.ExprError();
4334
4335 // FIXME: Poor location information
4336 SourceLocation FakeLParenLoc
4337 = SemaRef.PP.getLocForEndOfToken(
4338 static_cast<Expr *>(Object.get())->getLocEnd());
4339
4340 // Transform the call arguments.
4341 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4342 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4343 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004344 if (getDerived().DropCallArgument(E->getArg(I)))
4345 break;
4346
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004347 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4348 if (Arg.isInvalid())
4349 return SemaRef.ExprError();
4350
4351 // FIXME: Poor source location information.
4352 SourceLocation FakeCommaLoc
4353 = SemaRef.PP.getLocForEndOfToken(
4354 static_cast<Expr *>(Arg.get())->getLocEnd());
4355 FakeCommaLocs.push_back(FakeCommaLoc);
4356 Args.push_back(Arg.release());
4357 }
4358
4359 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4360 move_arg(Args),
4361 FakeCommaLocs.data(),
4362 E->getLocEnd());
4363 }
4364
4365#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4366 case OO_##Name:
4367#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4368#include "clang/Basic/OperatorKinds.def"
4369 case OO_Subscript:
4370 // Handled below.
4371 break;
4372
4373 case OO_Conditional:
4374 llvm_unreachable("conditional operator is not actually overloadable");
4375 return SemaRef.ExprError();
4376
4377 case OO_None:
4378 case NUM_OVERLOADED_OPERATORS:
4379 llvm_unreachable("not an overloaded operator?");
4380 return SemaRef.ExprError();
4381 }
4382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4384 if (Callee.isInvalid())
4385 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004386
John McCall47f29ea2009-12-08 09:21:05 +00004387 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 if (First.isInvalid())
4389 return SemaRef.ExprError();
4390
4391 OwningExprResult Second(SemaRef);
4392 if (E->getNumArgs() == 2) {
4393 Second = getDerived().TransformExpr(E->getArg(1));
4394 if (Second.isInvalid())
4395 return SemaRef.ExprError();
4396 }
Mike Stump11289f42009-09-09 15:08:12 +00004397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 if (!getDerived().AlwaysRebuild() &&
4399 Callee.get() == E->getCallee() &&
4400 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004401 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4402 return SemaRef.Owned(E->Retain());
4403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4405 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004406 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004407 move(First),
4408 move(Second));
4409}
Mike Stump11289f42009-09-09 15:08:12 +00004410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411template<typename Derived>
4412Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004413TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4414 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004420 TypeSourceInfo *OldT;
4421 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004422 {
4423 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004424 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4426 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004427
John McCall97513962010-01-15 18:39:57 +00004428 OldT = E->getTypeInfoAsWritten();
4429 NewT = getDerived().TransformType(OldT);
4430 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 return SemaRef.ExprError();
4432 }
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregor6131b442009-12-12 18:16:41 +00004434 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004435 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 if (SubExpr.isInvalid())
4437 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004440 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004442 return SemaRef.Owned(E->Retain());
4443
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004445 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4447 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4448 SourceLocation FakeRParenLoc
4449 = SemaRef.PP.getLocForEndOfToken(
4450 E->getSubExpr()->getSourceRange().getEnd());
4451 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004452 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004454 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 FakeRAngleLoc,
4456 FakeRAngleLoc,
4457 move(SubExpr),
4458 FakeRParenLoc);
4459}
Mike Stump11289f42009-09-09 15:08:12 +00004460
Douglas Gregora16548e2009-08-11 05:31:07 +00004461template<typename Derived>
4462Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004463TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4464 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004465}
Mike Stump11289f42009-09-09 15:08:12 +00004466
4467template<typename Derived>
4468Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004469TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4470 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004471}
4472
Douglas Gregora16548e2009-08-11 05:31:07 +00004473template<typename Derived>
4474Sema::OwningExprResult
4475TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004476 CXXReinterpretCastExpr *E) {
4477 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004478}
Mike Stump11289f42009-09-09 15:08:12 +00004479
Douglas Gregora16548e2009-08-11 05:31:07 +00004480template<typename Derived>
4481Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004482TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *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
4488TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004489 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004490 TypeSourceInfo *OldT;
4491 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 {
4493 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004494
John McCall97513962010-01-15 18:39:57 +00004495 OldT = E->getTypeInfoAsWritten();
4496 NewT = getDerived().TransformType(OldT);
4497 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 return SemaRef.ExprError();
4499 }
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregor6131b442009-12-12 18:16:41 +00004501 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004502 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 if (SubExpr.isInvalid())
4504 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004507 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004509 return SemaRef.Owned(E->Retain());
4510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 // FIXME: The end of the type's source range is wrong
4512 return getDerived().RebuildCXXFunctionalCastExpr(
4513 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004514 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 /*FIXME:*/E->getSubExpr()->getLocStart(),
4516 move(SubExpr),
4517 E->getRParenLoc());
4518}
Mike Stump11289f42009-09-09 15:08:12 +00004519
Douglas Gregora16548e2009-08-11 05:31:07 +00004520template<typename Derived>
4521Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004522TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004523 if (E->isTypeOperand()) {
4524 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 QualType T = getDerived().TransformType(E->getTypeOperand());
4527 if (T.isNull())
4528 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 if (!getDerived().AlwaysRebuild() &&
4531 T == E->getTypeOperand())
4532 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4535 /*FIXME:*/E->getLocStart(),
4536 T,
4537 E->getLocEnd());
4538 }
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 // We don't know whether the expression is potentially evaluated until
4541 // after we perform semantic analysis, so the expression is potentially
4542 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004543 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4547 if (SubExpr.isInvalid())
4548 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004549
Douglas Gregora16548e2009-08-11 05:31:07 +00004550 if (!getDerived().AlwaysRebuild() &&
4551 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004552 return SemaRef.Owned(E->Retain());
4553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4555 /*FIXME:*/E->getLocStart(),
4556 move(SubExpr),
4557 E->getLocEnd());
4558}
4559
4560template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004561Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004562TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004563 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004564}
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566template<typename Derived>
4567Sema::OwningExprResult
4568TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004569 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004570 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004571}
Mike Stump11289f42009-09-09 15:08:12 +00004572
Douglas Gregora16548e2009-08-11 05:31:07 +00004573template<typename Derived>
4574Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004575TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 QualType T = getDerived().TransformType(E->getType());
4579 if (T.isNull())
4580 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 if (!getDerived().AlwaysRebuild() &&
4583 T == E->getType())
4584 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004585
Douglas Gregorb15af892010-01-07 23:12:05 +00004586 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004587}
Mike Stump11289f42009-09-09 15:08:12 +00004588
Douglas Gregora16548e2009-08-11 05:31:07 +00004589template<typename Derived>
4590Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004591TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4593 if (SubExpr.isInvalid())
4594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 if (!getDerived().AlwaysRebuild() &&
4597 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004598 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004599
4600 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4601}
Mike Stump11289f42009-09-09 15:08:12 +00004602
Douglas Gregora16548e2009-08-11 05:31:07 +00004603template<typename Derived>
4604Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004605TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004606 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004607 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4608 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 if (!Param)
4610 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004611
Chandler Carruth794da4c2010-02-08 06:42:49 +00004612 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004613 Param == E->getParam())
4614 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregor033f6752009-12-23 23:03:06 +00004616 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregora16548e2009-08-11 05:31:07 +00004619template<typename Derived>
4620Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4623
4624 QualType T = getDerived().TransformType(E->getType());
4625 if (T.isNull())
4626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004627
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 if (!getDerived().AlwaysRebuild() &&
4629 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004630 return SemaRef.Owned(E->Retain());
4631
4632 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 /*FIXME:*/E->getTypeBeginLoc(),
4634 T,
4635 E->getRParenLoc());
4636}
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregora16548e2009-08-11 05:31:07 +00004638template<typename Derived>
4639Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004640TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 // Transform the type that we're allocating
4642 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4643 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4644 if (AllocType.isNull())
4645 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 // Transform the size of the array we're allocating (if any).
4648 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4649 if (ArraySize.isInvalid())
4650 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 // Transform the placement arguments (if any).
4653 bool ArgumentChanged = false;
4654 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4655 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4656 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4657 if (Arg.isInvalid())
4658 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4661 PlacementArgs.push_back(Arg.take());
4662 }
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregorebe10102009-08-20 07:17:43 +00004664 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4666 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4667 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4668 if (Arg.isInvalid())
4669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4672 ConstructorArgs.push_back(Arg.take());
4673 }
Mike Stump11289f42009-09-09 15:08:12 +00004674
Douglas Gregord2d9da02010-02-26 00:38:10 +00004675 // Transform constructor, new operator, and delete operator.
4676 CXXConstructorDecl *Constructor = 0;
4677 if (E->getConstructor()) {
4678 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004679 getDerived().TransformDecl(E->getLocStart(),
4680 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004681 if (!Constructor)
4682 return SemaRef.ExprError();
4683 }
4684
4685 FunctionDecl *OperatorNew = 0;
4686 if (E->getOperatorNew()) {
4687 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004688 getDerived().TransformDecl(E->getLocStart(),
4689 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004690 if (!OperatorNew)
4691 return SemaRef.ExprError();
4692 }
4693
4694 FunctionDecl *OperatorDelete = 0;
4695 if (E->getOperatorDelete()) {
4696 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004697 getDerived().TransformDecl(E->getLocStart(),
4698 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004699 if (!OperatorDelete)
4700 return SemaRef.ExprError();
4701 }
4702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703 if (!getDerived().AlwaysRebuild() &&
4704 AllocType == E->getAllocatedType() &&
4705 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004706 Constructor == E->getConstructor() &&
4707 OperatorNew == E->getOperatorNew() &&
4708 OperatorDelete == E->getOperatorDelete() &&
4709 !ArgumentChanged) {
4710 // Mark any declarations we need as referenced.
4711 // FIXME: instantiation-specific.
4712 if (Constructor)
4713 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4714 if (OperatorNew)
4715 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4716 if (OperatorDelete)
4717 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004718 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004719 }
Mike Stump11289f42009-09-09 15:08:12 +00004720
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004721 if (!ArraySize.get()) {
4722 // If no array size was specified, but the new expression was
4723 // instantiated with an array type (e.g., "new T" where T is
4724 // instantiated with "int[4]"), extract the outer bound from the
4725 // array type as our array size. We do this with constant and
4726 // dependently-sized array types.
4727 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4728 if (!ArrayT) {
4729 // Do nothing
4730 } else if (const ConstantArrayType *ConsArrayT
4731 = dyn_cast<ConstantArrayType>(ArrayT)) {
4732 ArraySize
4733 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4734 ConsArrayT->getSize(),
4735 SemaRef.Context.getSizeType(),
4736 /*FIXME:*/E->getLocStart()));
4737 AllocType = ConsArrayT->getElementType();
4738 } else if (const DependentSizedArrayType *DepArrayT
4739 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4740 if (DepArrayT->getSizeExpr()) {
4741 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4742 AllocType = DepArrayT->getElementType();
4743 }
4744 }
4745 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4747 E->isGlobalNew(),
4748 /*FIXME:*/E->getLocStart(),
4749 move_arg(PlacementArgs),
4750 /*FIXME:*/E->getLocStart(),
4751 E->isParenTypeId(),
4752 AllocType,
4753 /*FIXME:*/E->getLocStart(),
4754 /*FIXME:*/SourceRange(),
4755 move(ArraySize),
4756 /*FIXME:*/E->getLocStart(),
4757 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004758 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004759}
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761template<typename Derived>
4762Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004763TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4765 if (Operand.isInvalid())
4766 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregord2d9da02010-02-26 00:38:10 +00004768 // Transform the delete operator, if known.
4769 FunctionDecl *OperatorDelete = 0;
4770 if (E->getOperatorDelete()) {
4771 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004772 getDerived().TransformDecl(E->getLocStart(),
4773 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004774 if (!OperatorDelete)
4775 return SemaRef.ExprError();
4776 }
4777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004779 Operand.get() == E->getArgument() &&
4780 OperatorDelete == E->getOperatorDelete()) {
4781 // Mark any declarations we need as referenced.
4782 // FIXME: instantiation-specific.
4783 if (OperatorDelete)
4784 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004785 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004786 }
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4789 E->isGlobalDelete(),
4790 E->isArrayForm(),
4791 move(Operand));
4792}
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794template<typename Derived>
4795Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004796TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004797 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004798 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4799 if (Base.isInvalid())
4800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregor678f90d2010-02-25 01:56:36 +00004802 Sema::TypeTy *ObjectTypePtr = 0;
4803 bool MayBePseudoDestructor = false;
4804 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4805 E->getOperatorLoc(),
4806 E->isArrow()? tok::arrow : tok::period,
4807 ObjectTypePtr,
4808 MayBePseudoDestructor);
4809 if (Base.isInvalid())
4810 return SemaRef.ExprError();
4811
4812 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004813 NestedNameSpecifier *Qualifier
4814 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004815 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004816 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004817 if (E->getQualifier() && !Qualifier)
4818 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregor678f90d2010-02-25 01:56:36 +00004820 PseudoDestructorTypeStorage Destroyed;
4821 if (E->getDestroyedTypeInfo()) {
4822 TypeSourceInfo *DestroyedTypeInfo
4823 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4824 if (!DestroyedTypeInfo)
4825 return SemaRef.ExprError();
4826 Destroyed = DestroyedTypeInfo;
4827 } else if (ObjectType->isDependentType()) {
4828 // We aren't likely to be able to resolve the identifier down to a type
4829 // now anyway, so just retain the identifier.
4830 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4831 E->getDestroyedTypeLoc());
4832 } else {
4833 // Look for a destructor known with the given name.
4834 CXXScopeSpec SS;
4835 if (Qualifier) {
4836 SS.setScopeRep(Qualifier);
4837 SS.setRange(E->getQualifierRange());
4838 }
4839
4840 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4841 *E->getDestroyedTypeIdentifier(),
4842 E->getDestroyedTypeLoc(),
4843 /*Scope=*/0,
4844 SS, ObjectTypePtr,
4845 false);
4846 if (!T)
4847 return SemaRef.ExprError();
4848
4849 Destroyed
4850 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4851 E->getDestroyedTypeLoc());
4852 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004853
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004854 TypeSourceInfo *ScopeTypeInfo = 0;
4855 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004856 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4857 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004858 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004859 return SemaRef.ExprError();
4860 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004861
Douglas Gregorad8a3362009-09-04 17:36:40 +00004862 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4863 E->getOperatorLoc(),
4864 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004865 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004866 E->getQualifierRange(),
4867 ScopeTypeInfo,
4868 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00004869 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004870 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004871}
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregorad8a3362009-09-04 17:36:40 +00004873template<typename Derived>
4874Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004875TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004876 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004877 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4878
4879 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4880 Sema::LookupOrdinaryName);
4881
4882 // Transform all the decls.
4883 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4884 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004885 NamedDecl *InstD = static_cast<NamedDecl*>(
4886 getDerived().TransformDecl(Old->getNameLoc(),
4887 *I));
John McCall84d87672009-12-10 09:41:52 +00004888 if (!InstD) {
4889 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4890 // This can happen because of dependent hiding.
4891 if (isa<UsingShadowDecl>(*I))
4892 continue;
4893 else
4894 return SemaRef.ExprError();
4895 }
John McCalle66edc12009-11-24 19:00:30 +00004896
4897 // Expand using declarations.
4898 if (isa<UsingDecl>(InstD)) {
4899 UsingDecl *UD = cast<UsingDecl>(InstD);
4900 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4901 E = UD->shadow_end(); I != E; ++I)
4902 R.addDecl(*I);
4903 continue;
4904 }
4905
4906 R.addDecl(InstD);
4907 }
4908
4909 // Resolve a kind, but don't do any further analysis. If it's
4910 // ambiguous, the callee needs to deal with it.
4911 R.resolveKind();
4912
4913 // Rebuild the nested-name qualifier, if present.
4914 CXXScopeSpec SS;
4915 NestedNameSpecifier *Qualifier = 0;
4916 if (Old->getQualifier()) {
4917 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004918 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00004919 if (!Qualifier)
4920 return SemaRef.ExprError();
4921
4922 SS.setScopeRep(Qualifier);
4923 SS.setRange(Old->getQualifierRange());
4924 }
4925
4926 // If we have no template arguments, it's a normal declaration name.
4927 if (!Old->hasExplicitTemplateArgs())
4928 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4929
4930 // If we have template arguments, rebuild them, then rebuild the
4931 // templateid expression.
4932 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4933 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4934 TemplateArgumentLoc Loc;
4935 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4936 return SemaRef.ExprError();
4937 TransArgs.addArgument(Loc);
4938 }
4939
4940 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4941 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004942}
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregora16548e2009-08-11 05:31:07 +00004944template<typename Derived>
4945Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004946TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004948
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 QualType T = getDerived().TransformType(E->getQueriedType());
4950 if (T.isNull())
4951 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004952
Douglas Gregora16548e2009-08-11 05:31:07 +00004953 if (!getDerived().AlwaysRebuild() &&
4954 T == E->getQueriedType())
4955 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004956
Douglas Gregora16548e2009-08-11 05:31:07 +00004957 // FIXME: Bad location information
4958 SourceLocation FakeLParenLoc
4959 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004960
4961 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004962 E->getLocStart(),
4963 /*FIXME:*/FakeLParenLoc,
4964 T,
4965 E->getLocEnd());
4966}
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregora16548e2009-08-11 05:31:07 +00004968template<typename Derived>
4969Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004970TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004971 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004973 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004974 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 if (!NNS)
4976 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004977
4978 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004979 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4980 if (!Name)
4981 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004982
John McCalle66edc12009-11-24 19:00:30 +00004983 if (!E->hasExplicitTemplateArgs()) {
4984 if (!getDerived().AlwaysRebuild() &&
4985 NNS == E->getQualifier() &&
4986 Name == E->getDeclName())
4987 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004988
John McCalle66edc12009-11-24 19:00:30 +00004989 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4990 E->getQualifierRange(),
4991 Name, E->getLocation(),
4992 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004993 }
John McCall6b51f282009-11-23 01:53:49 +00004994
4995 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004996 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004997 TemplateArgumentLoc Loc;
4998 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005000 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 }
5002
John McCalle66edc12009-11-24 19:00:30 +00005003 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5004 E->getQualifierRange(),
5005 Name, E->getLocation(),
5006 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005007}
5008
5009template<typename Derived>
5010Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005011TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005012 // CXXConstructExprs are always implicit, so when we have a
5013 // 1-argument construction we just transform that argument.
5014 if (E->getNumArgs() == 1 ||
5015 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5016 return getDerived().TransformExpr(E->getArg(0));
5017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5019
5020 QualType T = getDerived().TransformType(E->getType());
5021 if (T.isNull())
5022 return SemaRef.ExprError();
5023
5024 CXXConstructorDecl *Constructor
5025 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005026 getDerived().TransformDecl(E->getLocStart(),
5027 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 if (!Constructor)
5029 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 bool ArgumentChanged = false;
5032 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005033 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 ArgEnd = E->arg_end();
5035 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005036 if (getDerived().DropCallArgument(*Arg)) {
5037 ArgumentChanged = true;
5038 break;
5039 }
5040
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5042 if (TransArg.isInvalid())
5043 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005044
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5046 Args.push_back(TransArg.takeAs<Expr>());
5047 }
5048
5049 if (!getDerived().AlwaysRebuild() &&
5050 T == E->getType() &&
5051 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005052 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005053 // Mark the constructor as referenced.
5054 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005055 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005057 }
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregordb121ba2009-12-14 16:27:04 +00005059 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5060 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 move_arg(Args));
5062}
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregora16548e2009-08-11 05:31:07 +00005064/// \brief Transform a C++ temporary-binding expression.
5065///
Douglas Gregor363b1512009-12-24 18:51:59 +00005066/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5067/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005068template<typename Derived>
5069Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005071 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005072}
Mike Stump11289f42009-09-09 15:08:12 +00005073
Anders Carlssonba6c4372010-01-29 02:39:32 +00005074/// \brief Transform a C++ reference-binding expression.
5075///
5076/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5077/// transform the subexpression and return that.
5078template<typename Derived>
5079Sema::OwningExprResult
5080TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5081 return getDerived().TransformExpr(E->getSubExpr());
5082}
5083
Mike Stump11289f42009-09-09 15:08:12 +00005084/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005085/// be destroyed after the expression is evaluated.
5086///
Douglas Gregor363b1512009-12-24 18:51:59 +00005087/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5088/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005089template<typename Derived>
5090Sema::OwningExprResult
5091TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005092 CXXExprWithTemporaries *E) {
5093 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096template<typename Derived>
5097Sema::OwningExprResult
5098TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005099 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5101 QualType T = getDerived().TransformType(E->getType());
5102 if (T.isNull())
5103 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 CXXConstructorDecl *Constructor
5106 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005107 getDerived().TransformDecl(E->getLocStart(),
5108 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 if (!Constructor)
5110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 bool ArgumentChanged = false;
5113 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5114 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005115 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 ArgEnd = E->arg_end();
5117 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005118 if (getDerived().DropCallArgument(*Arg)) {
5119 ArgumentChanged = true;
5120 break;
5121 }
5122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5124 if (TransArg.isInvalid())
5125 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5128 Args.push_back((Expr *)TransArg.release());
5129 }
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 if (!getDerived().AlwaysRebuild() &&
5132 T == E->getType() &&
5133 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005134 !ArgumentChanged) {
5135 // FIXME: Instantiation-specific
5136 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005137 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005138 }
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 // FIXME: Bogus location information
5141 SourceLocation CommaLoc;
5142 if (Args.size() > 1) {
5143 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005144 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5146 }
5147 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5148 T,
5149 /*FIXME:*/E->getTypeBeginLoc(),
5150 move_arg(Args),
5151 &CommaLoc,
5152 E->getLocEnd());
5153}
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155template<typename Derived>
5156Sema::OwningExprResult
5157TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005158 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5160 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5161 if (T.isNull())
5162 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 bool ArgumentChanged = false;
5165 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5166 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5167 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5168 ArgEnd = E->arg_end();
5169 Arg != ArgEnd; ++Arg) {
5170 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5171 if (TransArg.isInvalid())
5172 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005173
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5175 FakeCommaLocs.push_back(
5176 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5177 Args.push_back(TransArg.takeAs<Expr>());
5178 }
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 if (!getDerived().AlwaysRebuild() &&
5181 T == E->getTypeAsWritten() &&
5182 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005183 return SemaRef.Owned(E->Retain());
5184
Douglas Gregora16548e2009-08-11 05:31:07 +00005185 // FIXME: we're faking the locations of the commas
5186 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5187 T,
5188 E->getLParenLoc(),
5189 move_arg(Args),
5190 FakeCommaLocs.data(),
5191 E->getRParenLoc());
5192}
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregora16548e2009-08-11 05:31:07 +00005194template<typename Derived>
5195Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005196TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005197 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005199 OwningExprResult Base(SemaRef, (Expr*) 0);
5200 Expr *OldBase;
5201 QualType BaseType;
5202 QualType ObjectType;
5203 if (!E->isImplicitAccess()) {
5204 OldBase = E->getBase();
5205 Base = getDerived().TransformExpr(OldBase);
5206 if (Base.isInvalid())
5207 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005208
John McCall2d74de92009-12-01 22:10:20 +00005209 // Start the member reference and compute the object's type.
5210 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005211 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005212 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5213 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005214 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005215 ObjectTy,
5216 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005217 if (Base.isInvalid())
5218 return SemaRef.ExprError();
5219
5220 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5221 BaseType = ((Expr*) Base.get())->getType();
5222 } else {
5223 OldBase = 0;
5224 BaseType = getDerived().TransformType(E->getBaseType());
5225 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5226 }
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005228 // Transform the first part of the nested-name-specifier that qualifies
5229 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005230 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005231 = getDerived().TransformFirstQualifierInScope(
5232 E->getFirstQualifierFoundInScope(),
5233 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005235 NestedNameSpecifier *Qualifier = 0;
5236 if (E->getQualifier()) {
5237 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5238 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005239 ObjectType,
5240 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005241 if (!Qualifier)
5242 return SemaRef.ExprError();
5243 }
Mike Stump11289f42009-09-09 15:08:12 +00005244
5245 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005246 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005247 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005248 if (!Name)
5249 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005250
John McCall2d74de92009-12-01 22:10:20 +00005251 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005252 // This is a reference to a member without an explicitly-specified
5253 // template argument list. Optimize for this common case.
5254 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005255 Base.get() == OldBase &&
5256 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005257 Qualifier == E->getQualifier() &&
5258 Name == E->getMember() &&
5259 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005260 return SemaRef.Owned(E->Retain());
5261
John McCall8cd78132009-11-19 22:55:06 +00005262 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005263 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005264 E->isArrow(),
5265 E->getOperatorLoc(),
5266 Qualifier,
5267 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005268 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005269 Name,
5270 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005271 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005272 }
5273
John McCall6b51f282009-11-23 01:53:49 +00005274 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005275 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005276 TemplateArgumentLoc Loc;
5277 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005278 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005279 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005280 }
Mike Stump11289f42009-09-09 15:08:12 +00005281
John McCall8cd78132009-11-19 22:55:06 +00005282 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005283 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005284 E->isArrow(),
5285 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005286 Qualifier,
5287 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005288 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005289 Name,
5290 E->getMemberLoc(),
5291 &TransArgs);
5292}
5293
5294template<typename Derived>
5295Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005296TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005297 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005298 OwningExprResult Base(SemaRef, (Expr*) 0);
5299 QualType BaseType;
5300 if (!Old->isImplicitAccess()) {
5301 Base = getDerived().TransformExpr(Old->getBase());
5302 if (Base.isInvalid())
5303 return SemaRef.ExprError();
5304 BaseType = ((Expr*) Base.get())->getType();
5305 } else {
5306 BaseType = getDerived().TransformType(Old->getBaseType());
5307 }
John McCall10eae182009-11-30 22:42:35 +00005308
5309 NestedNameSpecifier *Qualifier = 0;
5310 if (Old->getQualifier()) {
5311 Qualifier
5312 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005313 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005314 if (Qualifier == 0)
5315 return SemaRef.ExprError();
5316 }
5317
5318 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5319 Sema::LookupOrdinaryName);
5320
5321 // Transform all the decls.
5322 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5323 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005324 NamedDecl *InstD = static_cast<NamedDecl*>(
5325 getDerived().TransformDecl(Old->getMemberLoc(),
5326 *I));
John McCall84d87672009-12-10 09:41:52 +00005327 if (!InstD) {
5328 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5329 // This can happen because of dependent hiding.
5330 if (isa<UsingShadowDecl>(*I))
5331 continue;
5332 else
5333 return SemaRef.ExprError();
5334 }
John McCall10eae182009-11-30 22:42:35 +00005335
5336 // Expand using declarations.
5337 if (isa<UsingDecl>(InstD)) {
5338 UsingDecl *UD = cast<UsingDecl>(InstD);
5339 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5340 E = UD->shadow_end(); I != E; ++I)
5341 R.addDecl(*I);
5342 continue;
5343 }
5344
5345 R.addDecl(InstD);
5346 }
5347
5348 R.resolveKind();
5349
5350 TemplateArgumentListInfo TransArgs;
5351 if (Old->hasExplicitTemplateArgs()) {
5352 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5353 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5354 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5355 TemplateArgumentLoc Loc;
5356 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5357 Loc))
5358 return SemaRef.ExprError();
5359 TransArgs.addArgument(Loc);
5360 }
5361 }
John McCall38836f02010-01-15 08:34:02 +00005362
5363 // FIXME: to do this check properly, we will need to preserve the
5364 // first-qualifier-in-scope here, just in case we had a dependent
5365 // base (and therefore couldn't do the check) and a
5366 // nested-name-qualifier (and therefore could do the lookup).
5367 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005368
5369 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005370 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005371 Old->getOperatorLoc(),
5372 Old->isArrow(),
5373 Qualifier,
5374 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005375 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005376 R,
5377 (Old->hasExplicitTemplateArgs()
5378 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005379}
5380
5381template<typename Derived>
5382Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005383TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005384 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005385}
5386
Mike Stump11289f42009-09-09 15:08:12 +00005387template<typename Derived>
5388Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005389TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 // FIXME: poor source location
5391 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5392 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5393 if (EncodedType.isNull())
5394 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 if (!getDerived().AlwaysRebuild() &&
5397 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005398 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005399
5400 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5401 EncodedType,
5402 E->getRParenLoc());
5403}
Mike Stump11289f42009-09-09 15:08:12 +00005404
Douglas Gregora16548e2009-08-11 05:31:07 +00005405template<typename Derived>
5406Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005407TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 // FIXME: Implement this!
5409 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005410 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005411}
5412
Mike Stump11289f42009-09-09 15:08:12 +00005413template<typename Derived>
5414Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005415TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005422 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005424 getDerived().TransformDecl(E->getLocStart(),
5425 E->getProtocol()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005426 if (!Protocol)
5427 return SemaRef.ExprError();
5428
5429 if (!getDerived().AlwaysRebuild() &&
5430 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005431 return SemaRef.Owned(E->Retain());
5432
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 return getDerived().RebuildObjCProtocolExpr(Protocol,
5434 E->getAtLoc(),
5435 /*FIXME:*/E->getAtLoc(),
5436 /*FIXME:*/E->getAtLoc(),
5437 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005438
Douglas Gregora16548e2009-08-11 05:31:07 +00005439}
5440
Mike Stump11289f42009-09-09 15:08:12 +00005441template<typename Derived>
5442Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005443TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 // FIXME: Implement this!
5445 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005446 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005447}
5448
Mike Stump11289f42009-09-09 15:08:12 +00005449template<typename Derived>
5450Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005451TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005452 // FIXME: Implement this!
5453 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005454 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005455}
5456
Mike Stump11289f42009-09-09 15:08:12 +00005457template<typename Derived>
5458Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005459TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005460 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 // FIXME: Implement this!
5462 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005463 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005464}
5465
Mike Stump11289f42009-09-09 15:08:12 +00005466template<typename Derived>
5467Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005468TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005469 // FIXME: Implement this!
5470 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005471 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005472}
5473
Mike Stump11289f42009-09-09 15:08:12 +00005474template<typename Derived>
5475Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005476TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005477 // FIXME: Implement this!
5478 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005479 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005480}
5481
Mike Stump11289f42009-09-09 15:08:12 +00005482template<typename Derived>
5483Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005484TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005485 bool ArgumentChanged = false;
5486 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5487 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5488 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5489 if (SubExpr.isInvalid())
5490 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005491
Douglas Gregora16548e2009-08-11 05:31:07 +00005492 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5493 SubExprs.push_back(SubExpr.takeAs<Expr>());
5494 }
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregora16548e2009-08-11 05:31:07 +00005496 if (!getDerived().AlwaysRebuild() &&
5497 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005498 return SemaRef.Owned(E->Retain());
5499
Douglas Gregora16548e2009-08-11 05:31:07 +00005500 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5501 move_arg(SubExprs),
5502 E->getRParenLoc());
5503}
5504
Mike Stump11289f42009-09-09 15:08:12 +00005505template<typename Derived>
5506Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005507TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 // FIXME: Implement this!
5509 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005510 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005511}
5512
Mike Stump11289f42009-09-09 15:08:12 +00005513template<typename Derived>
5514Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005515TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 // FIXME: Implement this!
5517 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005518 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005519}
Mike Stump11289f42009-09-09 15:08:12 +00005520
Douglas Gregora16548e2009-08-11 05:31:07 +00005521//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005522// Type reconstruction
5523//===----------------------------------------------------------------------===//
5524
Mike Stump11289f42009-09-09 15:08:12 +00005525template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005526QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5527 SourceLocation Star) {
5528 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005529 getDerived().getBaseEntity());
5530}
5531
Mike Stump11289f42009-09-09 15:08:12 +00005532template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005533QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5534 SourceLocation Star) {
5535 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005536 getDerived().getBaseEntity());
5537}
5538
Mike Stump11289f42009-09-09 15:08:12 +00005539template<typename Derived>
5540QualType
John McCall70dd5f62009-10-30 00:06:24 +00005541TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5542 bool WrittenAsLValue,
5543 SourceLocation Sigil) {
5544 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5545 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005546}
5547
5548template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005549QualType
John McCall70dd5f62009-10-30 00:06:24 +00005550TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5551 QualType ClassType,
5552 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005553 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005554 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005555}
5556
5557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005558QualType
John McCall70dd5f62009-10-30 00:06:24 +00005559TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5560 SourceLocation Sigil) {
5561 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005562 getDerived().getBaseEntity());
5563}
5564
5565template<typename Derived>
5566QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005567TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5568 ArrayType::ArraySizeModifier SizeMod,
5569 const llvm::APInt *Size,
5570 Expr *SizeExpr,
5571 unsigned IndexTypeQuals,
5572 SourceRange BracketsRange) {
5573 if (SizeExpr || !Size)
5574 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5575 IndexTypeQuals, BracketsRange,
5576 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005577
5578 QualType Types[] = {
5579 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5580 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5581 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005582 };
5583 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5584 QualType SizeType;
5585 for (unsigned I = 0; I != NumTypes; ++I)
5586 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5587 SizeType = Types[I];
5588 break;
5589 }
Mike Stump11289f42009-09-09 15:08:12 +00005590
Douglas Gregord6ff3322009-08-04 16:50:30 +00005591 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005592 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005593 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005594 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005595}
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregord6ff3322009-08-04 16:50:30 +00005597template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005598QualType
5599TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005600 ArrayType::ArraySizeModifier SizeMod,
5601 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005602 unsigned IndexTypeQuals,
5603 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005604 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005605 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005606}
5607
5608template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005609QualType
Mike Stump11289f42009-09-09 15:08:12 +00005610TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005611 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005612 unsigned IndexTypeQuals,
5613 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005614 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005615 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregord6ff3322009-08-04 16:50:30 +00005618template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005619QualType
5620TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005621 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005623 unsigned IndexTypeQuals,
5624 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005625 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005626 SizeExpr.takeAs<Expr>(),
5627 IndexTypeQuals, BracketsRange);
5628}
5629
5630template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005631QualType
5632TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005633 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005635 unsigned IndexTypeQuals,
5636 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005637 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005638 SizeExpr.takeAs<Expr>(),
5639 IndexTypeQuals, BracketsRange);
5640}
5641
5642template<typename Derived>
5643QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005644 unsigned NumElements,
5645 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005646 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005647 return SemaRef.Context.getVectorType(ElementType, NumElements,
5648 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005649}
Mike Stump11289f42009-09-09 15:08:12 +00005650
Douglas Gregord6ff3322009-08-04 16:50:30 +00005651template<typename Derived>
5652QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5653 unsigned NumElements,
5654 SourceLocation AttributeLoc) {
5655 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5656 NumElements, true);
5657 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005658 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005659 AttributeLoc);
5660 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5661 AttributeLoc);
5662}
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregord6ff3322009-08-04 16:50:30 +00005664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005665QualType
5666TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005668 SourceLocation AttributeLoc) {
5669 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5670}
Mike Stump11289f42009-09-09 15:08:12 +00005671
Douglas Gregord6ff3322009-08-04 16:50:30 +00005672template<typename Derived>
5673QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005674 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005675 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005676 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005677 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005678 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005679 Quals,
5680 getDerived().getBaseLocation(),
5681 getDerived().getBaseEntity());
5682}
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregord6ff3322009-08-04 16:50:30 +00005684template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005685QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5686 return SemaRef.Context.getFunctionNoProtoType(T);
5687}
5688
5689template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005690QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5691 assert(D && "no decl found");
5692 if (D->isInvalidDecl()) return QualType();
5693
5694 TypeDecl *Ty;
5695 if (isa<UsingDecl>(D)) {
5696 UsingDecl *Using = cast<UsingDecl>(D);
5697 assert(Using->isTypeName() &&
5698 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5699
5700 // A valid resolved using typename decl points to exactly one type decl.
5701 assert(++Using->shadow_begin() == Using->shadow_end());
5702 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5703
5704 } else {
5705 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5706 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5707 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5708 }
5709
5710 return SemaRef.Context.getTypeDeclType(Ty);
5711}
5712
5713template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005714QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005715 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5716}
5717
5718template<typename Derived>
5719QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5720 return SemaRef.Context.getTypeOfType(Underlying);
5721}
5722
5723template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005724QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005725 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5726}
5727
5728template<typename Derived>
5729QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005730 TemplateName Template,
5731 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005732 const TemplateArgumentListInfo &TemplateArgs) {
5733 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005734}
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregor1135c352009-08-06 05:28:30 +00005736template<typename Derived>
5737NestedNameSpecifier *
5738TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5739 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005740 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005741 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005742 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005743 CXXScopeSpec SS;
5744 // FIXME: The source location information is all wrong.
5745 SS.setRange(Range);
5746 SS.setScopeRep(Prefix);
5747 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005748 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005749 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005750 ObjectType,
5751 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005752 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005753}
5754
5755template<typename Derived>
5756NestedNameSpecifier *
5757TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5758 SourceRange Range,
5759 NamespaceDecl *NS) {
5760 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5761}
5762
5763template<typename Derived>
5764NestedNameSpecifier *
5765TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5766 SourceRange Range,
5767 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005768 QualType T) {
5769 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005770 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005771 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005772 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5773 T.getTypePtr());
5774 }
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregor1135c352009-08-06 05:28:30 +00005776 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5777 return 0;
5778}
Mike Stump11289f42009-09-09 15:08:12 +00005779
Douglas Gregor71dc5092009-08-06 06:41:21 +00005780template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005781TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005782TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5783 bool TemplateKW,
5784 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005785 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005786 Template);
5787}
5788
5789template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005790TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005791TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005792 const IdentifierInfo &II,
5793 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005794 CXXScopeSpec SS;
5795 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005796 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005797 UnqualifiedId Name;
5798 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005799 return getSema().ActOnDependentTemplateName(
5800 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005801 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005802 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005803 ObjectType.getAsOpaquePtr(),
5804 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005805 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005806}
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005809TemplateName
5810TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5811 OverloadedOperatorKind Operator,
5812 QualType ObjectType) {
5813 CXXScopeSpec SS;
5814 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5815 SS.setScopeRep(Qualifier);
5816 UnqualifiedId Name;
5817 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5818 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5819 Operator, SymbolLocations);
5820 return getSema().ActOnDependentTemplateName(
5821 /*FIXME:*/getDerived().getBaseLocation(),
5822 SS,
5823 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005824 ObjectType.getAsOpaquePtr(),
5825 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005826 .template getAsVal<TemplateName>();
5827}
5828
5829template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005830Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005831TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5832 SourceLocation OpLoc,
5833 ExprArg Callee,
5834 ExprArg First,
5835 ExprArg Second) {
5836 Expr *FirstExpr = (Expr *)First.get();
5837 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005838 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005840
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005842 if (Op == OO_Subscript) {
5843 if (!FirstExpr->getType()->isOverloadableType() &&
5844 !SecondExpr->getType()->isOverloadableType())
5845 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005846 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005847 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005848 } else if (Op == OO_Arrow) {
5849 // -> is never a builtin operation.
5850 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005851 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005852 if (!FirstExpr->getType()->isOverloadableType()) {
5853 // The argument is not of overloadable type, so try to create a
5854 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005855 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005857
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5859 }
5860 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005861 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 !SecondExpr->getType()->isOverloadableType()) {
5863 // Neither of the arguments is an overloadable type, so try to
5864 // create a built-in binary operation.
5865 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005866 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5868 if (Result.isInvalid())
5869 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 First.release();
5872 Second.release();
5873 return move(Result);
5874 }
5875 }
Mike Stump11289f42009-09-09 15:08:12 +00005876
5877 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005878 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005879 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005880
John McCalld14a8642009-11-21 08:51:07 +00005881 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5882 assert(ULE->requiresADL());
5883
5884 // FIXME: Do we have to check
5885 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005886 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005887 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005888 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005889 }
Mike Stump11289f42009-09-09 15:08:12 +00005890
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 // Add any functions found via argument-dependent lookup.
5892 Expr *Args[2] = { FirstExpr, SecondExpr };
5893 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregora16548e2009-08-11 05:31:07 +00005895 // Create the overloaded operator invocation for unary operators.
5896 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005897 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5899 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5900 }
Mike Stump11289f42009-09-09 15:08:12 +00005901
Sebastian Redladba46e2009-10-29 20:17:01 +00005902 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005903 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5904 OpLoc,
5905 move(First),
5906 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005907
Douglas Gregora16548e2009-08-11 05:31:07 +00005908 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005909 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005911 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5913 if (Result.isInvalid())
5914 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 First.release();
5917 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005918 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005919}
Mike Stump11289f42009-09-09 15:08:12 +00005920
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005921template<typename Derived>
5922Sema::OwningExprResult
5923TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5924 SourceLocation OperatorLoc,
5925 bool isArrow,
5926 NestedNameSpecifier *Qualifier,
5927 SourceRange QualifierRange,
5928 TypeSourceInfo *ScopeType,
5929 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005930 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005931 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005932 CXXScopeSpec SS;
5933 if (Qualifier) {
5934 SS.setRange(QualifierRange);
5935 SS.setScopeRep(Qualifier);
5936 }
5937
5938 Expr *BaseE = (Expr *)Base.get();
5939 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005940 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005941 (!isArrow && !BaseType->getAs<RecordType>()) ||
5942 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00005943 !BaseType->getAs<PointerType>()->getPointeeType()
5944 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005945 // This pseudo-destructor expression is still a pseudo-destructor.
5946 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5947 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005948 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005949 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005950 /*FIXME?*/true);
5951 }
5952
Douglas Gregor678f90d2010-02-25 01:56:36 +00005953 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005954 DeclarationName Name
5955 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5956 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5957
5958 // FIXME: the ScopeType should be tacked onto SS.
5959
5960 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5961 OperatorLoc, isArrow,
5962 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005963 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005964 /*TemplateArgs*/ 0);
5965}
5966
Douglas Gregord6ff3322009-08-04 16:50:30 +00005967} // end namespace clang
5968
5969#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H