blob: 9d7f936bd72c9d45a5f9bc23f00736c26a72a968 [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 Gregor6148de72010-04-22 22:01:21 +0000893 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000894 ///
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 Gregor6148de72010-04-22 22:01:21 +0000902 /// \brief Build a new Objective-C @synchronized statement.
903 ///
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
907 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
908 ExprArg Object,
909 StmtArg Body) {
910 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
911 move(Body));
912 }
913
Douglas Gregorebe10102009-08-20 07:17:43 +0000914 /// \brief Build a new C++ exception declaration.
915 ///
916 /// By default, performs semantic analysis to build the new decaration.
917 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000918 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000919 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000920 IdentifierInfo *Name,
921 SourceLocation Loc,
922 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000923 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000924 TypeRange);
925 }
926
927 /// \brief Build a new C++ catch 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 RebuildCXXCatchStmt(SourceLocation CatchLoc,
932 VarDecl *ExceptionDecl,
933 StmtArg Handler) {
934 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000935 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000936 Handler.takeAs<Stmt>()));
937 }
Mike Stump11289f42009-09-09 15:08:12 +0000938
Douglas Gregorebe10102009-08-20 07:17:43 +0000939 /// \brief Build a new C++ try statement.
940 ///
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
943 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
944 StmtArg TryBlock,
945 MultiStmtArg Handlers) {
946 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
947 }
Mike Stump11289f42009-09-09 15:08:12 +0000948
Douglas Gregora16548e2009-08-11 05:31:07 +0000949 /// \brief Build a new expression that references a declaration.
950 ///
951 /// By default, performs semantic analysis to build the new expression.
952 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000953 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
954 LookupResult &R,
955 bool RequiresADL) {
956 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
957 }
958
959
960 /// \brief Build a new expression that references a declaration.
961 ///
962 /// By default, performs semantic analysis to build the new expression.
963 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000964 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
965 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000966 ValueDecl *VD, SourceLocation Loc,
967 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000968 CXXScopeSpec SS;
969 SS.setScopeRep(Qualifier);
970 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000971
972 // FIXME: loses template args.
973
974 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregora16548e2009-08-11 05:31:07 +0000977 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000978 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000979 /// By default, performs semantic analysis to build the new expression.
980 /// Subclasses may override this routine to provide different behavior.
981 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
982 SourceLocation RParen) {
983 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
984 }
985
Douglas Gregorad8a3362009-09-04 17:36:40 +0000986 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000987 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000988 /// By default, performs semantic analysis to build the new expression.
989 /// Subclasses may override this routine to provide different behavior.
990 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
991 SourceLocation OperatorLoc,
992 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000993 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000994 SourceRange QualifierRange,
995 TypeSourceInfo *ScopeType,
996 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000997 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000998 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregora16548e2009-08-11 05:31:07 +00001000 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001001 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001002 /// By default, performs semantic analysis to build the new expression.
1003 /// Subclasses may override this routine to provide different behavior.
1004 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1005 UnaryOperator::Opcode Opc,
1006 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001007 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001014 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001015 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001017 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 }
1019
Mike Stump11289f42009-09-09 15:08:12 +00001020 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001021 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001022 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
1025 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1026 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001027 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001028 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1029 OpLoc, isSizeOf, R);
1030 if (Result.isInvalid())
1031 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001032
Douglas Gregora16548e2009-08-11 05:31:07 +00001033 SubExpr.release();
1034 return move(Result);
1035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001041 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 SourceLocation LBracketLoc,
1043 ExprArg RHS,
1044 SourceLocation RBracketLoc) {
1045 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001046 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 RBracketLoc);
1048 }
1049
1050 /// \brief Build a new call 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 RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1055 MultiExprArg Args,
1056 SourceLocation *CommaLocs,
1057 SourceLocation RParenLoc) {
1058 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1059 move(Args), CommaLocs, RParenLoc);
1060 }
1061
1062 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001063 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
1066 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001067 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001068 NestedNameSpecifier *Qualifier,
1069 SourceRange QualifierRange,
1070 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001071 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001072 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001073 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001074 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001075 if (!Member->getDeclName()) {
1076 // We have a reference to an unnamed field.
1077 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001078
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001079 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001080 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1081 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001082 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001083
Mike Stump11289f42009-09-09 15:08:12 +00001084 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001085 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001086 Member, MemberLoc,
1087 cast<FieldDecl>(Member)->getType());
1088 return getSema().Owned(ME);
1089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001091 CXXScopeSpec SS;
1092 if (Qualifier) {
1093 SS.setRange(QualifierRange);
1094 SS.setScopeRep(Qualifier);
1095 }
1096
John McCall2d74de92009-12-01 22:10:20 +00001097 QualType BaseType = ((Expr*) Base.get())->getType();
1098
John McCall16df1e52010-03-30 21:47:33 +00001099 // FIXME: this involves duplicating earlier analysis in a lot of
1100 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001101 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1102 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001103 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001104 R.resolveKind();
1105
John McCall2d74de92009-12-01 22:10:20 +00001106 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1107 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001108 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001109 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 }
Mike Stump11289f42009-09-09 15:08:12 +00001111
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001113 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 /// By default, performs semantic analysis to build the new expression.
1115 /// Subclasses may override this routine to provide different behavior.
1116 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1117 BinaryOperator::Opcode Opc,
1118 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001119 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1120 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 }
1122
1123 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
1127 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1128 SourceLocation QuestionLoc,
1129 ExprArg LHS,
1130 SourceLocation ColonLoc,
1131 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001132 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 move(LHS), move(RHS));
1134 }
1135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new C-style cast 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.
John McCall97513962010-01-15 18:39:57 +00001140 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1141 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 SourceLocation RParenLoc,
1143 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001144 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1145 move(SubExpr));
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 compound literal 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.
1152 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001153 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001154 SourceLocation RParenLoc,
1155 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001156 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1157 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 }
Mike Stump11289f42009-09-09 15:08:12 +00001159
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001161 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 /// By default, performs semantic analysis to build the new expression.
1163 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001164 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 SourceLocation OpLoc,
1166 SourceLocation AccessorLoc,
1167 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001168
John McCall10eae182009-11-30 22:42:35 +00001169 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001170 QualType BaseType = ((Expr*) Base.get())->getType();
1171 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001172 OpLoc, /*IsArrow*/ false,
1173 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001174 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001175 AccessorLoc,
1176 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001177 }
Mike Stump11289f42009-09-09 15:08:12 +00001178
Douglas Gregora16548e2009-08-11 05:31:07 +00001179 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001180 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 /// By default, performs semantic analysis to build the new expression.
1182 /// Subclasses may override this routine to provide different behavior.
1183 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1184 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001185 SourceLocation RBraceLoc,
1186 QualType ResultTy) {
1187 OwningExprResult Result
1188 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1189 if (Result.isInvalid() || ResultTy->isDependentType())
1190 return move(Result);
1191
1192 // Patch in the result type we were given, which may have been computed
1193 // when the initial InitListExpr was built.
1194 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1195 ILE->setType(ResultTy);
1196 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 }
Mike Stump11289f42009-09-09 15:08:12 +00001198
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001200 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 /// By default, performs semantic analysis to build the new expression.
1202 /// Subclasses may override this routine to provide different behavior.
1203 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1204 MultiExprArg ArrayExprs,
1205 SourceLocation EqualOrColonLoc,
1206 bool GNUSyntax,
1207 ExprArg Init) {
1208 OwningExprResult Result
1209 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1210 move(Init));
1211 if (Result.isInvalid())
1212 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 ArrayExprs.release();
1215 return move(Result);
1216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001219 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// By default, builds the implicit value initialization without performing
1221 /// any semantic analysis. Subclasses may override this routine to provide
1222 /// different behavior.
1223 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1224 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1225 }
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001228 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// By default, performs semantic analysis to build the new expression.
1230 /// Subclasses may override this routine to provide different behavior.
1231 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1232 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001233 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 RParenLoc);
1235 }
1236
1237 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001238 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
1241 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1242 MultiExprArg SubExprs,
1243 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001244 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1245 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
1250 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// rather than attempting to map the label statement itself.
1252 /// Subclasses may override this routine to provide different behavior.
1253 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1254 SourceLocation LabelLoc,
1255 LabelStmt *Label) {
1256 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1264 StmtArg SubStmt,
1265 SourceLocation RParenLoc) {
1266 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 /// \brief Build a new __builtin_types_compatible_p expression.
1270 ///
1271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
1273 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1274 QualType T1, QualType T2,
1275 SourceLocation RParenLoc) {
1276 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1277 T1.getAsOpaquePtr(),
1278 T2.getAsOpaquePtr(),
1279 RParenLoc);
1280 }
Mike Stump11289f42009-09-09 15:08:12 +00001281
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// \brief Build a new __builtin_choose_expr expression.
1283 ///
1284 /// By default, performs semantic analysis to build the new expression.
1285 /// Subclasses may override this routine to provide different behavior.
1286 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1287 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1288 SourceLocation RParenLoc) {
1289 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1290 move(Cond), move(LHS), move(RHS),
1291 RParenLoc);
1292 }
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 /// \brief Build a new overloaded operator call expression.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// The semantic analysis provides the behavior of template instantiation,
1298 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001299 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// argument-dependent lookup, etc. Subclasses may override this routine to
1301 /// provide different behavior.
1302 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1303 SourceLocation OpLoc,
1304 ExprArg Callee,
1305 ExprArg First,
1306 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001307
1308 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// reinterpret_cast.
1310 ///
1311 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001312 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1315 Stmt::StmtClass Class,
1316 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001317 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 SourceLocation RAngleLoc,
1319 SourceLocation LParenLoc,
1320 ExprArg SubExpr,
1321 SourceLocation RParenLoc) {
1322 switch (Class) {
1323 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001324 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001325 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 move(SubExpr), RParenLoc);
1327
1328 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001329 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001330 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001332
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001334 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001335 RAngleLoc, LParenLoc,
1336 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001338
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001340 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001341 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001343
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 default:
1345 assert(false && "Invalid C++ named cast");
1346 break;
1347 }
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 return getSema().ExprError();
1350 }
Mike Stump11289f42009-09-09 15:08:12 +00001351
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 /// \brief Build a new C++ static_cast expression.
1353 ///
1354 /// By default, performs semantic analysis to build the new expression.
1355 /// Subclasses may override this routine to provide different behavior.
1356 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1357 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001358 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 SourceLocation RAngleLoc,
1360 SourceLocation LParenLoc,
1361 ExprArg SubExpr,
1362 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001363 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1364 TInfo, move(SubExpr),
1365 SourceRange(LAngleLoc, RAngleLoc),
1366 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 }
1368
1369 /// \brief Build a new C++ dynamic_cast expression.
1370 ///
1371 /// By default, performs semantic analysis to build the new expression.
1372 /// Subclasses may override this routine to provide different behavior.
1373 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1374 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001375 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 SourceLocation RAngleLoc,
1377 SourceLocation LParenLoc,
1378 ExprArg SubExpr,
1379 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001380 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1381 TInfo, move(SubExpr),
1382 SourceRange(LAngleLoc, RAngleLoc),
1383 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 }
1385
1386 /// \brief Build a new C++ reinterpret_cast expression.
1387 ///
1388 /// By default, performs semantic analysis to build the new expression.
1389 /// Subclasses may override this routine to provide different behavior.
1390 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1391 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001392 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 SourceLocation RAngleLoc,
1394 SourceLocation LParenLoc,
1395 ExprArg SubExpr,
1396 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001397 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1398 TInfo, move(SubExpr),
1399 SourceRange(LAngleLoc, RAngleLoc),
1400 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 }
1402
1403 /// \brief Build a new C++ const_cast expression.
1404 ///
1405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
1407 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1408 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001409 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 SourceLocation RAngleLoc,
1411 SourceLocation LParenLoc,
1412 ExprArg SubExpr,
1413 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001414 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1415 TInfo, move(SubExpr),
1416 SourceRange(LAngleLoc, RAngleLoc),
1417 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 /// \brief Build a new C++ functional-style cast expression.
1421 ///
1422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
1424 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001425 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation LParenLoc,
1427 ExprArg SubExpr,
1428 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001429 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001431 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001433 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001434 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 RParenLoc);
1436 }
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// \brief Build a new C++ typeid(type) 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 QualType T,
1445 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001446 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 T.getAsOpaquePtr(), RParenLoc);
1448 }
Mike Stump11289f42009-09-09 15:08:12 +00001449
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 /// \brief Build a new C++ typeid(expr) expression.
1451 ///
1452 /// By default, performs semantic analysis to build the new expression.
1453 /// Subclasses may override this routine to provide different behavior.
1454 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1455 SourceLocation LParenLoc,
1456 ExprArg Operand,
1457 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001458 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1460 RParenLoc);
1461 if (Result.isInvalid())
1462 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001463
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1465 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001466 }
1467
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 /// \brief Build a new C++ "this" expression.
1469 ///
1470 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001471 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001473 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001474 QualType ThisType,
1475 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001477 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1478 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 }
1480
1481 /// \brief Build a new C++ throw expression.
1482 ///
1483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
1485 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1486 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1487 }
1488
1489 /// \brief Build a new C++ default-argument expression.
1490 ///
1491 /// By default, builds a new default-argument expression, which does not
1492 /// require any semantic analysis. Subclasses may override this routine to
1493 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001494 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1495 ParmVarDecl *Param) {
1496 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1497 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 }
1499
1500 /// \brief Build a new C++ zero-initialization expression.
1501 ///
1502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001504 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 SourceLocation LParenLoc,
1506 QualType T,
1507 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001508 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1509 T.getAsOpaquePtr(), LParenLoc,
1510 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 0, RParenLoc);
1512 }
Mike Stump11289f42009-09-09 15:08:12 +00001513
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// \brief Build a new C++ "new" expression.
1515 ///
1516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001518 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 bool UseGlobal,
1520 SourceLocation PlacementLParen,
1521 MultiExprArg PlacementArgs,
1522 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001523 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 QualType AllocType,
1525 SourceLocation TypeLoc,
1526 SourceRange TypeRange,
1527 ExprArg ArraySize,
1528 SourceLocation ConstructorLParen,
1529 MultiExprArg ConstructorArgs,
1530 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001531 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 PlacementLParen,
1533 move(PlacementArgs),
1534 PlacementRParen,
1535 ParenTypeId,
1536 AllocType,
1537 TypeLoc,
1538 TypeRange,
1539 move(ArraySize),
1540 ConstructorLParen,
1541 move(ConstructorArgs),
1542 ConstructorRParen);
1543 }
Mike Stump11289f42009-09-09 15:08:12 +00001544
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// \brief Build a new C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc,
1550 bool IsGlobalDelete,
1551 bool IsArrayForm,
1552 ExprArg Operand) {
1553 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1554 move(Operand));
1555 }
Mike Stump11289f42009-09-09 15:08:12 +00001556
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// \brief Build a new unary type trait expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
1561 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1562 SourceLocation StartLoc,
1563 SourceLocation LParenLoc,
1564 QualType T,
1565 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001566 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 T.getAsOpaquePtr(), RParenLoc);
1568 }
1569
Mike Stump11289f42009-09-09 15:08:12 +00001570 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 /// expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001575 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 SourceRange QualifierRange,
1577 DeclarationName Name,
1578 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001579 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 CXXScopeSpec SS;
1581 SS.setRange(QualifierRange);
1582 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001583
1584 if (TemplateArgs)
1585 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1586 *TemplateArgs);
1587
1588 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 }
1590
1591 /// \brief Build a new template-id expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001595 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1596 LookupResult &R,
1597 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001598 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001599 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 }
1601
1602 /// \brief Build a new object-construction expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
1606 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001607 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 CXXConstructorDecl *Constructor,
1609 bool IsElidable,
1610 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001611 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1612 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1613 ConvertedArgs))
1614 return getSema().ExprError();
1615
1616 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1617 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 }
1619
1620 /// \brief Build a new object-construction expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
1624 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1625 QualType T,
1626 SourceLocation LParenLoc,
1627 MultiExprArg Args,
1628 SourceLocation *Commas,
1629 SourceLocation RParenLoc) {
1630 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1631 T.getAsOpaquePtr(),
1632 LParenLoc,
1633 move(Args),
1634 Commas,
1635 RParenLoc);
1636 }
1637
1638 /// \brief Build a new object-construction expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
1642 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1643 QualType T,
1644 SourceLocation LParenLoc,
1645 MultiExprArg Args,
1646 SourceLocation *Commas,
1647 SourceLocation RParenLoc) {
1648 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1649 /*FIXME*/LParenLoc),
1650 T.getAsOpaquePtr(),
1651 LParenLoc,
1652 move(Args),
1653 Commas,
1654 RParenLoc);
1655 }
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 /// \brief Build a new member reference expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001661 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001662 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 bool IsArrow,
1664 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001665 NestedNameSpecifier *Qualifier,
1666 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001667 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001669 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001670 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001672 SS.setRange(QualifierRange);
1673 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001674
John McCall2d74de92009-12-01 22:10:20 +00001675 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1676 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001677 SS, FirstQualifierInScope,
1678 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 }
1680
John McCall10eae182009-11-30 22:42:35 +00001681 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001685 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001686 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001687 SourceLocation OperatorLoc,
1688 bool IsArrow,
1689 NestedNameSpecifier *Qualifier,
1690 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001691 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001692 LookupResult &R,
1693 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001694 CXXScopeSpec SS;
1695 SS.setRange(QualifierRange);
1696 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001697
John McCall2d74de92009-12-01 22:10:20 +00001698 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1699 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001700 SS, FirstQualifierInScope,
1701 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// \brief Build a new Objective-C @encode expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
1708 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001709 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001711 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001713 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001714
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001715 /// \brief Build a new Objective-C class message.
1716 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1717 Selector Sel,
1718 ObjCMethodDecl *Method,
1719 SourceLocation LBracLoc,
1720 MultiExprArg Args,
1721 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001722 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1723 ReceiverTypeInfo->getType(),
1724 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001725 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001726 move(Args));
1727 }
1728
1729 /// \brief Build a new Objective-C instance message.
1730 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1731 Selector Sel,
1732 ObjCMethodDecl *Method,
1733 SourceLocation LBracLoc,
1734 MultiExprArg Args,
1735 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001736 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1737 return SemaRef.BuildInstanceMessage(move(Receiver),
1738 ReceiverType,
1739 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001740 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001741 move(Args));
1742 }
1743
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 /// \brief Build a new shuffle vector expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
1748 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1749 MultiExprArg SubExprs,
1750 SourceLocation RParenLoc) {
1751 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001752 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1754 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1755 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1756 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 // Build a reference to the __builtin_shufflevector builtin
1759 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001760 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001762 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001764
1765 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 unsigned NumSubExprs = SubExprs.size();
1767 Expr **Subs = (Expr **)SubExprs.release();
1768 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1769 Subs, NumSubExprs,
1770 Builtin->getResultType(),
1771 RParenLoc);
1772 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 // Type-check the __builtin_shufflevector expression.
1775 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1776 if (Result.isInvalid())
1777 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001780 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001782};
Douglas Gregora16548e2009-08-11 05:31:07 +00001783
Douglas Gregorebe10102009-08-20 07:17:43 +00001784template<typename Derived>
1785Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1786 if (!S)
1787 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregorebe10102009-08-20 07:17:43 +00001789 switch (S->getStmtClass()) {
1790 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001791
Douglas Gregorebe10102009-08-20 07:17:43 +00001792 // Transform individual statement nodes
1793#define STMT(Node, Parent) \
1794 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1795#define EXPR(Node, Parent)
1796#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001797
Douglas Gregorebe10102009-08-20 07:17:43 +00001798 // Transform expressions by calling TransformExpr.
1799#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001800#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001801#define EXPR(Node, Parent) case Stmt::Node##Class:
1802#include "clang/AST/StmtNodes.def"
1803 {
1804 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1805 if (E.isInvalid())
1806 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001807
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001808 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001809 }
Mike Stump11289f42009-09-09 15:08:12 +00001810 }
1811
Douglas Gregorebe10102009-08-20 07:17:43 +00001812 return SemaRef.Owned(S->Retain());
1813}
Mike Stump11289f42009-09-09 15:08:12 +00001814
1815
Douglas Gregore922c772009-08-04 22:27:00 +00001816template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001817Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 if (!E)
1819 return SemaRef.Owned(E);
1820
1821 switch (E->getStmtClass()) {
1822 case Stmt::NoStmtClass: break;
1823#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001824#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001825#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001826 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001827#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001828 }
1829
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001831}
1832
1833template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001834NestedNameSpecifier *
1835TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001836 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001837 QualType ObjectType,
1838 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001839 if (!NNS)
1840 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregorebe10102009-08-20 07:17:43 +00001842 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001843 NestedNameSpecifier *Prefix = NNS->getPrefix();
1844 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001845 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001846 ObjectType,
1847 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001848 if (!Prefix)
1849 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001850
1851 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001852 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001853 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001854 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001855 }
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregor1135c352009-08-06 05:28:30 +00001857 switch (NNS->getKind()) {
1858 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001859 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001860 "Identifier nested-name-specifier with no prefix or object type");
1861 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1862 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001863 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001864
1865 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001866 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001867 ObjectType,
1868 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001869
Douglas Gregor1135c352009-08-06 05:28:30 +00001870 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001871 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001872 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001873 getDerived().TransformDecl(Range.getBegin(),
1874 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001875 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001876 Prefix == NNS->getPrefix() &&
1877 NS == NNS->getAsNamespace())
1878 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001879
Douglas Gregor1135c352009-08-06 05:28:30 +00001880 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1881 }
Mike Stump11289f42009-09-09 15:08:12 +00001882
Douglas Gregor1135c352009-08-06 05:28:30 +00001883 case NestedNameSpecifier::Global:
1884 // There is no meaningful transformation that one could perform on the
1885 // global scope.
1886 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregor1135c352009-08-06 05:28:30 +00001888 case NestedNameSpecifier::TypeSpecWithTemplate:
1889 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001890 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001891 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1892 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001893 if (T.isNull())
1894 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregor1135c352009-08-06 05:28:30 +00001896 if (!getDerived().AlwaysRebuild() &&
1897 Prefix == NNS->getPrefix() &&
1898 T == QualType(NNS->getAsType(), 0))
1899 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001900
1901 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1902 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001903 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001904 }
1905 }
Mike Stump11289f42009-09-09 15:08:12 +00001906
Douglas Gregor1135c352009-08-06 05:28:30 +00001907 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001908 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001909}
1910
1911template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001912DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001913TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001914 SourceLocation Loc,
1915 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001916 if (!Name)
1917 return Name;
1918
1919 switch (Name.getNameKind()) {
1920 case DeclarationName::Identifier:
1921 case DeclarationName::ObjCZeroArgSelector:
1922 case DeclarationName::ObjCOneArgSelector:
1923 case DeclarationName::ObjCMultiArgSelector:
1924 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001925 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001926 case DeclarationName::CXXUsingDirective:
1927 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001928
Douglas Gregorf816bd72009-09-03 22:13:48 +00001929 case DeclarationName::CXXConstructorName:
1930 case DeclarationName::CXXDestructorName:
1931 case DeclarationName::CXXConversionFunctionName: {
1932 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001933 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1934 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001935 if (T.isNull())
1936 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001937
Douglas Gregorf816bd72009-09-03 22:13:48 +00001938 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001939 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001940 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001941 }
Mike Stump11289f42009-09-09 15:08:12 +00001942 }
1943
Douglas Gregorf816bd72009-09-03 22:13:48 +00001944 return DeclarationName();
1945}
1946
1947template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001948TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001949TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1950 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001951 SourceLocation Loc = getDerived().getBaseLocation();
1952
Douglas Gregor71dc5092009-08-06 06:41:21 +00001953 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001954 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001955 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001956 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1957 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001958 if (!NNS)
1959 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregor71dc5092009-08-06 06:41:21 +00001961 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001962 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001963 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001964 if (!TransTemplate)
1965 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregor71dc5092009-08-06 06:41:21 +00001967 if (!getDerived().AlwaysRebuild() &&
1968 NNS == QTN->getQualifier() &&
1969 TransTemplate == Template)
1970 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregor71dc5092009-08-06 06:41:21 +00001972 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1973 TransTemplate);
1974 }
Mike Stump11289f42009-09-09 15:08:12 +00001975
John McCalle66edc12009-11-24 19:00:30 +00001976 // These should be getting filtered out before they make it into the AST.
1977 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979
Douglas Gregor71dc5092009-08-06 06:41:21 +00001980 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001981 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001982 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001983 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1984 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001985 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001986 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregor71dc5092009-08-06 06:41:21 +00001988 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001989 NNS == DTN->getQualifier() &&
1990 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001991 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregor71395fa2009-11-04 00:56:37 +00001993 if (DTN->isIdentifier())
1994 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1995 ObjectType);
1996
1997 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1998 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001999 }
Mike Stump11289f42009-09-09 15:08:12 +00002000
Douglas Gregor71dc5092009-08-06 06:41:21 +00002001 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002002 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002003 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002004 if (!TransTemplate)
2005 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002006
Douglas Gregor71dc5092009-08-06 06:41:21 +00002007 if (!getDerived().AlwaysRebuild() &&
2008 TransTemplate == Template)
2009 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002010
Douglas Gregor71dc5092009-08-06 06:41:21 +00002011 return TemplateName(TransTemplate);
2012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
John McCalle66edc12009-11-24 19:00:30 +00002014 // These should be getting filtered out before they reach the AST.
2015 assert(false && "overloaded function decl survived to here");
2016 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002017}
2018
2019template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002020void TreeTransform<Derived>::InventTemplateArgumentLoc(
2021 const TemplateArgument &Arg,
2022 TemplateArgumentLoc &Output) {
2023 SourceLocation Loc = getDerived().getBaseLocation();
2024 switch (Arg.getKind()) {
2025 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002026 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002027 break;
2028
2029 case TemplateArgument::Type:
2030 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002031 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002032
2033 break;
2034
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002035 case TemplateArgument::Template:
2036 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2037 break;
2038
John McCall0ad16662009-10-29 08:12:44 +00002039 case TemplateArgument::Expression:
2040 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2041 break;
2042
2043 case TemplateArgument::Declaration:
2044 case TemplateArgument::Integral:
2045 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002046 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002047 break;
2048 }
2049}
2050
2051template<typename Derived>
2052bool TreeTransform<Derived>::TransformTemplateArgument(
2053 const TemplateArgumentLoc &Input,
2054 TemplateArgumentLoc &Output) {
2055 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002056 switch (Arg.getKind()) {
2057 case TemplateArgument::Null:
2058 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002059 Output = Input;
2060 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002061
Douglas Gregore922c772009-08-04 22:27:00 +00002062 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002063 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002064 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002065 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002066
2067 DI = getDerived().TransformType(DI);
2068 if (!DI) return true;
2069
2070 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2071 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002072 }
Mike Stump11289f42009-09-09 15:08:12 +00002073
Douglas Gregore922c772009-08-04 22:27:00 +00002074 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002075 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002076 DeclarationName Name;
2077 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2078 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002079 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002080 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002081 if (!D) return true;
2082
John McCall0d07eb32009-10-29 18:45:58 +00002083 Expr *SourceExpr = Input.getSourceDeclExpression();
2084 if (SourceExpr) {
2085 EnterExpressionEvaluationContext Unevaluated(getSema(),
2086 Action::Unevaluated);
2087 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2088 if (E.isInvalid())
2089 SourceExpr = NULL;
2090 else {
2091 SourceExpr = E.takeAs<Expr>();
2092 SourceExpr->Retain();
2093 }
2094 }
2095
2096 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002097 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002098 }
Mike Stump11289f42009-09-09 15:08:12 +00002099
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002100 case TemplateArgument::Template: {
2101 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2102 TemplateName Template
2103 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2104 if (Template.isNull())
2105 return true;
2106
2107 Output = TemplateArgumentLoc(TemplateArgument(Template),
2108 Input.getTemplateQualifierRange(),
2109 Input.getTemplateNameLoc());
2110 return false;
2111 }
2112
Douglas Gregore922c772009-08-04 22:27:00 +00002113 case TemplateArgument::Expression: {
2114 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002115 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002116 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002117
John McCall0ad16662009-10-29 08:12:44 +00002118 Expr *InputExpr = Input.getSourceExpression();
2119 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2120
2121 Sema::OwningExprResult E
2122 = getDerived().TransformExpr(InputExpr);
2123 if (E.isInvalid()) return true;
2124
2125 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002126 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002127 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2128 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002129 }
Mike Stump11289f42009-09-09 15:08:12 +00002130
Douglas Gregore922c772009-08-04 22:27:00 +00002131 case TemplateArgument::Pack: {
2132 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2133 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002134 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002135 AEnd = Arg.pack_end();
2136 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002137
John McCall0ad16662009-10-29 08:12:44 +00002138 // FIXME: preserve source information here when we start
2139 // caring about parameter packs.
2140
John McCall0d07eb32009-10-29 18:45:58 +00002141 TemplateArgumentLoc InputArg;
2142 TemplateArgumentLoc OutputArg;
2143 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2144 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002145 return true;
2146
John McCall0d07eb32009-10-29 18:45:58 +00002147 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002148 }
2149 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002150 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002151 true);
John McCall0d07eb32009-10-29 18:45:58 +00002152 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002153 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002154 }
2155 }
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregore922c772009-08-04 22:27:00 +00002157 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002158 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002159}
2160
Douglas Gregord6ff3322009-08-04 16:50:30 +00002161//===----------------------------------------------------------------------===//
2162// Type transformation
2163//===----------------------------------------------------------------------===//
2164
2165template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002166QualType TreeTransform<Derived>::TransformType(QualType T,
2167 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002168 if (getDerived().AlreadyTransformed(T))
2169 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002170
John McCall550e0c22009-10-21 00:40:46 +00002171 // Temporary workaround. All of these transformations should
2172 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002173 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002174 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002175
Douglas Gregorfe17d252010-02-16 19:09:40 +00002176 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002177
John McCall550e0c22009-10-21 00:40:46 +00002178 if (!NewDI)
2179 return QualType();
2180
2181 return NewDI->getType();
2182}
2183
2184template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002185TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2186 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002187 if (getDerived().AlreadyTransformed(DI->getType()))
2188 return DI;
2189
2190 TypeLocBuilder TLB;
2191
2192 TypeLoc TL = DI->getTypeLoc();
2193 TLB.reserve(TL.getFullDataSize());
2194
Douglas Gregorfe17d252010-02-16 19:09:40 +00002195 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002196 if (Result.isNull())
2197 return 0;
2198
John McCallbcd03502009-12-07 02:54:59 +00002199 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002200}
2201
2202template<typename Derived>
2203QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002204TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2205 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002206 switch (T.getTypeLocClass()) {
2207#define ABSTRACT_TYPELOC(CLASS, PARENT)
2208#define TYPELOC(CLASS, PARENT) \
2209 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002210 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2211 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002212#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002213 }
Mike Stump11289f42009-09-09 15:08:12 +00002214
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002215 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002216 return QualType();
2217}
2218
2219/// FIXME: By default, this routine adds type qualifiers only to types
2220/// that can have qualifiers, and silently suppresses those qualifiers
2221/// that are not permitted (e.g., qualifiers on reference or function
2222/// types). This is the right thing for template instantiation, but
2223/// probably not for other clients.
2224template<typename Derived>
2225QualType
2226TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002227 QualifiedTypeLoc T,
2228 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002229 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002230
Douglas Gregorfe17d252010-02-16 19:09:40 +00002231 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2232 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002233 if (Result.isNull())
2234 return QualType();
2235
2236 // Silently suppress qualifiers if the result type can't be qualified.
2237 // FIXME: this is the right thing for template instantiation, but
2238 // probably not for other clients.
2239 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002240 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002241
John McCall550e0c22009-10-21 00:40:46 +00002242 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2243
2244 TLB.push<QualifiedTypeLoc>(Result);
2245
2246 // No location information to preserve.
2247
2248 return Result;
2249}
2250
2251template <class TyLoc> static inline
2252QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2253 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2254 NewT.setNameLoc(T.getNameLoc());
2255 return T.getType();
2256}
2257
John McCall550e0c22009-10-21 00:40:46 +00002258template<typename Derived>
2259QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002260 BuiltinTypeLoc T,
2261 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002262 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2263 NewT.setBuiltinLoc(T.getBuiltinLoc());
2264 if (T.needsExtraLocalData())
2265 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2266 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002267}
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregord6ff3322009-08-04 16:50:30 +00002269template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002270QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002271 ComplexTypeLoc T,
2272 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002273 // FIXME: recurse?
2274 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002275}
Mike Stump11289f42009-09-09 15:08:12 +00002276
Douglas Gregord6ff3322009-08-04 16:50:30 +00002277template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002278QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002279 PointerTypeLoc TL,
2280 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002281 QualType PointeeType
2282 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2283 if (PointeeType.isNull())
2284 return QualType();
2285
2286 QualType Result = TL.getType();
2287 if (PointeeType->isObjCInterfaceType()) {
2288 // A dependent pointer type 'T *' has is being transformed such
2289 // that an Objective-C class type is being replaced for 'T'. The
2290 // resulting pointer type is an ObjCObjectPointerType, not a
2291 // PointerType.
2292 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2293 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2294 const_cast<ObjCProtocolDecl **>(
2295 IFace->qual_begin()),
2296 IFace->getNumProtocols());
2297
2298 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2299 NewT.setStarLoc(TL.getSigilLoc());
2300 NewT.setHasProtocolsAsWritten(false);
2301 NewT.setLAngleLoc(SourceLocation());
2302 NewT.setRAngleLoc(SourceLocation());
2303 NewT.setHasBaseTypeAsWritten(true);
2304 return Result;
2305 }
2306
2307 if (getDerived().AlwaysRebuild() ||
2308 PointeeType != TL.getPointeeLoc().getType()) {
2309 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2310 if (Result.isNull())
2311 return QualType();
2312 }
2313
2314 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2315 NewT.setSigilLoc(TL.getSigilLoc());
2316 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002317}
Mike Stump11289f42009-09-09 15:08:12 +00002318
2319template<typename Derived>
2320QualType
John McCall550e0c22009-10-21 00:40:46 +00002321TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002322 BlockPointerTypeLoc TL,
2323 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002324 QualType PointeeType
2325 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2326 if (PointeeType.isNull())
2327 return QualType();
2328
2329 QualType Result = TL.getType();
2330 if (getDerived().AlwaysRebuild() ||
2331 PointeeType != TL.getPointeeLoc().getType()) {
2332 Result = getDerived().RebuildBlockPointerType(PointeeType,
2333 TL.getSigilLoc());
2334 if (Result.isNull())
2335 return QualType();
2336 }
2337
Douglas Gregor049211a2010-04-22 16:50:51 +00002338 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002339 NewT.setSigilLoc(TL.getSigilLoc());
2340 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341}
2342
John McCall70dd5f62009-10-30 00:06:24 +00002343/// Transforms a reference type. Note that somewhat paradoxically we
2344/// don't care whether the type itself is an l-value type or an r-value
2345/// type; we only care if the type was *written* as an l-value type
2346/// or an r-value type.
2347template<typename Derived>
2348QualType
2349TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002350 ReferenceTypeLoc TL,
2351 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002352 const ReferenceType *T = TL.getTypePtr();
2353
2354 // Note that this works with the pointee-as-written.
2355 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2356 if (PointeeType.isNull())
2357 return QualType();
2358
2359 QualType Result = TL.getType();
2360 if (getDerived().AlwaysRebuild() ||
2361 PointeeType != T->getPointeeTypeAsWritten()) {
2362 Result = getDerived().RebuildReferenceType(PointeeType,
2363 T->isSpelledAsLValue(),
2364 TL.getSigilLoc());
2365 if (Result.isNull())
2366 return QualType();
2367 }
2368
2369 // r-value references can be rebuilt as l-value references.
2370 ReferenceTypeLoc NewTL;
2371 if (isa<LValueReferenceType>(Result))
2372 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2373 else
2374 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2375 NewTL.setSigilLoc(TL.getSigilLoc());
2376
2377 return Result;
2378}
2379
Mike Stump11289f42009-09-09 15:08:12 +00002380template<typename Derived>
2381QualType
John McCall550e0c22009-10-21 00:40:46 +00002382TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002383 LValueReferenceTypeLoc TL,
2384 QualType ObjectType) {
2385 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386}
2387
Mike Stump11289f42009-09-09 15:08:12 +00002388template<typename Derived>
2389QualType
John McCall550e0c22009-10-21 00:40:46 +00002390TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002391 RValueReferenceTypeLoc TL,
2392 QualType ObjectType) {
2393 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002394}
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregord6ff3322009-08-04 16:50:30 +00002396template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002397QualType
John McCall550e0c22009-10-21 00:40:46 +00002398TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002399 MemberPointerTypeLoc TL,
2400 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002401 MemberPointerType *T = TL.getTypePtr();
2402
2403 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002404 if (PointeeType.isNull())
2405 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002406
John McCall550e0c22009-10-21 00:40:46 +00002407 // TODO: preserve source information for this.
2408 QualType ClassType
2409 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410 if (ClassType.isNull())
2411 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002412
John McCall550e0c22009-10-21 00:40:46 +00002413 QualType Result = TL.getType();
2414 if (getDerived().AlwaysRebuild() ||
2415 PointeeType != T->getPointeeType() ||
2416 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002417 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2418 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002419 if (Result.isNull())
2420 return QualType();
2421 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422
John McCall550e0c22009-10-21 00:40:46 +00002423 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2424 NewTL.setSigilLoc(TL.getSigilLoc());
2425
2426 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002427}
2428
Mike Stump11289f42009-09-09 15:08:12 +00002429template<typename Derived>
2430QualType
John McCall550e0c22009-10-21 00:40:46 +00002431TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002432 ConstantArrayTypeLoc TL,
2433 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002434 ConstantArrayType *T = TL.getTypePtr();
2435 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002436 if (ElementType.isNull())
2437 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002438
John McCall550e0c22009-10-21 00:40:46 +00002439 QualType Result = TL.getType();
2440 if (getDerived().AlwaysRebuild() ||
2441 ElementType != T->getElementType()) {
2442 Result = getDerived().RebuildConstantArrayType(ElementType,
2443 T->getSizeModifier(),
2444 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002445 T->getIndexTypeCVRQualifiers(),
2446 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002447 if (Result.isNull())
2448 return QualType();
2449 }
2450
2451 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2452 NewTL.setLBracketLoc(TL.getLBracketLoc());
2453 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002454
John McCall550e0c22009-10-21 00:40:46 +00002455 Expr *Size = TL.getSizeExpr();
2456 if (Size) {
2457 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2458 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2459 }
2460 NewTL.setSizeExpr(Size);
2461
2462 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002463}
Mike Stump11289f42009-09-09 15:08:12 +00002464
Douglas Gregord6ff3322009-08-04 16:50:30 +00002465template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002466QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002467 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002468 IncompleteArrayTypeLoc TL,
2469 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002470 IncompleteArrayType *T = TL.getTypePtr();
2471 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472 if (ElementType.isNull())
2473 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002474
John McCall550e0c22009-10-21 00:40:46 +00002475 QualType Result = TL.getType();
2476 if (getDerived().AlwaysRebuild() ||
2477 ElementType != T->getElementType()) {
2478 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002479 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002480 T->getIndexTypeCVRQualifiers(),
2481 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002482 if (Result.isNull())
2483 return QualType();
2484 }
2485
2486 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2487 NewTL.setLBracketLoc(TL.getLBracketLoc());
2488 NewTL.setRBracketLoc(TL.getRBracketLoc());
2489 NewTL.setSizeExpr(0);
2490
2491 return Result;
2492}
2493
2494template<typename Derived>
2495QualType
2496TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002497 VariableArrayTypeLoc TL,
2498 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002499 VariableArrayType *T = TL.getTypePtr();
2500 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2501 if (ElementType.isNull())
2502 return QualType();
2503
2504 // Array bounds are not potentially evaluated contexts
2505 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2506
2507 Sema::OwningExprResult SizeResult
2508 = getDerived().TransformExpr(T->getSizeExpr());
2509 if (SizeResult.isInvalid())
2510 return QualType();
2511
2512 Expr *Size = static_cast<Expr*>(SizeResult.get());
2513
2514 QualType Result = TL.getType();
2515 if (getDerived().AlwaysRebuild() ||
2516 ElementType != T->getElementType() ||
2517 Size != T->getSizeExpr()) {
2518 Result = getDerived().RebuildVariableArrayType(ElementType,
2519 T->getSizeModifier(),
2520 move(SizeResult),
2521 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002522 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002523 if (Result.isNull())
2524 return QualType();
2525 }
2526 else SizeResult.take();
2527
2528 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2529 NewTL.setLBracketLoc(TL.getLBracketLoc());
2530 NewTL.setRBracketLoc(TL.getRBracketLoc());
2531 NewTL.setSizeExpr(Size);
2532
2533 return Result;
2534}
2535
2536template<typename Derived>
2537QualType
2538TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002539 DependentSizedArrayTypeLoc TL,
2540 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002541 DependentSizedArrayType *T = TL.getTypePtr();
2542 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2543 if (ElementType.isNull())
2544 return QualType();
2545
2546 // Array bounds are not potentially evaluated contexts
2547 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2548
2549 Sema::OwningExprResult SizeResult
2550 = getDerived().TransformExpr(T->getSizeExpr());
2551 if (SizeResult.isInvalid())
2552 return QualType();
2553
2554 Expr *Size = static_cast<Expr*>(SizeResult.get());
2555
2556 QualType Result = TL.getType();
2557 if (getDerived().AlwaysRebuild() ||
2558 ElementType != T->getElementType() ||
2559 Size != T->getSizeExpr()) {
2560 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2561 T->getSizeModifier(),
2562 move(SizeResult),
2563 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002564 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002565 if (Result.isNull())
2566 return QualType();
2567 }
2568 else SizeResult.take();
2569
2570 // We might have any sort of array type now, but fortunately they
2571 // all have the same location layout.
2572 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2573 NewTL.setLBracketLoc(TL.getLBracketLoc());
2574 NewTL.setRBracketLoc(TL.getRBracketLoc());
2575 NewTL.setSizeExpr(Size);
2576
2577 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002578}
Mike Stump11289f42009-09-09 15:08:12 +00002579
2580template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002582 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002583 DependentSizedExtVectorTypeLoc TL,
2584 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002585 DependentSizedExtVectorType *T = TL.getTypePtr();
2586
2587 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002588 QualType ElementType = getDerived().TransformType(T->getElementType());
2589 if (ElementType.isNull())
2590 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002591
Douglas Gregore922c772009-08-04 22:27:00 +00002592 // Vector sizes are not potentially evaluated contexts
2593 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2594
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2596 if (Size.isInvalid())
2597 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002598
John McCall550e0c22009-10-21 00:40:46 +00002599 QualType Result = TL.getType();
2600 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002601 ElementType != T->getElementType() ||
2602 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002603 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604 move(Size),
2605 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002606 if (Result.isNull())
2607 return QualType();
2608 }
2609 else Size.take();
2610
2611 // Result might be dependent or not.
2612 if (isa<DependentSizedExtVectorType>(Result)) {
2613 DependentSizedExtVectorTypeLoc NewTL
2614 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2615 NewTL.setNameLoc(TL.getNameLoc());
2616 } else {
2617 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2618 NewTL.setNameLoc(TL.getNameLoc());
2619 }
2620
2621 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002622}
Mike Stump11289f42009-09-09 15:08:12 +00002623
2624template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002625QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002626 VectorTypeLoc TL,
2627 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002628 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002629 QualType ElementType = getDerived().TransformType(T->getElementType());
2630 if (ElementType.isNull())
2631 return QualType();
2632
John McCall550e0c22009-10-21 00:40:46 +00002633 QualType Result = TL.getType();
2634 if (getDerived().AlwaysRebuild() ||
2635 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002636 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2637 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002638 if (Result.isNull())
2639 return QualType();
2640 }
2641
2642 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2643 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002644
John McCall550e0c22009-10-21 00:40:46 +00002645 return Result;
2646}
2647
2648template<typename Derived>
2649QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002650 ExtVectorTypeLoc TL,
2651 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002652 VectorType *T = TL.getTypePtr();
2653 QualType ElementType = getDerived().TransformType(T->getElementType());
2654 if (ElementType.isNull())
2655 return QualType();
2656
2657 QualType Result = TL.getType();
2658 if (getDerived().AlwaysRebuild() ||
2659 ElementType != T->getElementType()) {
2660 Result = getDerived().RebuildExtVectorType(ElementType,
2661 T->getNumElements(),
2662 /*FIXME*/ SourceLocation());
2663 if (Result.isNull())
2664 return QualType();
2665 }
2666
2667 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2668 NewTL.setNameLoc(TL.getNameLoc());
2669
2670 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002671}
Mike Stump11289f42009-09-09 15:08:12 +00002672
2673template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002674ParmVarDecl *
2675TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2676 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2677 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2678 if (!NewDI)
2679 return 0;
2680
2681 if (NewDI == OldDI)
2682 return OldParm;
2683 else
2684 return ParmVarDecl::Create(SemaRef.Context,
2685 OldParm->getDeclContext(),
2686 OldParm->getLocation(),
2687 OldParm->getIdentifier(),
2688 NewDI->getType(),
2689 NewDI,
2690 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002691 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002692 /* DefArg */ NULL);
2693}
2694
2695template<typename Derived>
2696bool TreeTransform<Derived>::
2697 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2698 llvm::SmallVectorImpl<QualType> &PTypes,
2699 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2700 FunctionProtoType *T = TL.getTypePtr();
2701
2702 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2703 ParmVarDecl *OldParm = TL.getArg(i);
2704
2705 QualType NewType;
2706 ParmVarDecl *NewParm;
2707
2708 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002709 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2710 if (!NewParm)
2711 return true;
2712 NewType = NewParm->getType();
2713
2714 // Deal with the possibility that we don't have a parameter
2715 // declaration for this parameter.
2716 } else {
2717 NewParm = 0;
2718
2719 QualType OldType = T->getArgType(i);
2720 NewType = getDerived().TransformType(OldType);
2721 if (NewType.isNull())
2722 return true;
2723 }
2724
2725 PTypes.push_back(NewType);
2726 PVars.push_back(NewParm);
2727 }
2728
2729 return false;
2730}
2731
2732template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002733QualType
John McCall550e0c22009-10-21 00:40:46 +00002734TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002735 FunctionProtoTypeLoc TL,
2736 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002737 FunctionProtoType *T = TL.getTypePtr();
2738 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002739 if (ResultType.isNull())
2740 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002741
John McCall550e0c22009-10-21 00:40:46 +00002742 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002743 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002744 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002745 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2746 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002747
John McCall550e0c22009-10-21 00:40:46 +00002748 QualType Result = TL.getType();
2749 if (getDerived().AlwaysRebuild() ||
2750 ResultType != T->getResultType() ||
2751 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2752 Result = getDerived().RebuildFunctionProtoType(ResultType,
2753 ParamTypes.data(),
2754 ParamTypes.size(),
2755 T->isVariadic(),
2756 T->getTypeQuals());
2757 if (Result.isNull())
2758 return QualType();
2759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
John McCall550e0c22009-10-21 00:40:46 +00002761 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2762 NewTL.setLParenLoc(TL.getLParenLoc());
2763 NewTL.setRParenLoc(TL.getRParenLoc());
2764 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2765 NewTL.setArg(i, ParamDecls[i]);
2766
2767 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768}
Mike Stump11289f42009-09-09 15:08:12 +00002769
Douglas Gregord6ff3322009-08-04 16:50:30 +00002770template<typename Derived>
2771QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002772 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002773 FunctionNoProtoTypeLoc TL,
2774 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002775 FunctionNoProtoType *T = TL.getTypePtr();
2776 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2777 if (ResultType.isNull())
2778 return QualType();
2779
2780 QualType Result = TL.getType();
2781 if (getDerived().AlwaysRebuild() ||
2782 ResultType != T->getResultType())
2783 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2784
2785 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2786 NewTL.setLParenLoc(TL.getLParenLoc());
2787 NewTL.setRParenLoc(TL.getRParenLoc());
2788
2789 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002790}
Mike Stump11289f42009-09-09 15:08:12 +00002791
John McCallb96ec562009-12-04 22:46:56 +00002792template<typename Derived> QualType
2793TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002794 UnresolvedUsingTypeLoc TL,
2795 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002796 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002797 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002798 if (!D)
2799 return QualType();
2800
2801 QualType Result = TL.getType();
2802 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2803 Result = getDerived().RebuildUnresolvedUsingType(D);
2804 if (Result.isNull())
2805 return QualType();
2806 }
2807
2808 // We might get an arbitrary type spec type back. We should at
2809 // least always get a type spec type, though.
2810 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2811 NewTL.setNameLoc(TL.getNameLoc());
2812
2813 return Result;
2814}
2815
Douglas Gregord6ff3322009-08-04 16:50:30 +00002816template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002817QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002818 TypedefTypeLoc TL,
2819 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002820 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002821 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002822 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2823 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002824 if (!Typedef)
2825 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002826
John McCall550e0c22009-10-21 00:40:46 +00002827 QualType Result = TL.getType();
2828 if (getDerived().AlwaysRebuild() ||
2829 Typedef != T->getDecl()) {
2830 Result = getDerived().RebuildTypedefType(Typedef);
2831 if (Result.isNull())
2832 return QualType();
2833 }
Mike Stump11289f42009-09-09 15:08:12 +00002834
John McCall550e0c22009-10-21 00:40:46 +00002835 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2836 NewTL.setNameLoc(TL.getNameLoc());
2837
2838 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002839}
Mike Stump11289f42009-09-09 15:08:12 +00002840
Douglas Gregord6ff3322009-08-04 16:50:30 +00002841template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002842QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002843 TypeOfExprTypeLoc TL,
2844 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002845 // typeof expressions are not potentially evaluated contexts
2846 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002847
John McCalle8595032010-01-13 20:03:27 +00002848 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002849 if (E.isInvalid())
2850 return QualType();
2851
John McCall550e0c22009-10-21 00:40:46 +00002852 QualType Result = TL.getType();
2853 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002854 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002855 Result = getDerived().RebuildTypeOfExprType(move(E));
2856 if (Result.isNull())
2857 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002858 }
John McCall550e0c22009-10-21 00:40:46 +00002859 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002860
John McCall550e0c22009-10-21 00:40:46 +00002861 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002862 NewTL.setTypeofLoc(TL.getTypeofLoc());
2863 NewTL.setLParenLoc(TL.getLParenLoc());
2864 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002865
2866 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002867}
Mike Stump11289f42009-09-09 15:08:12 +00002868
2869template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002870QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002871 TypeOfTypeLoc TL,
2872 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002873 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2874 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2875 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002876 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002877
John McCall550e0c22009-10-21 00:40:46 +00002878 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002879 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2880 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002881 if (Result.isNull())
2882 return QualType();
2883 }
Mike Stump11289f42009-09-09 15:08:12 +00002884
John McCall550e0c22009-10-21 00:40:46 +00002885 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002886 NewTL.setTypeofLoc(TL.getTypeofLoc());
2887 NewTL.setLParenLoc(TL.getLParenLoc());
2888 NewTL.setRParenLoc(TL.getRParenLoc());
2889 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002890
2891 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002892}
Mike Stump11289f42009-09-09 15:08:12 +00002893
2894template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002895QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002896 DecltypeTypeLoc TL,
2897 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002898 DecltypeType *T = TL.getTypePtr();
2899
Douglas Gregore922c772009-08-04 22:27:00 +00002900 // decltype expressions are not potentially evaluated contexts
2901 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002902
Douglas Gregord6ff3322009-08-04 16:50:30 +00002903 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2904 if (E.isInvalid())
2905 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002906
John McCall550e0c22009-10-21 00:40:46 +00002907 QualType Result = TL.getType();
2908 if (getDerived().AlwaysRebuild() ||
2909 E.get() != T->getUnderlyingExpr()) {
2910 Result = getDerived().RebuildDecltypeType(move(E));
2911 if (Result.isNull())
2912 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 }
John McCall550e0c22009-10-21 00:40:46 +00002914 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002915
John McCall550e0c22009-10-21 00:40:46 +00002916 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2917 NewTL.setNameLoc(TL.getNameLoc());
2918
2919 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920}
2921
2922template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002923QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002924 RecordTypeLoc TL,
2925 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002926 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002927 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002928 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2929 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930 if (!Record)
2931 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002932
John McCall550e0c22009-10-21 00:40:46 +00002933 QualType Result = TL.getType();
2934 if (getDerived().AlwaysRebuild() ||
2935 Record != T->getDecl()) {
2936 Result = getDerived().RebuildRecordType(Record);
2937 if (Result.isNull())
2938 return QualType();
2939 }
Mike Stump11289f42009-09-09 15:08:12 +00002940
John McCall550e0c22009-10-21 00:40:46 +00002941 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2942 NewTL.setNameLoc(TL.getNameLoc());
2943
2944 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002945}
Mike Stump11289f42009-09-09 15:08:12 +00002946
2947template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002948QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002949 EnumTypeLoc TL,
2950 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002951 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002953 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2954 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002955 if (!Enum)
2956 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002957
John McCall550e0c22009-10-21 00:40:46 +00002958 QualType Result = TL.getType();
2959 if (getDerived().AlwaysRebuild() ||
2960 Enum != T->getDecl()) {
2961 Result = getDerived().RebuildEnumType(Enum);
2962 if (Result.isNull())
2963 return QualType();
2964 }
Mike Stump11289f42009-09-09 15:08:12 +00002965
John McCall550e0c22009-10-21 00:40:46 +00002966 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2967 NewTL.setNameLoc(TL.getNameLoc());
2968
2969 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970}
John McCallfcc33b02009-09-05 00:15:47 +00002971
2972template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002973QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002974 ElaboratedTypeLoc TL,
2975 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002976 ElaboratedType *T = TL.getTypePtr();
2977
2978 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002979 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2980 if (Underlying.isNull())
2981 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002982
John McCall550e0c22009-10-21 00:40:46 +00002983 QualType Result = TL.getType();
2984 if (getDerived().AlwaysRebuild() ||
2985 Underlying != T->getUnderlyingType()) {
2986 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2987 if (Result.isNull())
2988 return QualType();
2989 }
Mike Stump11289f42009-09-09 15:08:12 +00002990
John McCall550e0c22009-10-21 00:40:46 +00002991 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2992 NewTL.setNameLoc(TL.getNameLoc());
2993
2994 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002995}
Mike Stump11289f42009-09-09 15:08:12 +00002996
John McCalle78aac42010-03-10 03:28:59 +00002997template<typename Derived>
2998QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2999 TypeLocBuilder &TLB,
3000 InjectedClassNameTypeLoc TL,
3001 QualType ObjectType) {
3002 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3003 TL.getTypePtr()->getDecl());
3004 if (!D) return QualType();
3005
3006 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3007 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3008 return T;
3009}
3010
Mike Stump11289f42009-09-09 15:08:12 +00003011
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012template<typename Derived>
3013QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003014 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003015 TemplateTypeParmTypeLoc TL,
3016 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003017 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018}
3019
Mike Stump11289f42009-09-09 15:08:12 +00003020template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003021QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003022 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003023 SubstTemplateTypeParmTypeLoc TL,
3024 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003025 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003026}
3027
3028template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003029QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3030 const TemplateSpecializationType *TST,
3031 QualType ObjectType) {
3032 // FIXME: this entire method is a temporary workaround; callers
3033 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003034
John McCall0ad16662009-10-29 08:12:44 +00003035 // Fake up a TemplateSpecializationTypeLoc.
3036 TypeLocBuilder TLB;
3037 TemplateSpecializationTypeLoc TL
3038 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3039
John McCall0d07eb32009-10-29 18:45:58 +00003040 SourceLocation BaseLoc = getDerived().getBaseLocation();
3041
3042 TL.setTemplateNameLoc(BaseLoc);
3043 TL.setLAngleLoc(BaseLoc);
3044 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003045 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3046 const TemplateArgument &TA = TST->getArg(i);
3047 TemplateArgumentLoc TAL;
3048 getDerived().InventTemplateArgumentLoc(TA, TAL);
3049 TL.setArgLocInfo(i, TAL.getLocInfo());
3050 }
3051
3052 TypeLocBuilder IgnoredTLB;
3053 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003054}
3055
3056template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003057QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003058 TypeLocBuilder &TLB,
3059 TemplateSpecializationTypeLoc TL,
3060 QualType ObjectType) {
3061 const TemplateSpecializationType *T = TL.getTypePtr();
3062
Mike Stump11289f42009-09-09 15:08:12 +00003063 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003064 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003065 if (Template.isNull())
3066 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003067
John McCall6b51f282009-11-23 01:53:49 +00003068 TemplateArgumentListInfo NewTemplateArgs;
3069 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3070 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3071
3072 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3073 TemplateArgumentLoc Loc;
3074 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003075 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003076 NewTemplateArgs.addArgument(Loc);
3077 }
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall0ad16662009-10-29 08:12:44 +00003079 // FIXME: maybe don't rebuild if all the template arguments are the same.
3080
3081 QualType Result =
3082 getDerived().RebuildTemplateSpecializationType(Template,
3083 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003084 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003085
3086 if (!Result.isNull()) {
3087 TemplateSpecializationTypeLoc NewTL
3088 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3089 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3090 NewTL.setLAngleLoc(TL.getLAngleLoc());
3091 NewTL.setRAngleLoc(TL.getRAngleLoc());
3092 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3093 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003094 }
Mike Stump11289f42009-09-09 15:08:12 +00003095
John McCall0ad16662009-10-29 08:12:44 +00003096 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003097}
Mike Stump11289f42009-09-09 15:08:12 +00003098
3099template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003100QualType
3101TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003102 QualifiedNameTypeLoc TL,
3103 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003104 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 NestedNameSpecifier *NNS
3106 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003107 SourceRange(),
3108 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003109 if (!NNS)
3110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003111
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112 QualType Named = getDerived().TransformType(T->getNamedType());
3113 if (Named.isNull())
3114 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003115
John McCall550e0c22009-10-21 00:40:46 +00003116 QualType Result = TL.getType();
3117 if (getDerived().AlwaysRebuild() ||
3118 NNS != T->getQualifier() ||
3119 Named != T->getNamedType()) {
3120 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3121 if (Result.isNull())
3122 return QualType();
3123 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124
John McCall550e0c22009-10-21 00:40:46 +00003125 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3126 NewTL.setNameLoc(TL.getNameLoc());
3127
3128 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129}
Mike Stump11289f42009-09-09 15:08:12 +00003130
3131template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003132QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3133 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003134 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003135 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003136
3137 /* FIXME: preserve source information better than this */
3138 SourceRange SR(TL.getNameLoc());
3139
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003141 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003142 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143 if (!NNS)
3144 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003145
John McCall550e0c22009-10-21 00:40:46 +00003146 QualType Result;
3147
Douglas Gregord6ff3322009-08-04 16:50:30 +00003148 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003149 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150 = getDerived().TransformType(QualType(TemplateId, 0));
3151 if (NewTemplateId.isNull())
3152 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003153
Douglas Gregord6ff3322009-08-04 16:50:30 +00003154 if (!getDerived().AlwaysRebuild() &&
3155 NNS == T->getQualifier() &&
3156 NewTemplateId == QualType(TemplateId, 0))
3157 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregor02085352010-03-31 20:19:30 +00003159 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3160 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003161 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003162 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3163 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003164 }
John McCall550e0c22009-10-21 00:40:46 +00003165 if (Result.isNull())
3166 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003168 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003169 NewTL.setNameLoc(TL.getNameLoc());
3170
3171 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003172}
Mike Stump11289f42009-09-09 15:08:12 +00003173
Douglas Gregord6ff3322009-08-04 16:50:30 +00003174template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003175QualType
3176TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003177 ObjCInterfaceTypeLoc TL,
3178 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003179 // ObjCInterfaceType is never dependent.
3180 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003181}
Mike Stump11289f42009-09-09 15:08:12 +00003182
3183template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003184QualType
3185TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003186 ObjCObjectPointerTypeLoc TL,
3187 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003188 // ObjCObjectPointerType is never dependent.
3189 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003190}
3191
Douglas Gregord6ff3322009-08-04 16:50:30 +00003192//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003193// Statement transformation
3194//===----------------------------------------------------------------------===//
3195template<typename Derived>
3196Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003197TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3198 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003199}
3200
3201template<typename Derived>
3202Sema::OwningStmtResult
3203TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3204 return getDerived().TransformCompoundStmt(S, false);
3205}
3206
3207template<typename Derived>
3208Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003209TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003210 bool IsStmtExpr) {
3211 bool SubStmtChanged = false;
3212 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3213 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3214 B != BEnd; ++B) {
3215 OwningStmtResult Result = getDerived().TransformStmt(*B);
3216 if (Result.isInvalid())
3217 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003218
Douglas Gregorebe10102009-08-20 07:17:43 +00003219 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3220 Statements.push_back(Result.takeAs<Stmt>());
3221 }
Mike Stump11289f42009-09-09 15:08:12 +00003222
Douglas Gregorebe10102009-08-20 07:17:43 +00003223 if (!getDerived().AlwaysRebuild() &&
3224 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003225 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003226
3227 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3228 move_arg(Statements),
3229 S->getRBracLoc(),
3230 IsStmtExpr);
3231}
Mike Stump11289f42009-09-09 15:08:12 +00003232
Douglas Gregorebe10102009-08-20 07:17:43 +00003233template<typename Derived>
3234Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003235TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003236 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3237 {
3238 // The case value expressions are not potentially evaluated.
3239 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003240
Eli Friedman06577382009-11-19 03:14:00 +00003241 // Transform the left-hand case value.
3242 LHS = getDerived().TransformExpr(S->getLHS());
3243 if (LHS.isInvalid())
3244 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003245
Eli Friedman06577382009-11-19 03:14:00 +00003246 // Transform the right-hand case value (for the GNU case-range extension).
3247 RHS = getDerived().TransformExpr(S->getRHS());
3248 if (RHS.isInvalid())
3249 return SemaRef.StmtError();
3250 }
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregorebe10102009-08-20 07:17:43 +00003252 // Build the case statement.
3253 // Case statements are always rebuilt so that they will attached to their
3254 // transformed switch statement.
3255 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3256 move(LHS),
3257 S->getEllipsisLoc(),
3258 move(RHS),
3259 S->getColonLoc());
3260 if (Case.isInvalid())
3261 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003262
Douglas Gregorebe10102009-08-20 07:17:43 +00003263 // Transform the statement following the 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 // Attach the body to the case statement
3269 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3270}
3271
3272template<typename Derived>
3273Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003274TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003275 // Transform the statement following the default case
3276 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 // Default statements are always rebuilt
3281 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3282 move(SubStmt));
3283}
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregorebe10102009-08-20 07:17:43 +00003285template<typename Derived>
3286Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003287TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3289 if (SubStmt.isInvalid())
3290 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003291
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 // FIXME: Pass the real colon location in.
3293 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3294 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3295 move(SubStmt));
3296}
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregorebe10102009-08-20 07:17:43 +00003298template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003299Sema::OwningStmtResult
3300TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003302 OwningExprResult Cond(SemaRef);
3303 VarDecl *ConditionVar = 0;
3304 if (S->getConditionVariable()) {
3305 ConditionVar
3306 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003307 getDerived().TransformDefinition(
3308 S->getConditionVariable()->getLocation(),
3309 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003310 if (!ConditionVar)
3311 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003312 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003313 Cond = getDerived().TransformExpr(S->getCond());
3314
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003315 if (Cond.isInvalid())
3316 return SemaRef.StmtError();
3317 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003318
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003319 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003320
Douglas Gregorebe10102009-08-20 07:17:43 +00003321 // Transform the "then" branch.
3322 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3323 if (Then.isInvalid())
3324 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003325
Douglas Gregorebe10102009-08-20 07:17:43 +00003326 // Transform the "else" branch.
3327 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3328 if (Else.isInvalid())
3329 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003330
Douglas Gregorebe10102009-08-20 07:17:43 +00003331 if (!getDerived().AlwaysRebuild() &&
3332 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003333 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003334 Then.get() == S->getThen() &&
3335 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003336 return SemaRef.Owned(S->Retain());
3337
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003338 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3339 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003340 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003341}
3342
3343template<typename Derived>
3344Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003345TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003346 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003347 OwningExprResult Cond(SemaRef);
3348 VarDecl *ConditionVar = 0;
3349 if (S->getConditionVariable()) {
3350 ConditionVar
3351 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003352 getDerived().TransformDefinition(
3353 S->getConditionVariable()->getLocation(),
3354 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003355 if (!ConditionVar)
3356 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003357 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003358 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003359
3360 if (Cond.isInvalid())
3361 return SemaRef.StmtError();
3362 }
Mike Stump11289f42009-09-09 15:08:12 +00003363
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003364 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003365
Douglas Gregorebe10102009-08-20 07:17:43 +00003366 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003367 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3368 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 if (Switch.isInvalid())
3370 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003371
Douglas Gregorebe10102009-08-20 07:17:43 +00003372 // Transform the body of the switch statement.
3373 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3374 if (Body.isInvalid())
3375 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003376
Douglas Gregorebe10102009-08-20 07:17:43 +00003377 // Complete the switch statement.
3378 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3379 move(Body));
3380}
Mike Stump11289f42009-09-09 15:08:12 +00003381
Douglas Gregorebe10102009-08-20 07:17:43 +00003382template<typename Derived>
3383Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003384TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003385 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003386 OwningExprResult Cond(SemaRef);
3387 VarDecl *ConditionVar = 0;
3388 if (S->getConditionVariable()) {
3389 ConditionVar
3390 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003391 getDerived().TransformDefinition(
3392 S->getConditionVariable()->getLocation(),
3393 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003394 if (!ConditionVar)
3395 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003396 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003397 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003398
3399 if (Cond.isInvalid())
3400 return SemaRef.StmtError();
3401 }
Mike Stump11289f42009-09-09 15:08:12 +00003402
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003403 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregorebe10102009-08-20 07:17:43 +00003405 // Transform the body
3406 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3407 if (Body.isInvalid())
3408 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregorebe10102009-08-20 07:17:43 +00003410 if (!getDerived().AlwaysRebuild() &&
3411 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003412 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003413 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003414 return SemaRef.Owned(S->Retain());
3415
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003416 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3417 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003418}
Mike Stump11289f42009-09-09 15:08:12 +00003419
Douglas Gregorebe10102009-08-20 07:17:43 +00003420template<typename Derived>
3421Sema::OwningStmtResult
3422TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3423 // Transform the condition
3424 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3425 if (Cond.isInvalid())
3426 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003427
Douglas Gregorebe10102009-08-20 07:17:43 +00003428 // Transform the body
3429 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3430 if (Body.isInvalid())
3431 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003432
Douglas Gregorebe10102009-08-20 07:17:43 +00003433 if (!getDerived().AlwaysRebuild() &&
3434 Cond.get() == S->getCond() &&
3435 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003436 return SemaRef.Owned(S->Retain());
3437
Douglas Gregorebe10102009-08-20 07:17:43 +00003438 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3439 /*FIXME:*/S->getWhileLoc(), move(Cond),
3440 S->getRParenLoc());
3441}
Mike Stump11289f42009-09-09 15:08:12 +00003442
Douglas Gregorebe10102009-08-20 07:17:43 +00003443template<typename Derived>
3444Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003445TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003446 // Transform the initialization statement
3447 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3448 if (Init.isInvalid())
3449 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003450
Douglas Gregorebe10102009-08-20 07:17:43 +00003451 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003452 OwningExprResult Cond(SemaRef);
3453 VarDecl *ConditionVar = 0;
3454 if (S->getConditionVariable()) {
3455 ConditionVar
3456 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003457 getDerived().TransformDefinition(
3458 S->getConditionVariable()->getLocation(),
3459 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003460 if (!ConditionVar)
3461 return SemaRef.StmtError();
3462 } else {
3463 Cond = getDerived().TransformExpr(S->getCond());
3464
3465 if (Cond.isInvalid())
3466 return SemaRef.StmtError();
3467 }
Mike Stump11289f42009-09-09 15:08:12 +00003468
Douglas Gregorebe10102009-08-20 07:17:43 +00003469 // Transform the increment
3470 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3471 if (Inc.isInvalid())
3472 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003473
Douglas Gregorebe10102009-08-20 07:17:43 +00003474 // Transform the body
3475 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3476 if (Body.isInvalid())
3477 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003478
Douglas Gregorebe10102009-08-20 07:17:43 +00003479 if (!getDerived().AlwaysRebuild() &&
3480 Init.get() == S->getInit() &&
3481 Cond.get() == S->getCond() &&
3482 Inc.get() == S->getInc() &&
3483 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003484 return SemaRef.Owned(S->Retain());
3485
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003487 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003488 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003489 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003490 S->getRParenLoc(), move(Body));
3491}
3492
3493template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003494Sema::OwningStmtResult
3495TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003497 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003498 S->getLabel());
3499}
3500
3501template<typename Derived>
3502Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003503TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3505 if (Target.isInvalid())
3506 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003507
Douglas Gregorebe10102009-08-20 07:17:43 +00003508 if (!getDerived().AlwaysRebuild() &&
3509 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003510 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003511
3512 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3513 move(Target));
3514}
3515
3516template<typename Derived>
3517Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3519 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003520}
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorebe10102009-08-20 07:17:43 +00003522template<typename Derived>
3523Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003524TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3525 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003526}
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>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3532 if (Result.isInvalid())
3533 return SemaRef.StmtError();
3534
Mike Stump11289f42009-09-09 15:08:12 +00003535 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // to tell whether the return type of the function has changed.
3537 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3538}
Mike Stump11289f42009-09-09 15:08:12 +00003539
Douglas Gregorebe10102009-08-20 07:17:43 +00003540template<typename Derived>
3541Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003542TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003543 bool DeclChanged = false;
3544 llvm::SmallVector<Decl *, 4> Decls;
3545 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3546 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003547 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3548 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003549 if (!Transformed)
3550 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 if (Transformed != *D)
3553 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555 Decls.push_back(Transformed);
3556 }
Mike Stump11289f42009-09-09 15:08:12 +00003557
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003559 return SemaRef.Owned(S->Retain());
3560
3561 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003562 S->getStartLoc(), S->getEndLoc());
3563}
Mike Stump11289f42009-09-09 15:08:12 +00003564
Douglas Gregorebe10102009-08-20 07:17:43 +00003565template<typename Derived>
3566Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003567TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003569 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003570}
3571
3572template<typename Derived>
3573Sema::OwningStmtResult
3574TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003575
3576 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3577 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003578 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003579
Anders Carlssonaaeef072010-01-24 05:50:09 +00003580 OwningExprResult AsmString(SemaRef);
3581 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3582
3583 bool ExprsChanged = false;
3584
3585 // Go through the outputs.
3586 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003587 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003588
Anders Carlssonaaeef072010-01-24 05:50:09 +00003589 // No need to transform the constraint literal.
3590 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3591
3592 // Transform the output expr.
3593 Expr *OutputExpr = S->getOutputExpr(I);
3594 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3595 if (Result.isInvalid())
3596 return SemaRef.StmtError();
3597
3598 ExprsChanged |= Result.get() != OutputExpr;
3599
3600 Exprs.push_back(Result.takeAs<Expr>());
3601 }
3602
3603 // Go through the inputs.
3604 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003605 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003606
Anders Carlssonaaeef072010-01-24 05:50:09 +00003607 // No need to transform the constraint literal.
3608 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3609
3610 // Transform the input expr.
3611 Expr *InputExpr = S->getInputExpr(I);
3612 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3613 if (Result.isInvalid())
3614 return SemaRef.StmtError();
3615
3616 ExprsChanged |= Result.get() != InputExpr;
3617
3618 Exprs.push_back(Result.takeAs<Expr>());
3619 }
3620
3621 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3622 return SemaRef.Owned(S->Retain());
3623
3624 // Go through the clobbers.
3625 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3626 Clobbers.push_back(S->getClobber(I)->Retain());
3627
3628 // No need to transform the asm string literal.
3629 AsmString = SemaRef.Owned(S->getAsmString());
3630
3631 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3632 S->isSimple(),
3633 S->isVolatile(),
3634 S->getNumOutputs(),
3635 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003636 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003637 move_arg(Constraints),
3638 move_arg(Exprs),
3639 move(AsmString),
3640 move_arg(Clobbers),
3641 S->getRParenLoc(),
3642 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003643}
3644
3645
3646template<typename Derived>
3647Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003648TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003649 // FIXME: Implement this
3650 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003651 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003652}
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorebe10102009-08-20 07:17:43 +00003654template<typename Derived>
3655Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003656TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003657 // FIXME: Implement this
3658 assert(false && "Cannot transform an Objective-C @catch statement");
3659 return SemaRef.Owned(S->Retain());
3660}
Mike Stump11289f42009-09-09 15:08:12 +00003661
Douglas Gregorebe10102009-08-20 07:17:43 +00003662template<typename Derived>
3663Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003664TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003665 // FIXME: Implement this
3666 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003667 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003668}
Mike Stump11289f42009-09-09 15:08:12 +00003669
Douglas Gregorebe10102009-08-20 07:17:43 +00003670template<typename Derived>
3671Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003672TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003673 OwningExprResult Operand(SemaRef);
3674 if (S->getThrowExpr()) {
3675 Operand = getDerived().TransformExpr(S->getThrowExpr());
3676 if (Operand.isInvalid())
3677 return getSema().StmtError();
3678 }
3679
3680 if (!getDerived().AlwaysRebuild() &&
3681 Operand.get() == S->getThrowExpr())
3682 return getSema().Owned(S->Retain());
3683
3684 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003685}
Mike Stump11289f42009-09-09 15:08:12 +00003686
Douglas Gregorebe10102009-08-20 07:17:43 +00003687template<typename Derived>
3688Sema::OwningStmtResult
3689TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003690 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003691 // Transform the object we are locking.
3692 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3693 if (Object.isInvalid())
3694 return SemaRef.StmtError();
3695
3696 // Transform the body.
3697 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3698 if (Body.isInvalid())
3699 return SemaRef.StmtError();
3700
3701 // If nothing change, just retain the current statement.
3702 if (!getDerived().AlwaysRebuild() &&
3703 Object.get() == S->getSynchExpr() &&
3704 Body.get() == S->getSynchBody())
3705 return SemaRef.Owned(S->Retain());
3706
3707 // Build a new statement.
3708 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3709 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003710}
3711
3712template<typename Derived>
3713Sema::OwningStmtResult
3714TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003715 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003716 // FIXME: Implement this
3717 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003718 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003719}
3720
3721
3722template<typename Derived>
3723Sema::OwningStmtResult
3724TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3725 // Transform the exception declaration, if any.
3726 VarDecl *Var = 0;
3727 if (S->getExceptionDecl()) {
3728 VarDecl *ExceptionDecl = S->getExceptionDecl();
3729 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3730 ExceptionDecl->getDeclName());
3731
3732 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3733 if (T.isNull())
3734 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003735
Douglas Gregorebe10102009-08-20 07:17:43 +00003736 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3737 T,
John McCallbcd03502009-12-07 02:54:59 +00003738 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003739 ExceptionDecl->getIdentifier(),
3740 ExceptionDecl->getLocation(),
3741 /*FIXME: Inaccurate*/
3742 SourceRange(ExceptionDecl->getLocation()));
3743 if (!Var || Var->isInvalidDecl()) {
3744 if (Var)
3745 Var->Destroy(SemaRef.Context);
3746 return SemaRef.StmtError();
3747 }
3748 }
Mike Stump11289f42009-09-09 15:08:12 +00003749
Douglas Gregorebe10102009-08-20 07:17:43 +00003750 // Transform the actual exception handler.
3751 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3752 if (Handler.isInvalid()) {
3753 if (Var)
3754 Var->Destroy(SemaRef.Context);
3755 return SemaRef.StmtError();
3756 }
Mike Stump11289f42009-09-09 15:08:12 +00003757
Douglas Gregorebe10102009-08-20 07:17:43 +00003758 if (!getDerived().AlwaysRebuild() &&
3759 !Var &&
3760 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003761 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003762
3763 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3764 Var,
3765 move(Handler));
3766}
Mike Stump11289f42009-09-09 15:08:12 +00003767
Douglas Gregorebe10102009-08-20 07:17:43 +00003768template<typename Derived>
3769Sema::OwningStmtResult
3770TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3771 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003772 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 = getDerived().TransformCompoundStmt(S->getTryBlock());
3774 if (TryBlock.isInvalid())
3775 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregorebe10102009-08-20 07:17:43 +00003777 // Transform the handlers.
3778 bool HandlerChanged = false;
3779 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3780 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003781 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3783 if (Handler.isInvalid())
3784 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003785
Douglas Gregorebe10102009-08-20 07:17:43 +00003786 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3787 Handlers.push_back(Handler.takeAs<Stmt>());
3788 }
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 TryBlock.get() == S->getTryBlock() &&
3792 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003793 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003794
3795 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003796 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003797}
Mike Stump11289f42009-09-09 15:08:12 +00003798
Douglas Gregorebe10102009-08-20 07:17:43 +00003799//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003800// Expression transformation
3801//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003802template<typename Derived>
3803Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003804TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003805 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003806}
Mike Stump11289f42009-09-09 15:08:12 +00003807
3808template<typename Derived>
3809Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003810TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003811 NestedNameSpecifier *Qualifier = 0;
3812 if (E->getQualifier()) {
3813 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003814 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003815 if (!Qualifier)
3816 return SemaRef.ExprError();
3817 }
John McCallce546572009-12-08 09:08:17 +00003818
3819 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003820 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3821 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003822 if (!ND)
3823 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003825 if (!getDerived().AlwaysRebuild() &&
3826 Qualifier == E->getQualifier() &&
3827 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003828 !E->hasExplicitTemplateArgumentList()) {
3829
3830 // Mark it referenced in the new context regardless.
3831 // FIXME: this is a bit instantiation-specific.
3832 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3833
Mike Stump11289f42009-09-09 15:08:12 +00003834 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003835 }
John McCallce546572009-12-08 09:08:17 +00003836
3837 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3838 if (E->hasExplicitTemplateArgumentList()) {
3839 TemplateArgs = &TransArgs;
3840 TransArgs.setLAngleLoc(E->getLAngleLoc());
3841 TransArgs.setRAngleLoc(E->getRAngleLoc());
3842 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3843 TemplateArgumentLoc Loc;
3844 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3845 return SemaRef.ExprError();
3846 TransArgs.addArgument(Loc);
3847 }
3848 }
3849
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003850 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003851 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003852}
Mike Stump11289f42009-09-09 15:08:12 +00003853
Douglas Gregora16548e2009-08-11 05:31:07 +00003854template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003855Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003856TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003857 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003858}
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregora16548e2009-08-11 05:31:07 +00003860template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003861Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003862TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003863 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003864}
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregora16548e2009-08-11 05:31:07 +00003866template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003867Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003868TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003869 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003870}
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregora16548e2009-08-11 05:31:07 +00003872template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003873Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003874TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003875 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003876}
Mike Stump11289f42009-09-09 15:08:12 +00003877
Douglas Gregora16548e2009-08-11 05:31:07 +00003878template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003879Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003880TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003881 return SemaRef.Owned(E->Retain());
3882}
3883
3884template<typename Derived>
3885Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003886TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3888 if (SubExpr.isInvalid())
3889 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003890
Douglas Gregora16548e2009-08-11 05:31:07 +00003891 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003892 return SemaRef.Owned(E->Retain());
3893
3894 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003895 E->getRParen());
3896}
3897
Mike Stump11289f42009-09-09 15:08:12 +00003898template<typename Derived>
3899Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003900TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3901 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 if (SubExpr.isInvalid())
3903 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003906 return SemaRef.Owned(E->Retain());
3907
Douglas Gregora16548e2009-08-11 05:31:07 +00003908 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3909 E->getOpcode(),
3910 move(SubExpr));
3911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregora16548e2009-08-11 05:31:07 +00003913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003914Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003915TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003917 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003918
John McCallbcd03502009-12-07 02:54:59 +00003919 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003920 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003921 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003922
John McCall4c98fd82009-11-04 07:28:41 +00003923 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003924 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003925
John McCall4c98fd82009-11-04 07:28:41 +00003926 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003927 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003928 E->getSourceRange());
3929 }
Mike Stump11289f42009-09-09 15:08:12 +00003930
Douglas Gregora16548e2009-08-11 05:31:07 +00003931 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003932 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 // C++0x [expr.sizeof]p1:
3934 // The operand is either an expression, which is an unevaluated operand
3935 // [...]
3936 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003937
Douglas Gregora16548e2009-08-11 05:31:07 +00003938 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3939 if (SubExpr.isInvalid())
3940 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003941
Douglas Gregora16548e2009-08-11 05:31:07 +00003942 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3943 return SemaRef.Owned(E->Retain());
3944 }
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregora16548e2009-08-11 05:31:07 +00003946 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3947 E->isSizeOf(),
3948 E->getSourceRange());
3949}
Mike Stump11289f42009-09-09 15:08:12 +00003950
Douglas Gregora16548e2009-08-11 05:31:07 +00003951template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003952Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003953TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3955 if (LHS.isInvalid())
3956 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3959 if (RHS.isInvalid())
3960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003961
3962
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 if (!getDerived().AlwaysRebuild() &&
3964 LHS.get() == E->getLHS() &&
3965 RHS.get() == E->getRHS())
3966 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003967
Douglas Gregora16548e2009-08-11 05:31:07 +00003968 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3969 /*FIXME:*/E->getLHS()->getLocStart(),
3970 move(RHS),
3971 E->getRBracketLoc());
3972}
Mike Stump11289f42009-09-09 15:08:12 +00003973
3974template<typename Derived>
3975Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003976TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 // Transform the callee.
3978 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3979 if (Callee.isInvalid())
3980 return SemaRef.ExprError();
3981
3982 // Transform arguments.
3983 bool ArgChanged = false;
3984 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3985 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3986 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3987 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3988 if (Arg.isInvalid())
3989 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991 // FIXME: Wrong source location information for the ','.
3992 FakeCommaLocs.push_back(
3993 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003994
3995 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003996 Args.push_back(Arg.takeAs<Expr>());
3997 }
Mike Stump11289f42009-09-09 15:08:12 +00003998
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 if (!getDerived().AlwaysRebuild() &&
4000 Callee.get() == E->getCallee() &&
4001 !ArgChanged)
4002 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregora16548e2009-08-11 05:31:07 +00004004 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004005 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4007 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4008 move_arg(Args),
4009 FakeCommaLocs.data(),
4010 E->getRParenLoc());
4011}
Mike Stump11289f42009-09-09 15:08:12 +00004012
4013template<typename Derived>
4014Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004015TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004016 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4017 if (Base.isInvalid())
4018 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004019
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004020 NestedNameSpecifier *Qualifier = 0;
4021 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004022 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004023 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004024 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004025 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004026 return SemaRef.ExprError();
4027 }
Mike Stump11289f42009-09-09 15:08:12 +00004028
Eli Friedman2cfcef62009-12-04 06:40:45 +00004029 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004030 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4031 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004032 if (!Member)
4033 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004034
John McCall16df1e52010-03-30 21:47:33 +00004035 NamedDecl *FoundDecl = E->getFoundDecl();
4036 if (FoundDecl == E->getMemberDecl()) {
4037 FoundDecl = Member;
4038 } else {
4039 FoundDecl = cast_or_null<NamedDecl>(
4040 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4041 if (!FoundDecl)
4042 return SemaRef.ExprError();
4043 }
4044
Douglas Gregora16548e2009-08-11 05:31:07 +00004045 if (!getDerived().AlwaysRebuild() &&
4046 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004047 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004048 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004049 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004050 !E->hasExplicitTemplateArgumentList()) {
4051
4052 // Mark it referenced in the new context regardless.
4053 // FIXME: this is a bit instantiation-specific.
4054 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004055 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004056 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004057
John McCall6b51f282009-11-23 01:53:49 +00004058 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004059 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004060 TransArgs.setLAngleLoc(E->getLAngleLoc());
4061 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004062 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004063 TemplateArgumentLoc Loc;
4064 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004065 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004066 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004067 }
4068 }
4069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 // FIXME: Bogus source location for the operator
4071 SourceLocation FakeOperatorLoc
4072 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4073
John McCall38836f02010-01-15 08:34:02 +00004074 // FIXME: to do this check properly, we will need to preserve the
4075 // first-qualifier-in-scope here, just in case we had a dependent
4076 // base (and therefore couldn't do the check) and a
4077 // nested-name-qualifier (and therefore could do the lookup).
4078 NamedDecl *FirstQualifierInScope = 0;
4079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4081 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004082 Qualifier,
4083 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004084 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004085 Member,
John McCall16df1e52010-03-30 21:47:33 +00004086 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004087 (E->hasExplicitTemplateArgumentList()
4088 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004089 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004090}
Mike Stump11289f42009-09-09 15:08:12 +00004091
Douglas Gregora16548e2009-08-11 05:31:07 +00004092template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004093Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004094TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004095 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4096 if (LHS.isInvalid())
4097 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregora16548e2009-08-11 05:31:07 +00004099 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4100 if (RHS.isInvalid())
4101 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 if (!getDerived().AlwaysRebuild() &&
4104 LHS.get() == E->getLHS() &&
4105 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004106 return SemaRef.Owned(E->Retain());
4107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4109 move(LHS), move(RHS));
4110}
4111
Mike Stump11289f42009-09-09 15:08:12 +00004112template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004113Sema::OwningExprResult
4114TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004115 CompoundAssignOperator *E) {
4116 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004117}
Mike Stump11289f42009-09-09 15:08:12 +00004118
Douglas Gregora16548e2009-08-11 05:31:07 +00004119template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004120Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004121TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004122 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4123 if (Cond.isInvalid())
4124 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregora16548e2009-08-11 05:31:07 +00004126 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4127 if (LHS.isInvalid())
4128 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004129
Douglas Gregora16548e2009-08-11 05:31:07 +00004130 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4131 if (RHS.isInvalid())
4132 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregora16548e2009-08-11 05:31:07 +00004134 if (!getDerived().AlwaysRebuild() &&
4135 Cond.get() == E->getCond() &&
4136 LHS.get() == E->getLHS() &&
4137 RHS.get() == E->getRHS())
4138 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004139
4140 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004141 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004142 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004143 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004144 move(RHS));
4145}
Mike Stump11289f42009-09-09 15:08:12 +00004146
4147template<typename Derived>
4148Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004149TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004150 // Implicit casts are eliminated during transformation, since they
4151 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004152 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004153}
Mike Stump11289f42009-09-09 15:08:12 +00004154
Douglas Gregora16548e2009-08-11 05:31:07 +00004155template<typename Derived>
4156Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004157TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004158 TypeSourceInfo *OldT;
4159 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 {
4161 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004162 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004163 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4164 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004165
John McCall97513962010-01-15 18:39:57 +00004166 OldT = E->getTypeInfoAsWritten();
4167 NewT = getDerived().TransformType(OldT);
4168 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004169 return SemaRef.ExprError();
4170 }
Mike Stump11289f42009-09-09 15:08:12 +00004171
Douglas Gregor6131b442009-12-12 18:16:41 +00004172 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004173 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 if (SubExpr.isInvalid())
4175 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004176
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004178 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004179 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004180 return SemaRef.Owned(E->Retain());
4181
John McCall97513962010-01-15 18:39:57 +00004182 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4183 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004184 E->getRParenLoc(),
4185 move(SubExpr));
4186}
Mike Stump11289f42009-09-09 15:08:12 +00004187
Douglas Gregora16548e2009-08-11 05:31:07 +00004188template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004189Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004190TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004191 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4192 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4193 if (!NewT)
4194 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004195
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4197 if (Init.isInvalid())
4198 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregora16548e2009-08-11 05:31:07 +00004200 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004201 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004203 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004204
John McCall5d7aa7f2010-01-19 22:33:45 +00004205 // Note: the expression type doesn't necessarily match the
4206 // type-as-written, but that's okay, because it should always be
4207 // derivable from the initializer.
4208
John McCalle15bbff2010-01-18 19:35:47 +00004209 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 /*FIXME:*/E->getInitializer()->getLocEnd(),
4211 move(Init));
4212}
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregora16548e2009-08-11 05:31:07 +00004214template<typename Derived>
4215Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004216TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004217 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4218 if (Base.isInvalid())
4219 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregora16548e2009-08-11 05:31:07 +00004221 if (!getDerived().AlwaysRebuild() &&
4222 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004223 return SemaRef.Owned(E->Retain());
4224
Douglas Gregora16548e2009-08-11 05:31:07 +00004225 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004226 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004227 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4228 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4229 E->getAccessorLoc(),
4230 E->getAccessor());
4231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregora16548e2009-08-11 05:31:07 +00004233template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004235TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004236 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregora16548e2009-08-11 05:31:07 +00004238 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4239 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4240 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4241 if (Init.isInvalid())
4242 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregora16548e2009-08-11 05:31:07 +00004244 InitChanged = InitChanged || Init.get() != E->getInit(I);
4245 Inits.push_back(Init.takeAs<Expr>());
4246 }
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004249 return SemaRef.Owned(E->Retain());
4250
Douglas Gregora16548e2009-08-11 05:31:07 +00004251 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004252 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregora16548e2009-08-11 05:31:07 +00004255template<typename Derived>
4256Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004257TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004259
Douglas Gregorebe10102009-08-20 07:17:43 +00004260 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4262 if (Init.isInvalid())
4263 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004264
Douglas Gregorebe10102009-08-20 07:17:43 +00004265 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4267 bool ExprChanged = false;
4268 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4269 DEnd = E->designators_end();
4270 D != DEnd; ++D) {
4271 if (D->isFieldDesignator()) {
4272 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4273 D->getDotLoc(),
4274 D->getFieldLoc()));
4275 continue;
4276 }
Mike Stump11289f42009-09-09 15:08:12 +00004277
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 if (D->isArrayDesignator()) {
4279 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4280 if (Index.isInvalid())
4281 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004282
4283 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004284 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4287 ArrayExprs.push_back(Index.release());
4288 continue;
4289 }
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004292 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4294 if (Start.isInvalid())
4295 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004296
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4298 if (End.isInvalid())
4299 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004300
4301 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 End.get(),
4303 D->getLBracketLoc(),
4304 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004305
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4307 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309 ArrayExprs.push_back(Start.release());
4310 ArrayExprs.push_back(End.release());
4311 }
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 if (!getDerived().AlwaysRebuild() &&
4314 Init.get() == E->getInit() &&
4315 !ExprChanged)
4316 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004317
Douglas Gregora16548e2009-08-11 05:31:07 +00004318 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4319 E->getEqualOrColonLoc(),
4320 E->usesGNUSyntax(), move(Init));
4321}
Mike Stump11289f42009-09-09 15:08:12 +00004322
Douglas Gregora16548e2009-08-11 05:31:07 +00004323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004324Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004325TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004326 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004327 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4328
4329 // FIXME: Will we ever have proper type location here? Will we actually
4330 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 QualType T = getDerived().TransformType(E->getType());
4332 if (T.isNull())
4333 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004334
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 if (!getDerived().AlwaysRebuild() &&
4336 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004337 return SemaRef.Owned(E->Retain());
4338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 return getDerived().RebuildImplicitValueInitExpr(T);
4340}
Mike Stump11289f42009-09-09 15:08:12 +00004341
Douglas Gregora16548e2009-08-11 05:31:07 +00004342template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004343Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004344TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 // FIXME: Do we want the type as written?
4346 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 {
4349 // FIXME: Source location isn't quite accurate.
4350 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4351 T = getDerived().TransformType(E->getType());
4352 if (T.isNull())
4353 return SemaRef.ExprError();
4354 }
Mike Stump11289f42009-09-09 15:08:12 +00004355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4357 if (SubExpr.isInvalid())
4358 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004359
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 if (!getDerived().AlwaysRebuild() &&
4361 T == E->getType() &&
4362 SubExpr.get() == E->getSubExpr())
4363 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4366 T, E->getRParenLoc());
4367}
4368
4369template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004370Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004371TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 bool ArgumentChanged = false;
4373 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4374 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4375 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4376 if (Init.isInvalid())
4377 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4380 Inits.push_back(Init.takeAs<Expr>());
4381 }
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4384 move_arg(Inits),
4385 E->getRParenLoc());
4386}
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388/// \brief Transform an address-of-label expression.
4389///
4390/// By default, the transformation of an address-of-label expression always
4391/// rebuilds the expression, so that the label identifier can be resolved to
4392/// the corresponding label statement by semantic analysis.
4393template<typename Derived>
4394Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004395TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4397 E->getLabel());
4398}
Mike Stump11289f42009-09-09 15:08:12 +00004399
4400template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004401Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004402TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004403 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4405 if (SubStmt.isInvalid())
4406 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 if (!getDerived().AlwaysRebuild() &&
4409 SubStmt.get() == E->getSubStmt())
4410 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004411
4412 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 move(SubStmt),
4414 E->getRParenLoc());
4415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
4418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 QualType T1, T2;
4421 {
4422 // FIXME: Source location isn't quite accurate.
4423 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 T1 = getDerived().TransformType(E->getArgType1());
4426 if (T1.isNull())
4427 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004428
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 T2 = getDerived().TransformType(E->getArgType2());
4430 if (T2.isNull())
4431 return SemaRef.ExprError();
4432 }
4433
4434 if (!getDerived().AlwaysRebuild() &&
4435 T1 == E->getArgType1() &&
4436 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004437 return SemaRef.Owned(E->Retain());
4438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4440 T1, T2, E->getRParenLoc());
4441}
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregora16548e2009-08-11 05:31:07 +00004443template<typename Derived>
4444Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004445TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4447 if (Cond.isInvalid())
4448 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4451 if (LHS.isInvalid())
4452 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004453
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4455 if (RHS.isInvalid())
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 if (!getDerived().AlwaysRebuild() &&
4459 Cond.get() == E->getCond() &&
4460 LHS.get() == E->getLHS() &&
4461 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004462 return SemaRef.Owned(E->Retain());
4463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4465 move(Cond), move(LHS), move(RHS),
4466 E->getRParenLoc());
4467}
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregora16548e2009-08-11 05:31:07 +00004469template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004470Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004471TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004472 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004473}
4474
4475template<typename Derived>
4476Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004477TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004478 switch (E->getOperator()) {
4479 case OO_New:
4480 case OO_Delete:
4481 case OO_Array_New:
4482 case OO_Array_Delete:
4483 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4484 return SemaRef.ExprError();
4485
4486 case OO_Call: {
4487 // This is a call to an object's operator().
4488 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4489
4490 // Transform the object itself.
4491 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4492 if (Object.isInvalid())
4493 return SemaRef.ExprError();
4494
4495 // FIXME: Poor location information
4496 SourceLocation FakeLParenLoc
4497 = SemaRef.PP.getLocForEndOfToken(
4498 static_cast<Expr *>(Object.get())->getLocEnd());
4499
4500 // Transform the call arguments.
4501 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4502 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4503 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004504 if (getDerived().DropCallArgument(E->getArg(I)))
4505 break;
4506
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004507 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4508 if (Arg.isInvalid())
4509 return SemaRef.ExprError();
4510
4511 // FIXME: Poor source location information.
4512 SourceLocation FakeCommaLoc
4513 = SemaRef.PP.getLocForEndOfToken(
4514 static_cast<Expr *>(Arg.get())->getLocEnd());
4515 FakeCommaLocs.push_back(FakeCommaLoc);
4516 Args.push_back(Arg.release());
4517 }
4518
4519 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4520 move_arg(Args),
4521 FakeCommaLocs.data(),
4522 E->getLocEnd());
4523 }
4524
4525#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4526 case OO_##Name:
4527#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4528#include "clang/Basic/OperatorKinds.def"
4529 case OO_Subscript:
4530 // Handled below.
4531 break;
4532
4533 case OO_Conditional:
4534 llvm_unreachable("conditional operator is not actually overloadable");
4535 return SemaRef.ExprError();
4536
4537 case OO_None:
4538 case NUM_OVERLOADED_OPERATORS:
4539 llvm_unreachable("not an overloaded operator?");
4540 return SemaRef.ExprError();
4541 }
4542
Douglas Gregora16548e2009-08-11 05:31:07 +00004543 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4544 if (Callee.isInvalid())
4545 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004546
John McCall47f29ea2009-12-08 09:21:05 +00004547 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004548 if (First.isInvalid())
4549 return SemaRef.ExprError();
4550
4551 OwningExprResult Second(SemaRef);
4552 if (E->getNumArgs() == 2) {
4553 Second = getDerived().TransformExpr(E->getArg(1));
4554 if (Second.isInvalid())
4555 return SemaRef.ExprError();
4556 }
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 if (!getDerived().AlwaysRebuild() &&
4559 Callee.get() == E->getCallee() &&
4560 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004561 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4562 return SemaRef.Owned(E->Retain());
4563
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4565 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004566 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 move(First),
4568 move(Second));
4569}
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571template<typename Derived>
4572Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004573TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4574 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004575}
Mike Stump11289f42009-09-09 15:08:12 +00004576
Douglas Gregora16548e2009-08-11 05:31:07 +00004577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004578Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004579TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004580 TypeSourceInfo *OldT;
4581 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 {
4583 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004584 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4586 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004587
John McCall97513962010-01-15 18:39:57 +00004588 OldT = E->getTypeInfoAsWritten();
4589 NewT = getDerived().TransformType(OldT);
4590 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 return SemaRef.ExprError();
4592 }
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregor6131b442009-12-12 18:16:41 +00004594 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004595 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 if (SubExpr.isInvalid())
4597 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004598
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004600 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004602 return SemaRef.Owned(E->Retain());
4603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004605 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4607 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4608 SourceLocation FakeRParenLoc
4609 = SemaRef.PP.getLocForEndOfToken(
4610 E->getSubExpr()->getSourceRange().getEnd());
4611 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004612 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004613 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004614 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 FakeRAngleLoc,
4616 FakeRAngleLoc,
4617 move(SubExpr),
4618 FakeRParenLoc);
4619}
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregora16548e2009-08-11 05:31:07 +00004621template<typename Derived>
4622Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004623TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4624 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004625}
Mike Stump11289f42009-09-09 15:08:12 +00004626
4627template<typename Derived>
4628Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004629TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4630 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004631}
4632
Douglas Gregora16548e2009-08-11 05:31:07 +00004633template<typename Derived>
4634Sema::OwningExprResult
4635TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004636 CXXReinterpretCastExpr *E) {
4637 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004638}
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregora16548e2009-08-11 05:31:07 +00004640template<typename Derived>
4641Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004642TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4643 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004644}
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregora16548e2009-08-11 05:31:07 +00004646template<typename Derived>
4647Sema::OwningExprResult
4648TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004649 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004650 TypeSourceInfo *OldT;
4651 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 {
4653 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004654
John McCall97513962010-01-15 18:39:57 +00004655 OldT = E->getTypeInfoAsWritten();
4656 NewT = getDerived().TransformType(OldT);
4657 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 return SemaRef.ExprError();
4659 }
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregor6131b442009-12-12 18:16:41 +00004661 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004662 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 if (SubExpr.isInvalid())
4664 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004667 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004669 return SemaRef.Owned(E->Retain());
4670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 // FIXME: The end of the type's source range is wrong
4672 return getDerived().RebuildCXXFunctionalCastExpr(
4673 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004674 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 /*FIXME:*/E->getSubExpr()->getLocStart(),
4676 move(SubExpr),
4677 E->getRParenLoc());
4678}
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680template<typename Derived>
4681Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004682TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004683 if (E->isTypeOperand()) {
4684 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 QualType T = getDerived().TransformType(E->getTypeOperand());
4687 if (T.isNull())
4688 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 if (!getDerived().AlwaysRebuild() &&
4691 T == E->getTypeOperand())
4692 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004693
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4695 /*FIXME:*/E->getLocStart(),
4696 T,
4697 E->getLocEnd());
4698 }
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 // We don't know whether the expression is potentially evaluated until
4701 // after we perform semantic analysis, so the expression is potentially
4702 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004703 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4707 if (SubExpr.isInvalid())
4708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 if (!getDerived().AlwaysRebuild() &&
4711 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004712 return SemaRef.Owned(E->Retain());
4713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4715 /*FIXME:*/E->getLocStart(),
4716 move(SubExpr),
4717 E->getLocEnd());
4718}
4719
4720template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004721Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004722TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004723 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004724}
Mike Stump11289f42009-09-09 15:08:12 +00004725
Douglas Gregora16548e2009-08-11 05:31:07 +00004726template<typename Derived>
4727Sema::OwningExprResult
4728TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004729 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004730 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004731}
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733template<typename Derived>
4734Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004735TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 QualType T = getDerived().TransformType(E->getType());
4739 if (T.isNull())
4740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 if (!getDerived().AlwaysRebuild() &&
4743 T == E->getType())
4744 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004745
Douglas Gregorb15af892010-01-07 23:12:05 +00004746 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004747}
Mike Stump11289f42009-09-09 15:08:12 +00004748
Douglas Gregora16548e2009-08-11 05:31:07 +00004749template<typename Derived>
4750Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004751TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4753 if (SubExpr.isInvalid())
4754 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 if (!getDerived().AlwaysRebuild() &&
4757 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004758 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004759
4760 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4761}
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregora16548e2009-08-11 05:31:07 +00004763template<typename Derived>
4764Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004765TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004766 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004767 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4768 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 if (!Param)
4770 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004771
Chandler Carruth794da4c2010-02-08 06:42:49 +00004772 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 Param == E->getParam())
4774 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregor033f6752009-12-23 23:03:06 +00004776 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004777}
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779template<typename Derived>
4780Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004781TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4783
4784 QualType T = getDerived().TransformType(E->getType());
4785 if (T.isNull())
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 if (!getDerived().AlwaysRebuild() &&
4789 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004790 return SemaRef.Owned(E->Retain());
4791
4792 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 /*FIXME:*/E->getTypeBeginLoc(),
4794 T,
4795 E->getRParenLoc());
4796}
Mike Stump11289f42009-09-09 15:08:12 +00004797
Douglas Gregora16548e2009-08-11 05:31:07 +00004798template<typename Derived>
4799Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004800TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 // Transform the type that we're allocating
4802 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4803 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4804 if (AllocType.isNull())
4805 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 // Transform the size of the array we're allocating (if any).
4808 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4809 if (ArraySize.isInvalid())
4810 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004811
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 // Transform the placement arguments (if any).
4813 bool ArgumentChanged = false;
4814 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4815 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4816 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4817 if (Arg.isInvalid())
4818 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4821 PlacementArgs.push_back(Arg.take());
4822 }
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregorebe10102009-08-20 07:17:43 +00004824 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4826 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4827 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4828 if (Arg.isInvalid())
4829 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4832 ConstructorArgs.push_back(Arg.take());
4833 }
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregord2d9da02010-02-26 00:38:10 +00004835 // Transform constructor, new operator, and delete operator.
4836 CXXConstructorDecl *Constructor = 0;
4837 if (E->getConstructor()) {
4838 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004839 getDerived().TransformDecl(E->getLocStart(),
4840 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004841 if (!Constructor)
4842 return SemaRef.ExprError();
4843 }
4844
4845 FunctionDecl *OperatorNew = 0;
4846 if (E->getOperatorNew()) {
4847 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004848 getDerived().TransformDecl(E->getLocStart(),
4849 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004850 if (!OperatorNew)
4851 return SemaRef.ExprError();
4852 }
4853
4854 FunctionDecl *OperatorDelete = 0;
4855 if (E->getOperatorDelete()) {
4856 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004857 getDerived().TransformDecl(E->getLocStart(),
4858 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004859 if (!OperatorDelete)
4860 return SemaRef.ExprError();
4861 }
4862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 if (!getDerived().AlwaysRebuild() &&
4864 AllocType == E->getAllocatedType() &&
4865 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004866 Constructor == E->getConstructor() &&
4867 OperatorNew == E->getOperatorNew() &&
4868 OperatorDelete == E->getOperatorDelete() &&
4869 !ArgumentChanged) {
4870 // Mark any declarations we need as referenced.
4871 // FIXME: instantiation-specific.
4872 if (Constructor)
4873 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4874 if (OperatorNew)
4875 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4876 if (OperatorDelete)
4877 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004878 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004879 }
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004881 if (!ArraySize.get()) {
4882 // If no array size was specified, but the new expression was
4883 // instantiated with an array type (e.g., "new T" where T is
4884 // instantiated with "int[4]"), extract the outer bound from the
4885 // array type as our array size. We do this with constant and
4886 // dependently-sized array types.
4887 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4888 if (!ArrayT) {
4889 // Do nothing
4890 } else if (const ConstantArrayType *ConsArrayT
4891 = dyn_cast<ConstantArrayType>(ArrayT)) {
4892 ArraySize
4893 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4894 ConsArrayT->getSize(),
4895 SemaRef.Context.getSizeType(),
4896 /*FIXME:*/E->getLocStart()));
4897 AllocType = ConsArrayT->getElementType();
4898 } else if (const DependentSizedArrayType *DepArrayT
4899 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4900 if (DepArrayT->getSizeExpr()) {
4901 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4902 AllocType = DepArrayT->getElementType();
4903 }
4904 }
4905 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004906 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4907 E->isGlobalNew(),
4908 /*FIXME:*/E->getLocStart(),
4909 move_arg(PlacementArgs),
4910 /*FIXME:*/E->getLocStart(),
4911 E->isParenTypeId(),
4912 AllocType,
4913 /*FIXME:*/E->getLocStart(),
4914 /*FIXME:*/SourceRange(),
4915 move(ArraySize),
4916 /*FIXME:*/E->getLocStart(),
4917 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004918 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004919}
Mike Stump11289f42009-09-09 15:08:12 +00004920
Douglas Gregora16548e2009-08-11 05:31:07 +00004921template<typename Derived>
4922Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004923TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004924 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4925 if (Operand.isInvalid())
4926 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregord2d9da02010-02-26 00:38:10 +00004928 // Transform the delete operator, if known.
4929 FunctionDecl *OperatorDelete = 0;
4930 if (E->getOperatorDelete()) {
4931 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004932 getDerived().TransformDecl(E->getLocStart(),
4933 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004934 if (!OperatorDelete)
4935 return SemaRef.ExprError();
4936 }
4937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004939 Operand.get() == E->getArgument() &&
4940 OperatorDelete == E->getOperatorDelete()) {
4941 // Mark any declarations we need as referenced.
4942 // FIXME: instantiation-specific.
4943 if (OperatorDelete)
4944 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004945 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004946 }
Mike Stump11289f42009-09-09 15:08:12 +00004947
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4949 E->isGlobalDelete(),
4950 E->isArrayForm(),
4951 move(Operand));
4952}
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregora16548e2009-08-11 05:31:07 +00004954template<typename Derived>
4955Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004956TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004957 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004958 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4959 if (Base.isInvalid())
4960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004961
Douglas Gregor678f90d2010-02-25 01:56:36 +00004962 Sema::TypeTy *ObjectTypePtr = 0;
4963 bool MayBePseudoDestructor = false;
4964 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4965 E->getOperatorLoc(),
4966 E->isArrow()? tok::arrow : tok::period,
4967 ObjectTypePtr,
4968 MayBePseudoDestructor);
4969 if (Base.isInvalid())
4970 return SemaRef.ExprError();
4971
4972 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004973 NestedNameSpecifier *Qualifier
4974 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004975 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004976 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004977 if (E->getQualifier() && !Qualifier)
4978 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregor678f90d2010-02-25 01:56:36 +00004980 PseudoDestructorTypeStorage Destroyed;
4981 if (E->getDestroyedTypeInfo()) {
4982 TypeSourceInfo *DestroyedTypeInfo
4983 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4984 if (!DestroyedTypeInfo)
4985 return SemaRef.ExprError();
4986 Destroyed = DestroyedTypeInfo;
4987 } else if (ObjectType->isDependentType()) {
4988 // We aren't likely to be able to resolve the identifier down to a type
4989 // now anyway, so just retain the identifier.
4990 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4991 E->getDestroyedTypeLoc());
4992 } else {
4993 // Look for a destructor known with the given name.
4994 CXXScopeSpec SS;
4995 if (Qualifier) {
4996 SS.setScopeRep(Qualifier);
4997 SS.setRange(E->getQualifierRange());
4998 }
4999
5000 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5001 *E->getDestroyedTypeIdentifier(),
5002 E->getDestroyedTypeLoc(),
5003 /*Scope=*/0,
5004 SS, ObjectTypePtr,
5005 false);
5006 if (!T)
5007 return SemaRef.ExprError();
5008
5009 Destroyed
5010 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5011 E->getDestroyedTypeLoc());
5012 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005013
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005014 TypeSourceInfo *ScopeTypeInfo = 0;
5015 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005016 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5017 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005018 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005019 return SemaRef.ExprError();
5020 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005021
Douglas Gregorad8a3362009-09-04 17:36:40 +00005022 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5023 E->getOperatorLoc(),
5024 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005025 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005026 E->getQualifierRange(),
5027 ScopeTypeInfo,
5028 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005029 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005030 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregorad8a3362009-09-04 17:36:40 +00005033template<typename Derived>
5034Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005035TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005036 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005037 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5038
5039 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5040 Sema::LookupOrdinaryName);
5041
5042 // Transform all the decls.
5043 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5044 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005045 NamedDecl *InstD = static_cast<NamedDecl*>(
5046 getDerived().TransformDecl(Old->getNameLoc(),
5047 *I));
John McCall84d87672009-12-10 09:41:52 +00005048 if (!InstD) {
5049 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5050 // This can happen because of dependent hiding.
5051 if (isa<UsingShadowDecl>(*I))
5052 continue;
5053 else
5054 return SemaRef.ExprError();
5055 }
John McCalle66edc12009-11-24 19:00:30 +00005056
5057 // Expand using declarations.
5058 if (isa<UsingDecl>(InstD)) {
5059 UsingDecl *UD = cast<UsingDecl>(InstD);
5060 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5061 E = UD->shadow_end(); I != E; ++I)
5062 R.addDecl(*I);
5063 continue;
5064 }
5065
5066 R.addDecl(InstD);
5067 }
5068
5069 // Resolve a kind, but don't do any further analysis. If it's
5070 // ambiguous, the callee needs to deal with it.
5071 R.resolveKind();
5072
5073 // Rebuild the nested-name qualifier, if present.
5074 CXXScopeSpec SS;
5075 NestedNameSpecifier *Qualifier = 0;
5076 if (Old->getQualifier()) {
5077 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005078 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005079 if (!Qualifier)
5080 return SemaRef.ExprError();
5081
5082 SS.setScopeRep(Qualifier);
5083 SS.setRange(Old->getQualifierRange());
5084 }
5085
5086 // If we have no template arguments, it's a normal declaration name.
5087 if (!Old->hasExplicitTemplateArgs())
5088 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5089
5090 // If we have template arguments, rebuild them, then rebuild the
5091 // templateid expression.
5092 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5093 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5094 TemplateArgumentLoc Loc;
5095 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5096 return SemaRef.ExprError();
5097 TransArgs.addArgument(Loc);
5098 }
5099
5100 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5101 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005102}
Mike Stump11289f42009-09-09 15:08:12 +00005103
Douglas Gregora16548e2009-08-11 05:31:07 +00005104template<typename Derived>
5105Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005106TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 QualType T = getDerived().TransformType(E->getQueriedType());
5110 if (T.isNull())
5111 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 if (!getDerived().AlwaysRebuild() &&
5114 T == E->getQueriedType())
5115 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 // FIXME: Bad location information
5118 SourceLocation FakeLParenLoc
5119 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005120
5121 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 E->getLocStart(),
5123 /*FIXME:*/FakeLParenLoc,
5124 T,
5125 E->getLocEnd());
5126}
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregora16548e2009-08-11 05:31:07 +00005128template<typename Derived>
5129Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005130TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005131 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005133 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005134 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 if (!NNS)
5136 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005137
5138 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005139 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5140 if (!Name)
5141 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005142
John McCalle66edc12009-11-24 19:00:30 +00005143 if (!E->hasExplicitTemplateArgs()) {
5144 if (!getDerived().AlwaysRebuild() &&
5145 NNS == E->getQualifier() &&
5146 Name == E->getDeclName())
5147 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005148
John McCalle66edc12009-11-24 19:00:30 +00005149 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5150 E->getQualifierRange(),
5151 Name, E->getLocation(),
5152 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005153 }
John McCall6b51f282009-11-23 01:53:49 +00005154
5155 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005157 TemplateArgumentLoc Loc;
5158 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005160 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 }
5162
John McCalle66edc12009-11-24 19:00:30 +00005163 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5164 E->getQualifierRange(),
5165 Name, E->getLocation(),
5166 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005167}
5168
5169template<typename Derived>
5170Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005171TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005172 // CXXConstructExprs are always implicit, so when we have a
5173 // 1-argument construction we just transform that argument.
5174 if (E->getNumArgs() == 1 ||
5175 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5176 return getDerived().TransformExpr(E->getArg(0));
5177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5179
5180 QualType T = getDerived().TransformType(E->getType());
5181 if (T.isNull())
5182 return SemaRef.ExprError();
5183
5184 CXXConstructorDecl *Constructor
5185 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005186 getDerived().TransformDecl(E->getLocStart(),
5187 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005188 if (!Constructor)
5189 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregora16548e2009-08-11 05:31:07 +00005191 bool ArgumentChanged = false;
5192 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005193 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005194 ArgEnd = E->arg_end();
5195 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005196 if (getDerived().DropCallArgument(*Arg)) {
5197 ArgumentChanged = true;
5198 break;
5199 }
5200
Douglas Gregora16548e2009-08-11 05:31:07 +00005201 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5202 if (TransArg.isInvalid())
5203 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregora16548e2009-08-11 05:31:07 +00005205 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5206 Args.push_back(TransArg.takeAs<Expr>());
5207 }
5208
5209 if (!getDerived().AlwaysRebuild() &&
5210 T == E->getType() &&
5211 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005212 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005213 // Mark the constructor as referenced.
5214 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005215 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005216 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005217 }
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregordb121ba2009-12-14 16:27:04 +00005219 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5220 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 move_arg(Args));
5222}
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregora16548e2009-08-11 05:31:07 +00005224/// \brief Transform a C++ temporary-binding expression.
5225///
Douglas Gregor363b1512009-12-24 18:51:59 +00005226/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5227/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005228template<typename Derived>
5229Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005230TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005231 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005232}
Mike Stump11289f42009-09-09 15:08:12 +00005233
Anders Carlssonba6c4372010-01-29 02:39:32 +00005234/// \brief Transform a C++ reference-binding expression.
5235///
5236/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5237/// transform the subexpression and return that.
5238template<typename Derived>
5239Sema::OwningExprResult
5240TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5241 return getDerived().TransformExpr(E->getSubExpr());
5242}
5243
Mike Stump11289f42009-09-09 15:08:12 +00005244/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005245/// be destroyed after the expression is evaluated.
5246///
Douglas Gregor363b1512009-12-24 18:51:59 +00005247/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5248/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005249template<typename Derived>
5250Sema::OwningExprResult
5251TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005252 CXXExprWithTemporaries *E) {
5253 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005254}
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregora16548e2009-08-11 05:31:07 +00005256template<typename Derived>
5257Sema::OwningExprResult
5258TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005259 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5261 QualType T = getDerived().TransformType(E->getType());
5262 if (T.isNull())
5263 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 CXXConstructorDecl *Constructor
5266 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005267 getDerived().TransformDecl(E->getLocStart(),
5268 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005269 if (!Constructor)
5270 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregora16548e2009-08-11 05:31:07 +00005272 bool ArgumentChanged = false;
5273 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5274 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005275 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 ArgEnd = E->arg_end();
5277 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005278 if (getDerived().DropCallArgument(*Arg)) {
5279 ArgumentChanged = true;
5280 break;
5281 }
5282
Douglas Gregora16548e2009-08-11 05:31:07 +00005283 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5284 if (TransArg.isInvalid())
5285 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005286
Douglas Gregora16548e2009-08-11 05:31:07 +00005287 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5288 Args.push_back((Expr *)TransArg.release());
5289 }
Mike Stump11289f42009-09-09 15:08:12 +00005290
Douglas Gregora16548e2009-08-11 05:31:07 +00005291 if (!getDerived().AlwaysRebuild() &&
5292 T == E->getType() &&
5293 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005294 !ArgumentChanged) {
5295 // FIXME: Instantiation-specific
5296 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005297 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005298 }
Mike Stump11289f42009-09-09 15:08:12 +00005299
Douglas Gregora16548e2009-08-11 05:31:07 +00005300 // FIXME: Bogus location information
5301 SourceLocation CommaLoc;
5302 if (Args.size() > 1) {
5303 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005304 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5306 }
5307 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5308 T,
5309 /*FIXME:*/E->getTypeBeginLoc(),
5310 move_arg(Args),
5311 &CommaLoc,
5312 E->getLocEnd());
5313}
Mike Stump11289f42009-09-09 15:08:12 +00005314
Douglas Gregora16548e2009-08-11 05:31:07 +00005315template<typename Derived>
5316Sema::OwningExprResult
5317TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005318 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005319 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5320 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5321 if (T.isNull())
5322 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 bool ArgumentChanged = false;
5325 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5326 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5327 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5328 ArgEnd = E->arg_end();
5329 Arg != ArgEnd; ++Arg) {
5330 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5331 if (TransArg.isInvalid())
5332 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregora16548e2009-08-11 05:31:07 +00005334 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5335 FakeCommaLocs.push_back(
5336 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5337 Args.push_back(TransArg.takeAs<Expr>());
5338 }
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregora16548e2009-08-11 05:31:07 +00005340 if (!getDerived().AlwaysRebuild() &&
5341 T == E->getTypeAsWritten() &&
5342 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005343 return SemaRef.Owned(E->Retain());
5344
Douglas Gregora16548e2009-08-11 05:31:07 +00005345 // FIXME: we're faking the locations of the commas
5346 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5347 T,
5348 E->getLParenLoc(),
5349 move_arg(Args),
5350 FakeCommaLocs.data(),
5351 E->getRParenLoc());
5352}
Mike Stump11289f42009-09-09 15:08:12 +00005353
Douglas Gregora16548e2009-08-11 05:31:07 +00005354template<typename Derived>
5355Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005356TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005357 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005359 OwningExprResult Base(SemaRef, (Expr*) 0);
5360 Expr *OldBase;
5361 QualType BaseType;
5362 QualType ObjectType;
5363 if (!E->isImplicitAccess()) {
5364 OldBase = E->getBase();
5365 Base = getDerived().TransformExpr(OldBase);
5366 if (Base.isInvalid())
5367 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005368
John McCall2d74de92009-12-01 22:10:20 +00005369 // Start the member reference and compute the object's type.
5370 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005371 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005372 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5373 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005374 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005375 ObjectTy,
5376 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005377 if (Base.isInvalid())
5378 return SemaRef.ExprError();
5379
5380 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5381 BaseType = ((Expr*) Base.get())->getType();
5382 } else {
5383 OldBase = 0;
5384 BaseType = getDerived().TransformType(E->getBaseType());
5385 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5386 }
Mike Stump11289f42009-09-09 15:08:12 +00005387
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005388 // Transform the first part of the nested-name-specifier that qualifies
5389 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005390 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005391 = getDerived().TransformFirstQualifierInScope(
5392 E->getFirstQualifierFoundInScope(),
5393 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005394
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005395 NestedNameSpecifier *Qualifier = 0;
5396 if (E->getQualifier()) {
5397 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5398 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005399 ObjectType,
5400 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005401 if (!Qualifier)
5402 return SemaRef.ExprError();
5403 }
Mike Stump11289f42009-09-09 15:08:12 +00005404
5405 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005406 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005407 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005408 if (!Name)
5409 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005410
John McCall2d74de92009-12-01 22:10:20 +00005411 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005412 // This is a reference to a member without an explicitly-specified
5413 // template argument list. Optimize for this common case.
5414 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005415 Base.get() == OldBase &&
5416 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005417 Qualifier == E->getQualifier() &&
5418 Name == E->getMember() &&
5419 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005420 return SemaRef.Owned(E->Retain());
5421
John McCall8cd78132009-11-19 22:55:06 +00005422 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005423 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005424 E->isArrow(),
5425 E->getOperatorLoc(),
5426 Qualifier,
5427 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005428 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005429 Name,
5430 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005431 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005432 }
5433
John McCall6b51f282009-11-23 01:53:49 +00005434 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005435 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005436 TemplateArgumentLoc Loc;
5437 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005438 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005439 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005440 }
Mike Stump11289f42009-09-09 15:08:12 +00005441
John McCall8cd78132009-11-19 22:55:06 +00005442 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005443 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 E->isArrow(),
5445 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005446 Qualifier,
5447 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005448 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005449 Name,
5450 E->getMemberLoc(),
5451 &TransArgs);
5452}
5453
5454template<typename Derived>
5455Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005456TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005457 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005458 OwningExprResult Base(SemaRef, (Expr*) 0);
5459 QualType BaseType;
5460 if (!Old->isImplicitAccess()) {
5461 Base = getDerived().TransformExpr(Old->getBase());
5462 if (Base.isInvalid())
5463 return SemaRef.ExprError();
5464 BaseType = ((Expr*) Base.get())->getType();
5465 } else {
5466 BaseType = getDerived().TransformType(Old->getBaseType());
5467 }
John McCall10eae182009-11-30 22:42:35 +00005468
5469 NestedNameSpecifier *Qualifier = 0;
5470 if (Old->getQualifier()) {
5471 Qualifier
5472 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005473 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005474 if (Qualifier == 0)
5475 return SemaRef.ExprError();
5476 }
5477
5478 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5479 Sema::LookupOrdinaryName);
5480
5481 // Transform all the decls.
5482 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5483 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005484 NamedDecl *InstD = static_cast<NamedDecl*>(
5485 getDerived().TransformDecl(Old->getMemberLoc(),
5486 *I));
John McCall84d87672009-12-10 09:41:52 +00005487 if (!InstD) {
5488 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5489 // This can happen because of dependent hiding.
5490 if (isa<UsingShadowDecl>(*I))
5491 continue;
5492 else
5493 return SemaRef.ExprError();
5494 }
John McCall10eae182009-11-30 22:42:35 +00005495
5496 // Expand using declarations.
5497 if (isa<UsingDecl>(InstD)) {
5498 UsingDecl *UD = cast<UsingDecl>(InstD);
5499 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5500 E = UD->shadow_end(); I != E; ++I)
5501 R.addDecl(*I);
5502 continue;
5503 }
5504
5505 R.addDecl(InstD);
5506 }
5507
5508 R.resolveKind();
5509
5510 TemplateArgumentListInfo TransArgs;
5511 if (Old->hasExplicitTemplateArgs()) {
5512 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5513 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5514 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5515 TemplateArgumentLoc Loc;
5516 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5517 Loc))
5518 return SemaRef.ExprError();
5519 TransArgs.addArgument(Loc);
5520 }
5521 }
John McCall38836f02010-01-15 08:34:02 +00005522
5523 // FIXME: to do this check properly, we will need to preserve the
5524 // first-qualifier-in-scope here, just in case we had a dependent
5525 // base (and therefore couldn't do the check) and a
5526 // nested-name-qualifier (and therefore could do the lookup).
5527 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005528
5529 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005530 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005531 Old->getOperatorLoc(),
5532 Old->isArrow(),
5533 Qualifier,
5534 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005535 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005536 R,
5537 (Old->hasExplicitTemplateArgs()
5538 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005539}
5540
5541template<typename Derived>
5542Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005543TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005544 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005545}
5546
Mike Stump11289f42009-09-09 15:08:12 +00005547template<typename Derived>
5548Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005549TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005550 TypeSourceInfo *EncodedTypeInfo
5551 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5552 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005554
Douglas Gregora16548e2009-08-11 05:31:07 +00005555 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005556 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005557 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005558
5559 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005560 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 E->getRParenLoc());
5562}
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregora16548e2009-08-11 05:31:07 +00005564template<typename Derived>
5565Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005566TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005567 // Transform arguments.
5568 bool ArgChanged = false;
5569 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5570 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5571 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5572 if (Arg.isInvalid())
5573 return SemaRef.ExprError();
5574
5575 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5576 Args.push_back(Arg.takeAs<Expr>());
5577 }
5578
5579 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5580 // Class message: transform the receiver type.
5581 TypeSourceInfo *ReceiverTypeInfo
5582 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5583 if (!ReceiverTypeInfo)
5584 return SemaRef.ExprError();
5585
5586 // If nothing changed, just retain the existing message send.
5587 if (!getDerived().AlwaysRebuild() &&
5588 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5589 return SemaRef.Owned(E->Retain());
5590
5591 // Build a new class message send.
5592 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5593 E->getSelector(),
5594 E->getMethodDecl(),
5595 E->getLeftLoc(),
5596 move_arg(Args),
5597 E->getRightLoc());
5598 }
5599
5600 // Instance message: transform the receiver
5601 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5602 "Only class and instance messages may be instantiated");
5603 OwningExprResult Receiver
5604 = getDerived().TransformExpr(E->getInstanceReceiver());
5605 if (Receiver.isInvalid())
5606 return SemaRef.ExprError();
5607
5608 // If nothing changed, just retain the existing message send.
5609 if (!getDerived().AlwaysRebuild() &&
5610 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5611 return SemaRef.Owned(E->Retain());
5612
5613 // Build a new instance message send.
5614 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5615 E->getSelector(),
5616 E->getMethodDecl(),
5617 E->getLeftLoc(),
5618 move_arg(Args),
5619 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005620}
5621
Mike Stump11289f42009-09-09 15:08:12 +00005622template<typename Derived>
5623Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005625 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005626}
5627
Mike Stump11289f42009-09-09 15:08:12 +00005628template<typename Derived>
5629Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005631 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005632}
5633
Mike Stump11289f42009-09-09 15:08:12 +00005634template<typename Derived>
5635Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005636TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 // FIXME: Implement this!
5638 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005639 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005640}
5641
Mike Stump11289f42009-09-09 15:08:12 +00005642template<typename Derived>
5643Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005644TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005645 // FIXME: Implement this!
5646 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005647 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005648}
5649
Mike Stump11289f42009-09-09 15:08:12 +00005650template<typename Derived>
5651Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005652TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005653 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 // FIXME: Implement this!
5655 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005656 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005657}
5658
Mike Stump11289f42009-09-09 15:08:12 +00005659template<typename Derived>
5660Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005661TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005662 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005663 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005664}
5665
Mike Stump11289f42009-09-09 15:08:12 +00005666template<typename Derived>
5667Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005668TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 // FIXME: Implement this!
5670 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005671 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005672}
5673
Mike Stump11289f42009-09-09 15:08:12 +00005674template<typename Derived>
5675Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 bool ArgumentChanged = false;
5678 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5679 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5680 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5681 if (SubExpr.isInvalid())
5682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5685 SubExprs.push_back(SubExpr.takeAs<Expr>());
5686 }
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 if (!getDerived().AlwaysRebuild() &&
5689 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005690 return SemaRef.Owned(E->Retain());
5691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5693 move_arg(SubExprs),
5694 E->getRParenLoc());
5695}
5696
Mike Stump11289f42009-09-09 15:08:12 +00005697template<typename Derived>
5698Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005699TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 // FIXME: Implement this!
5701 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005702 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005703}
5704
Mike Stump11289f42009-09-09 15:08:12 +00005705template<typename Derived>
5706Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005707TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 // FIXME: Implement this!
5709 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005710 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005711}
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregora16548e2009-08-11 05:31:07 +00005713//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005714// Type reconstruction
5715//===----------------------------------------------------------------------===//
5716
Mike Stump11289f42009-09-09 15:08:12 +00005717template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005718QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5719 SourceLocation Star) {
5720 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005721 getDerived().getBaseEntity());
5722}
5723
Mike Stump11289f42009-09-09 15:08:12 +00005724template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005725QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5726 SourceLocation Star) {
5727 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005728 getDerived().getBaseEntity());
5729}
5730
Mike Stump11289f42009-09-09 15:08:12 +00005731template<typename Derived>
5732QualType
John McCall70dd5f62009-10-30 00:06:24 +00005733TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5734 bool WrittenAsLValue,
5735 SourceLocation Sigil) {
5736 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5737 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005738}
5739
5740template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005741QualType
John McCall70dd5f62009-10-30 00:06:24 +00005742TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5743 QualType ClassType,
5744 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005745 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005746 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005747}
5748
5749template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005750QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005751TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5752 ArrayType::ArraySizeModifier SizeMod,
5753 const llvm::APInt *Size,
5754 Expr *SizeExpr,
5755 unsigned IndexTypeQuals,
5756 SourceRange BracketsRange) {
5757 if (SizeExpr || !Size)
5758 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5759 IndexTypeQuals, BracketsRange,
5760 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005761
5762 QualType Types[] = {
5763 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5764 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5765 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005766 };
5767 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5768 QualType SizeType;
5769 for (unsigned I = 0; I != NumTypes; ++I)
5770 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5771 SizeType = Types[I];
5772 break;
5773 }
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregord6ff3322009-08-04 16:50:30 +00005775 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005776 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005777 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005778 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005779}
Mike Stump11289f42009-09-09 15:08:12 +00005780
Douglas Gregord6ff3322009-08-04 16:50:30 +00005781template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005782QualType
5783TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005784 ArrayType::ArraySizeModifier SizeMod,
5785 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005786 unsigned IndexTypeQuals,
5787 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005788 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005789 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005790}
5791
5792template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005793QualType
Mike Stump11289f42009-09-09 15:08:12 +00005794TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005795 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005796 unsigned IndexTypeQuals,
5797 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005798 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005799 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005800}
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregord6ff3322009-08-04 16:50:30 +00005802template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005803QualType
5804TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005805 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005807 unsigned IndexTypeQuals,
5808 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005809 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005810 SizeExpr.takeAs<Expr>(),
5811 IndexTypeQuals, BracketsRange);
5812}
5813
5814template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005815QualType
5816TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005817 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005818 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005819 unsigned IndexTypeQuals,
5820 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005821 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005822 SizeExpr.takeAs<Expr>(),
5823 IndexTypeQuals, BracketsRange);
5824}
5825
5826template<typename Derived>
5827QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005828 unsigned NumElements,
5829 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005830 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005831 return SemaRef.Context.getVectorType(ElementType, NumElements,
5832 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005833}
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregord6ff3322009-08-04 16:50:30 +00005835template<typename Derived>
5836QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5837 unsigned NumElements,
5838 SourceLocation AttributeLoc) {
5839 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5840 NumElements, true);
5841 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005842 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005843 AttributeLoc);
5844 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5845 AttributeLoc);
5846}
Mike Stump11289f42009-09-09 15:08:12 +00005847
Douglas Gregord6ff3322009-08-04 16:50:30 +00005848template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005849QualType
5850TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005851 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005852 SourceLocation AttributeLoc) {
5853 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5854}
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregord6ff3322009-08-04 16:50:30 +00005856template<typename Derived>
5857QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005858 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005859 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005860 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005861 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005862 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005863 Quals,
5864 getDerived().getBaseLocation(),
5865 getDerived().getBaseEntity());
5866}
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregord6ff3322009-08-04 16:50:30 +00005868template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005869QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5870 return SemaRef.Context.getFunctionNoProtoType(T);
5871}
5872
5873template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005874QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5875 assert(D && "no decl found");
5876 if (D->isInvalidDecl()) return QualType();
5877
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005878 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00005879 TypeDecl *Ty;
5880 if (isa<UsingDecl>(D)) {
5881 UsingDecl *Using = cast<UsingDecl>(D);
5882 assert(Using->isTypeName() &&
5883 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5884
5885 // A valid resolved using typename decl points to exactly one type decl.
5886 assert(++Using->shadow_begin() == Using->shadow_end());
5887 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5888
5889 } else {
5890 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5891 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5892 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5893 }
5894
5895 return SemaRef.Context.getTypeDeclType(Ty);
5896}
5897
5898template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005899QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005900 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5901}
5902
5903template<typename Derived>
5904QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5905 return SemaRef.Context.getTypeOfType(Underlying);
5906}
5907
5908template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005909QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005910 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5911}
5912
5913template<typename Derived>
5914QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005915 TemplateName Template,
5916 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005917 const TemplateArgumentListInfo &TemplateArgs) {
5918 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005919}
Mike Stump11289f42009-09-09 15:08:12 +00005920
Douglas Gregor1135c352009-08-06 05:28:30 +00005921template<typename Derived>
5922NestedNameSpecifier *
5923TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5924 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005925 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005926 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005927 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005928 CXXScopeSpec SS;
5929 // FIXME: The source location information is all wrong.
5930 SS.setRange(Range);
5931 SS.setScopeRep(Prefix);
5932 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005933 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005934 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005935 ObjectType,
5936 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005937 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005938}
5939
5940template<typename Derived>
5941NestedNameSpecifier *
5942TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5943 SourceRange Range,
5944 NamespaceDecl *NS) {
5945 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5946}
5947
5948template<typename Derived>
5949NestedNameSpecifier *
5950TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5951 SourceRange Range,
5952 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005953 QualType T) {
5954 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005955 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005956 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005957 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5958 T.getTypePtr());
5959 }
Mike Stump11289f42009-09-09 15:08:12 +00005960
Douglas Gregor1135c352009-08-06 05:28:30 +00005961 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5962 return 0;
5963}
Mike Stump11289f42009-09-09 15:08:12 +00005964
Douglas Gregor71dc5092009-08-06 06:41:21 +00005965template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005966TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005967TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5968 bool TemplateKW,
5969 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005970 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005971 Template);
5972}
5973
5974template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005975TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005976TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005977 const IdentifierInfo &II,
5978 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005979 CXXScopeSpec SS;
5980 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005981 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005982 UnqualifiedId Name;
5983 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005984 return getSema().ActOnDependentTemplateName(
5985 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005986 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005987 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005988 ObjectType.getAsOpaquePtr(),
5989 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005990 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005991}
Mike Stump11289f42009-09-09 15:08:12 +00005992
Douglas Gregora16548e2009-08-11 05:31:07 +00005993template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005994TemplateName
5995TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5996 OverloadedOperatorKind Operator,
5997 QualType ObjectType) {
5998 CXXScopeSpec SS;
5999 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6000 SS.setScopeRep(Qualifier);
6001 UnqualifiedId Name;
6002 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6003 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6004 Operator, SymbolLocations);
6005 return getSema().ActOnDependentTemplateName(
6006 /*FIXME:*/getDerived().getBaseLocation(),
6007 SS,
6008 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006009 ObjectType.getAsOpaquePtr(),
6010 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006011 .template getAsVal<TemplateName>();
6012}
6013
6014template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006015Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006016TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6017 SourceLocation OpLoc,
6018 ExprArg Callee,
6019 ExprArg First,
6020 ExprArg Second) {
6021 Expr *FirstExpr = (Expr *)First.get();
6022 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006023 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006027 if (Op == OO_Subscript) {
6028 if (!FirstExpr->getType()->isOverloadableType() &&
6029 !SecondExpr->getType()->isOverloadableType())
6030 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006031 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006032 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006033 } else if (Op == OO_Arrow) {
6034 // -> is never a builtin operation.
6035 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006036 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006037 if (!FirstExpr->getType()->isOverloadableType()) {
6038 // The argument is not of overloadable type, so try to create a
6039 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006040 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6044 }
6045 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006046 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 !SecondExpr->getType()->isOverloadableType()) {
6048 // Neither of the arguments is an overloadable type, so try to
6049 // create a built-in binary operation.
6050 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006051 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006052 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6053 if (Result.isInvalid())
6054 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006055
Douglas Gregora16548e2009-08-11 05:31:07 +00006056 First.release();
6057 Second.release();
6058 return move(Result);
6059 }
6060 }
Mike Stump11289f42009-09-09 15:08:12 +00006061
6062 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006064 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006065
John McCalld14a8642009-11-21 08:51:07 +00006066 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6067 assert(ULE->requiresADL());
6068
6069 // FIXME: Do we have to check
6070 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006071 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006072 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006073 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006074 }
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregora16548e2009-08-11 05:31:07 +00006076 // Add any functions found via argument-dependent lookup.
6077 Expr *Args[2] = { FirstExpr, SecondExpr };
6078 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006079
Douglas Gregora16548e2009-08-11 05:31:07 +00006080 // Create the overloaded operator invocation for unary operators.
6081 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006082 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6084 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6085 }
Mike Stump11289f42009-09-09 15:08:12 +00006086
Sebastian Redladba46e2009-10-29 20:17:01 +00006087 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006088 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6089 OpLoc,
6090 move(First),
6091 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006092
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006094 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006095 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006096 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6098 if (Result.isInvalid())
6099 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregora16548e2009-08-11 05:31:07 +00006101 First.release();
6102 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006103 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006104}
Mike Stump11289f42009-09-09 15:08:12 +00006105
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006106template<typename Derived>
6107Sema::OwningExprResult
6108TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6109 SourceLocation OperatorLoc,
6110 bool isArrow,
6111 NestedNameSpecifier *Qualifier,
6112 SourceRange QualifierRange,
6113 TypeSourceInfo *ScopeType,
6114 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006115 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006116 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006117 CXXScopeSpec SS;
6118 if (Qualifier) {
6119 SS.setRange(QualifierRange);
6120 SS.setScopeRep(Qualifier);
6121 }
6122
6123 Expr *BaseE = (Expr *)Base.get();
6124 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006125 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006126 (!isArrow && !BaseType->getAs<RecordType>()) ||
6127 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006128 !BaseType->getAs<PointerType>()->getPointeeType()
6129 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006130 // This pseudo-destructor expression is still a pseudo-destructor.
6131 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6132 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006133 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006134 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006135 /*FIXME?*/true);
6136 }
6137
Douglas Gregor678f90d2010-02-25 01:56:36 +00006138 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006139 DeclarationName Name
6140 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6141 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6142
6143 // FIXME: the ScopeType should be tacked onto SS.
6144
6145 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6146 OperatorLoc, isArrow,
6147 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006148 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006149 /*TemplateArgs*/ 0);
6150}
6151
Douglas Gregord6ff3322009-08-04 16:50:30 +00006152} // end namespace clang
6153
6154#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H