blob: db44a36ccfd773bbf55d38a5ab7f44af94edd453 [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);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregore677daf2010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
577 // FIXME: Note the lack of the "typename" specifier!
578 // Fall through
579 case ETK_Typename:
580 return SemaRef.CheckTypenameType(NNS, *Id, SR);
581
582 case ETK_Class: Kind = TagDecl::TK_class; break;
583 case ETK_Struct: Kind = TagDecl::TK_struct; break;
584 case ETK_Union: Kind = TagDecl::TK_union; break;
585 case ETK_Enum: Kind = TagDecl::TK_enum; break;
586 }
587
588 // We had a dependent elaborated-type-specifier that as been transformed
589 // into a non-dependent elaborated-type-specifier. Find the tag we're
590 // referring to.
591 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
592 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
593 if (!DC)
594 return QualType();
595
596 TagDecl *Tag = 0;
597 SemaRef.LookupQualifiedName(Result, DC);
598 switch (Result.getResultKind()) {
599 case LookupResult::NotFound:
600 case LookupResult::NotFoundInCurrentInstantiation:
601 break;
602
603 case LookupResult::Found:
604 Tag = Result.getAsSingle<TagDecl>();
605 break;
606
607 case LookupResult::FoundOverloaded:
608 case LookupResult::FoundUnresolvedValue:
609 llvm_unreachable("Tag lookup cannot find non-tags");
610 return QualType();
611
612 case LookupResult::Ambiguous:
613 // Let the LookupResult structure handle ambiguities.
614 return QualType();
615 }
616
617 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000618 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000619 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000620 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000621 return QualType();
622 }
623
624 // FIXME: Terrible location information
625 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
626 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
627 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
628 return QualType();
629 }
630
631 // Build the elaborated-type-specifier type.
632 QualType T = SemaRef.Context.getTypeDeclType(Tag);
633 T = SemaRef.Context.getQualifiedNameType(NNS, T);
634 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000635 }
Mike Stump11289f42009-09-09 15:08:12 +0000636
Douglas Gregor1135c352009-08-06 05:28:30 +0000637 /// \brief Build a new nested-name-specifier given the prefix and an
638 /// identifier that names the next step in the nested-name-specifier.
639 ///
640 /// By default, performs semantic analysis when building the new
641 /// nested-name-specifier. Subclasses may override this routine to provide
642 /// different behavior.
643 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
644 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000645 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000646 QualType ObjectType,
647 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000648
649 /// \brief Build a new nested-name-specifier given the prefix and the
650 /// namespace named in the next step in the nested-name-specifier.
651 ///
652 /// By default, performs semantic analysis when building the new
653 /// nested-name-specifier. Subclasses may override this routine to provide
654 /// different behavior.
655 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
656 SourceRange Range,
657 NamespaceDecl *NS);
658
659 /// \brief Build a new nested-name-specifier given the prefix and the
660 /// type named in the next step in the nested-name-specifier.
661 ///
662 /// By default, performs semantic analysis when building the new
663 /// nested-name-specifier. Subclasses may override this routine to provide
664 /// different behavior.
665 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
666 SourceRange Range,
667 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000668 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000669
670 /// \brief Build a new template name given a nested name specifier, a flag
671 /// indicating whether the "template" keyword was provided, and the template
672 /// that the template name refers to.
673 ///
674 /// By default, builds the new template name directly. Subclasses may override
675 /// this routine to provide different behavior.
676 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
677 bool TemplateKW,
678 TemplateDecl *Template);
679
Douglas Gregor71dc5092009-08-06 06:41:21 +0000680 /// \brief Build a new template name given a nested name specifier and the
681 /// name that is referred to as a template.
682 ///
683 /// By default, performs semantic analysis to determine whether the name can
684 /// be resolved to a specific template, then builds the appropriate kind of
685 /// template name. Subclasses may override this routine to provide different
686 /// behavior.
687 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000688 const IdentifierInfo &II,
689 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000690
Douglas Gregor71395fa2009-11-04 00:56:37 +0000691 /// \brief Build a new template name given a nested name specifier and the
692 /// overloaded operator name that is referred to as a template.
693 ///
694 /// By default, performs semantic analysis to determine whether the name can
695 /// be resolved to a specific template, then builds the appropriate kind of
696 /// template name. Subclasses may override this routine to provide different
697 /// behavior.
698 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
699 OverloadedOperatorKind Operator,
700 QualType ObjectType);
701
Douglas Gregorebe10102009-08-20 07:17:43 +0000702 /// \brief Build a new compound statement.
703 ///
704 /// By default, performs semantic analysis to build the new statement.
705 /// Subclasses may override this routine to provide different behavior.
706 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
707 MultiStmtArg Statements,
708 SourceLocation RBraceLoc,
709 bool IsStmtExpr) {
710 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
711 IsStmtExpr);
712 }
713
714 /// \brief Build a new case statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
719 ExprArg LHS,
720 SourceLocation EllipsisLoc,
721 ExprArg RHS,
722 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000723 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 ColonLoc);
725 }
Mike Stump11289f42009-09-09 15:08:12 +0000726
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 /// \brief Attach the body to a new case statement.
728 ///
729 /// By default, performs semantic analysis to build the new statement.
730 /// Subclasses may override this routine to provide different behavior.
731 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
732 getSema().ActOnCaseStmtBody(S.get(), move(Body));
733 return move(S);
734 }
Mike Stump11289f42009-09-09 15:08:12 +0000735
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 /// \brief Build a new default statement.
737 ///
738 /// By default, performs semantic analysis to build the new statement.
739 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000740 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 SourceLocation ColonLoc,
742 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000743 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000744 /*CurScope=*/0);
745 }
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 /// \brief Build a new label statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000751 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 IdentifierInfo *Id,
753 SourceLocation ColonLoc,
754 StmtArg SubStmt) {
755 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
756 }
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 /// \brief Build a new "if" statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000762 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000763 VarDecl *CondVar, StmtArg Then,
764 SourceLocation ElseLoc, StmtArg Else) {
765 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
766 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000767 }
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 /// \brief Start building a new switch statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000773 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
774 VarDecl *CondVar) {
775 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 }
Mike Stump11289f42009-09-09 15:08:12 +0000777
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 /// \brief Attach the body to the switch statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000782 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 StmtArg Switch, StmtArg Body) {
784 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
785 move(Body));
786 }
787
788 /// \brief Build a new while statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
792 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
793 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000794 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000795 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000796 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
797 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000798 }
Mike Stump11289f42009-09-09 15:08:12 +0000799
Douglas Gregorebe10102009-08-20 07:17:43 +0000800 /// \brief Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
805 SourceLocation WhileLoc,
806 SourceLocation LParenLoc,
807 ExprArg Cond,
808 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000809 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 move(Cond), RParenLoc);
811 }
812
813 /// \brief Build a new for statement.
814 ///
815 /// By default, performs semantic analysis to build the new statement.
816 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000817 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000819 StmtArg Init, Sema::FullExprArg Cond,
820 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000822 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
823 DeclPtrTy::make(CondVar),
824 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000825 }
Mike Stump11289f42009-09-09 15:08:12 +0000826
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 /// \brief Build a new goto statement.
828 ///
829 /// By default, performs semantic analysis to build the new statement.
830 /// Subclasses may override this routine to provide different behavior.
831 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
832 SourceLocation LabelLoc,
833 LabelStmt *Label) {
834 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
835 }
836
837 /// \brief Build a new indirect goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
841 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
842 SourceLocation StarLoc,
843 ExprArg Target) {
844 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
845 }
Mike Stump11289f42009-09-09 15:08:12 +0000846
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 /// \brief Build a new return 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 RebuildReturnStmt(SourceLocation ReturnLoc,
852 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 /// \brief Build a new declaration statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
861 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000862 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 SourceLocation EndLoc) {
864 return getSema().Owned(
865 new (getSema().Context) DeclStmt(
866 DeclGroupRef::Create(getSema().Context,
867 Decls, NumDecls),
868 StartLoc, EndLoc));
869 }
Mike Stump11289f42009-09-09 15:08:12 +0000870
Anders Carlssonaaeef072010-01-24 05:50:09 +0000871 /// \brief Build a new inline asm statement.
872 ///
873 /// By default, performs semantic analysis to build the new statement.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
876 bool IsSimple,
877 bool IsVolatile,
878 unsigned NumOutputs,
879 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000880 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 MultiExprArg Constraints,
882 MultiExprArg Exprs,
883 ExprArg AsmString,
884 MultiExprArg Clobbers,
885 SourceLocation RParenLoc,
886 bool MSAsm) {
887 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
888 NumInputs, Names, move(Constraints),
889 move(Exprs), move(AsmString), move(Clobbers),
890 RParenLoc, MSAsm);
891 }
892
Douglas Gregor2900c162010-04-22 21:44:01 +0000893 /// \brief Build a new Objective-C throw statement.
894 ///
895 /// By default, performs semantic analysis to build the new statement.
896 /// Subclasses may override this routine to provide different behavior.
897 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
898 ExprArg Operand) {
899 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
900 }
901
Douglas Gregorebe10102009-08-20 07:17:43 +0000902 /// \brief Build a new C++ exception declaration.
903 ///
904 /// By default, performs semantic analysis to build the new decaration.
905 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000906 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000907 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000908 IdentifierInfo *Name,
909 SourceLocation Loc,
910 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000911 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000912 TypeRange);
913 }
914
915 /// \brief Build a new C++ catch statement.
916 ///
917 /// By default, performs semantic analysis to build the new statement.
918 /// Subclasses may override this routine to provide different behavior.
919 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
920 VarDecl *ExceptionDecl,
921 StmtArg Handler) {
922 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000923 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000924 Handler.takeAs<Stmt>()));
925 }
Mike Stump11289f42009-09-09 15:08:12 +0000926
Douglas Gregorebe10102009-08-20 07:17:43 +0000927 /// \brief Build a new C++ try statement.
928 ///
929 /// By default, performs semantic analysis to build the new statement.
930 /// Subclasses may override this routine to provide different behavior.
931 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
932 StmtArg TryBlock,
933 MultiStmtArg Handlers) {
934 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
935 }
Mike Stump11289f42009-09-09 15:08:12 +0000936
Douglas Gregora16548e2009-08-11 05:31:07 +0000937 /// \brief Build a new expression that references a declaration.
938 ///
939 /// By default, performs semantic analysis to build the new expression.
940 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000941 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
942 LookupResult &R,
943 bool RequiresADL) {
944 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
945 }
946
947
948 /// \brief Build a new expression that references a declaration.
949 ///
950 /// By default, performs semantic analysis to build the new expression.
951 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000952 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
953 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000954 ValueDecl *VD, SourceLocation Loc,
955 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000956 CXXScopeSpec SS;
957 SS.setScopeRep(Qualifier);
958 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000959
960 // FIXME: loses template args.
961
962 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000963 }
Mike Stump11289f42009-09-09 15:08:12 +0000964
Douglas Gregora16548e2009-08-11 05:31:07 +0000965 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000966 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000967 /// By default, performs semantic analysis to build the new expression.
968 /// Subclasses may override this routine to provide different behavior.
969 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
970 SourceLocation RParen) {
971 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
972 }
973
Douglas Gregorad8a3362009-09-04 17:36:40 +0000974 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000975 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000976 /// By default, performs semantic analysis to build the new expression.
977 /// Subclasses may override this routine to provide different behavior.
978 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
979 SourceLocation OperatorLoc,
980 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000981 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000982 SourceRange QualifierRange,
983 TypeSourceInfo *ScopeType,
984 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000985 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000986 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000987
Douglas Gregora16548e2009-08-11 05:31:07 +0000988 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000989 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000990 /// By default, performs semantic analysis to build the new expression.
991 /// Subclasses may override this routine to provide different behavior.
992 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
993 UnaryOperator::Opcode Opc,
994 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000995 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000996 }
Mike Stump11289f42009-09-09 15:08:12 +0000997
Douglas Gregora16548e2009-08-11 05:31:07 +0000998 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000999 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001000 /// By default, performs semantic analysis to build the new expression.
1001 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001002 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001003 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001004 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001005 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001006 }
1007
Mike Stump11289f42009-09-09 15:08:12 +00001008 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001011 /// By default, performs semantic analysis to build the new expression.
1012 /// Subclasses may override this routine to provide different behavior.
1013 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1014 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001015 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1017 OpLoc, isSizeOf, R);
1018 if (Result.isInvalid())
1019 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001020
Douglas Gregora16548e2009-08-11 05:31:07 +00001021 SubExpr.release();
1022 return move(Result);
1023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001029 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001030 SourceLocation LBracketLoc,
1031 ExprArg RHS,
1032 SourceLocation RBracketLoc) {
1033 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001034 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 RBracketLoc);
1036 }
1037
1038 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001039 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 /// By default, performs semantic analysis to build the new expression.
1041 /// Subclasses may override this routine to provide different behavior.
1042 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1043 MultiExprArg Args,
1044 SourceLocation *CommaLocs,
1045 SourceLocation RParenLoc) {
1046 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1047 move(Args), CommaLocs, RParenLoc);
1048 }
1049
1050 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001051 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
1054 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001055 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001056 NestedNameSpecifier *Qualifier,
1057 SourceRange QualifierRange,
1058 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001059 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001060 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001061 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001062 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001063 if (!Member->getDeclName()) {
1064 // We have a reference to an unnamed field.
1065 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001067 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001068 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1069 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001070 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001071
Mike Stump11289f42009-09-09 15:08:12 +00001072 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001073 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001074 Member, MemberLoc,
1075 cast<FieldDecl>(Member)->getType());
1076 return getSema().Owned(ME);
1077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001079 CXXScopeSpec SS;
1080 if (Qualifier) {
1081 SS.setRange(QualifierRange);
1082 SS.setScopeRep(Qualifier);
1083 }
1084
John McCall2d74de92009-12-01 22:10:20 +00001085 QualType BaseType = ((Expr*) Base.get())->getType();
1086
John McCall16df1e52010-03-30 21:47:33 +00001087 // FIXME: this involves duplicating earlier analysis in a lot of
1088 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001089 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1090 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001091 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001092 R.resolveKind();
1093
John McCall2d74de92009-12-01 22:10:20 +00001094 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1095 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001096 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001097 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 }
Mike Stump11289f42009-09-09 15:08:12 +00001099
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001101 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// By default, performs semantic analysis to build the new expression.
1103 /// Subclasses may override this routine to provide different behavior.
1104 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1105 BinaryOperator::Opcode Opc,
1106 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001107 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1108 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 }
1110
1111 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
1115 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1116 SourceLocation QuestionLoc,
1117 ExprArg LHS,
1118 SourceLocation ColonLoc,
1119 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001120 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 move(LHS), move(RHS));
1122 }
1123
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001128 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1129 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 SourceLocation RParenLoc,
1131 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001132 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1133 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
1140 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001141 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 SourceLocation RParenLoc,
1143 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001144 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1145 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 }
Mike Stump11289f42009-09-09 15:08:12 +00001147
Douglas Gregora16548e2009-08-11 05:31:07 +00001148 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001149 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001152 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001153 SourceLocation OpLoc,
1154 SourceLocation AccessorLoc,
1155 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001156
John McCall10eae182009-11-30 22:42:35 +00001157 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001158 QualType BaseType = ((Expr*) Base.get())->getType();
1159 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001160 OpLoc, /*IsArrow*/ false,
1161 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001162 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001163 AccessorLoc,
1164 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregora16548e2009-08-11 05:31:07 +00001167 /// \brief Build a new initializer list 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 RebuildInitList(SourceLocation LBraceLoc,
1172 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001173 SourceLocation RBraceLoc,
1174 QualType ResultTy) {
1175 OwningExprResult Result
1176 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1177 if (Result.isInvalid() || ResultTy->isDependentType())
1178 return move(Result);
1179
1180 // Patch in the result type we were given, which may have been computed
1181 // when the initial InitListExpr was built.
1182 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1183 ILE->setType(ResultTy);
1184 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 }
Mike Stump11289f42009-09-09 15:08:12 +00001186
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001188 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001189 /// By default, performs semantic analysis to build the new expression.
1190 /// Subclasses may override this routine to provide different behavior.
1191 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1192 MultiExprArg ArrayExprs,
1193 SourceLocation EqualOrColonLoc,
1194 bool GNUSyntax,
1195 ExprArg Init) {
1196 OwningExprResult Result
1197 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1198 move(Init));
1199 if (Result.isInvalid())
1200 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001201
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 ArrayExprs.release();
1203 return move(Result);
1204 }
Mike Stump11289f42009-09-09 15:08:12 +00001205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001207 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// By default, builds the implicit value initialization without performing
1209 /// any semantic analysis. Subclasses may override this routine to provide
1210 /// different behavior.
1211 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1212 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1213 }
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001216 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// By default, performs semantic analysis to build the new expression.
1218 /// Subclasses may override this routine to provide different behavior.
1219 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1220 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001221 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 RParenLoc);
1223 }
1224
1225 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
1229 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1230 MultiExprArg SubExprs,
1231 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001232 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1233 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 }
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001237 ///
1238 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// rather than attempting to map the label statement itself.
1240 /// Subclasses may override this routine to provide different behavior.
1241 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1242 SourceLocation LabelLoc,
1243 LabelStmt *Label) {
1244 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1245 }
Mike Stump11289f42009-09-09 15:08:12 +00001246
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001248 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 /// By default, performs semantic analysis to build the new expression.
1250 /// Subclasses may override this routine to provide different behavior.
1251 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1252 StmtArg SubStmt,
1253 SourceLocation RParenLoc) {
1254 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1255 }
Mike Stump11289f42009-09-09 15:08:12 +00001256
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 /// \brief Build a new __builtin_types_compatible_p expression.
1258 ///
1259 /// By default, performs semantic analysis to build the new expression.
1260 /// Subclasses may override this routine to provide different behavior.
1261 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1262 QualType T1, QualType T2,
1263 SourceLocation RParenLoc) {
1264 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1265 T1.getAsOpaquePtr(),
1266 T2.getAsOpaquePtr(),
1267 RParenLoc);
1268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// \brief Build a new __builtin_choose_expr expression.
1271 ///
1272 /// By default, performs semantic analysis to build the new expression.
1273 /// Subclasses may override this routine to provide different behavior.
1274 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1275 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1276 SourceLocation RParenLoc) {
1277 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1278 move(Cond), move(LHS), move(RHS),
1279 RParenLoc);
1280 }
Mike Stump11289f42009-09-09 15:08:12 +00001281
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// \brief Build a new overloaded operator call expression.
1283 ///
1284 /// By default, performs semantic analysis to build the new expression.
1285 /// The semantic analysis provides the behavior of template instantiation,
1286 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001287 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// argument-dependent lookup, etc. Subclasses may override this routine to
1289 /// provide different behavior.
1290 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1291 SourceLocation OpLoc,
1292 ExprArg Callee,
1293 ExprArg First,
1294 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001295
1296 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// reinterpret_cast.
1298 ///
1299 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001300 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 /// Subclasses may override this routine to provide different behavior.
1302 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1303 Stmt::StmtClass Class,
1304 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001305 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 SourceLocation RAngleLoc,
1307 SourceLocation LParenLoc,
1308 ExprArg SubExpr,
1309 SourceLocation RParenLoc) {
1310 switch (Class) {
1311 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001312 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001313 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 move(SubExpr), RParenLoc);
1315
1316 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001317 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001318 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001322 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001323 RAngleLoc, LParenLoc,
1324 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001326
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001328 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001329 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 default:
1333 assert(false && "Invalid C++ named cast");
1334 break;
1335 }
Mike Stump11289f42009-09-09 15:08:12 +00001336
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 return getSema().ExprError();
1338 }
Mike Stump11289f42009-09-09 15:08:12 +00001339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// \brief Build a new C++ static_cast expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
1344 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1345 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001346 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RAngleLoc,
1348 SourceLocation LParenLoc,
1349 ExprArg SubExpr,
1350 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001351 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1352 TInfo, move(SubExpr),
1353 SourceRange(LAngleLoc, RAngleLoc),
1354 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 }
1356
1357 /// \brief Build a new C++ dynamic_cast expression.
1358 ///
1359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
1361 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1362 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001363 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 SourceLocation RAngleLoc,
1365 SourceLocation LParenLoc,
1366 ExprArg SubExpr,
1367 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001368 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1369 TInfo, move(SubExpr),
1370 SourceRange(LAngleLoc, RAngleLoc),
1371 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 }
1373
1374 /// \brief Build a new C++ reinterpret_cast expression.
1375 ///
1376 /// By default, performs semantic analysis to build the new expression.
1377 /// Subclasses may override this routine to provide different behavior.
1378 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1379 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001380 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 SourceLocation RAngleLoc,
1382 SourceLocation LParenLoc,
1383 ExprArg SubExpr,
1384 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001385 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1386 TInfo, move(SubExpr),
1387 SourceRange(LAngleLoc, RAngleLoc),
1388 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 }
1390
1391 /// \brief Build a new C++ const_cast expression.
1392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
1395 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1396 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001397 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 SourceLocation RAngleLoc,
1399 SourceLocation LParenLoc,
1400 ExprArg SubExpr,
1401 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001402 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1403 TInfo, move(SubExpr),
1404 SourceRange(LAngleLoc, RAngleLoc),
1405 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 }
Mike Stump11289f42009-09-09 15:08:12 +00001407
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// \brief Build a new C++ functional-style cast expression.
1409 ///
1410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
1412 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001413 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 SourceLocation LParenLoc,
1415 ExprArg SubExpr,
1416 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001417 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001419 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001421 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001422 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 RParenLoc);
1424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// \brief Build a new C++ typeid(type) expression.
1427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
1430 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1431 SourceLocation LParenLoc,
1432 QualType T,
1433 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001434 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 T.getAsOpaquePtr(), RParenLoc);
1436 }
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// \brief Build a new C++ typeid(expr) expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
1442 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1443 SourceLocation LParenLoc,
1444 ExprArg Operand,
1445 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001446 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1448 RParenLoc);
1449 if (Result.isInvalid())
1450 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001451
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1453 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001454 }
1455
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// \brief Build a new C++ "this" expression.
1457 ///
1458 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001459 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001461 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001462 QualType ThisType,
1463 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001465 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1466 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 }
1468
1469 /// \brief Build a new C++ throw expression.
1470 ///
1471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
1473 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1474 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1475 }
1476
1477 /// \brief Build a new C++ default-argument expression.
1478 ///
1479 /// By default, builds a new default-argument expression, which does not
1480 /// require any semantic analysis. Subclasses may override this routine to
1481 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001482 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1483 ParmVarDecl *Param) {
1484 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1485 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 }
1487
1488 /// \brief Build a new C++ zero-initialization expression.
1489 ///
1490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001492 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 SourceLocation LParenLoc,
1494 QualType T,
1495 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001496 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1497 T.getAsOpaquePtr(), LParenLoc,
1498 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 0, RParenLoc);
1500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new C++ "new" expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001506 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 bool UseGlobal,
1508 SourceLocation PlacementLParen,
1509 MultiExprArg PlacementArgs,
1510 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001511 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 QualType AllocType,
1513 SourceLocation TypeLoc,
1514 SourceRange TypeRange,
1515 ExprArg ArraySize,
1516 SourceLocation ConstructorLParen,
1517 MultiExprArg ConstructorArgs,
1518 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001519 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 PlacementLParen,
1521 move(PlacementArgs),
1522 PlacementRParen,
1523 ParenTypeId,
1524 AllocType,
1525 TypeLoc,
1526 TypeRange,
1527 move(ArraySize),
1528 ConstructorLParen,
1529 move(ConstructorArgs),
1530 ConstructorRParen);
1531 }
Mike Stump11289f42009-09-09 15:08:12 +00001532
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 /// \brief Build a new C++ "delete" expression.
1534 ///
1535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
1537 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1538 bool IsGlobalDelete,
1539 bool IsArrayForm,
1540 ExprArg Operand) {
1541 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1542 move(Operand));
1543 }
Mike Stump11289f42009-09-09 15:08:12 +00001544
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// \brief Build a new unary type trait expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
1549 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1550 SourceLocation StartLoc,
1551 SourceLocation LParenLoc,
1552 QualType T,
1553 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001554 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 T.getAsOpaquePtr(), RParenLoc);
1556 }
1557
Mike Stump11289f42009-09-09 15:08:12 +00001558 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 /// expression.
1560 ///
1561 /// By default, performs semantic analysis to build the new expression.
1562 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001563 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 SourceRange QualifierRange,
1565 DeclarationName Name,
1566 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001567 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 CXXScopeSpec SS;
1569 SS.setRange(QualifierRange);
1570 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001571
1572 if (TemplateArgs)
1573 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1574 *TemplateArgs);
1575
1576 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 }
1578
1579 /// \brief Build a new template-id expression.
1580 ///
1581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001583 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1584 LookupResult &R,
1585 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001586 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001587 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 }
1589
1590 /// \brief Build a new object-construction expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
1594 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001595 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 CXXConstructorDecl *Constructor,
1597 bool IsElidable,
1598 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001599 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1600 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1601 ConvertedArgs))
1602 return getSema().ExprError();
1603
1604 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1605 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
1607
1608 /// \brief Build a new object-construction expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
1612 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1613 QualType T,
1614 SourceLocation LParenLoc,
1615 MultiExprArg Args,
1616 SourceLocation *Commas,
1617 SourceLocation RParenLoc) {
1618 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1619 T.getAsOpaquePtr(),
1620 LParenLoc,
1621 move(Args),
1622 Commas,
1623 RParenLoc);
1624 }
1625
1626 /// \brief Build a new object-construction expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
1630 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1631 QualType T,
1632 SourceLocation LParenLoc,
1633 MultiExprArg Args,
1634 SourceLocation *Commas,
1635 SourceLocation RParenLoc) {
1636 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1637 /*FIXME*/LParenLoc),
1638 T.getAsOpaquePtr(),
1639 LParenLoc,
1640 move(Args),
1641 Commas,
1642 RParenLoc);
1643 }
Mike Stump11289f42009-09-09 15:08:12 +00001644
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 /// \brief Build a new member reference expression.
1646 ///
1647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001649 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001650 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 bool IsArrow,
1652 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001653 NestedNameSpecifier *Qualifier,
1654 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001655 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001657 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001662
John McCall2d74de92009-12-01 22:10:20 +00001663 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1664 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001665 SS, FirstQualifierInScope,
1666 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 }
1668
John McCall10eae182009-11-30 22:42:35 +00001669 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001670 ///
1671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001673 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001674 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001675 SourceLocation OperatorLoc,
1676 bool IsArrow,
1677 NestedNameSpecifier *Qualifier,
1678 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001679 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001680 LookupResult &R,
1681 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001682 CXXScopeSpec SS;
1683 SS.setRange(QualifierRange);
1684 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001685
John McCall2d74de92009-12-01 22:10:20 +00001686 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1687 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001688 SS, FirstQualifierInScope,
1689 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001690 }
Mike Stump11289f42009-09-09 15:08:12 +00001691
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 /// \brief Build a new Objective-C @encode expression.
1693 ///
1694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001697 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001699 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001701 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001702
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001703 /// \brief Build a new Objective-C class message.
1704 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1705 Selector Sel,
1706 ObjCMethodDecl *Method,
1707 SourceLocation LBracLoc,
1708 MultiExprArg Args,
1709 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001710 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1711 ReceiverTypeInfo->getType(),
1712 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001713 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001714 move(Args));
1715 }
1716
1717 /// \brief Build a new Objective-C instance message.
1718 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1719 Selector Sel,
1720 ObjCMethodDecl *Method,
1721 SourceLocation LBracLoc,
1722 MultiExprArg Args,
1723 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001724 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1725 return SemaRef.BuildInstanceMessage(move(Receiver),
1726 ReceiverType,
1727 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001728 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001729 move(Args));
1730 }
1731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new shuffle vector expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1737 MultiExprArg SubExprs,
1738 SourceLocation RParenLoc) {
1739 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001740 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1742 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1743 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1744 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001745
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 // Build a reference to the __builtin_shufflevector builtin
1747 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001748 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001750 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001752
1753 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 unsigned NumSubExprs = SubExprs.size();
1755 Expr **Subs = (Expr **)SubExprs.release();
1756 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1757 Subs, NumSubExprs,
1758 Builtin->getResultType(),
1759 RParenLoc);
1760 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001761
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 // Type-check the __builtin_shufflevector expression.
1763 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1764 if (Result.isInvalid())
1765 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001766
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001768 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001770};
Douglas Gregora16548e2009-08-11 05:31:07 +00001771
Douglas Gregorebe10102009-08-20 07:17:43 +00001772template<typename Derived>
1773Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1774 if (!S)
1775 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001776
Douglas Gregorebe10102009-08-20 07:17:43 +00001777 switch (S->getStmtClass()) {
1778 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001779
Douglas Gregorebe10102009-08-20 07:17:43 +00001780 // Transform individual statement nodes
1781#define STMT(Node, Parent) \
1782 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1783#define EXPR(Node, Parent)
1784#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001785
Douglas Gregorebe10102009-08-20 07:17:43 +00001786 // Transform expressions by calling TransformExpr.
1787#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001788#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001789#define EXPR(Node, Parent) case Stmt::Node##Class:
1790#include "clang/AST/StmtNodes.def"
1791 {
1792 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1793 if (E.isInvalid())
1794 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001795
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001796 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001797 }
Mike Stump11289f42009-09-09 15:08:12 +00001798 }
1799
Douglas Gregorebe10102009-08-20 07:17:43 +00001800 return SemaRef.Owned(S->Retain());
1801}
Mike Stump11289f42009-09-09 15:08:12 +00001802
1803
Douglas Gregore922c772009-08-04 22:27:00 +00001804template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001805Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 if (!E)
1807 return SemaRef.Owned(E);
1808
1809 switch (E->getStmtClass()) {
1810 case Stmt::NoStmtClass: break;
1811#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001812#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001813#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001814 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001815#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001816 }
1817
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001819}
1820
1821template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001822NestedNameSpecifier *
1823TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001824 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001825 QualType ObjectType,
1826 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001827 if (!NNS)
1828 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregorebe10102009-08-20 07:17:43 +00001830 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001831 NestedNameSpecifier *Prefix = NNS->getPrefix();
1832 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001833 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001834 ObjectType,
1835 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001836 if (!Prefix)
1837 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001838
1839 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001840 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001841 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001842 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001843 }
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregor1135c352009-08-06 05:28:30 +00001845 switch (NNS->getKind()) {
1846 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001847 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001848 "Identifier nested-name-specifier with no prefix or object type");
1849 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1850 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001851 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001852
1853 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001854 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001855 ObjectType,
1856 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregor1135c352009-08-06 05:28:30 +00001858 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001859 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001860 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001861 getDerived().TransformDecl(Range.getBegin(),
1862 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001863 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001864 Prefix == NNS->getPrefix() &&
1865 NS == NNS->getAsNamespace())
1866 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor1135c352009-08-06 05:28:30 +00001868 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1869 }
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregor1135c352009-08-06 05:28:30 +00001871 case NestedNameSpecifier::Global:
1872 // There is no meaningful transformation that one could perform on the
1873 // global scope.
1874 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor1135c352009-08-06 05:28:30 +00001876 case NestedNameSpecifier::TypeSpecWithTemplate:
1877 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001878 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001879 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1880 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001881 if (T.isNull())
1882 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregor1135c352009-08-06 05:28:30 +00001884 if (!getDerived().AlwaysRebuild() &&
1885 Prefix == NNS->getPrefix() &&
1886 T == QualType(NNS->getAsType(), 0))
1887 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001888
1889 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1890 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001891 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001892 }
1893 }
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregor1135c352009-08-06 05:28:30 +00001895 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001896 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001897}
1898
1899template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001900DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001901TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001902 SourceLocation Loc,
1903 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001904 if (!Name)
1905 return Name;
1906
1907 switch (Name.getNameKind()) {
1908 case DeclarationName::Identifier:
1909 case DeclarationName::ObjCZeroArgSelector:
1910 case DeclarationName::ObjCOneArgSelector:
1911 case DeclarationName::ObjCMultiArgSelector:
1912 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001913 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001914 case DeclarationName::CXXUsingDirective:
1915 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001916
Douglas Gregorf816bd72009-09-03 22:13:48 +00001917 case DeclarationName::CXXConstructorName:
1918 case DeclarationName::CXXDestructorName:
1919 case DeclarationName::CXXConversionFunctionName: {
1920 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001921 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1922 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001923 if (T.isNull())
1924 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregorf816bd72009-09-03 22:13:48 +00001926 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001927 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001928 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001929 }
Mike Stump11289f42009-09-09 15:08:12 +00001930 }
1931
Douglas Gregorf816bd72009-09-03 22:13:48 +00001932 return DeclarationName();
1933}
1934
1935template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001936TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001937TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1938 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001939 SourceLocation Loc = getDerived().getBaseLocation();
1940
Douglas Gregor71dc5092009-08-06 06:41:21 +00001941 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001942 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001943 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001944 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1945 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001946 if (!NNS)
1947 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregor71dc5092009-08-06 06:41:21 +00001949 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001950 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001951 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001952 if (!TransTemplate)
1953 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001954
Douglas Gregor71dc5092009-08-06 06:41:21 +00001955 if (!getDerived().AlwaysRebuild() &&
1956 NNS == QTN->getQualifier() &&
1957 TransTemplate == Template)
1958 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001959
Douglas Gregor71dc5092009-08-06 06:41:21 +00001960 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1961 TransTemplate);
1962 }
Mike Stump11289f42009-09-09 15:08:12 +00001963
John McCalle66edc12009-11-24 19:00:30 +00001964 // These should be getting filtered out before they make it into the AST.
1965 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001966 }
Mike Stump11289f42009-09-09 15:08:12 +00001967
Douglas Gregor71dc5092009-08-06 06:41:21 +00001968 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001969 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001970 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001971 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1972 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001973 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001974 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregor71dc5092009-08-06 06:41:21 +00001976 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001977 NNS == DTN->getQualifier() &&
1978 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001979 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001980
Douglas Gregor71395fa2009-11-04 00:56:37 +00001981 if (DTN->isIdentifier())
1982 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1983 ObjectType);
1984
1985 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1986 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001987 }
Mike Stump11289f42009-09-09 15:08:12 +00001988
Douglas Gregor71dc5092009-08-06 06:41:21 +00001989 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001990 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001991 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001992 if (!TransTemplate)
1993 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregor71dc5092009-08-06 06:41:21 +00001995 if (!getDerived().AlwaysRebuild() &&
1996 TransTemplate == Template)
1997 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001998
Douglas Gregor71dc5092009-08-06 06:41:21 +00001999 return TemplateName(TransTemplate);
2000 }
Mike Stump11289f42009-09-09 15:08:12 +00002001
John McCalle66edc12009-11-24 19:00:30 +00002002 // These should be getting filtered out before they reach the AST.
2003 assert(false && "overloaded function decl survived to here");
2004 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002005}
2006
2007template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002008void TreeTransform<Derived>::InventTemplateArgumentLoc(
2009 const TemplateArgument &Arg,
2010 TemplateArgumentLoc &Output) {
2011 SourceLocation Loc = getDerived().getBaseLocation();
2012 switch (Arg.getKind()) {
2013 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002014 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002015 break;
2016
2017 case TemplateArgument::Type:
2018 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002019 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002020
2021 break;
2022
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002023 case TemplateArgument::Template:
2024 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2025 break;
2026
John McCall0ad16662009-10-29 08:12:44 +00002027 case TemplateArgument::Expression:
2028 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2029 break;
2030
2031 case TemplateArgument::Declaration:
2032 case TemplateArgument::Integral:
2033 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002034 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002035 break;
2036 }
2037}
2038
2039template<typename Derived>
2040bool TreeTransform<Derived>::TransformTemplateArgument(
2041 const TemplateArgumentLoc &Input,
2042 TemplateArgumentLoc &Output) {
2043 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002044 switch (Arg.getKind()) {
2045 case TemplateArgument::Null:
2046 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002047 Output = Input;
2048 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002049
Douglas Gregore922c772009-08-04 22:27:00 +00002050 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002051 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002052 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002053 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002054
2055 DI = getDerived().TransformType(DI);
2056 if (!DI) return true;
2057
2058 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2059 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002060 }
Mike Stump11289f42009-09-09 15:08:12 +00002061
Douglas Gregore922c772009-08-04 22:27:00 +00002062 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002063 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002064 DeclarationName Name;
2065 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2066 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002067 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002068 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002069 if (!D) return true;
2070
John McCall0d07eb32009-10-29 18:45:58 +00002071 Expr *SourceExpr = Input.getSourceDeclExpression();
2072 if (SourceExpr) {
2073 EnterExpressionEvaluationContext Unevaluated(getSema(),
2074 Action::Unevaluated);
2075 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2076 if (E.isInvalid())
2077 SourceExpr = NULL;
2078 else {
2079 SourceExpr = E.takeAs<Expr>();
2080 SourceExpr->Retain();
2081 }
2082 }
2083
2084 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002085 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002086 }
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002088 case TemplateArgument::Template: {
2089 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2090 TemplateName Template
2091 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2092 if (Template.isNull())
2093 return true;
2094
2095 Output = TemplateArgumentLoc(TemplateArgument(Template),
2096 Input.getTemplateQualifierRange(),
2097 Input.getTemplateNameLoc());
2098 return false;
2099 }
2100
Douglas Gregore922c772009-08-04 22:27:00 +00002101 case TemplateArgument::Expression: {
2102 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002103 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002104 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002105
John McCall0ad16662009-10-29 08:12:44 +00002106 Expr *InputExpr = Input.getSourceExpression();
2107 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2108
2109 Sema::OwningExprResult E
2110 = getDerived().TransformExpr(InputExpr);
2111 if (E.isInvalid()) return true;
2112
2113 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002114 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002115 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2116 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002117 }
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregore922c772009-08-04 22:27:00 +00002119 case TemplateArgument::Pack: {
2120 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2121 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002122 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002123 AEnd = Arg.pack_end();
2124 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002125
John McCall0ad16662009-10-29 08:12:44 +00002126 // FIXME: preserve source information here when we start
2127 // caring about parameter packs.
2128
John McCall0d07eb32009-10-29 18:45:58 +00002129 TemplateArgumentLoc InputArg;
2130 TemplateArgumentLoc OutputArg;
2131 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2132 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002133 return true;
2134
John McCall0d07eb32009-10-29 18:45:58 +00002135 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002136 }
2137 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002138 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002139 true);
John McCall0d07eb32009-10-29 18:45:58 +00002140 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002141 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002142 }
2143 }
Mike Stump11289f42009-09-09 15:08:12 +00002144
Douglas Gregore922c772009-08-04 22:27:00 +00002145 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002146 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002147}
2148
Douglas Gregord6ff3322009-08-04 16:50:30 +00002149//===----------------------------------------------------------------------===//
2150// Type transformation
2151//===----------------------------------------------------------------------===//
2152
2153template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002154QualType TreeTransform<Derived>::TransformType(QualType T,
2155 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002156 if (getDerived().AlreadyTransformed(T))
2157 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002158
John McCall550e0c22009-10-21 00:40:46 +00002159 // Temporary workaround. All of these transformations should
2160 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002161 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002162 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002163
Douglas Gregorfe17d252010-02-16 19:09:40 +00002164 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002165
John McCall550e0c22009-10-21 00:40:46 +00002166 if (!NewDI)
2167 return QualType();
2168
2169 return NewDI->getType();
2170}
2171
2172template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002173TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2174 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002175 if (getDerived().AlreadyTransformed(DI->getType()))
2176 return DI;
2177
2178 TypeLocBuilder TLB;
2179
2180 TypeLoc TL = DI->getTypeLoc();
2181 TLB.reserve(TL.getFullDataSize());
2182
Douglas Gregorfe17d252010-02-16 19:09:40 +00002183 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002184 if (Result.isNull())
2185 return 0;
2186
John McCallbcd03502009-12-07 02:54:59 +00002187 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002188}
2189
2190template<typename Derived>
2191QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002192TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2193 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002194 switch (T.getTypeLocClass()) {
2195#define ABSTRACT_TYPELOC(CLASS, PARENT)
2196#define TYPELOC(CLASS, PARENT) \
2197 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002198 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2199 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002200#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002203 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002204 return QualType();
2205}
2206
2207/// FIXME: By default, this routine adds type qualifiers only to types
2208/// that can have qualifiers, and silently suppresses those qualifiers
2209/// that are not permitted (e.g., qualifiers on reference or function
2210/// types). This is the right thing for template instantiation, but
2211/// probably not for other clients.
2212template<typename Derived>
2213QualType
2214TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002215 QualifiedTypeLoc T,
2216 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002217 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002218
Douglas Gregorfe17d252010-02-16 19:09:40 +00002219 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2220 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002221 if (Result.isNull())
2222 return QualType();
2223
2224 // Silently suppress qualifiers if the result type can't be qualified.
2225 // FIXME: this is the right thing for template instantiation, but
2226 // probably not for other clients.
2227 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002228 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002229
John McCall550e0c22009-10-21 00:40:46 +00002230 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2231
2232 TLB.push<QualifiedTypeLoc>(Result);
2233
2234 // No location information to preserve.
2235
2236 return Result;
2237}
2238
2239template <class TyLoc> static inline
2240QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2241 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2242 NewT.setNameLoc(T.getNameLoc());
2243 return T.getType();
2244}
2245
John McCall550e0c22009-10-21 00:40:46 +00002246template<typename Derived>
2247QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002248 BuiltinTypeLoc T,
2249 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002250 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2251 NewT.setBuiltinLoc(T.getBuiltinLoc());
2252 if (T.needsExtraLocalData())
2253 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2254 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002255}
Mike Stump11289f42009-09-09 15:08:12 +00002256
Douglas Gregord6ff3322009-08-04 16:50:30 +00002257template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002258QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002259 ComplexTypeLoc T,
2260 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002261 // FIXME: recurse?
2262 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002263}
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregord6ff3322009-08-04 16:50:30 +00002265template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002266QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002267 PointerTypeLoc TL,
2268 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002269 QualType PointeeType
2270 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2271 if (PointeeType.isNull())
2272 return QualType();
2273
2274 QualType Result = TL.getType();
2275 if (PointeeType->isObjCInterfaceType()) {
2276 // A dependent pointer type 'T *' has is being transformed such
2277 // that an Objective-C class type is being replaced for 'T'. The
2278 // resulting pointer type is an ObjCObjectPointerType, not a
2279 // PointerType.
2280 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2281 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2282 const_cast<ObjCProtocolDecl **>(
2283 IFace->qual_begin()),
2284 IFace->getNumProtocols());
2285
2286 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2287 NewT.setStarLoc(TL.getSigilLoc());
2288 NewT.setHasProtocolsAsWritten(false);
2289 NewT.setLAngleLoc(SourceLocation());
2290 NewT.setRAngleLoc(SourceLocation());
2291 NewT.setHasBaseTypeAsWritten(true);
2292 return Result;
2293 }
2294
2295 if (getDerived().AlwaysRebuild() ||
2296 PointeeType != TL.getPointeeLoc().getType()) {
2297 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2298 if (Result.isNull())
2299 return QualType();
2300 }
2301
2302 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2303 NewT.setSigilLoc(TL.getSigilLoc());
2304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002305}
Mike Stump11289f42009-09-09 15:08:12 +00002306
2307template<typename Derived>
2308QualType
John McCall550e0c22009-10-21 00:40:46 +00002309TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002310 BlockPointerTypeLoc TL,
2311 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002312 QualType PointeeType
2313 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2314 if (PointeeType.isNull())
2315 return QualType();
2316
2317 QualType Result = TL.getType();
2318 if (getDerived().AlwaysRebuild() ||
2319 PointeeType != TL.getPointeeLoc().getType()) {
2320 Result = getDerived().RebuildBlockPointerType(PointeeType,
2321 TL.getSigilLoc());
2322 if (Result.isNull())
2323 return QualType();
2324 }
2325
Douglas Gregor049211a2010-04-22 16:50:51 +00002326 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002327 NewT.setSigilLoc(TL.getSigilLoc());
2328 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329}
2330
John McCall70dd5f62009-10-30 00:06:24 +00002331/// Transforms a reference type. Note that somewhat paradoxically we
2332/// don't care whether the type itself is an l-value type or an r-value
2333/// type; we only care if the type was *written* as an l-value type
2334/// or an r-value type.
2335template<typename Derived>
2336QualType
2337TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002338 ReferenceTypeLoc TL,
2339 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002340 const ReferenceType *T = TL.getTypePtr();
2341
2342 // Note that this works with the pointee-as-written.
2343 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2344 if (PointeeType.isNull())
2345 return QualType();
2346
2347 QualType Result = TL.getType();
2348 if (getDerived().AlwaysRebuild() ||
2349 PointeeType != T->getPointeeTypeAsWritten()) {
2350 Result = getDerived().RebuildReferenceType(PointeeType,
2351 T->isSpelledAsLValue(),
2352 TL.getSigilLoc());
2353 if (Result.isNull())
2354 return QualType();
2355 }
2356
2357 // r-value references can be rebuilt as l-value references.
2358 ReferenceTypeLoc NewTL;
2359 if (isa<LValueReferenceType>(Result))
2360 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2361 else
2362 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2363 NewTL.setSigilLoc(TL.getSigilLoc());
2364
2365 return Result;
2366}
2367
Mike Stump11289f42009-09-09 15:08:12 +00002368template<typename Derived>
2369QualType
John McCall550e0c22009-10-21 00:40:46 +00002370TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002371 LValueReferenceTypeLoc TL,
2372 QualType ObjectType) {
2373 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002374}
2375
Mike Stump11289f42009-09-09 15:08:12 +00002376template<typename Derived>
2377QualType
John McCall550e0c22009-10-21 00:40:46 +00002378TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002379 RValueReferenceTypeLoc TL,
2380 QualType ObjectType) {
2381 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002382}
Mike Stump11289f42009-09-09 15:08:12 +00002383
Douglas Gregord6ff3322009-08-04 16:50:30 +00002384template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002385QualType
John McCall550e0c22009-10-21 00:40:46 +00002386TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002387 MemberPointerTypeLoc TL,
2388 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002389 MemberPointerType *T = TL.getTypePtr();
2390
2391 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002392 if (PointeeType.isNull())
2393 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002394
John McCall550e0c22009-10-21 00:40:46 +00002395 // TODO: preserve source information for this.
2396 QualType ClassType
2397 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002398 if (ClassType.isNull())
2399 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002400
John McCall550e0c22009-10-21 00:40:46 +00002401 QualType Result = TL.getType();
2402 if (getDerived().AlwaysRebuild() ||
2403 PointeeType != T->getPointeeType() ||
2404 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002405 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2406 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002407 if (Result.isNull())
2408 return QualType();
2409 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410
John McCall550e0c22009-10-21 00:40:46 +00002411 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2412 NewTL.setSigilLoc(TL.getSigilLoc());
2413
2414 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002415}
2416
Mike Stump11289f42009-09-09 15:08:12 +00002417template<typename Derived>
2418QualType
John McCall550e0c22009-10-21 00:40:46 +00002419TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002420 ConstantArrayTypeLoc TL,
2421 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002422 ConstantArrayType *T = TL.getTypePtr();
2423 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002424 if (ElementType.isNull())
2425 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002426
John McCall550e0c22009-10-21 00:40:46 +00002427 QualType Result = TL.getType();
2428 if (getDerived().AlwaysRebuild() ||
2429 ElementType != T->getElementType()) {
2430 Result = getDerived().RebuildConstantArrayType(ElementType,
2431 T->getSizeModifier(),
2432 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002433 T->getIndexTypeCVRQualifiers(),
2434 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002435 if (Result.isNull())
2436 return QualType();
2437 }
2438
2439 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2440 NewTL.setLBracketLoc(TL.getLBracketLoc());
2441 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002442
John McCall550e0c22009-10-21 00:40:46 +00002443 Expr *Size = TL.getSizeExpr();
2444 if (Size) {
2445 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2446 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2447 }
2448 NewTL.setSizeExpr(Size);
2449
2450 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002451}
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregord6ff3322009-08-04 16:50:30 +00002453template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002454QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002455 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002456 IncompleteArrayTypeLoc TL,
2457 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002458 IncompleteArrayType *T = TL.getTypePtr();
2459 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002460 if (ElementType.isNull())
2461 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002462
John McCall550e0c22009-10-21 00:40:46 +00002463 QualType Result = TL.getType();
2464 if (getDerived().AlwaysRebuild() ||
2465 ElementType != T->getElementType()) {
2466 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002467 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002468 T->getIndexTypeCVRQualifiers(),
2469 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002470 if (Result.isNull())
2471 return QualType();
2472 }
2473
2474 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2475 NewTL.setLBracketLoc(TL.getLBracketLoc());
2476 NewTL.setRBracketLoc(TL.getRBracketLoc());
2477 NewTL.setSizeExpr(0);
2478
2479 return Result;
2480}
2481
2482template<typename Derived>
2483QualType
2484TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002485 VariableArrayTypeLoc TL,
2486 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002487 VariableArrayType *T = TL.getTypePtr();
2488 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2489 if (ElementType.isNull())
2490 return QualType();
2491
2492 // Array bounds are not potentially evaluated contexts
2493 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2494
2495 Sema::OwningExprResult SizeResult
2496 = getDerived().TransformExpr(T->getSizeExpr());
2497 if (SizeResult.isInvalid())
2498 return QualType();
2499
2500 Expr *Size = static_cast<Expr*>(SizeResult.get());
2501
2502 QualType Result = TL.getType();
2503 if (getDerived().AlwaysRebuild() ||
2504 ElementType != T->getElementType() ||
2505 Size != T->getSizeExpr()) {
2506 Result = getDerived().RebuildVariableArrayType(ElementType,
2507 T->getSizeModifier(),
2508 move(SizeResult),
2509 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002510 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002511 if (Result.isNull())
2512 return QualType();
2513 }
2514 else SizeResult.take();
2515
2516 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2517 NewTL.setLBracketLoc(TL.getLBracketLoc());
2518 NewTL.setRBracketLoc(TL.getRBracketLoc());
2519 NewTL.setSizeExpr(Size);
2520
2521 return Result;
2522}
2523
2524template<typename Derived>
2525QualType
2526TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002527 DependentSizedArrayTypeLoc TL,
2528 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002529 DependentSizedArrayType *T = TL.getTypePtr();
2530 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2531 if (ElementType.isNull())
2532 return QualType();
2533
2534 // Array bounds are not potentially evaluated contexts
2535 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2536
2537 Sema::OwningExprResult SizeResult
2538 = getDerived().TransformExpr(T->getSizeExpr());
2539 if (SizeResult.isInvalid())
2540 return QualType();
2541
2542 Expr *Size = static_cast<Expr*>(SizeResult.get());
2543
2544 QualType Result = TL.getType();
2545 if (getDerived().AlwaysRebuild() ||
2546 ElementType != T->getElementType() ||
2547 Size != T->getSizeExpr()) {
2548 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2549 T->getSizeModifier(),
2550 move(SizeResult),
2551 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002552 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002553 if (Result.isNull())
2554 return QualType();
2555 }
2556 else SizeResult.take();
2557
2558 // We might have any sort of array type now, but fortunately they
2559 // all have the same location layout.
2560 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2561 NewTL.setLBracketLoc(TL.getLBracketLoc());
2562 NewTL.setRBracketLoc(TL.getRBracketLoc());
2563 NewTL.setSizeExpr(Size);
2564
2565 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002566}
Mike Stump11289f42009-09-09 15:08:12 +00002567
2568template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002569QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002570 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002571 DependentSizedExtVectorTypeLoc TL,
2572 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002573 DependentSizedExtVectorType *T = TL.getTypePtr();
2574
2575 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576 QualType ElementType = getDerived().TransformType(T->getElementType());
2577 if (ElementType.isNull())
2578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002579
Douglas Gregore922c772009-08-04 22:27:00 +00002580 // Vector sizes are not potentially evaluated contexts
2581 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2582
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2584 if (Size.isInvalid())
2585 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002586
John McCall550e0c22009-10-21 00:40:46 +00002587 QualType Result = TL.getType();
2588 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002589 ElementType != T->getElementType() ||
2590 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002591 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002592 move(Size),
2593 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002594 if (Result.isNull())
2595 return QualType();
2596 }
2597 else Size.take();
2598
2599 // Result might be dependent or not.
2600 if (isa<DependentSizedExtVectorType>(Result)) {
2601 DependentSizedExtVectorTypeLoc NewTL
2602 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2603 NewTL.setNameLoc(TL.getNameLoc());
2604 } else {
2605 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2606 NewTL.setNameLoc(TL.getNameLoc());
2607 }
2608
2609 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610}
Mike Stump11289f42009-09-09 15:08:12 +00002611
2612template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002613QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002614 VectorTypeLoc TL,
2615 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002616 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002617 QualType ElementType = getDerived().TransformType(T->getElementType());
2618 if (ElementType.isNull())
2619 return QualType();
2620
John McCall550e0c22009-10-21 00:40:46 +00002621 QualType Result = TL.getType();
2622 if (getDerived().AlwaysRebuild() ||
2623 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002624 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2625 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002626 if (Result.isNull())
2627 return QualType();
2628 }
2629
2630 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2631 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002632
John McCall550e0c22009-10-21 00:40:46 +00002633 return Result;
2634}
2635
2636template<typename Derived>
2637QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002638 ExtVectorTypeLoc TL,
2639 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002640 VectorType *T = TL.getTypePtr();
2641 QualType ElementType = getDerived().TransformType(T->getElementType());
2642 if (ElementType.isNull())
2643 return QualType();
2644
2645 QualType Result = TL.getType();
2646 if (getDerived().AlwaysRebuild() ||
2647 ElementType != T->getElementType()) {
2648 Result = getDerived().RebuildExtVectorType(ElementType,
2649 T->getNumElements(),
2650 /*FIXME*/ SourceLocation());
2651 if (Result.isNull())
2652 return QualType();
2653 }
2654
2655 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2656 NewTL.setNameLoc(TL.getNameLoc());
2657
2658 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002659}
Mike Stump11289f42009-09-09 15:08:12 +00002660
2661template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002662ParmVarDecl *
2663TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2664 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2665 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2666 if (!NewDI)
2667 return 0;
2668
2669 if (NewDI == OldDI)
2670 return OldParm;
2671 else
2672 return ParmVarDecl::Create(SemaRef.Context,
2673 OldParm->getDeclContext(),
2674 OldParm->getLocation(),
2675 OldParm->getIdentifier(),
2676 NewDI->getType(),
2677 NewDI,
2678 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002679 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002680 /* DefArg */ NULL);
2681}
2682
2683template<typename Derived>
2684bool TreeTransform<Derived>::
2685 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2686 llvm::SmallVectorImpl<QualType> &PTypes,
2687 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2688 FunctionProtoType *T = TL.getTypePtr();
2689
2690 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2691 ParmVarDecl *OldParm = TL.getArg(i);
2692
2693 QualType NewType;
2694 ParmVarDecl *NewParm;
2695
2696 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002697 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2698 if (!NewParm)
2699 return true;
2700 NewType = NewParm->getType();
2701
2702 // Deal with the possibility that we don't have a parameter
2703 // declaration for this parameter.
2704 } else {
2705 NewParm = 0;
2706
2707 QualType OldType = T->getArgType(i);
2708 NewType = getDerived().TransformType(OldType);
2709 if (NewType.isNull())
2710 return true;
2711 }
2712
2713 PTypes.push_back(NewType);
2714 PVars.push_back(NewParm);
2715 }
2716
2717 return false;
2718}
2719
2720template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002721QualType
John McCall550e0c22009-10-21 00:40:46 +00002722TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002723 FunctionProtoTypeLoc TL,
2724 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002725 FunctionProtoType *T = TL.getTypePtr();
2726 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002727 if (ResultType.isNull())
2728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002729
John McCall550e0c22009-10-21 00:40:46 +00002730 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002731 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002732 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002733 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2734 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002735
John McCall550e0c22009-10-21 00:40:46 +00002736 QualType Result = TL.getType();
2737 if (getDerived().AlwaysRebuild() ||
2738 ResultType != T->getResultType() ||
2739 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2740 Result = getDerived().RebuildFunctionProtoType(ResultType,
2741 ParamTypes.data(),
2742 ParamTypes.size(),
2743 T->isVariadic(),
2744 T->getTypeQuals());
2745 if (Result.isNull())
2746 return QualType();
2747 }
Mike Stump11289f42009-09-09 15:08:12 +00002748
John McCall550e0c22009-10-21 00:40:46 +00002749 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2750 NewTL.setLParenLoc(TL.getLParenLoc());
2751 NewTL.setRParenLoc(TL.getRParenLoc());
2752 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2753 NewTL.setArg(i, ParamDecls[i]);
2754
2755 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756}
Mike Stump11289f42009-09-09 15:08:12 +00002757
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758template<typename Derived>
2759QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002760 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002761 FunctionNoProtoTypeLoc TL,
2762 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002763 FunctionNoProtoType *T = TL.getTypePtr();
2764 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2765 if (ResultType.isNull())
2766 return QualType();
2767
2768 QualType Result = TL.getType();
2769 if (getDerived().AlwaysRebuild() ||
2770 ResultType != T->getResultType())
2771 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2772
2773 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2774 NewTL.setLParenLoc(TL.getLParenLoc());
2775 NewTL.setRParenLoc(TL.getRParenLoc());
2776
2777 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778}
Mike Stump11289f42009-09-09 15:08:12 +00002779
John McCallb96ec562009-12-04 22:46:56 +00002780template<typename Derived> QualType
2781TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002782 UnresolvedUsingTypeLoc TL,
2783 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002784 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002785 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002786 if (!D)
2787 return QualType();
2788
2789 QualType Result = TL.getType();
2790 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2791 Result = getDerived().RebuildUnresolvedUsingType(D);
2792 if (Result.isNull())
2793 return QualType();
2794 }
2795
2796 // We might get an arbitrary type spec type back. We should at
2797 // least always get a type spec type, though.
2798 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2799 NewTL.setNameLoc(TL.getNameLoc());
2800
2801 return Result;
2802}
2803
Douglas Gregord6ff3322009-08-04 16:50:30 +00002804template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002805QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002806 TypedefTypeLoc TL,
2807 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002808 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002809 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002810 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2811 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002812 if (!Typedef)
2813 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002814
John McCall550e0c22009-10-21 00:40:46 +00002815 QualType Result = TL.getType();
2816 if (getDerived().AlwaysRebuild() ||
2817 Typedef != T->getDecl()) {
2818 Result = getDerived().RebuildTypedefType(Typedef);
2819 if (Result.isNull())
2820 return QualType();
2821 }
Mike Stump11289f42009-09-09 15:08:12 +00002822
John McCall550e0c22009-10-21 00:40:46 +00002823 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2824 NewTL.setNameLoc(TL.getNameLoc());
2825
2826 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002827}
Mike Stump11289f42009-09-09 15:08:12 +00002828
Douglas Gregord6ff3322009-08-04 16:50:30 +00002829template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002830QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002831 TypeOfExprTypeLoc TL,
2832 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002833 // typeof expressions are not potentially evaluated contexts
2834 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002835
John McCalle8595032010-01-13 20:03:27 +00002836 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837 if (E.isInvalid())
2838 return QualType();
2839
John McCall550e0c22009-10-21 00:40:46 +00002840 QualType Result = TL.getType();
2841 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002842 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002843 Result = getDerived().RebuildTypeOfExprType(move(E));
2844 if (Result.isNull())
2845 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002846 }
John McCall550e0c22009-10-21 00:40:46 +00002847 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002848
John McCall550e0c22009-10-21 00:40:46 +00002849 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002850 NewTL.setTypeofLoc(TL.getTypeofLoc());
2851 NewTL.setLParenLoc(TL.getLParenLoc());
2852 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002853
2854 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002855}
Mike Stump11289f42009-09-09 15:08:12 +00002856
2857template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002858QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002859 TypeOfTypeLoc TL,
2860 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002861 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2862 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2863 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002864 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002865
John McCall550e0c22009-10-21 00:40:46 +00002866 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002867 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2868 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002869 if (Result.isNull())
2870 return QualType();
2871 }
Mike Stump11289f42009-09-09 15:08:12 +00002872
John McCall550e0c22009-10-21 00:40:46 +00002873 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002874 NewTL.setTypeofLoc(TL.getTypeofLoc());
2875 NewTL.setLParenLoc(TL.getLParenLoc());
2876 NewTL.setRParenLoc(TL.getRParenLoc());
2877 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002878
2879 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002880}
Mike Stump11289f42009-09-09 15:08:12 +00002881
2882template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002883QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002884 DecltypeTypeLoc TL,
2885 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002886 DecltypeType *T = TL.getTypePtr();
2887
Douglas Gregore922c772009-08-04 22:27:00 +00002888 // decltype expressions are not potentially evaluated contexts
2889 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002890
Douglas Gregord6ff3322009-08-04 16:50:30 +00002891 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2892 if (E.isInvalid())
2893 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002894
John McCall550e0c22009-10-21 00:40:46 +00002895 QualType Result = TL.getType();
2896 if (getDerived().AlwaysRebuild() ||
2897 E.get() != T->getUnderlyingExpr()) {
2898 Result = getDerived().RebuildDecltypeType(move(E));
2899 if (Result.isNull())
2900 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002901 }
John McCall550e0c22009-10-21 00:40:46 +00002902 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002903
John McCall550e0c22009-10-21 00:40:46 +00002904 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2905 NewTL.setNameLoc(TL.getNameLoc());
2906
2907 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002908}
2909
2910template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002911QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002912 RecordTypeLoc TL,
2913 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002914 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002915 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002916 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2917 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002918 if (!Record)
2919 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002920
John McCall550e0c22009-10-21 00:40:46 +00002921 QualType Result = TL.getType();
2922 if (getDerived().AlwaysRebuild() ||
2923 Record != T->getDecl()) {
2924 Result = getDerived().RebuildRecordType(Record);
2925 if (Result.isNull())
2926 return QualType();
2927 }
Mike Stump11289f42009-09-09 15:08:12 +00002928
John McCall550e0c22009-10-21 00:40:46 +00002929 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2930 NewTL.setNameLoc(TL.getNameLoc());
2931
2932 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933}
Mike Stump11289f42009-09-09 15:08:12 +00002934
2935template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002936QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002937 EnumTypeLoc TL,
2938 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002939 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002941 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2942 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943 if (!Enum)
2944 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002945
John McCall550e0c22009-10-21 00:40:46 +00002946 QualType Result = TL.getType();
2947 if (getDerived().AlwaysRebuild() ||
2948 Enum != T->getDecl()) {
2949 Result = getDerived().RebuildEnumType(Enum);
2950 if (Result.isNull())
2951 return QualType();
2952 }
Mike Stump11289f42009-09-09 15:08:12 +00002953
John McCall550e0c22009-10-21 00:40:46 +00002954 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2955 NewTL.setNameLoc(TL.getNameLoc());
2956
2957 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002958}
John McCallfcc33b02009-09-05 00:15:47 +00002959
2960template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002961QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002962 ElaboratedTypeLoc TL,
2963 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002964 ElaboratedType *T = TL.getTypePtr();
2965
2966 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002967 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2968 if (Underlying.isNull())
2969 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002970
John McCall550e0c22009-10-21 00:40:46 +00002971 QualType Result = TL.getType();
2972 if (getDerived().AlwaysRebuild() ||
2973 Underlying != T->getUnderlyingType()) {
2974 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2975 if (Result.isNull())
2976 return QualType();
2977 }
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2980 NewTL.setNameLoc(TL.getNameLoc());
2981
2982 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002983}
Mike Stump11289f42009-09-09 15:08:12 +00002984
John McCalle78aac42010-03-10 03:28:59 +00002985template<typename Derived>
2986QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2987 TypeLocBuilder &TLB,
2988 InjectedClassNameTypeLoc TL,
2989 QualType ObjectType) {
2990 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2991 TL.getTypePtr()->getDecl());
2992 if (!D) return QualType();
2993
2994 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2995 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2996 return T;
2997}
2998
Mike Stump11289f42009-09-09 15:08:12 +00002999
Douglas Gregord6ff3322009-08-04 16:50:30 +00003000template<typename Derived>
3001QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003002 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003003 TemplateTypeParmTypeLoc TL,
3004 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003005 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003006}
3007
Mike Stump11289f42009-09-09 15:08:12 +00003008template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003009QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003010 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003011 SubstTemplateTypeParmTypeLoc TL,
3012 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003013 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003014}
3015
3016template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003017QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3018 const TemplateSpecializationType *TST,
3019 QualType ObjectType) {
3020 // FIXME: this entire method is a temporary workaround; callers
3021 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003022
John McCall0ad16662009-10-29 08:12:44 +00003023 // Fake up a TemplateSpecializationTypeLoc.
3024 TypeLocBuilder TLB;
3025 TemplateSpecializationTypeLoc TL
3026 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3027
John McCall0d07eb32009-10-29 18:45:58 +00003028 SourceLocation BaseLoc = getDerived().getBaseLocation();
3029
3030 TL.setTemplateNameLoc(BaseLoc);
3031 TL.setLAngleLoc(BaseLoc);
3032 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003033 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3034 const TemplateArgument &TA = TST->getArg(i);
3035 TemplateArgumentLoc TAL;
3036 getDerived().InventTemplateArgumentLoc(TA, TAL);
3037 TL.setArgLocInfo(i, TAL.getLocInfo());
3038 }
3039
3040 TypeLocBuilder IgnoredTLB;
3041 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003042}
3043
3044template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003045QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003046 TypeLocBuilder &TLB,
3047 TemplateSpecializationTypeLoc TL,
3048 QualType ObjectType) {
3049 const TemplateSpecializationType *T = TL.getTypePtr();
3050
Mike Stump11289f42009-09-09 15:08:12 +00003051 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003052 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003053 if (Template.isNull())
3054 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003055
John McCall6b51f282009-11-23 01:53:49 +00003056 TemplateArgumentListInfo NewTemplateArgs;
3057 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3058 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3059
3060 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3061 TemplateArgumentLoc Loc;
3062 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003064 NewTemplateArgs.addArgument(Loc);
3065 }
Mike Stump11289f42009-09-09 15:08:12 +00003066
John McCall0ad16662009-10-29 08:12:44 +00003067 // FIXME: maybe don't rebuild if all the template arguments are the same.
3068
3069 QualType Result =
3070 getDerived().RebuildTemplateSpecializationType(Template,
3071 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003072 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003073
3074 if (!Result.isNull()) {
3075 TemplateSpecializationTypeLoc NewTL
3076 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3077 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3078 NewTL.setLAngleLoc(TL.getLAngleLoc());
3079 NewTL.setRAngleLoc(TL.getRAngleLoc());
3080 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3081 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003082 }
Mike Stump11289f42009-09-09 15:08:12 +00003083
John McCall0ad16662009-10-29 08:12:44 +00003084 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003085}
Mike Stump11289f42009-09-09 15:08:12 +00003086
3087template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003088QualType
3089TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003090 QualifiedNameTypeLoc TL,
3091 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003092 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093 NestedNameSpecifier *NNS
3094 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003095 SourceRange(),
3096 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003097 if (!NNS)
3098 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003099
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100 QualType Named = getDerived().TransformType(T->getNamedType());
3101 if (Named.isNull())
3102 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 QualType Result = TL.getType();
3105 if (getDerived().AlwaysRebuild() ||
3106 NNS != T->getQualifier() ||
3107 Named != T->getNamedType()) {
3108 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3109 if (Result.isNull())
3110 return QualType();
3111 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112
John McCall550e0c22009-10-21 00:40:46 +00003113 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3114 NewTL.setNameLoc(TL.getNameLoc());
3115
3116 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117}
Mike Stump11289f42009-09-09 15:08:12 +00003118
3119template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003120QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3121 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003122 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003123 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003124
3125 /* FIXME: preserve source information better than this */
3126 SourceRange SR(TL.getNameLoc());
3127
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003129 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003130 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003131 if (!NNS)
3132 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003133
John McCall550e0c22009-10-21 00:40:46 +00003134 QualType Result;
3135
Douglas Gregord6ff3322009-08-04 16:50:30 +00003136 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003137 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003138 = getDerived().TransformType(QualType(TemplateId, 0));
3139 if (NewTemplateId.isNull())
3140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142 if (!getDerived().AlwaysRebuild() &&
3143 NNS == T->getQualifier() &&
3144 NewTemplateId == QualType(TemplateId, 0))
3145 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003146
Douglas Gregor02085352010-03-31 20:19:30 +00003147 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3148 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003149 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003150 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3151 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 }
John McCall550e0c22009-10-21 00:40:46 +00003153 if (Result.isNull())
3154 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003155
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003156 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003157 NewTL.setNameLoc(TL.getNameLoc());
3158
3159 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003160}
Mike Stump11289f42009-09-09 15:08:12 +00003161
Douglas Gregord6ff3322009-08-04 16:50:30 +00003162template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003163QualType
3164TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003165 ObjCInterfaceTypeLoc TL,
3166 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003167 // ObjCInterfaceType is never dependent.
3168 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003169}
Mike Stump11289f42009-09-09 15:08:12 +00003170
3171template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003172QualType
3173TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003174 ObjCObjectPointerTypeLoc TL,
3175 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003176 // ObjCObjectPointerType is never dependent.
3177 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003178}
3179
Douglas Gregord6ff3322009-08-04 16:50:30 +00003180//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003181// Statement transformation
3182//===----------------------------------------------------------------------===//
3183template<typename Derived>
3184Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003185TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3186 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003187}
3188
3189template<typename Derived>
3190Sema::OwningStmtResult
3191TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3192 return getDerived().TransformCompoundStmt(S, false);
3193}
3194
3195template<typename Derived>
3196Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003197TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003198 bool IsStmtExpr) {
3199 bool SubStmtChanged = false;
3200 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3201 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3202 B != BEnd; ++B) {
3203 OwningStmtResult Result = getDerived().TransformStmt(*B);
3204 if (Result.isInvalid())
3205 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003206
Douglas Gregorebe10102009-08-20 07:17:43 +00003207 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3208 Statements.push_back(Result.takeAs<Stmt>());
3209 }
Mike Stump11289f42009-09-09 15:08:12 +00003210
Douglas Gregorebe10102009-08-20 07:17:43 +00003211 if (!getDerived().AlwaysRebuild() &&
3212 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003213 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003214
3215 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3216 move_arg(Statements),
3217 S->getRBracLoc(),
3218 IsStmtExpr);
3219}
Mike Stump11289f42009-09-09 15:08:12 +00003220
Douglas Gregorebe10102009-08-20 07:17:43 +00003221template<typename Derived>
3222Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003223TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003224 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3225 {
3226 // The case value expressions are not potentially evaluated.
3227 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003228
Eli Friedman06577382009-11-19 03:14:00 +00003229 // Transform the left-hand case value.
3230 LHS = getDerived().TransformExpr(S->getLHS());
3231 if (LHS.isInvalid())
3232 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003233
Eli Friedman06577382009-11-19 03:14:00 +00003234 // Transform the right-hand case value (for the GNU case-range extension).
3235 RHS = getDerived().TransformExpr(S->getRHS());
3236 if (RHS.isInvalid())
3237 return SemaRef.StmtError();
3238 }
Mike Stump11289f42009-09-09 15:08:12 +00003239
Douglas Gregorebe10102009-08-20 07:17:43 +00003240 // Build the case statement.
3241 // Case statements are always rebuilt so that they will attached to their
3242 // transformed switch statement.
3243 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3244 move(LHS),
3245 S->getEllipsisLoc(),
3246 move(RHS),
3247 S->getColonLoc());
3248 if (Case.isInvalid())
3249 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003250
Douglas Gregorebe10102009-08-20 07:17:43 +00003251 // Transform the statement following the case
3252 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3253 if (SubStmt.isInvalid())
3254 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003255
Douglas Gregorebe10102009-08-20 07:17:43 +00003256 // Attach the body to the case statement
3257 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3258}
3259
3260template<typename Derived>
3261Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003262TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003263 // Transform the statement following the default case
3264 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3265 if (SubStmt.isInvalid())
3266 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003267
Douglas Gregorebe10102009-08-20 07:17:43 +00003268 // Default statements are always rebuilt
3269 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3270 move(SubStmt));
3271}
Mike Stump11289f42009-09-09 15:08:12 +00003272
Douglas Gregorebe10102009-08-20 07:17:43 +00003273template<typename Derived>
3274Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003275TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3277 if (SubStmt.isInvalid())
3278 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003279
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 // FIXME: Pass the real colon location in.
3281 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3282 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3283 move(SubStmt));
3284}
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregorebe10102009-08-20 07:17:43 +00003286template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003287Sema::OwningStmtResult
3288TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003289 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003290 OwningExprResult Cond(SemaRef);
3291 VarDecl *ConditionVar = 0;
3292 if (S->getConditionVariable()) {
3293 ConditionVar
3294 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003295 getDerived().TransformDefinition(
3296 S->getConditionVariable()->getLocation(),
3297 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003298 if (!ConditionVar)
3299 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003300 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003301 Cond = getDerived().TransformExpr(S->getCond());
3302
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003303 if (Cond.isInvalid())
3304 return SemaRef.StmtError();
3305 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003306
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003307 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003308
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 // Transform the "then" branch.
3310 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3311 if (Then.isInvalid())
3312 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregorebe10102009-08-20 07:17:43 +00003314 // Transform the "else" branch.
3315 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3316 if (Else.isInvalid())
3317 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003318
Douglas Gregorebe10102009-08-20 07:17:43 +00003319 if (!getDerived().AlwaysRebuild() &&
3320 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003321 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003322 Then.get() == S->getThen() &&
3323 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003324 return SemaRef.Owned(S->Retain());
3325
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003326 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3327 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003328 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003329}
3330
3331template<typename Derived>
3332Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003333TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003334 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003335 OwningExprResult Cond(SemaRef);
3336 VarDecl *ConditionVar = 0;
3337 if (S->getConditionVariable()) {
3338 ConditionVar
3339 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003340 getDerived().TransformDefinition(
3341 S->getConditionVariable()->getLocation(),
3342 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003343 if (!ConditionVar)
3344 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003345 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003346 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003347
3348 if (Cond.isInvalid())
3349 return SemaRef.StmtError();
3350 }
Mike Stump11289f42009-09-09 15:08:12 +00003351
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003352 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003353
Douglas Gregorebe10102009-08-20 07:17:43 +00003354 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003355 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3356 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003357 if (Switch.isInvalid())
3358 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003359
Douglas Gregorebe10102009-08-20 07:17:43 +00003360 // Transform the body of the switch statement.
3361 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3362 if (Body.isInvalid())
3363 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003364
Douglas Gregorebe10102009-08-20 07:17:43 +00003365 // Complete the switch statement.
3366 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3367 move(Body));
3368}
Mike Stump11289f42009-09-09 15:08:12 +00003369
Douglas Gregorebe10102009-08-20 07:17:43 +00003370template<typename Derived>
3371Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003372TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003373 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003374 OwningExprResult Cond(SemaRef);
3375 VarDecl *ConditionVar = 0;
3376 if (S->getConditionVariable()) {
3377 ConditionVar
3378 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003379 getDerived().TransformDefinition(
3380 S->getConditionVariable()->getLocation(),
3381 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003382 if (!ConditionVar)
3383 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003384 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003385 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003386
3387 if (Cond.isInvalid())
3388 return SemaRef.StmtError();
3389 }
Mike Stump11289f42009-09-09 15:08:12 +00003390
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003391 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregorebe10102009-08-20 07:17:43 +00003393 // Transform the body
3394 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3395 if (Body.isInvalid())
3396 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003397
Douglas Gregorebe10102009-08-20 07:17:43 +00003398 if (!getDerived().AlwaysRebuild() &&
3399 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003400 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003401 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003402 return SemaRef.Owned(S->Retain());
3403
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003404 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3405 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003406}
Mike Stump11289f42009-09-09 15:08:12 +00003407
Douglas Gregorebe10102009-08-20 07:17:43 +00003408template<typename Derived>
3409Sema::OwningStmtResult
3410TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3411 // Transform the condition
3412 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3413 if (Cond.isInvalid())
3414 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003415
Douglas Gregorebe10102009-08-20 07:17:43 +00003416 // Transform the body
3417 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3418 if (Body.isInvalid())
3419 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003420
Douglas Gregorebe10102009-08-20 07:17:43 +00003421 if (!getDerived().AlwaysRebuild() &&
3422 Cond.get() == S->getCond() &&
3423 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003424 return SemaRef.Owned(S->Retain());
3425
Douglas Gregorebe10102009-08-20 07:17:43 +00003426 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3427 /*FIXME:*/S->getWhileLoc(), move(Cond),
3428 S->getRParenLoc());
3429}
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregorebe10102009-08-20 07:17:43 +00003431template<typename Derived>
3432Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003433TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 // Transform the initialization statement
3435 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3436 if (Init.isInvalid())
3437 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003438
Douglas Gregorebe10102009-08-20 07:17:43 +00003439 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003440 OwningExprResult Cond(SemaRef);
3441 VarDecl *ConditionVar = 0;
3442 if (S->getConditionVariable()) {
3443 ConditionVar
3444 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003445 getDerived().TransformDefinition(
3446 S->getConditionVariable()->getLocation(),
3447 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003448 if (!ConditionVar)
3449 return SemaRef.StmtError();
3450 } else {
3451 Cond = getDerived().TransformExpr(S->getCond());
3452
3453 if (Cond.isInvalid())
3454 return SemaRef.StmtError();
3455 }
Mike Stump11289f42009-09-09 15:08:12 +00003456
Douglas Gregorebe10102009-08-20 07:17:43 +00003457 // Transform the increment
3458 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3459 if (Inc.isInvalid())
3460 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003461
Douglas Gregorebe10102009-08-20 07:17:43 +00003462 // Transform the body
3463 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3464 if (Body.isInvalid())
3465 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 if (!getDerived().AlwaysRebuild() &&
3468 Init.get() == S->getInit() &&
3469 Cond.get() == S->getCond() &&
3470 Inc.get() == S->getInc() &&
3471 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003472 return SemaRef.Owned(S->Retain());
3473
Douglas Gregorebe10102009-08-20 07:17:43 +00003474 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003475 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003476 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003477 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003478 S->getRParenLoc(), move(Body));
3479}
3480
3481template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003482Sema::OwningStmtResult
3483TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003484 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003485 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 S->getLabel());
3487}
3488
3489template<typename Derived>
3490Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003491TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003492 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3493 if (Target.isInvalid())
3494 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 if (!getDerived().AlwaysRebuild() &&
3497 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003498 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003499
3500 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3501 move(Target));
3502}
3503
3504template<typename Derived>
3505Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003506TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3507 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003508}
Mike Stump11289f42009-09-09 15:08:12 +00003509
Douglas Gregorebe10102009-08-20 07:17:43 +00003510template<typename Derived>
3511Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003512TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3513 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003514}
Mike Stump11289f42009-09-09 15:08:12 +00003515
Douglas Gregorebe10102009-08-20 07:17:43 +00003516template<typename Derived>
3517Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3520 if (Result.isInvalid())
3521 return SemaRef.StmtError();
3522
Mike Stump11289f42009-09-09 15:08:12 +00003523 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 // to tell whether the return type of the function has changed.
3525 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3526}
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregorebe10102009-08-20 07:17:43 +00003528template<typename Derived>
3529Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003530TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 bool DeclChanged = false;
3532 llvm::SmallVector<Decl *, 4> Decls;
3533 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3534 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003535 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3536 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003537 if (!Transformed)
3538 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003539
Douglas Gregorebe10102009-08-20 07:17:43 +00003540 if (Transformed != *D)
3541 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003542
Douglas Gregorebe10102009-08-20 07:17:43 +00003543 Decls.push_back(Transformed);
3544 }
Mike Stump11289f42009-09-09 15:08:12 +00003545
Douglas Gregorebe10102009-08-20 07:17:43 +00003546 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003547 return SemaRef.Owned(S->Retain());
3548
3549 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003550 S->getStartLoc(), S->getEndLoc());
3551}
Mike Stump11289f42009-09-09 15:08:12 +00003552
Douglas Gregorebe10102009-08-20 07:17:43 +00003553template<typename Derived>
3554Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003555TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003556 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003557 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003558}
3559
3560template<typename Derived>
3561Sema::OwningStmtResult
3562TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003563
3564 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3565 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003566 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003567
Anders Carlssonaaeef072010-01-24 05:50:09 +00003568 OwningExprResult AsmString(SemaRef);
3569 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3570
3571 bool ExprsChanged = false;
3572
3573 // Go through the outputs.
3574 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003575 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003576
Anders Carlssonaaeef072010-01-24 05:50:09 +00003577 // No need to transform the constraint literal.
3578 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3579
3580 // Transform the output expr.
3581 Expr *OutputExpr = S->getOutputExpr(I);
3582 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3583 if (Result.isInvalid())
3584 return SemaRef.StmtError();
3585
3586 ExprsChanged |= Result.get() != OutputExpr;
3587
3588 Exprs.push_back(Result.takeAs<Expr>());
3589 }
3590
3591 // Go through the inputs.
3592 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003593 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003594
Anders Carlssonaaeef072010-01-24 05:50:09 +00003595 // No need to transform the constraint literal.
3596 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3597
3598 // Transform the input expr.
3599 Expr *InputExpr = S->getInputExpr(I);
3600 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3601 if (Result.isInvalid())
3602 return SemaRef.StmtError();
3603
3604 ExprsChanged |= Result.get() != InputExpr;
3605
3606 Exprs.push_back(Result.takeAs<Expr>());
3607 }
3608
3609 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3610 return SemaRef.Owned(S->Retain());
3611
3612 // Go through the clobbers.
3613 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3614 Clobbers.push_back(S->getClobber(I)->Retain());
3615
3616 // No need to transform the asm string literal.
3617 AsmString = SemaRef.Owned(S->getAsmString());
3618
3619 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3620 S->isSimple(),
3621 S->isVolatile(),
3622 S->getNumOutputs(),
3623 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003624 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003625 move_arg(Constraints),
3626 move_arg(Exprs),
3627 move(AsmString),
3628 move_arg(Clobbers),
3629 S->getRParenLoc(),
3630 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003631}
3632
3633
3634template<typename Derived>
3635Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003636TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003637 // FIXME: Implement this
3638 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003639 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003640}
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregorebe10102009-08-20 07:17:43 +00003642template<typename Derived>
3643Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003644TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 // FIXME: Implement this
3646 assert(false && "Cannot transform an Objective-C @catch statement");
3647 return SemaRef.Owned(S->Retain());
3648}
Mike Stump11289f42009-09-09 15:08:12 +00003649
Douglas Gregorebe10102009-08-20 07:17:43 +00003650template<typename Derived>
3651Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003652TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003653 // FIXME: Implement this
3654 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003655 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003656}
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregorebe10102009-08-20 07:17:43 +00003658template<typename Derived>
3659Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003660TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003661 OwningExprResult Operand(SemaRef);
3662 if (S->getThrowExpr()) {
3663 Operand = getDerived().TransformExpr(S->getThrowExpr());
3664 if (Operand.isInvalid())
3665 return getSema().StmtError();
3666 }
3667
3668 if (!getDerived().AlwaysRebuild() &&
3669 Operand.get() == S->getThrowExpr())
3670 return getSema().Owned(S->Retain());
3671
3672 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003673}
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregorebe10102009-08-20 07:17:43 +00003675template<typename Derived>
3676Sema::OwningStmtResult
3677TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003678 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003679 // FIXME: Implement this
3680 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003681 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003682}
3683
3684template<typename Derived>
3685Sema::OwningStmtResult
3686TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003687 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003688 // FIXME: Implement this
3689 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003690 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003691}
3692
3693
3694template<typename Derived>
3695Sema::OwningStmtResult
3696TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3697 // Transform the exception declaration, if any.
3698 VarDecl *Var = 0;
3699 if (S->getExceptionDecl()) {
3700 VarDecl *ExceptionDecl = S->getExceptionDecl();
3701 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3702 ExceptionDecl->getDeclName());
3703
3704 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3705 if (T.isNull())
3706 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3709 T,
John McCallbcd03502009-12-07 02:54:59 +00003710 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003711 ExceptionDecl->getIdentifier(),
3712 ExceptionDecl->getLocation(),
3713 /*FIXME: Inaccurate*/
3714 SourceRange(ExceptionDecl->getLocation()));
3715 if (!Var || Var->isInvalidDecl()) {
3716 if (Var)
3717 Var->Destroy(SemaRef.Context);
3718 return SemaRef.StmtError();
3719 }
3720 }
Mike Stump11289f42009-09-09 15:08:12 +00003721
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 // Transform the actual exception handler.
3723 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3724 if (Handler.isInvalid()) {
3725 if (Var)
3726 Var->Destroy(SemaRef.Context);
3727 return SemaRef.StmtError();
3728 }
Mike Stump11289f42009-09-09 15:08:12 +00003729
Douglas Gregorebe10102009-08-20 07:17:43 +00003730 if (!getDerived().AlwaysRebuild() &&
3731 !Var &&
3732 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003733 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003734
3735 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3736 Var,
3737 move(Handler));
3738}
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740template<typename Derived>
3741Sema::OwningStmtResult
3742TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3743 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003744 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003745 = getDerived().TransformCompoundStmt(S->getTryBlock());
3746 if (TryBlock.isInvalid())
3747 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003748
Douglas Gregorebe10102009-08-20 07:17:43 +00003749 // Transform the handlers.
3750 bool HandlerChanged = false;
3751 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3752 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003753 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003754 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3755 if (Handler.isInvalid())
3756 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003757
Douglas Gregorebe10102009-08-20 07:17:43 +00003758 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3759 Handlers.push_back(Handler.takeAs<Stmt>());
3760 }
Mike Stump11289f42009-09-09 15:08:12 +00003761
Douglas Gregorebe10102009-08-20 07:17:43 +00003762 if (!getDerived().AlwaysRebuild() &&
3763 TryBlock.get() == S->getTryBlock() &&
3764 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003765 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003766
3767 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003768 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003769}
Mike Stump11289f42009-09-09 15:08:12 +00003770
Douglas Gregorebe10102009-08-20 07:17:43 +00003771//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003772// Expression transformation
3773//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003774template<typename Derived>
3775Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003776TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003777 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003778}
Mike Stump11289f42009-09-09 15:08:12 +00003779
3780template<typename Derived>
3781Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003782TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003783 NestedNameSpecifier *Qualifier = 0;
3784 if (E->getQualifier()) {
3785 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003786 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003787 if (!Qualifier)
3788 return SemaRef.ExprError();
3789 }
John McCallce546572009-12-08 09:08:17 +00003790
3791 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003792 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3793 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003794 if (!ND)
3795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003797 if (!getDerived().AlwaysRebuild() &&
3798 Qualifier == E->getQualifier() &&
3799 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003800 !E->hasExplicitTemplateArgumentList()) {
3801
3802 // Mark it referenced in the new context regardless.
3803 // FIXME: this is a bit instantiation-specific.
3804 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3805
Mike Stump11289f42009-09-09 15:08:12 +00003806 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003807 }
John McCallce546572009-12-08 09:08:17 +00003808
3809 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3810 if (E->hasExplicitTemplateArgumentList()) {
3811 TemplateArgs = &TransArgs;
3812 TransArgs.setLAngleLoc(E->getLAngleLoc());
3813 TransArgs.setRAngleLoc(E->getRAngleLoc());
3814 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3815 TemplateArgumentLoc Loc;
3816 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3817 return SemaRef.ExprError();
3818 TransArgs.addArgument(Loc);
3819 }
3820 }
3821
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003822 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003823 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003824}
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregora16548e2009-08-11 05:31:07 +00003826template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003827Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003828TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003829 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003830}
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregora16548e2009-08-11 05:31:07 +00003832template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003833Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003834TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003835 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003836}
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003839Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003840TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003841 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003842}
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003845Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003846TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003847 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003848}
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregora16548e2009-08-11 05:31:07 +00003850template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003851Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003852TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003853 return SemaRef.Owned(E->Retain());
3854}
3855
3856template<typename Derived>
3857Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003858TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003859 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3860 if (SubExpr.isInvalid())
3861 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregora16548e2009-08-11 05:31:07 +00003863 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003864 return SemaRef.Owned(E->Retain());
3865
3866 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 E->getRParen());
3868}
3869
Mike Stump11289f42009-09-09 15:08:12 +00003870template<typename Derived>
3871Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003872TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3873 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 if (SubExpr.isInvalid())
3875 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003876
Douglas Gregora16548e2009-08-11 05:31:07 +00003877 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003878 return SemaRef.Owned(E->Retain());
3879
Douglas Gregora16548e2009-08-11 05:31:07 +00003880 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3881 E->getOpcode(),
3882 move(SubExpr));
3883}
Mike Stump11289f42009-09-09 15:08:12 +00003884
Douglas Gregora16548e2009-08-11 05:31:07 +00003885template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003886Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003887TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003888 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003889 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003890
John McCallbcd03502009-12-07 02:54:59 +00003891 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003892 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003894
John McCall4c98fd82009-11-04 07:28:41 +00003895 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003896 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003897
John McCall4c98fd82009-11-04 07:28:41 +00003898 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003899 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 E->getSourceRange());
3901 }
Mike Stump11289f42009-09-09 15:08:12 +00003902
Douglas Gregora16548e2009-08-11 05:31:07 +00003903 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003904 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 // C++0x [expr.sizeof]p1:
3906 // The operand is either an expression, which is an unevaluated operand
3907 // [...]
3908 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003909
Douglas Gregora16548e2009-08-11 05:31:07 +00003910 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3911 if (SubExpr.isInvalid())
3912 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregora16548e2009-08-11 05:31:07 +00003914 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3915 return SemaRef.Owned(E->Retain());
3916 }
Mike Stump11289f42009-09-09 15:08:12 +00003917
Douglas Gregora16548e2009-08-11 05:31:07 +00003918 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3919 E->isSizeOf(),
3920 E->getSourceRange());
3921}
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregora16548e2009-08-11 05:31:07 +00003923template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003924Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003925TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3927 if (LHS.isInvalid())
3928 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003929
Douglas Gregora16548e2009-08-11 05:31:07 +00003930 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3931 if (RHS.isInvalid())
3932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003933
3934
Douglas Gregora16548e2009-08-11 05:31:07 +00003935 if (!getDerived().AlwaysRebuild() &&
3936 LHS.get() == E->getLHS() &&
3937 RHS.get() == E->getRHS())
3938 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3941 /*FIXME:*/E->getLHS()->getLocStart(),
3942 move(RHS),
3943 E->getRBracketLoc());
3944}
Mike Stump11289f42009-09-09 15:08:12 +00003945
3946template<typename Derived>
3947Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003948TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003949 // Transform the callee.
3950 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3951 if (Callee.isInvalid())
3952 return SemaRef.ExprError();
3953
3954 // Transform arguments.
3955 bool ArgChanged = false;
3956 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3957 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3958 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3959 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3960 if (Arg.isInvalid())
3961 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003962
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 // FIXME: Wrong source location information for the ','.
3964 FakeCommaLocs.push_back(
3965 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003966
3967 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 Args.push_back(Arg.takeAs<Expr>());
3969 }
Mike Stump11289f42009-09-09 15:08:12 +00003970
Douglas Gregora16548e2009-08-11 05:31:07 +00003971 if (!getDerived().AlwaysRebuild() &&
3972 Callee.get() == E->getCallee() &&
3973 !ArgChanged)
3974 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003975
Douglas Gregora16548e2009-08-11 05:31:07 +00003976 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003977 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003978 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3979 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3980 move_arg(Args),
3981 FakeCommaLocs.data(),
3982 E->getRParenLoc());
3983}
Mike Stump11289f42009-09-09 15:08:12 +00003984
3985template<typename Derived>
3986Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003987TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3989 if (Base.isInvalid())
3990 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003991
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003992 NestedNameSpecifier *Qualifier = 0;
3993 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003994 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003995 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003996 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003997 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003998 return SemaRef.ExprError();
3999 }
Mike Stump11289f42009-09-09 15:08:12 +00004000
Eli Friedman2cfcef62009-12-04 06:40:45 +00004001 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004002 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4003 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004004 if (!Member)
4005 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004006
John McCall16df1e52010-03-30 21:47:33 +00004007 NamedDecl *FoundDecl = E->getFoundDecl();
4008 if (FoundDecl == E->getMemberDecl()) {
4009 FoundDecl = Member;
4010 } else {
4011 FoundDecl = cast_or_null<NamedDecl>(
4012 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4013 if (!FoundDecl)
4014 return SemaRef.ExprError();
4015 }
4016
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 if (!getDerived().AlwaysRebuild() &&
4018 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004019 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004020 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004021 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004022 !E->hasExplicitTemplateArgumentList()) {
4023
4024 // Mark it referenced in the new context regardless.
4025 // FIXME: this is a bit instantiation-specific.
4026 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004027 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004028 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004029
John McCall6b51f282009-11-23 01:53:49 +00004030 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004031 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004032 TransArgs.setLAngleLoc(E->getLAngleLoc());
4033 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004034 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004035 TemplateArgumentLoc Loc;
4036 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004037 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004038 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004039 }
4040 }
4041
Douglas Gregora16548e2009-08-11 05:31:07 +00004042 // FIXME: Bogus source location for the operator
4043 SourceLocation FakeOperatorLoc
4044 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4045
John McCall38836f02010-01-15 08:34:02 +00004046 // FIXME: to do this check properly, we will need to preserve the
4047 // first-qualifier-in-scope here, just in case we had a dependent
4048 // base (and therefore couldn't do the check) and a
4049 // nested-name-qualifier (and therefore could do the lookup).
4050 NamedDecl *FirstQualifierInScope = 0;
4051
Douglas Gregora16548e2009-08-11 05:31:07 +00004052 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4053 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004054 Qualifier,
4055 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004056 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004057 Member,
John McCall16df1e52010-03-30 21:47:33 +00004058 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004059 (E->hasExplicitTemplateArgumentList()
4060 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004061 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004062}
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregora16548e2009-08-11 05:31:07 +00004064template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004065Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004066TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004067 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4068 if (LHS.isInvalid())
4069 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregora16548e2009-08-11 05:31:07 +00004071 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4072 if (RHS.isInvalid())
4073 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 if (!getDerived().AlwaysRebuild() &&
4076 LHS.get() == E->getLHS() &&
4077 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004078 return SemaRef.Owned(E->Retain());
4079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4081 move(LHS), move(RHS));
4082}
4083
Mike Stump11289f42009-09-09 15:08:12 +00004084template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004085Sema::OwningExprResult
4086TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004087 CompoundAssignOperator *E) {
4088 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004089}
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004092Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004093TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004094 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4095 if (Cond.isInvalid())
4096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004097
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4099 if (LHS.isInvalid())
4100 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004101
Douglas Gregora16548e2009-08-11 05:31:07 +00004102 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4103 if (RHS.isInvalid())
4104 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregora16548e2009-08-11 05:31:07 +00004106 if (!getDerived().AlwaysRebuild() &&
4107 Cond.get() == E->getCond() &&
4108 LHS.get() == E->getLHS() &&
4109 RHS.get() == E->getRHS())
4110 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004111
4112 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004113 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004114 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004115 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004116 move(RHS));
4117}
Mike Stump11289f42009-09-09 15:08:12 +00004118
4119template<typename Derived>
4120Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004121TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004122 // Implicit casts are eliminated during transformation, since they
4123 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004124 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004125}
Mike Stump11289f42009-09-09 15:08:12 +00004126
Douglas Gregora16548e2009-08-11 05:31:07 +00004127template<typename Derived>
4128Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004129TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004130 TypeSourceInfo *OldT;
4131 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 {
4133 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004134 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004135 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4136 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004137
John McCall97513962010-01-15 18:39:57 +00004138 OldT = E->getTypeInfoAsWritten();
4139 NewT = getDerived().TransformType(OldT);
4140 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004141 return SemaRef.ExprError();
4142 }
Mike Stump11289f42009-09-09 15:08:12 +00004143
Douglas Gregor6131b442009-12-12 18:16:41 +00004144 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004145 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004146 if (SubExpr.isInvalid())
4147 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregora16548e2009-08-11 05:31:07 +00004149 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004150 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004151 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004152 return SemaRef.Owned(E->Retain());
4153
John McCall97513962010-01-15 18:39:57 +00004154 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4155 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004156 E->getRParenLoc(),
4157 move(SubExpr));
4158}
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregora16548e2009-08-11 05:31:07 +00004160template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004161Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004162TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004163 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4164 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4165 if (!NewT)
4166 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4169 if (Init.isInvalid())
4170 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004171
Douglas Gregora16548e2009-08-11 05:31:07 +00004172 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004173 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004175 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004176
John McCall5d7aa7f2010-01-19 22:33:45 +00004177 // Note: the expression type doesn't necessarily match the
4178 // type-as-written, but that's okay, because it should always be
4179 // derivable from the initializer.
4180
John McCalle15bbff2010-01-18 19:35:47 +00004181 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004182 /*FIXME:*/E->getInitializer()->getLocEnd(),
4183 move(Init));
4184}
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregora16548e2009-08-11 05:31:07 +00004186template<typename Derived>
4187Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004188TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004189 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4190 if (Base.isInvalid())
4191 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 if (!getDerived().AlwaysRebuild() &&
4194 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004195 return SemaRef.Owned(E->Retain());
4196
Douglas Gregora16548e2009-08-11 05:31:07 +00004197 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004198 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004199 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4200 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4201 E->getAccessorLoc(),
4202 E->getAccessor());
4203}
Mike Stump11289f42009-09-09 15:08:12 +00004204
Douglas Gregora16548e2009-08-11 05:31:07 +00004205template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004206Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004207TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004209
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4211 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4212 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4213 if (Init.isInvalid())
4214 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004215
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 InitChanged = InitChanged || Init.get() != E->getInit(I);
4217 Inits.push_back(Init.takeAs<Expr>());
4218 }
Mike Stump11289f42009-09-09 15:08:12 +00004219
Douglas Gregora16548e2009-08-11 05:31:07 +00004220 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004221 return SemaRef.Owned(E->Retain());
4222
Douglas Gregora16548e2009-08-11 05:31:07 +00004223 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004224 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004225}
Mike Stump11289f42009-09-09 15:08:12 +00004226
Douglas Gregora16548e2009-08-11 05:31:07 +00004227template<typename Derived>
4228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004229TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004230 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004231
Douglas Gregorebe10102009-08-20 07:17:43 +00004232 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004233 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4234 if (Init.isInvalid())
4235 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004236
Douglas Gregorebe10102009-08-20 07:17:43 +00004237 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004238 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4239 bool ExprChanged = false;
4240 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4241 DEnd = E->designators_end();
4242 D != DEnd; ++D) {
4243 if (D->isFieldDesignator()) {
4244 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4245 D->getDotLoc(),
4246 D->getFieldLoc()));
4247 continue;
4248 }
Mike Stump11289f42009-09-09 15:08:12 +00004249
Douglas Gregora16548e2009-08-11 05:31:07 +00004250 if (D->isArrayDesignator()) {
4251 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4252 if (Index.isInvalid())
4253 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004254
4255 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004256 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004257
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4259 ArrayExprs.push_back(Index.release());
4260 continue;
4261 }
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004264 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4266 if (Start.isInvalid())
4267 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregora16548e2009-08-11 05:31:07 +00004269 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4270 if (End.isInvalid())
4271 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004272
4273 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 End.get(),
4275 D->getLBracketLoc(),
4276 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004277
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4279 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 ArrayExprs.push_back(Start.release());
4282 ArrayExprs.push_back(End.release());
4283 }
Mike Stump11289f42009-09-09 15:08:12 +00004284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 if (!getDerived().AlwaysRebuild() &&
4286 Init.get() == E->getInit() &&
4287 !ExprChanged)
4288 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004289
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4291 E->getEqualOrColonLoc(),
4292 E->usesGNUSyntax(), move(Init));
4293}
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004296Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004297TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004298 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004299 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4300
4301 // FIXME: Will we ever have proper type location here? Will we actually
4302 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 QualType T = getDerived().TransformType(E->getType());
4304 if (T.isNull())
4305 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004306
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 if (!getDerived().AlwaysRebuild() &&
4308 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004309 return SemaRef.Owned(E->Retain());
4310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 return getDerived().RebuildImplicitValueInitExpr(T);
4312}
Mike Stump11289f42009-09-09 15:08:12 +00004313
Douglas Gregora16548e2009-08-11 05:31:07 +00004314template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004315Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004316TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004317 // FIXME: Do we want the type as written?
4318 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 {
4321 // FIXME: Source location isn't quite accurate.
4322 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4323 T = getDerived().TransformType(E->getType());
4324 if (T.isNull())
4325 return SemaRef.ExprError();
4326 }
Mike Stump11289f42009-09-09 15:08:12 +00004327
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4329 if (SubExpr.isInvalid())
4330 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332 if (!getDerived().AlwaysRebuild() &&
4333 T == E->getType() &&
4334 SubExpr.get() == E->getSubExpr())
4335 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004336
Douglas Gregora16548e2009-08-11 05:31:07 +00004337 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4338 T, E->getRParenLoc());
4339}
4340
4341template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004342Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004343TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 bool ArgumentChanged = false;
4345 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4346 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4347 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4348 if (Init.isInvalid())
4349 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4352 Inits.push_back(Init.takeAs<Expr>());
4353 }
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4356 move_arg(Inits),
4357 E->getRParenLoc());
4358}
Mike Stump11289f42009-09-09 15:08:12 +00004359
Douglas Gregora16548e2009-08-11 05:31:07 +00004360/// \brief Transform an address-of-label expression.
4361///
4362/// By default, the transformation of an address-of-label expression always
4363/// rebuilds the expression, so that the label identifier can be resolved to
4364/// the corresponding label statement by semantic analysis.
4365template<typename Derived>
4366Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004367TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004368 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4369 E->getLabel());
4370}
Mike Stump11289f42009-09-09 15:08:12 +00004371
4372template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004373Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004374TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004375 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4377 if (SubStmt.isInvalid())
4378 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004379
Douglas Gregora16548e2009-08-11 05:31:07 +00004380 if (!getDerived().AlwaysRebuild() &&
4381 SubStmt.get() == E->getSubStmt())
4382 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004383
4384 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004385 move(SubStmt),
4386 E->getRParenLoc());
4387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389template<typename Derived>
4390Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 QualType T1, T2;
4393 {
4394 // FIXME: Source location isn't quite accurate.
4395 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 T1 = getDerived().TransformType(E->getArgType1());
4398 if (T1.isNull())
4399 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401 T2 = getDerived().TransformType(E->getArgType2());
4402 if (T2.isNull())
4403 return SemaRef.ExprError();
4404 }
4405
4406 if (!getDerived().AlwaysRebuild() &&
4407 T1 == E->getArgType1() &&
4408 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004409 return SemaRef.Owned(E->Retain());
4410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4412 T1, T2, E->getRParenLoc());
4413}
Mike Stump11289f42009-09-09 15:08:12 +00004414
Douglas Gregora16548e2009-08-11 05:31:07 +00004415template<typename Derived>
4416Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004417TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4419 if (Cond.isInvalid())
4420 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004421
Douglas Gregora16548e2009-08-11 05:31:07 +00004422 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4423 if (LHS.isInvalid())
4424 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4427 if (RHS.isInvalid())
4428 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 if (!getDerived().AlwaysRebuild() &&
4431 Cond.get() == E->getCond() &&
4432 LHS.get() == E->getLHS() &&
4433 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004434 return SemaRef.Owned(E->Retain());
4435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4437 move(Cond), move(LHS), move(RHS),
4438 E->getRParenLoc());
4439}
Mike Stump11289f42009-09-09 15:08:12 +00004440
Douglas Gregora16548e2009-08-11 05:31:07 +00004441template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004442Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004443TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004444 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004445}
4446
4447template<typename Derived>
4448Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004449TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004450 switch (E->getOperator()) {
4451 case OO_New:
4452 case OO_Delete:
4453 case OO_Array_New:
4454 case OO_Array_Delete:
4455 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4456 return SemaRef.ExprError();
4457
4458 case OO_Call: {
4459 // This is a call to an object's operator().
4460 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4461
4462 // Transform the object itself.
4463 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4464 if (Object.isInvalid())
4465 return SemaRef.ExprError();
4466
4467 // FIXME: Poor location information
4468 SourceLocation FakeLParenLoc
4469 = SemaRef.PP.getLocForEndOfToken(
4470 static_cast<Expr *>(Object.get())->getLocEnd());
4471
4472 // Transform the call arguments.
4473 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4474 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4475 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004476 if (getDerived().DropCallArgument(E->getArg(I)))
4477 break;
4478
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004479 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4480 if (Arg.isInvalid())
4481 return SemaRef.ExprError();
4482
4483 // FIXME: Poor source location information.
4484 SourceLocation FakeCommaLoc
4485 = SemaRef.PP.getLocForEndOfToken(
4486 static_cast<Expr *>(Arg.get())->getLocEnd());
4487 FakeCommaLocs.push_back(FakeCommaLoc);
4488 Args.push_back(Arg.release());
4489 }
4490
4491 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4492 move_arg(Args),
4493 FakeCommaLocs.data(),
4494 E->getLocEnd());
4495 }
4496
4497#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4498 case OO_##Name:
4499#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4500#include "clang/Basic/OperatorKinds.def"
4501 case OO_Subscript:
4502 // Handled below.
4503 break;
4504
4505 case OO_Conditional:
4506 llvm_unreachable("conditional operator is not actually overloadable");
4507 return SemaRef.ExprError();
4508
4509 case OO_None:
4510 case NUM_OVERLOADED_OPERATORS:
4511 llvm_unreachable("not an overloaded operator?");
4512 return SemaRef.ExprError();
4513 }
4514
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4516 if (Callee.isInvalid())
4517 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004518
John McCall47f29ea2009-12-08 09:21:05 +00004519 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 if (First.isInvalid())
4521 return SemaRef.ExprError();
4522
4523 OwningExprResult Second(SemaRef);
4524 if (E->getNumArgs() == 2) {
4525 Second = getDerived().TransformExpr(E->getArg(1));
4526 if (Second.isInvalid())
4527 return SemaRef.ExprError();
4528 }
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 if (!getDerived().AlwaysRebuild() &&
4531 Callee.get() == E->getCallee() &&
4532 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004533 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4534 return SemaRef.Owned(E->Retain());
4535
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4537 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004538 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 move(First),
4540 move(Second));
4541}
Mike Stump11289f42009-09-09 15:08:12 +00004542
Douglas Gregora16548e2009-08-11 05:31:07 +00004543template<typename Derived>
4544Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004545TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4546 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004547}
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004550Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004551TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004552 TypeSourceInfo *OldT;
4553 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 {
4555 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004556 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4558 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004559
John McCall97513962010-01-15 18:39:57 +00004560 OldT = E->getTypeInfoAsWritten();
4561 NewT = getDerived().TransformType(OldT);
4562 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 return SemaRef.ExprError();
4564 }
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregor6131b442009-12-12 18:16:41 +00004566 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004567 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 if (SubExpr.isInvalid())
4569 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004572 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004574 return SemaRef.Owned(E->Retain());
4575
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004577 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4579 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4580 SourceLocation FakeRParenLoc
4581 = SemaRef.PP.getLocForEndOfToken(
4582 E->getSubExpr()->getSourceRange().getEnd());
4583 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004584 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004586 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 FakeRAngleLoc,
4588 FakeRAngleLoc,
4589 move(SubExpr),
4590 FakeRParenLoc);
4591}
Mike Stump11289f42009-09-09 15:08:12 +00004592
Douglas Gregora16548e2009-08-11 05:31:07 +00004593template<typename Derived>
4594Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004595TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4596 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004597}
Mike Stump11289f42009-09-09 15:08:12 +00004598
4599template<typename Derived>
4600Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004601TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4602 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004603}
4604
Douglas Gregora16548e2009-08-11 05:31:07 +00004605template<typename Derived>
4606Sema::OwningExprResult
4607TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004608 CXXReinterpretCastExpr *E) {
4609 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004610}
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612template<typename Derived>
4613Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004614TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4615 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004616}
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618template<typename Derived>
4619Sema::OwningExprResult
4620TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004621 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004622 TypeSourceInfo *OldT;
4623 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 {
4625 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004626
John McCall97513962010-01-15 18:39:57 +00004627 OldT = E->getTypeInfoAsWritten();
4628 NewT = getDerived().TransformType(OldT);
4629 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 return SemaRef.ExprError();
4631 }
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregor6131b442009-12-12 18:16:41 +00004633 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004634 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 if (SubExpr.isInvalid())
4636 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004639 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004641 return SemaRef.Owned(E->Retain());
4642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 // FIXME: The end of the type's source range is wrong
4644 return getDerived().RebuildCXXFunctionalCastExpr(
4645 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004646 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 /*FIXME:*/E->getSubExpr()->getLocStart(),
4648 move(SubExpr),
4649 E->getRParenLoc());
4650}
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652template<typename Derived>
4653Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004654TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 if (E->isTypeOperand()) {
4656 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 QualType T = getDerived().TransformType(E->getTypeOperand());
4659 if (T.isNull())
4660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 if (!getDerived().AlwaysRebuild() &&
4663 T == E->getTypeOperand())
4664 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4667 /*FIXME:*/E->getLocStart(),
4668 T,
4669 E->getLocEnd());
4670 }
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 // We don't know whether the expression is potentially evaluated until
4673 // after we perform semantic analysis, so the expression is potentially
4674 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004675 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4679 if (SubExpr.isInvalid())
4680 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 if (!getDerived().AlwaysRebuild() &&
4683 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004684 return SemaRef.Owned(E->Retain());
4685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4687 /*FIXME:*/E->getLocStart(),
4688 move(SubExpr),
4689 E->getLocEnd());
4690}
4691
4692template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004693Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004694TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004695 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004696}
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregora16548e2009-08-11 05:31:07 +00004698template<typename Derived>
4699Sema::OwningExprResult
4700TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004701 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004702 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004703}
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregora16548e2009-08-11 05:31:07 +00004705template<typename Derived>
4706Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004707TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 QualType T = getDerived().TransformType(E->getType());
4711 if (T.isNull())
4712 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 if (!getDerived().AlwaysRebuild() &&
4715 T == E->getType())
4716 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregorb15af892010-01-07 23:12:05 +00004718 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004719}
Mike Stump11289f42009-09-09 15:08:12 +00004720
Douglas Gregora16548e2009-08-11 05:31:07 +00004721template<typename Derived>
4722Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004723TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4725 if (SubExpr.isInvalid())
4726 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 if (!getDerived().AlwaysRebuild() &&
4729 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004730 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004731
4732 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregora16548e2009-08-11 05:31:07 +00004735template<typename Derived>
4736Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004737TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004738 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004739 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4740 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 if (!Param)
4742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004743
Chandler Carruth794da4c2010-02-08 06:42:49 +00004744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 Param == E->getParam())
4746 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregor033f6752009-12-23 23:03:06 +00004748 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004749}
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregora16548e2009-08-11 05:31:07 +00004751template<typename Derived>
4752Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004753TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4755
4756 QualType T = getDerived().TransformType(E->getType());
4757 if (T.isNull())
4758 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregora16548e2009-08-11 05:31:07 +00004760 if (!getDerived().AlwaysRebuild() &&
4761 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004762 return SemaRef.Owned(E->Retain());
4763
4764 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 /*FIXME:*/E->getTypeBeginLoc(),
4766 T,
4767 E->getRParenLoc());
4768}
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770template<typename Derived>
4771Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004772TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 // Transform the type that we're allocating
4774 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4775 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4776 if (AllocType.isNull())
4777 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 // Transform the size of the array we're allocating (if any).
4780 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4781 if (ArraySize.isInvalid())
4782 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 // Transform the placement arguments (if any).
4785 bool ArgumentChanged = false;
4786 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4787 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4788 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4789 if (Arg.isInvalid())
4790 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4793 PlacementArgs.push_back(Arg.take());
4794 }
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregorebe10102009-08-20 07:17:43 +00004796 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4798 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4799 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4800 if (Arg.isInvalid())
4801 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4804 ConstructorArgs.push_back(Arg.take());
4805 }
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregord2d9da02010-02-26 00:38:10 +00004807 // Transform constructor, new operator, and delete operator.
4808 CXXConstructorDecl *Constructor = 0;
4809 if (E->getConstructor()) {
4810 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004811 getDerived().TransformDecl(E->getLocStart(),
4812 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004813 if (!Constructor)
4814 return SemaRef.ExprError();
4815 }
4816
4817 FunctionDecl *OperatorNew = 0;
4818 if (E->getOperatorNew()) {
4819 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004820 getDerived().TransformDecl(E->getLocStart(),
4821 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004822 if (!OperatorNew)
4823 return SemaRef.ExprError();
4824 }
4825
4826 FunctionDecl *OperatorDelete = 0;
4827 if (E->getOperatorDelete()) {
4828 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004829 getDerived().TransformDecl(E->getLocStart(),
4830 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004831 if (!OperatorDelete)
4832 return SemaRef.ExprError();
4833 }
4834
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 if (!getDerived().AlwaysRebuild() &&
4836 AllocType == E->getAllocatedType() &&
4837 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004838 Constructor == E->getConstructor() &&
4839 OperatorNew == E->getOperatorNew() &&
4840 OperatorDelete == E->getOperatorDelete() &&
4841 !ArgumentChanged) {
4842 // Mark any declarations we need as referenced.
4843 // FIXME: instantiation-specific.
4844 if (Constructor)
4845 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4846 if (OperatorNew)
4847 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4848 if (OperatorDelete)
4849 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004850 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004851 }
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004853 if (!ArraySize.get()) {
4854 // If no array size was specified, but the new expression was
4855 // instantiated with an array type (e.g., "new T" where T is
4856 // instantiated with "int[4]"), extract the outer bound from the
4857 // array type as our array size. We do this with constant and
4858 // dependently-sized array types.
4859 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4860 if (!ArrayT) {
4861 // Do nothing
4862 } else if (const ConstantArrayType *ConsArrayT
4863 = dyn_cast<ConstantArrayType>(ArrayT)) {
4864 ArraySize
4865 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4866 ConsArrayT->getSize(),
4867 SemaRef.Context.getSizeType(),
4868 /*FIXME:*/E->getLocStart()));
4869 AllocType = ConsArrayT->getElementType();
4870 } else if (const DependentSizedArrayType *DepArrayT
4871 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4872 if (DepArrayT->getSizeExpr()) {
4873 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4874 AllocType = DepArrayT->getElementType();
4875 }
4876 }
4877 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4879 E->isGlobalNew(),
4880 /*FIXME:*/E->getLocStart(),
4881 move_arg(PlacementArgs),
4882 /*FIXME:*/E->getLocStart(),
4883 E->isParenTypeId(),
4884 AllocType,
4885 /*FIXME:*/E->getLocStart(),
4886 /*FIXME:*/SourceRange(),
4887 move(ArraySize),
4888 /*FIXME:*/E->getLocStart(),
4889 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004890 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004891}
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregora16548e2009-08-11 05:31:07 +00004893template<typename Derived>
4894Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004895TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4897 if (Operand.isInvalid())
4898 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregord2d9da02010-02-26 00:38:10 +00004900 // Transform the delete operator, if known.
4901 FunctionDecl *OperatorDelete = 0;
4902 if (E->getOperatorDelete()) {
4903 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004904 getDerived().TransformDecl(E->getLocStart(),
4905 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004906 if (!OperatorDelete)
4907 return SemaRef.ExprError();
4908 }
4909
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004911 Operand.get() == E->getArgument() &&
4912 OperatorDelete == E->getOperatorDelete()) {
4913 // Mark any declarations we need as referenced.
4914 // FIXME: instantiation-specific.
4915 if (OperatorDelete)
4916 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004917 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004918 }
Mike Stump11289f42009-09-09 15:08:12 +00004919
Douglas Gregora16548e2009-08-11 05:31:07 +00004920 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4921 E->isGlobalDelete(),
4922 E->isArrayForm(),
4923 move(Operand));
4924}
Mike Stump11289f42009-09-09 15:08:12 +00004925
Douglas Gregora16548e2009-08-11 05:31:07 +00004926template<typename Derived>
4927Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004928TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004929 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004930 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4931 if (Base.isInvalid())
4932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
Douglas Gregor678f90d2010-02-25 01:56:36 +00004934 Sema::TypeTy *ObjectTypePtr = 0;
4935 bool MayBePseudoDestructor = false;
4936 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4937 E->getOperatorLoc(),
4938 E->isArrow()? tok::arrow : tok::period,
4939 ObjectTypePtr,
4940 MayBePseudoDestructor);
4941 if (Base.isInvalid())
4942 return SemaRef.ExprError();
4943
4944 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004945 NestedNameSpecifier *Qualifier
4946 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004947 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004948 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004949 if (E->getQualifier() && !Qualifier)
4950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregor678f90d2010-02-25 01:56:36 +00004952 PseudoDestructorTypeStorage Destroyed;
4953 if (E->getDestroyedTypeInfo()) {
4954 TypeSourceInfo *DestroyedTypeInfo
4955 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4956 if (!DestroyedTypeInfo)
4957 return SemaRef.ExprError();
4958 Destroyed = DestroyedTypeInfo;
4959 } else if (ObjectType->isDependentType()) {
4960 // We aren't likely to be able to resolve the identifier down to a type
4961 // now anyway, so just retain the identifier.
4962 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4963 E->getDestroyedTypeLoc());
4964 } else {
4965 // Look for a destructor known with the given name.
4966 CXXScopeSpec SS;
4967 if (Qualifier) {
4968 SS.setScopeRep(Qualifier);
4969 SS.setRange(E->getQualifierRange());
4970 }
4971
4972 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4973 *E->getDestroyedTypeIdentifier(),
4974 E->getDestroyedTypeLoc(),
4975 /*Scope=*/0,
4976 SS, ObjectTypePtr,
4977 false);
4978 if (!T)
4979 return SemaRef.ExprError();
4980
4981 Destroyed
4982 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4983 E->getDestroyedTypeLoc());
4984 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004985
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004986 TypeSourceInfo *ScopeTypeInfo = 0;
4987 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004988 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4989 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004990 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004991 return SemaRef.ExprError();
4992 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004993
Douglas Gregorad8a3362009-09-04 17:36:40 +00004994 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4995 E->getOperatorLoc(),
4996 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004997 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004998 E->getQualifierRange(),
4999 ScopeTypeInfo,
5000 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005001 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005002 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregorad8a3362009-09-04 17:36:40 +00005005template<typename Derived>
5006Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005007TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005008 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005009 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5010
5011 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5012 Sema::LookupOrdinaryName);
5013
5014 // Transform all the decls.
5015 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5016 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005017 NamedDecl *InstD = static_cast<NamedDecl*>(
5018 getDerived().TransformDecl(Old->getNameLoc(),
5019 *I));
John McCall84d87672009-12-10 09:41:52 +00005020 if (!InstD) {
5021 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5022 // This can happen because of dependent hiding.
5023 if (isa<UsingShadowDecl>(*I))
5024 continue;
5025 else
5026 return SemaRef.ExprError();
5027 }
John McCalle66edc12009-11-24 19:00:30 +00005028
5029 // Expand using declarations.
5030 if (isa<UsingDecl>(InstD)) {
5031 UsingDecl *UD = cast<UsingDecl>(InstD);
5032 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5033 E = UD->shadow_end(); I != E; ++I)
5034 R.addDecl(*I);
5035 continue;
5036 }
5037
5038 R.addDecl(InstD);
5039 }
5040
5041 // Resolve a kind, but don't do any further analysis. If it's
5042 // ambiguous, the callee needs to deal with it.
5043 R.resolveKind();
5044
5045 // Rebuild the nested-name qualifier, if present.
5046 CXXScopeSpec SS;
5047 NestedNameSpecifier *Qualifier = 0;
5048 if (Old->getQualifier()) {
5049 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005050 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005051 if (!Qualifier)
5052 return SemaRef.ExprError();
5053
5054 SS.setScopeRep(Qualifier);
5055 SS.setRange(Old->getQualifierRange());
5056 }
5057
5058 // If we have no template arguments, it's a normal declaration name.
5059 if (!Old->hasExplicitTemplateArgs())
5060 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5061
5062 // If we have template arguments, rebuild them, then rebuild the
5063 // templateid expression.
5064 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5065 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5066 TemplateArgumentLoc Loc;
5067 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5068 return SemaRef.ExprError();
5069 TransArgs.addArgument(Loc);
5070 }
5071
5072 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5073 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005074}
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregora16548e2009-08-11 05:31:07 +00005076template<typename Derived>
5077Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005079 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005080
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 QualType T = getDerived().TransformType(E->getQueriedType());
5082 if (T.isNull())
5083 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 if (!getDerived().AlwaysRebuild() &&
5086 T == E->getQueriedType())
5087 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 // FIXME: Bad location information
5090 SourceLocation FakeLParenLoc
5091 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005092
5093 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 E->getLocStart(),
5095 /*FIXME:*/FakeLParenLoc,
5096 T,
5097 E->getLocEnd());
5098}
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregora16548e2009-08-11 05:31:07 +00005100template<typename Derived>
5101Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005102TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005103 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005105 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005106 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 if (!NNS)
5108 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005109
5110 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005111 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5112 if (!Name)
5113 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005114
John McCalle66edc12009-11-24 19:00:30 +00005115 if (!E->hasExplicitTemplateArgs()) {
5116 if (!getDerived().AlwaysRebuild() &&
5117 NNS == E->getQualifier() &&
5118 Name == E->getDeclName())
5119 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005120
John McCalle66edc12009-11-24 19:00:30 +00005121 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5122 E->getQualifierRange(),
5123 Name, E->getLocation(),
5124 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005125 }
John McCall6b51f282009-11-23 01:53:49 +00005126
5127 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005129 TemplateArgumentLoc Loc;
5130 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005132 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 }
5134
John McCalle66edc12009-11-24 19:00:30 +00005135 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5136 E->getQualifierRange(),
5137 Name, E->getLocation(),
5138 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005139}
5140
5141template<typename Derived>
5142Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005143TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005144 // CXXConstructExprs are always implicit, so when we have a
5145 // 1-argument construction we just transform that argument.
5146 if (E->getNumArgs() == 1 ||
5147 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5148 return getDerived().TransformExpr(E->getArg(0));
5149
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5151
5152 QualType T = getDerived().TransformType(E->getType());
5153 if (T.isNull())
5154 return SemaRef.ExprError();
5155
5156 CXXConstructorDecl *Constructor
5157 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005158 getDerived().TransformDecl(E->getLocStart(),
5159 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 if (!Constructor)
5161 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 bool ArgumentChanged = false;
5164 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005165 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 ArgEnd = E->arg_end();
5167 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005168 if (getDerived().DropCallArgument(*Arg)) {
5169 ArgumentChanged = true;
5170 break;
5171 }
5172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5174 if (TransArg.isInvalid())
5175 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5178 Args.push_back(TransArg.takeAs<Expr>());
5179 }
5180
5181 if (!getDerived().AlwaysRebuild() &&
5182 T == E->getType() &&
5183 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005184 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005185 // Mark the constructor as referenced.
5186 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005187 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005188 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005189 }
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregordb121ba2009-12-14 16:27:04 +00005191 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5192 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 move_arg(Args));
5194}
Mike Stump11289f42009-09-09 15:08:12 +00005195
Douglas Gregora16548e2009-08-11 05:31:07 +00005196/// \brief Transform a C++ temporary-binding expression.
5197///
Douglas Gregor363b1512009-12-24 18:51:59 +00005198/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5199/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005200template<typename Derived>
5201Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005202TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005203 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
Mike Stump11289f42009-09-09 15:08:12 +00005205
Anders Carlssonba6c4372010-01-29 02:39:32 +00005206/// \brief Transform a C++ reference-binding expression.
5207///
5208/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5209/// transform the subexpression and return that.
5210template<typename Derived>
5211Sema::OwningExprResult
5212TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5213 return getDerived().TransformExpr(E->getSubExpr());
5214}
5215
Mike Stump11289f42009-09-09 15:08:12 +00005216/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005217/// be destroyed after the expression is evaluated.
5218///
Douglas Gregor363b1512009-12-24 18:51:59 +00005219/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5220/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005221template<typename Derived>
5222Sema::OwningExprResult
5223TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005224 CXXExprWithTemporaries *E) {
5225 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005226}
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregora16548e2009-08-11 05:31:07 +00005228template<typename Derived>
5229Sema::OwningExprResult
5230TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005231 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005232 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5233 QualType T = getDerived().TransformType(E->getType());
5234 if (T.isNull())
5235 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 CXXConstructorDecl *Constructor
5238 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005239 getDerived().TransformDecl(E->getLocStart(),
5240 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 if (!Constructor)
5242 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 bool ArgumentChanged = false;
5245 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5246 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005247 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 ArgEnd = E->arg_end();
5249 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005250 if (getDerived().DropCallArgument(*Arg)) {
5251 ArgumentChanged = true;
5252 break;
5253 }
5254
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5256 if (TransArg.isInvalid())
5257 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5260 Args.push_back((Expr *)TransArg.release());
5261 }
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregora16548e2009-08-11 05:31:07 +00005263 if (!getDerived().AlwaysRebuild() &&
5264 T == E->getType() &&
5265 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005266 !ArgumentChanged) {
5267 // FIXME: Instantiation-specific
5268 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005269 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005270 }
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregora16548e2009-08-11 05:31:07 +00005272 // FIXME: Bogus location information
5273 SourceLocation CommaLoc;
5274 if (Args.size() > 1) {
5275 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005276 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005277 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5278 }
5279 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5280 T,
5281 /*FIXME:*/E->getTypeBeginLoc(),
5282 move_arg(Args),
5283 &CommaLoc,
5284 E->getLocEnd());
5285}
Mike Stump11289f42009-09-09 15:08:12 +00005286
Douglas Gregora16548e2009-08-11 05:31:07 +00005287template<typename Derived>
5288Sema::OwningExprResult
5289TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005290 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005291 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5292 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5293 if (T.isNull())
5294 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005295
Douglas Gregora16548e2009-08-11 05:31:07 +00005296 bool ArgumentChanged = false;
5297 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5298 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5299 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5300 ArgEnd = E->arg_end();
5301 Arg != ArgEnd; ++Arg) {
5302 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5303 if (TransArg.isInvalid())
5304 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005305
Douglas Gregora16548e2009-08-11 05:31:07 +00005306 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5307 FakeCommaLocs.push_back(
5308 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5309 Args.push_back(TransArg.takeAs<Expr>());
5310 }
Mike Stump11289f42009-09-09 15:08:12 +00005311
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 if (!getDerived().AlwaysRebuild() &&
5313 T == E->getTypeAsWritten() &&
5314 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005315 return SemaRef.Owned(E->Retain());
5316
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 // FIXME: we're faking the locations of the commas
5318 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5319 T,
5320 E->getLParenLoc(),
5321 move_arg(Args),
5322 FakeCommaLocs.data(),
5323 E->getRParenLoc());
5324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregora16548e2009-08-11 05:31:07 +00005326template<typename Derived>
5327Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005328TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005329 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005330 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005331 OwningExprResult Base(SemaRef, (Expr*) 0);
5332 Expr *OldBase;
5333 QualType BaseType;
5334 QualType ObjectType;
5335 if (!E->isImplicitAccess()) {
5336 OldBase = E->getBase();
5337 Base = getDerived().TransformExpr(OldBase);
5338 if (Base.isInvalid())
5339 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005340
John McCall2d74de92009-12-01 22:10:20 +00005341 // Start the member reference and compute the object's type.
5342 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005343 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005344 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5345 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005346 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005347 ObjectTy,
5348 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005349 if (Base.isInvalid())
5350 return SemaRef.ExprError();
5351
5352 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5353 BaseType = ((Expr*) Base.get())->getType();
5354 } else {
5355 OldBase = 0;
5356 BaseType = getDerived().TransformType(E->getBaseType());
5357 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5358 }
Mike Stump11289f42009-09-09 15:08:12 +00005359
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005360 // Transform the first part of the nested-name-specifier that qualifies
5361 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005362 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005363 = getDerived().TransformFirstQualifierInScope(
5364 E->getFirstQualifierFoundInScope(),
5365 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005367 NestedNameSpecifier *Qualifier = 0;
5368 if (E->getQualifier()) {
5369 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5370 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005371 ObjectType,
5372 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005373 if (!Qualifier)
5374 return SemaRef.ExprError();
5375 }
Mike Stump11289f42009-09-09 15:08:12 +00005376
5377 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005378 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005379 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005380 if (!Name)
5381 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005382
John McCall2d74de92009-12-01 22:10:20 +00005383 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005384 // This is a reference to a member without an explicitly-specified
5385 // template argument list. Optimize for this common case.
5386 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005387 Base.get() == OldBase &&
5388 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005389 Qualifier == E->getQualifier() &&
5390 Name == E->getMember() &&
5391 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005392 return SemaRef.Owned(E->Retain());
5393
John McCall8cd78132009-11-19 22:55:06 +00005394 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005395 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005396 E->isArrow(),
5397 E->getOperatorLoc(),
5398 Qualifier,
5399 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005400 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005401 Name,
5402 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005403 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005404 }
5405
John McCall6b51f282009-11-23 01:53:49 +00005406 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005407 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005408 TemplateArgumentLoc Loc;
5409 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005410 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005411 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005412 }
Mike Stump11289f42009-09-09 15:08:12 +00005413
John McCall8cd78132009-11-19 22:55:06 +00005414 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005415 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005416 E->isArrow(),
5417 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005418 Qualifier,
5419 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005420 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005421 Name,
5422 E->getMemberLoc(),
5423 &TransArgs);
5424}
5425
5426template<typename Derived>
5427Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005428TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005429 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005430 OwningExprResult Base(SemaRef, (Expr*) 0);
5431 QualType BaseType;
5432 if (!Old->isImplicitAccess()) {
5433 Base = getDerived().TransformExpr(Old->getBase());
5434 if (Base.isInvalid())
5435 return SemaRef.ExprError();
5436 BaseType = ((Expr*) Base.get())->getType();
5437 } else {
5438 BaseType = getDerived().TransformType(Old->getBaseType());
5439 }
John McCall10eae182009-11-30 22:42:35 +00005440
5441 NestedNameSpecifier *Qualifier = 0;
5442 if (Old->getQualifier()) {
5443 Qualifier
5444 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005445 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005446 if (Qualifier == 0)
5447 return SemaRef.ExprError();
5448 }
5449
5450 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5451 Sema::LookupOrdinaryName);
5452
5453 // Transform all the decls.
5454 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5455 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005456 NamedDecl *InstD = static_cast<NamedDecl*>(
5457 getDerived().TransformDecl(Old->getMemberLoc(),
5458 *I));
John McCall84d87672009-12-10 09:41:52 +00005459 if (!InstD) {
5460 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5461 // This can happen because of dependent hiding.
5462 if (isa<UsingShadowDecl>(*I))
5463 continue;
5464 else
5465 return SemaRef.ExprError();
5466 }
John McCall10eae182009-11-30 22:42:35 +00005467
5468 // Expand using declarations.
5469 if (isa<UsingDecl>(InstD)) {
5470 UsingDecl *UD = cast<UsingDecl>(InstD);
5471 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5472 E = UD->shadow_end(); I != E; ++I)
5473 R.addDecl(*I);
5474 continue;
5475 }
5476
5477 R.addDecl(InstD);
5478 }
5479
5480 R.resolveKind();
5481
5482 TemplateArgumentListInfo TransArgs;
5483 if (Old->hasExplicitTemplateArgs()) {
5484 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5485 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5486 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5487 TemplateArgumentLoc Loc;
5488 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5489 Loc))
5490 return SemaRef.ExprError();
5491 TransArgs.addArgument(Loc);
5492 }
5493 }
John McCall38836f02010-01-15 08:34:02 +00005494
5495 // FIXME: to do this check properly, we will need to preserve the
5496 // first-qualifier-in-scope here, just in case we had a dependent
5497 // base (and therefore couldn't do the check) and a
5498 // nested-name-qualifier (and therefore could do the lookup).
5499 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005500
5501 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005502 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005503 Old->getOperatorLoc(),
5504 Old->isArrow(),
5505 Qualifier,
5506 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005507 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005508 R,
5509 (Old->hasExplicitTemplateArgs()
5510 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005511}
5512
5513template<typename Derived>
5514Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005515TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005516 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005517}
5518
Mike Stump11289f42009-09-09 15:08:12 +00005519template<typename Derived>
5520Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005521TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005522 TypeSourceInfo *EncodedTypeInfo
5523 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5524 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005528 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005529 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005530
5531 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005532 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 E->getRParenLoc());
5534}
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregora16548e2009-08-11 05:31:07 +00005536template<typename Derived>
5537Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005538TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005539 // Transform arguments.
5540 bool ArgChanged = false;
5541 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5542 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5543 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5544 if (Arg.isInvalid())
5545 return SemaRef.ExprError();
5546
5547 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5548 Args.push_back(Arg.takeAs<Expr>());
5549 }
5550
5551 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5552 // Class message: transform the receiver type.
5553 TypeSourceInfo *ReceiverTypeInfo
5554 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5555 if (!ReceiverTypeInfo)
5556 return SemaRef.ExprError();
5557
5558 // If nothing changed, just retain the existing message send.
5559 if (!getDerived().AlwaysRebuild() &&
5560 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5561 return SemaRef.Owned(E->Retain());
5562
5563 // Build a new class message send.
5564 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5565 E->getSelector(),
5566 E->getMethodDecl(),
5567 E->getLeftLoc(),
5568 move_arg(Args),
5569 E->getRightLoc());
5570 }
5571
5572 // Instance message: transform the receiver
5573 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5574 "Only class and instance messages may be instantiated");
5575 OwningExprResult Receiver
5576 = getDerived().TransformExpr(E->getInstanceReceiver());
5577 if (Receiver.isInvalid())
5578 return SemaRef.ExprError();
5579
5580 // If nothing changed, just retain the existing message send.
5581 if (!getDerived().AlwaysRebuild() &&
5582 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5583 return SemaRef.Owned(E->Retain());
5584
5585 // Build a new instance message send.
5586 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5587 E->getSelector(),
5588 E->getMethodDecl(),
5589 E->getLeftLoc(),
5590 move_arg(Args),
5591 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005592}
5593
Mike Stump11289f42009-09-09 15:08:12 +00005594template<typename Derived>
5595Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005596TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005597 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005598}
5599
Mike Stump11289f42009-09-09 15:08:12 +00005600template<typename Derived>
5601Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005602TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005603 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005604}
5605
Mike Stump11289f42009-09-09 15:08:12 +00005606template<typename Derived>
5607Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005608TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 // FIXME: Implement this!
5610 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005611 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005612}
5613
Mike Stump11289f42009-09-09 15:08:12 +00005614template<typename Derived>
5615Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005617 // FIXME: Implement this!
5618 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005619 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005620}
5621
Mike Stump11289f42009-09-09 15:08:12 +00005622template<typename Derived>
5623Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005624TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005625 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005626 // FIXME: Implement this!
5627 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005628 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005629}
5630
Mike Stump11289f42009-09-09 15:08:12 +00005631template<typename Derived>
5632Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005633TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005634 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005635 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005636}
5637
Mike Stump11289f42009-09-09 15:08:12 +00005638template<typename Derived>
5639Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005640TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005641 // FIXME: Implement this!
5642 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005643 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005644}
5645
Mike Stump11289f42009-09-09 15:08:12 +00005646template<typename Derived>
5647Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005648TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 bool ArgumentChanged = false;
5650 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5651 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5652 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5653 if (SubExpr.isInvalid())
5654 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005655
Douglas Gregora16548e2009-08-11 05:31:07 +00005656 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5657 SubExprs.push_back(SubExpr.takeAs<Expr>());
5658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 if (!getDerived().AlwaysRebuild() &&
5661 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005662 return SemaRef.Owned(E->Retain());
5663
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5665 move_arg(SubExprs),
5666 E->getRParenLoc());
5667}
5668
Mike Stump11289f42009-09-09 15:08:12 +00005669template<typename Derived>
5670Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005671TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005672 // FIXME: Implement this!
5673 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005674 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005675}
5676
Mike Stump11289f42009-09-09 15:08:12 +00005677template<typename Derived>
5678Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005679TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 // FIXME: Implement this!
5681 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005682 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005683}
Mike Stump11289f42009-09-09 15:08:12 +00005684
Douglas Gregora16548e2009-08-11 05:31:07 +00005685//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005686// Type reconstruction
5687//===----------------------------------------------------------------------===//
5688
Mike Stump11289f42009-09-09 15:08:12 +00005689template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005690QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5691 SourceLocation Star) {
5692 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005693 getDerived().getBaseEntity());
5694}
5695
Mike Stump11289f42009-09-09 15:08:12 +00005696template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005697QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5698 SourceLocation Star) {
5699 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005700 getDerived().getBaseEntity());
5701}
5702
Mike Stump11289f42009-09-09 15:08:12 +00005703template<typename Derived>
5704QualType
John McCall70dd5f62009-10-30 00:06:24 +00005705TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5706 bool WrittenAsLValue,
5707 SourceLocation Sigil) {
5708 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5709 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005710}
5711
5712template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005713QualType
John McCall70dd5f62009-10-30 00:06:24 +00005714TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5715 QualType ClassType,
5716 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005717 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005718 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005719}
5720
5721template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005722QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005723TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5724 ArrayType::ArraySizeModifier SizeMod,
5725 const llvm::APInt *Size,
5726 Expr *SizeExpr,
5727 unsigned IndexTypeQuals,
5728 SourceRange BracketsRange) {
5729 if (SizeExpr || !Size)
5730 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5731 IndexTypeQuals, BracketsRange,
5732 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005733
5734 QualType Types[] = {
5735 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5736 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5737 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005738 };
5739 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5740 QualType SizeType;
5741 for (unsigned I = 0; I != NumTypes; ++I)
5742 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5743 SizeType = Types[I];
5744 break;
5745 }
Mike Stump11289f42009-09-09 15:08:12 +00005746
Douglas Gregord6ff3322009-08-04 16:50:30 +00005747 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005748 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005749 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005750 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005751}
Mike Stump11289f42009-09-09 15:08:12 +00005752
Douglas Gregord6ff3322009-08-04 16:50:30 +00005753template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005754QualType
5755TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005756 ArrayType::ArraySizeModifier SizeMod,
5757 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005758 unsigned IndexTypeQuals,
5759 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005760 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005761 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005762}
5763
5764template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005765QualType
Mike Stump11289f42009-09-09 15:08:12 +00005766TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005767 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005768 unsigned IndexTypeQuals,
5769 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005770 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005771 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregord6ff3322009-08-04 16:50:30 +00005774template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005775QualType
5776TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005777 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005779 unsigned IndexTypeQuals,
5780 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005781 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005782 SizeExpr.takeAs<Expr>(),
5783 IndexTypeQuals, BracketsRange);
5784}
5785
5786template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005787QualType
5788TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005789 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005791 unsigned IndexTypeQuals,
5792 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005793 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005794 SizeExpr.takeAs<Expr>(),
5795 IndexTypeQuals, BracketsRange);
5796}
5797
5798template<typename Derived>
5799QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005800 unsigned NumElements,
5801 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005802 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005803 return SemaRef.Context.getVectorType(ElementType, NumElements,
5804 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005805}
Mike Stump11289f42009-09-09 15:08:12 +00005806
Douglas Gregord6ff3322009-08-04 16:50:30 +00005807template<typename Derived>
5808QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5809 unsigned NumElements,
5810 SourceLocation AttributeLoc) {
5811 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5812 NumElements, true);
5813 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005814 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005815 AttributeLoc);
5816 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5817 AttributeLoc);
5818}
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregord6ff3322009-08-04 16:50:30 +00005820template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005821QualType
5822TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005824 SourceLocation AttributeLoc) {
5825 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregord6ff3322009-08-04 16:50:30 +00005828template<typename Derived>
5829QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005830 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005831 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005832 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005833 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005834 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005835 Quals,
5836 getDerived().getBaseLocation(),
5837 getDerived().getBaseEntity());
5838}
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregord6ff3322009-08-04 16:50:30 +00005840template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005841QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5842 return SemaRef.Context.getFunctionNoProtoType(T);
5843}
5844
5845template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005846QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5847 assert(D && "no decl found");
5848 if (D->isInvalidDecl()) return QualType();
5849
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005850 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00005851 TypeDecl *Ty;
5852 if (isa<UsingDecl>(D)) {
5853 UsingDecl *Using = cast<UsingDecl>(D);
5854 assert(Using->isTypeName() &&
5855 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5856
5857 // A valid resolved using typename decl points to exactly one type decl.
5858 assert(++Using->shadow_begin() == Using->shadow_end());
5859 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5860
5861 } else {
5862 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5863 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5864 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5865 }
5866
5867 return SemaRef.Context.getTypeDeclType(Ty);
5868}
5869
5870template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005871QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005872 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5873}
5874
5875template<typename Derived>
5876QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5877 return SemaRef.Context.getTypeOfType(Underlying);
5878}
5879
5880template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005881QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005882 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5883}
5884
5885template<typename Derived>
5886QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005887 TemplateName Template,
5888 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005889 const TemplateArgumentListInfo &TemplateArgs) {
5890 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005891}
Mike Stump11289f42009-09-09 15:08:12 +00005892
Douglas Gregor1135c352009-08-06 05:28:30 +00005893template<typename Derived>
5894NestedNameSpecifier *
5895TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5896 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005897 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005898 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005899 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005900 CXXScopeSpec SS;
5901 // FIXME: The source location information is all wrong.
5902 SS.setRange(Range);
5903 SS.setScopeRep(Prefix);
5904 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005905 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005906 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005907 ObjectType,
5908 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005909 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005910}
5911
5912template<typename Derived>
5913NestedNameSpecifier *
5914TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5915 SourceRange Range,
5916 NamespaceDecl *NS) {
5917 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5918}
5919
5920template<typename Derived>
5921NestedNameSpecifier *
5922TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5923 SourceRange Range,
5924 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005925 QualType T) {
5926 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005927 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005928 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005929 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5930 T.getTypePtr());
5931 }
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregor1135c352009-08-06 05:28:30 +00005933 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5934 return 0;
5935}
Mike Stump11289f42009-09-09 15:08:12 +00005936
Douglas Gregor71dc5092009-08-06 06:41:21 +00005937template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005938TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005939TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5940 bool TemplateKW,
5941 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005942 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005943 Template);
5944}
5945
5946template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005947TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005948TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005949 const IdentifierInfo &II,
5950 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005951 CXXScopeSpec SS;
5952 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005953 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005954 UnqualifiedId Name;
5955 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005956 return getSema().ActOnDependentTemplateName(
5957 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005958 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005959 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005960 ObjectType.getAsOpaquePtr(),
5961 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005962 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005963}
Mike Stump11289f42009-09-09 15:08:12 +00005964
Douglas Gregora16548e2009-08-11 05:31:07 +00005965template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005966TemplateName
5967TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5968 OverloadedOperatorKind Operator,
5969 QualType ObjectType) {
5970 CXXScopeSpec SS;
5971 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5972 SS.setScopeRep(Qualifier);
5973 UnqualifiedId Name;
5974 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5975 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5976 Operator, SymbolLocations);
5977 return getSema().ActOnDependentTemplateName(
5978 /*FIXME:*/getDerived().getBaseLocation(),
5979 SS,
5980 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005981 ObjectType.getAsOpaquePtr(),
5982 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005983 .template getAsVal<TemplateName>();
5984}
5985
5986template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005987Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005988TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5989 SourceLocation OpLoc,
5990 ExprArg Callee,
5991 ExprArg First,
5992 ExprArg Second) {
5993 Expr *FirstExpr = (Expr *)First.get();
5994 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005995 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005999 if (Op == OO_Subscript) {
6000 if (!FirstExpr->getType()->isOverloadableType() &&
6001 !SecondExpr->getType()->isOverloadableType())
6002 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006003 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006004 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006005 } else if (Op == OO_Arrow) {
6006 // -> is never a builtin operation.
6007 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006008 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 if (!FirstExpr->getType()->isOverloadableType()) {
6010 // The argument is not of overloadable type, so try to create a
6011 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006012 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006013 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregora16548e2009-08-11 05:31:07 +00006015 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6016 }
6017 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006018 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 !SecondExpr->getType()->isOverloadableType()) {
6020 // Neither of the arguments is an overloadable type, so try to
6021 // create a built-in binary operation.
6022 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006023 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6025 if (Result.isInvalid())
6026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 First.release();
6029 Second.release();
6030 return move(Result);
6031 }
6032 }
Mike Stump11289f42009-09-09 15:08:12 +00006033
6034 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006036 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006037
John McCalld14a8642009-11-21 08:51:07 +00006038 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6039 assert(ULE->requiresADL());
6040
6041 // FIXME: Do we have to check
6042 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006043 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006044 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006045 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006046 }
Mike Stump11289f42009-09-09 15:08:12 +00006047
Douglas Gregora16548e2009-08-11 05:31:07 +00006048 // Add any functions found via argument-dependent lookup.
6049 Expr *Args[2] = { FirstExpr, SecondExpr };
6050 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006051
Douglas Gregora16548e2009-08-11 05:31:07 +00006052 // Create the overloaded operator invocation for unary operators.
6053 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006054 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6056 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6057 }
Mike Stump11289f42009-09-09 15:08:12 +00006058
Sebastian Redladba46e2009-10-29 20:17:01 +00006059 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006060 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6061 OpLoc,
6062 move(First),
6063 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006064
Douglas Gregora16548e2009-08-11 05:31:07 +00006065 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006066 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006067 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006068 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6070 if (Result.isInvalid())
6071 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006072
Douglas Gregora16548e2009-08-11 05:31:07 +00006073 First.release();
6074 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006075 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006076}
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006078template<typename Derived>
6079Sema::OwningExprResult
6080TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6081 SourceLocation OperatorLoc,
6082 bool isArrow,
6083 NestedNameSpecifier *Qualifier,
6084 SourceRange QualifierRange,
6085 TypeSourceInfo *ScopeType,
6086 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006087 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006088 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006089 CXXScopeSpec SS;
6090 if (Qualifier) {
6091 SS.setRange(QualifierRange);
6092 SS.setScopeRep(Qualifier);
6093 }
6094
6095 Expr *BaseE = (Expr *)Base.get();
6096 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006097 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006098 (!isArrow && !BaseType->getAs<RecordType>()) ||
6099 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006100 !BaseType->getAs<PointerType>()->getPointeeType()
6101 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006102 // This pseudo-destructor expression is still a pseudo-destructor.
6103 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6104 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006105 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006106 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006107 /*FIXME?*/true);
6108 }
6109
Douglas Gregor678f90d2010-02-25 01:56:36 +00006110 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006111 DeclarationName Name
6112 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6113 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6114
6115 // FIXME: the ScopeType should be tacked onto SS.
6116
6117 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6118 OperatorLoc, isArrow,
6119 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006120 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006121 /*TemplateArgs*/ 0);
6122}
6123
Douglas Gregord6ff3322009-08-04 16:50:30 +00006124} // end namespace clang
6125
6126#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H