blob: 5143b77f592d6d58a960741252ddbafcac876b13 [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:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000577 // Fall through.
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 case ETK_Typename:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000579 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
Douglas Gregore677daf2010-03-31 22:19:08 +0000580
581 case ETK_Class: Kind = TagDecl::TK_class; break;
582 case ETK_Struct: Kind = TagDecl::TK_struct; break;
583 case ETK_Union: Kind = TagDecl::TK_union; break;
584 case ETK_Enum: Kind = TagDecl::TK_enum; break;
585 }
586
587 // We had a dependent elaborated-type-specifier that as been transformed
588 // into a non-dependent elaborated-type-specifier. Find the tag we're
589 // referring to.
590 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
591 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
592 if (!DC)
593 return QualType();
594
595 TagDecl *Tag = 0;
596 SemaRef.LookupQualifiedName(Result, DC);
597 switch (Result.getResultKind()) {
598 case LookupResult::NotFound:
599 case LookupResult::NotFoundInCurrentInstantiation:
600 break;
601
602 case LookupResult::Found:
603 Tag = Result.getAsSingle<TagDecl>();
604 break;
605
606 case LookupResult::FoundOverloaded:
607 case LookupResult::FoundUnresolvedValue:
608 llvm_unreachable("Tag lookup cannot find non-tags");
609 return QualType();
610
611 case LookupResult::Ambiguous:
612 // Let the LookupResult structure handle ambiguities.
613 return QualType();
614 }
615
616 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000617 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000619 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 return QualType();
621 }
622
623 // FIXME: Terrible location information
624 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
625 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
626 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
627 return QualType();
628 }
629
630 // Build the elaborated-type-specifier type.
631 QualType T = SemaRef.Context.getTypeDeclType(Tag);
632 T = SemaRef.Context.getQualifiedNameType(NNS, T);
633 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000634 }
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregor1135c352009-08-06 05:28:30 +0000636 /// \brief Build a new nested-name-specifier given the prefix and an
637 /// identifier that names the next step in the nested-name-specifier.
638 ///
639 /// By default, performs semantic analysis when building the new
640 /// nested-name-specifier. Subclasses may override this routine to provide
641 /// different behavior.
642 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
643 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000644 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000645 QualType ObjectType,
646 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000647
648 /// \brief Build a new nested-name-specifier given the prefix and the
649 /// namespace named in the next step in the nested-name-specifier.
650 ///
651 /// By default, performs semantic analysis when building the new
652 /// nested-name-specifier. Subclasses may override this routine to provide
653 /// different behavior.
654 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
655 SourceRange Range,
656 NamespaceDecl *NS);
657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// type named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000667 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000668
669 /// \brief Build a new template name given a nested name specifier, a flag
670 /// indicating whether the "template" keyword was provided, and the template
671 /// that the template name refers to.
672 ///
673 /// By default, builds the new template name directly. Subclasses may override
674 /// this routine to provide different behavior.
675 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
676 bool TemplateKW,
677 TemplateDecl *Template);
678
Douglas Gregor71dc5092009-08-06 06:41:21 +0000679 /// \brief Build a new template name given a nested name specifier and the
680 /// name that is referred to as a template.
681 ///
682 /// By default, performs semantic analysis to determine whether the name can
683 /// be resolved to a specific template, then builds the appropriate kind of
684 /// template name. Subclasses may override this routine to provide different
685 /// behavior.
686 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000687 const IdentifierInfo &II,
688 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregor71395fa2009-11-04 00:56:37 +0000690 /// \brief Build a new template name given a nested name specifier and the
691 /// overloaded operator name that is referred to as a template.
692 ///
693 /// By default, performs semantic analysis to determine whether the name can
694 /// be resolved to a specific template, then builds the appropriate kind of
695 /// template name. Subclasses may override this routine to provide different
696 /// behavior.
697 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
698 OverloadedOperatorKind Operator,
699 QualType ObjectType);
700
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 /// \brief Build a new compound statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
706 MultiStmtArg Statements,
707 SourceLocation RBraceLoc,
708 bool IsStmtExpr) {
709 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
710 IsStmtExpr);
711 }
712
713 /// \brief Build a new case statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
718 ExprArg LHS,
719 SourceLocation EllipsisLoc,
720 ExprArg RHS,
721 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000722 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 ColonLoc);
724 }
Mike Stump11289f42009-09-09 15:08:12 +0000725
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 /// \brief Attach the body to a new case statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
730 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
731 getSema().ActOnCaseStmtBody(S.get(), move(Body));
732 return move(S);
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new default statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000742 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /*CurScope=*/0);
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Build a new label statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 IdentifierInfo *Id,
752 SourceLocation ColonLoc,
753 StmtArg SubStmt) {
754 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
755 }
Mike Stump11289f42009-09-09 15:08:12 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new "if" statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000761 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000762 VarDecl *CondVar, StmtArg Then,
763 SourceLocation ElseLoc, StmtArg Else) {
764 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
765 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 }
Mike Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 /// \brief Start building a new switch statement.
769 ///
770 /// By default, performs semantic analysis to build the new statement.
771 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000772 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
773 VarDecl *CondVar) {
774 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 }
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 /// \brief Attach the body to the switch statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000781 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 StmtArg Switch, StmtArg Body) {
783 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
784 move(Body));
785 }
786
787 /// \brief Build a new while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
792 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000793 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000795 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
796 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
Mike Stump11289f42009-09-09 15:08:12 +0000798
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 /// \brief Build a new do-while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
803 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
804 SourceLocation WhileLoc,
805 SourceLocation LParenLoc,
806 ExprArg Cond,
807 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000808 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000809 move(Cond), RParenLoc);
810 }
811
812 /// \brief Build a new for statement.
813 ///
814 /// By default, performs semantic analysis to build the new statement.
815 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000816 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000818 StmtArg Init, Sema::FullExprArg Cond,
819 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000821 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
822 DeclPtrTy::make(CondVar),
823 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 }
Mike Stump11289f42009-09-09 15:08:12 +0000825
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 /// \brief Build a new goto statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
831 SourceLocation LabelLoc,
832 LabelStmt *Label) {
833 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
834 }
835
836 /// \brief Build a new indirect goto statement.
837 ///
838 /// By default, performs semantic analysis to build the new statement.
839 /// Subclasses may override this routine to provide different behavior.
840 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
841 SourceLocation StarLoc,
842 ExprArg Target) {
843 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
844 }
Mike Stump11289f42009-09-09 15:08:12 +0000845
Douglas Gregorebe10102009-08-20 07:17:43 +0000846 /// \brief Build a new return statement.
847 ///
848 /// By default, performs semantic analysis to build the new statement.
849 /// Subclasses may override this routine to provide different behavior.
850 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
851 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000852
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregorebe10102009-08-20 07:17:43 +0000856 /// \brief Build a new declaration statement.
857 ///
858 /// By default, performs semantic analysis to build the new statement.
859 /// Subclasses may override this routine to provide different behavior.
860 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000861 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 SourceLocation EndLoc) {
863 return getSema().Owned(
864 new (getSema().Context) DeclStmt(
865 DeclGroupRef::Create(getSema().Context,
866 Decls, NumDecls),
867 StartLoc, EndLoc));
868 }
Mike Stump11289f42009-09-09 15:08:12 +0000869
Anders Carlssonaaeef072010-01-24 05:50:09 +0000870 /// \brief Build a new inline asm statement.
871 ///
872 /// By default, performs semantic analysis to build the new statement.
873 /// Subclasses may override this routine to provide different behavior.
874 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
875 bool IsSimple,
876 bool IsVolatile,
877 unsigned NumOutputs,
878 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000879 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000880 MultiExprArg Constraints,
881 MultiExprArg Exprs,
882 ExprArg AsmString,
883 MultiExprArg Clobbers,
884 SourceLocation RParenLoc,
885 bool MSAsm) {
886 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
887 NumInputs, Names, move(Constraints),
888 move(Exprs), move(AsmString), move(Clobbers),
889 RParenLoc, MSAsm);
890 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000891
892 /// \brief Build a new Objective-C @try statement.
893 ///
894 /// By default, performs semantic analysis to build the new statement.
895 /// Subclasses may override this routine to provide different behavior.
896 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
897 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000898 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000899 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000900 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000901 move(Finally));
902 }
903
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000904 /// \brief Rebuild an Objective-C exception declaration.
905 ///
906 /// By default, performs semantic analysis to build the new declaration.
907 /// Subclasses may override this routine to provide different behavior.
908 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
909 TypeSourceInfo *TInfo, QualType T) {
910 return getSema().BuildObjCExceptionDecl(TInfo, T,
911 ExceptionDecl->getIdentifier(),
912 ExceptionDecl->getLocation());
913 }
914
915 /// \brief Build a new Objective-C @catch statement.
916 ///
917 /// By default, performs semantic analysis to build the new statement.
918 /// Subclasses may override this routine to provide different behavior.
919 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
920 SourceLocation RParenLoc,
921 VarDecl *Var,
922 StmtArg Body) {
923 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
924 Sema::DeclPtrTy::make(Var),
925 move(Body));
926 }
927
Douglas Gregor306de2f2010-04-22 23:59:56 +0000928 /// \brief Build a new Objective-C @finally statement.
929 ///
930 /// By default, performs semantic analysis to build the new statement.
931 /// Subclasses may override this routine to provide different behavior.
932 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
933 StmtArg Body) {
934 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
935 }
Anders Carlssonaaeef072010-01-24 05:50:09 +0000936
Douglas Gregor6148de72010-04-22 22:01:21 +0000937 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
942 ExprArg Operand) {
943 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
944 }
945
Douglas Gregor6148de72010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @synchronized statement.
947 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
951 ExprArg Object,
952 StmtArg Body) {
953 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
954 move(Body));
955 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000956
957 /// \brief Build a new Objective-C fast enumeration statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
961 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
962 SourceLocation LParenLoc,
963 StmtArg Element,
964 ExprArg Collection,
965 SourceLocation RParenLoc,
966 StmtArg Body) {
967 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
968 move(Element),
969 move(Collection),
970 RParenLoc,
971 move(Body));
972 }
Douglas Gregor6148de72010-04-22 22:01:21 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new C++ exception declaration.
975 ///
976 /// By default, performs semantic analysis to build the new decaration.
977 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000978 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000979 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 IdentifierInfo *Name,
981 SourceLocation Loc,
982 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000983 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 TypeRange);
985 }
986
987 /// \brief Build a new C++ catch statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
992 VarDecl *ExceptionDecl,
993 StmtArg Handler) {
994 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000995 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 Handler.takeAs<Stmt>()));
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /// \brief Build a new C++ try statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
1003 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1004 StmtArg TryBlock,
1005 MultiStmtArg Handlers) {
1006 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 /// \brief Build a new expression that references a declaration.
1010 ///
1011 /// By default, performs semantic analysis to build the new expression.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001013 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1014 LookupResult &R,
1015 bool RequiresADL) {
1016 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1017 }
1018
1019
1020 /// \brief Build a new expression that references a declaration.
1021 ///
1022 /// By default, performs semantic analysis to build the new expression.
1023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001024 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1025 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001026 ValueDecl *VD, SourceLocation Loc,
1027 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001028 CXXScopeSpec SS;
1029 SS.setScopeRep(Qualifier);
1030 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001031
1032 // FIXME: loses template args.
1033
1034 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new expression in parentheses.
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.
1041 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1042 SourceLocation RParen) {
1043 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1044 }
1045
Douglas Gregorad8a3362009-09-04 17:36:40 +00001046 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001047 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// By default, performs semantic analysis to build the new expression.
1049 /// Subclasses may override this routine to provide different behavior.
1050 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1051 SourceLocation OperatorLoc,
1052 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001053 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001054 SourceRange QualifierRange,
1055 TypeSourceInfo *ScopeType,
1056 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001057 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001058 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001061 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1065 UnaryOperator::Opcode Opc,
1066 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001067 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregor882211c2010-04-28 22:16:22 +00001070 /// \brief Build a new builtin offsetof expression.
1071 ///
1072 /// By default, performs semantic analysis to build the new expression.
1073 /// Subclasses may override this routine to provide different behavior.
1074 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1075 TypeSourceInfo *Type,
1076 Action::OffsetOfComponent *Components,
1077 unsigned NumComponents,
1078 SourceLocation RParenLoc) {
1079 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1080 NumComponents, RParenLoc);
1081 }
1082
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001084 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// By default, performs semantic analysis to build the new expression.
1086 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001087 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001088 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001090 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 }
1092
Mike Stump11289f42009-09-09 15:08:12 +00001093 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001095 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// By default, performs semantic analysis to build the new expression.
1097 /// Subclasses may override this routine to provide different behavior.
1098 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1099 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001100 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1102 OpLoc, isSizeOf, R);
1103 if (Result.isInvalid())
1104 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001105
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 SubExpr.release();
1107 return move(Result);
1108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001114 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 SourceLocation LBracketLoc,
1116 ExprArg RHS,
1117 SourceLocation RBracketLoc) {
1118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001119 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 RBracketLoc);
1121 }
1122
1123 /// \brief Build a new call 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 RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1128 MultiExprArg Args,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
1131 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1132 move(Args), CommaLocs, RParenLoc);
1133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
1139 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
1143 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001152 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001153 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1154 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001155 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001156
Mike Stump11289f42009-09-09 15:08:12 +00001157 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001158 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001159 Member, MemberLoc,
1160 cast<FieldDecl>(Member)->getType());
1161 return getSema().Owned(ME);
1162 }
Mike Stump11289f42009-09-09 15:08:12 +00001163
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001164 CXXScopeSpec SS;
1165 if (Qualifier) {
1166 SS.setRange(QualifierRange);
1167 SS.setScopeRep(Qualifier);
1168 }
1169
John McCall2d74de92009-12-01 22:10:20 +00001170 QualType BaseType = ((Expr*) Base.get())->getType();
1171
John McCall16df1e52010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001174 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1175 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001176 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001177 R.resolveKind();
1178
John McCall2d74de92009-12-01 22:10:20 +00001179 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1180 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001181 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001182 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001186 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
1189 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1190 BinaryOperator::Opcode Opc,
1191 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001192 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1193 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 }
1195
1196 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
1200 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1201 SourceLocation QuestionLoc,
1202 ExprArg LHS,
1203 SourceLocation ColonLoc,
1204 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001205 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 move(LHS), move(RHS));
1207 }
1208
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001210 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001213 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1214 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
1216 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001217 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1218 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
1225 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001226 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 SourceLocation RParenLoc,
1228 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001229 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1230 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001234 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001237 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 SourceLocation OpLoc,
1239 SourceLocation AccessorLoc,
1240 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001241
John McCall10eae182009-11-30 22:42:35 +00001242 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001243 QualType BaseType = ((Expr*) Base.get())->getType();
1244 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001245 OpLoc, /*IsArrow*/ false,
1246 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001247 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001248 AccessorLoc,
1249 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001253 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 /// By default, performs semantic analysis to build the new expression.
1255 /// Subclasses may override this routine to provide different behavior.
1256 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1257 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001258 SourceLocation RBraceLoc,
1259 QualType ResultTy) {
1260 OwningExprResult Result
1261 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1262 if (Result.isInvalid() || ResultTy->isDependentType())
1263 return move(Result);
1264
1265 // Patch in the result type we were given, which may have been computed
1266 // when the initial InitListExpr was built.
1267 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1268 ILE->setType(ResultTy);
1269 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 }
Mike Stump11289f42009-09-09 15:08:12 +00001271
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001273 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 /// By default, performs semantic analysis to build the new expression.
1275 /// Subclasses may override this routine to provide different behavior.
1276 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1277 MultiExprArg ArrayExprs,
1278 SourceLocation EqualOrColonLoc,
1279 bool GNUSyntax,
1280 ExprArg Init) {
1281 OwningExprResult Result
1282 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1283 move(Init));
1284 if (Result.isInvalid())
1285 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 ArrayExprs.release();
1288 return move(Result);
1289 }
Mike Stump11289f42009-09-09 15:08:12 +00001290
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001292 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 /// By default, builds the implicit value initialization without performing
1294 /// any semantic analysis. Subclasses may override this routine to provide
1295 /// different behavior.
1296 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1297 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
1304 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1305 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001306 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 RParenLoc);
1308 }
1309
1310 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1315 MultiExprArg SubExprs,
1316 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001317 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1318 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
1323 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// rather than attempting to map the label statement itself.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1327 SourceLocation LabelLoc,
1328 LabelStmt *Label) {
1329 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1337 StmtArg SubStmt,
1338 SourceLocation RParenLoc) {
1339 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_types_compatible_p expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1347 QualType T1, QualType T2,
1348 SourceLocation RParenLoc) {
1349 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1350 T1.getAsOpaquePtr(),
1351 T2.getAsOpaquePtr(),
1352 RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_choose_expr expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
1359 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1360 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1361 SourceLocation RParenLoc) {
1362 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1363 move(Cond), move(LHS), move(RHS),
1364 RParenLoc);
1365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new overloaded operator call expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// The semantic analysis provides the behavior of template instantiation,
1371 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// argument-dependent lookup, etc. Subclasses may override this routine to
1374 /// provide different behavior.
1375 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1376 SourceLocation OpLoc,
1377 ExprArg Callee,
1378 ExprArg First,
1379 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001380
1381 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// reinterpret_cast.
1383 ///
1384 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001385 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// Subclasses may override this routine to provide different behavior.
1387 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1388 Stmt::StmtClass Class,
1389 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001390 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 SourceLocation RAngleLoc,
1392 SourceLocation LParenLoc,
1393 ExprArg SubExpr,
1394 SourceLocation RParenLoc) {
1395 switch (Class) {
1396 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 move(SubExpr), RParenLoc);
1400
1401 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001402 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001403 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001405
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001407 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001408 RAngleLoc, LParenLoc,
1409 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001413 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001414 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 default:
1418 assert(false && "Invalid C++ named cast");
1419 break;
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 return getSema().ExprError();
1423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new C++ static_cast expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1430 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001431 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 SourceLocation RAngleLoc,
1433 SourceLocation LParenLoc,
1434 ExprArg SubExpr,
1435 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001436 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1437 TInfo, move(SubExpr),
1438 SourceRange(LAngleLoc, RAngleLoc),
1439 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
1441
1442 /// \brief Build a new C++ dynamic_cast expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1447 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001448 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 SourceLocation RAngleLoc,
1450 SourceLocation LParenLoc,
1451 ExprArg SubExpr,
1452 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001453 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1454 TInfo, move(SubExpr),
1455 SourceRange(LAngleLoc, RAngleLoc),
1456 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new C++ reinterpret_cast expression.
1460 ///
1461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
1463 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1464 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001465 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 SourceLocation RAngleLoc,
1467 SourceLocation LParenLoc,
1468 ExprArg SubExpr,
1469 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001470 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1471 TInfo, move(SubExpr),
1472 SourceRange(LAngleLoc, RAngleLoc),
1473 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 }
1475
1476 /// \brief Build a new C++ const_cast expression.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1481 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001482 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 SourceLocation RAngleLoc,
1484 SourceLocation LParenLoc,
1485 ExprArg SubExpr,
1486 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001487 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1488 TInfo, move(SubExpr),
1489 SourceRange(LAngleLoc, RAngleLoc),
1490 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 }
Mike Stump11289f42009-09-09 15:08:12 +00001492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new C++ functional-style cast expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
1497 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001498 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 SourceLocation LParenLoc,
1500 ExprArg SubExpr,
1501 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001502 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001504 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001506 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001507 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 RParenLoc);
1509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new C++ typeid(type) expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001515 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1516 SourceLocation TypeidLoc,
1517 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1520 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 }
Mike Stump11289f42009-09-09 15:08:12 +00001522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(expr) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001527 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1528 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 ExprArg Operand,
1530 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1532 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001533 }
1534
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 /// \brief Build a new C++ "this" expression.
1536 ///
1537 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001538 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001540 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001541 QualType ThisType,
1542 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001544 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1545 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 }
1547
1548 /// \brief Build a new C++ throw expression.
1549 ///
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
1552 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1553 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1554 }
1555
1556 /// \brief Build a new C++ default-argument expression.
1557 ///
1558 /// By default, builds a new default-argument expression, which does not
1559 /// require any semantic analysis. Subclasses may override this routine to
1560 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001561 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1562 ParmVarDecl *Param) {
1563 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1564 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new C++ zero-initialization expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001571 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 SourceLocation LParenLoc,
1573 QualType T,
1574 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001575 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1576 T.getAsOpaquePtr(), LParenLoc,
1577 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 0, RParenLoc);
1579 }
Mike Stump11289f42009-09-09 15:08:12 +00001580
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// \brief Build a new C++ "new" expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001585 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 bool UseGlobal,
1587 SourceLocation PlacementLParen,
1588 MultiExprArg PlacementArgs,
1589 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001590 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 QualType AllocType,
1592 SourceLocation TypeLoc,
1593 SourceRange TypeRange,
1594 ExprArg ArraySize,
1595 SourceLocation ConstructorLParen,
1596 MultiExprArg ConstructorArgs,
1597 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001598 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 PlacementLParen,
1600 move(PlacementArgs),
1601 PlacementRParen,
1602 ParenTypeId,
1603 AllocType,
1604 TypeLoc,
1605 TypeRange,
1606 move(ArraySize),
1607 ConstructorLParen,
1608 move(ConstructorArgs),
1609 ConstructorRParen);
1610 }
Mike Stump11289f42009-09-09 15:08:12 +00001611
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// \brief Build a new C++ "delete" expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1617 bool IsGlobalDelete,
1618 bool IsArrayForm,
1619 ExprArg Operand) {
1620 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1621 move(Operand));
1622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new unary type trait expression.
1625 ///
1626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
1628 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1629 SourceLocation StartLoc,
1630 SourceLocation LParenLoc,
1631 QualType T,
1632 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001633 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 T.getAsOpaquePtr(), RParenLoc);
1635 }
1636
Mike Stump11289f42009-09-09 15:08:12 +00001637 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001642 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceRange QualifierRange,
1644 DeclarationName Name,
1645 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001646 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 CXXScopeSpec SS;
1648 SS.setRange(QualifierRange);
1649 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001650
1651 if (TemplateArgs)
1652 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1653 *TemplateArgs);
1654
1655 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
1657
1658 /// \brief Build a new template-id expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001662 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1663 LookupResult &R,
1664 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001665 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001666 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 }
1668
1669 /// \brief Build a new object-construction expression.
1670 ///
1671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001674 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 CXXConstructorDecl *Constructor,
1676 bool IsElidable,
1677 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001678 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1679 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1680 ConvertedArgs))
1681 return getSema().ExprError();
1682
1683 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1684 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new object-construction expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
1691 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1692 QualType T,
1693 SourceLocation LParenLoc,
1694 MultiExprArg Args,
1695 SourceLocation *Commas,
1696 SourceLocation RParenLoc) {
1697 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1698 T.getAsOpaquePtr(),
1699 LParenLoc,
1700 move(Args),
1701 Commas,
1702 RParenLoc);
1703 }
1704
1705 /// \brief Build a new object-construction expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
1709 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1710 QualType T,
1711 SourceLocation LParenLoc,
1712 MultiExprArg Args,
1713 SourceLocation *Commas,
1714 SourceLocation RParenLoc) {
1715 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1716 /*FIXME*/LParenLoc),
1717 T.getAsOpaquePtr(),
1718 LParenLoc,
1719 move(Args),
1720 Commas,
1721 RParenLoc);
1722 }
Mike Stump11289f42009-09-09 15:08:12 +00001723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// \brief Build a new member reference expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001728 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001729 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 bool IsArrow,
1731 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 NestedNameSpecifier *Qualifier,
1733 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001734 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001736 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001737 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001739 SS.setRange(QualifierRange);
1740 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001741
John McCall2d74de92009-12-01 22:10:20 +00001742 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1743 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001744 SS, FirstQualifierInScope,
1745 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
1747
John McCall10eae182009-11-30 22:42:35 +00001748 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001752 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001753 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001754 SourceLocation OperatorLoc,
1755 bool IsArrow,
1756 NestedNameSpecifier *Qualifier,
1757 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001758 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001759 LookupResult &R,
1760 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001761 CXXScopeSpec SS;
1762 SS.setRange(QualifierRange);
1763 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001764
John McCall2d74de92009-12-01 22:10:20 +00001765 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1766 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001767 SS, FirstQualifierInScope,
1768 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001769 }
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// \brief Build a new Objective-C @encode expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
1775 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001776 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001778 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001780 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001781
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001782 /// \brief Build a new Objective-C class message.
1783 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1784 Selector Sel,
1785 ObjCMethodDecl *Method,
1786 SourceLocation LBracLoc,
1787 MultiExprArg Args,
1788 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1790 ReceiverTypeInfo->getType(),
1791 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001792 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001793 move(Args));
1794 }
1795
1796 /// \brief Build a new Objective-C instance message.
1797 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1798 Selector Sel,
1799 ObjCMethodDecl *Method,
1800 SourceLocation LBracLoc,
1801 MultiExprArg Args,
1802 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001803 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1804 return SemaRef.BuildInstanceMessage(move(Receiver),
1805 ReceiverType,
1806 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001807 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001808 move(Args));
1809 }
1810
Douglas Gregord51d90d2010-04-26 20:11:03 +00001811 /// \brief Build a new Objective-C ivar reference expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
1815 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1816 SourceLocation IvarLoc,
1817 bool IsArrow, bool IsFreeIvar) {
1818 // FIXME: We lose track of the IsFreeIvar bit.
1819 CXXScopeSpec SS;
1820 Expr *Base = BaseArg.takeAs<Expr>();
1821 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1822 Sema::LookupMemberName);
1823 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1824 /*FIME:*/IvarLoc,
1825 SS, DeclPtrTy());
1826 if (Result.isInvalid())
1827 return getSema().ExprError();
1828
1829 if (Result.get())
1830 return move(Result);
1831
1832 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1833 Base->getType(),
1834 /*FIXME:*/IvarLoc, IsArrow, SS,
1835 /*FirstQualifierInScope=*/0,
1836 R,
1837 /*TemplateArgs=*/0);
1838 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001839
1840 /// \brief Build a new Objective-C property reference expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
1844 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
1845 ObjCPropertyDecl *Property,
1846 SourceLocation PropertyLoc) {
1847 CXXScopeSpec SS;
1848 Expr *Base = BaseArg.takeAs<Expr>();
1849 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1850 Sema::LookupMemberName);
1851 bool IsArrow = false;
1852 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1853 /*FIME:*/PropertyLoc,
1854 SS, DeclPtrTy());
1855 if (Result.isInvalid())
1856 return getSema().ExprError();
1857
1858 if (Result.get())
1859 return move(Result);
1860
1861 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1862 Base->getType(),
1863 /*FIXME:*/PropertyLoc, IsArrow,
1864 SS,
1865 /*FirstQualifierInScope=*/0,
1866 R,
1867 /*TemplateArgs=*/0);
1868 }
1869
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001870 /// \brief Build a new Objective-C implicit setter/getter reference
1871 /// expression.
1872 ///
1873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
1875 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1876 ObjCMethodDecl *Getter,
1877 QualType T,
1878 ObjCMethodDecl *Setter,
1879 SourceLocation NameLoc,
1880 ExprArg Base) {
1881 // Since these expressions can only be value-dependent, we do not need to
1882 // perform semantic analysis again.
1883 return getSema().Owned(
1884 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1885 Setter,
1886 NameLoc,
1887 Base.takeAs<Expr>()));
1888 }
1889
Douglas Gregord51d90d2010-04-26 20:11:03 +00001890 /// \brief Build a new Objective-C "isa" expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
1894 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1895 bool IsArrow) {
1896 CXXScopeSpec SS;
1897 Expr *Base = BaseArg.takeAs<Expr>();
1898 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1899 Sema::LookupMemberName);
1900 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1901 /*FIME:*/IsaLoc,
1902 SS, DeclPtrTy());
1903 if (Result.isInvalid())
1904 return getSema().ExprError();
1905
1906 if (Result.get())
1907 return move(Result);
1908
1909 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1910 Base->getType(),
1911 /*FIXME:*/IsaLoc, IsArrow, SS,
1912 /*FirstQualifierInScope=*/0,
1913 R,
1914 /*TemplateArgs=*/0);
1915 }
1916
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// \brief Build a new shuffle vector expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
1921 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1922 MultiExprArg SubExprs,
1923 SourceLocation RParenLoc) {
1924 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001925 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1927 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1928 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1929 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001930
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 // Build a reference to the __builtin_shufflevector builtin
1932 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001933 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001935 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001937
1938 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 unsigned NumSubExprs = SubExprs.size();
1940 Expr **Subs = (Expr **)SubExprs.release();
1941 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1942 Subs, NumSubExprs,
1943 Builtin->getResultType(),
1944 RParenLoc);
1945 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 // Type-check the __builtin_shufflevector expression.
1948 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1949 if (Result.isInvalid())
1950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001953 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001955};
Douglas Gregora16548e2009-08-11 05:31:07 +00001956
Douglas Gregorebe10102009-08-20 07:17:43 +00001957template<typename Derived>
1958Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1959 if (!S)
1960 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregorebe10102009-08-20 07:17:43 +00001962 switch (S->getStmtClass()) {
1963 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001964
Douglas Gregorebe10102009-08-20 07:17:43 +00001965 // Transform individual statement nodes
1966#define STMT(Node, Parent) \
1967 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1968#define EXPR(Node, Parent)
1969#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregorebe10102009-08-20 07:17:43 +00001971 // Transform expressions by calling TransformExpr.
1972#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001973#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001974#define EXPR(Node, Parent) case Stmt::Node##Class:
1975#include "clang/AST/StmtNodes.def"
1976 {
1977 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1978 if (E.isInvalid())
1979 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001980
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001981 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001982 }
Mike Stump11289f42009-09-09 15:08:12 +00001983 }
1984
Douglas Gregorebe10102009-08-20 07:17:43 +00001985 return SemaRef.Owned(S->Retain());
1986}
Mike Stump11289f42009-09-09 15:08:12 +00001987
1988
Douglas Gregore922c772009-08-04 22:27:00 +00001989template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001990Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 if (!E)
1992 return SemaRef.Owned(E);
1993
1994 switch (E->getStmtClass()) {
1995 case Stmt::NoStmtClass: break;
1996#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001997#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001998#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001999 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00002000#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00002001 }
2002
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002004}
2005
2006template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002007NestedNameSpecifier *
2008TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002009 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002010 QualType ObjectType,
2011 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002012 if (!NNS)
2013 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002014
Douglas Gregorebe10102009-08-20 07:17:43 +00002015 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002016 NestedNameSpecifier *Prefix = NNS->getPrefix();
2017 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002018 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002019 ObjectType,
2020 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002021 if (!Prefix)
2022 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002023
2024 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002025 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002026 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002027 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002028 }
Mike Stump11289f42009-09-09 15:08:12 +00002029
Douglas Gregor1135c352009-08-06 05:28:30 +00002030 switch (NNS->getKind()) {
2031 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002032 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002033 "Identifier nested-name-specifier with no prefix or object type");
2034 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2035 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002036 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002037
2038 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002039 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002040 ObjectType,
2041 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002044 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002045 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002046 getDerived().TransformDecl(Range.getBegin(),
2047 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 Prefix == NNS->getPrefix() &&
2050 NS == NNS->getAsNamespace())
2051 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2054 }
Mike Stump11289f42009-09-09 15:08:12 +00002055
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 case NestedNameSpecifier::Global:
2057 // There is no meaningful transformation that one could perform on the
2058 // global scope.
2059 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 case NestedNameSpecifier::TypeSpecWithTemplate:
2062 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002063 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002064 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2065 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002066 if (T.isNull())
2067 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregor1135c352009-08-06 05:28:30 +00002069 if (!getDerived().AlwaysRebuild() &&
2070 Prefix == NNS->getPrefix() &&
2071 T == QualType(NNS->getAsType(), 0))
2072 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002073
2074 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2075 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002076 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002077 }
2078 }
Mike Stump11289f42009-09-09 15:08:12 +00002079
Douglas Gregor1135c352009-08-06 05:28:30 +00002080 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002081 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002082}
2083
2084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002085DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002086TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002087 SourceLocation Loc,
2088 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002089 if (!Name)
2090 return Name;
2091
2092 switch (Name.getNameKind()) {
2093 case DeclarationName::Identifier:
2094 case DeclarationName::ObjCZeroArgSelector:
2095 case DeclarationName::ObjCOneArgSelector:
2096 case DeclarationName::ObjCMultiArgSelector:
2097 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002098 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002099 case DeclarationName::CXXUsingDirective:
2100 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregorf816bd72009-09-03 22:13:48 +00002102 case DeclarationName::CXXConstructorName:
2103 case DeclarationName::CXXDestructorName:
2104 case DeclarationName::CXXConversionFunctionName: {
2105 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00002106 QualType T = getDerived().TransformType(Name.getCXXNameType(),
2107 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002108 if (T.isNull())
2109 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002110
Douglas Gregorf816bd72009-09-03 22:13:48 +00002111 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002112 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002113 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002114 }
Mike Stump11289f42009-09-09 15:08:12 +00002115 }
2116
Douglas Gregorf816bd72009-09-03 22:13:48 +00002117 return DeclarationName();
2118}
2119
2120template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002121TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002122TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2123 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002124 SourceLocation Loc = getDerived().getBaseLocation();
2125
Douglas Gregor71dc5092009-08-06 06:41:21 +00002126 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002127 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002128 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002129 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2130 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002131 if (!NNS)
2132 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002133
Douglas Gregor71dc5092009-08-06 06:41:21 +00002134 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002135 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002136 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002137 if (!TransTemplate)
2138 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002139
Douglas Gregor71dc5092009-08-06 06:41:21 +00002140 if (!getDerived().AlwaysRebuild() &&
2141 NNS == QTN->getQualifier() &&
2142 TransTemplate == Template)
2143 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002144
Douglas Gregor71dc5092009-08-06 06:41:21 +00002145 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2146 TransTemplate);
2147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
John McCalle66edc12009-11-24 19:00:30 +00002149 // These should be getting filtered out before they make it into the AST.
2150 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 }
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregor71dc5092009-08-06 06:41:21 +00002153 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002154 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002155 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002156 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2157 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002158 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002160
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002162 NNS == DTN->getQualifier() &&
2163 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002164 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregor71395fa2009-11-04 00:56:37 +00002166 if (DTN->isIdentifier())
2167 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2168 ObjectType);
2169
2170 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2171 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002172 }
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002175 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002176 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 if (!TransTemplate)
2178 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180 if (!getDerived().AlwaysRebuild() &&
2181 TransTemplate == Template)
2182 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 return TemplateName(TransTemplate);
2185 }
Mike Stump11289f42009-09-09 15:08:12 +00002186
John McCalle66edc12009-11-24 19:00:30 +00002187 // These should be getting filtered out before they reach the AST.
2188 assert(false && "overloaded function decl survived to here");
2189 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190}
2191
2192template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002193void TreeTransform<Derived>::InventTemplateArgumentLoc(
2194 const TemplateArgument &Arg,
2195 TemplateArgumentLoc &Output) {
2196 SourceLocation Loc = getDerived().getBaseLocation();
2197 switch (Arg.getKind()) {
2198 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002199 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002200 break;
2201
2202 case TemplateArgument::Type:
2203 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002204 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002205
2206 break;
2207
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002208 case TemplateArgument::Template:
2209 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2210 break;
2211
John McCall0ad16662009-10-29 08:12:44 +00002212 case TemplateArgument::Expression:
2213 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2214 break;
2215
2216 case TemplateArgument::Declaration:
2217 case TemplateArgument::Integral:
2218 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002219 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002220 break;
2221 }
2222}
2223
2224template<typename Derived>
2225bool TreeTransform<Derived>::TransformTemplateArgument(
2226 const TemplateArgumentLoc &Input,
2227 TemplateArgumentLoc &Output) {
2228 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002229 switch (Arg.getKind()) {
2230 case TemplateArgument::Null:
2231 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002232 Output = Input;
2233 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregore922c772009-08-04 22:27:00 +00002235 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002236 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002237 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002238 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002239
2240 DI = getDerived().TransformType(DI);
2241 if (!DI) return true;
2242
2243 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2244 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregore922c772009-08-04 22:27:00 +00002247 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002248 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002249 DeclarationName Name;
2250 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2251 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002252 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002253 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002254 if (!D) return true;
2255
John McCall0d07eb32009-10-29 18:45:58 +00002256 Expr *SourceExpr = Input.getSourceDeclExpression();
2257 if (SourceExpr) {
2258 EnterExpressionEvaluationContext Unevaluated(getSema(),
2259 Action::Unevaluated);
2260 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2261 if (E.isInvalid())
2262 SourceExpr = NULL;
2263 else {
2264 SourceExpr = E.takeAs<Expr>();
2265 SourceExpr->Retain();
2266 }
2267 }
2268
2269 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002270 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002271 }
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002273 case TemplateArgument::Template: {
2274 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2275 TemplateName Template
2276 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2277 if (Template.isNull())
2278 return true;
2279
2280 Output = TemplateArgumentLoc(TemplateArgument(Template),
2281 Input.getTemplateQualifierRange(),
2282 Input.getTemplateNameLoc());
2283 return false;
2284 }
2285
Douglas Gregore922c772009-08-04 22:27:00 +00002286 case TemplateArgument::Expression: {
2287 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002288 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002289 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002290
John McCall0ad16662009-10-29 08:12:44 +00002291 Expr *InputExpr = Input.getSourceExpression();
2292 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2293
2294 Sema::OwningExprResult E
2295 = getDerived().TransformExpr(InputExpr);
2296 if (E.isInvalid()) return true;
2297
2298 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002299 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002300 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2301 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002302 }
Mike Stump11289f42009-09-09 15:08:12 +00002303
Douglas Gregore922c772009-08-04 22:27:00 +00002304 case TemplateArgument::Pack: {
2305 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2306 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002307 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002308 AEnd = Arg.pack_end();
2309 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002310
John McCall0ad16662009-10-29 08:12:44 +00002311 // FIXME: preserve source information here when we start
2312 // caring about parameter packs.
2313
John McCall0d07eb32009-10-29 18:45:58 +00002314 TemplateArgumentLoc InputArg;
2315 TemplateArgumentLoc OutputArg;
2316 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2317 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002318 return true;
2319
John McCall0d07eb32009-10-29 18:45:58 +00002320 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002321 }
2322 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002323 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002324 true);
John McCall0d07eb32009-10-29 18:45:58 +00002325 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002326 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002327 }
2328 }
Mike Stump11289f42009-09-09 15:08:12 +00002329
Douglas Gregore922c772009-08-04 22:27:00 +00002330 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002331 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002332}
2333
Douglas Gregord6ff3322009-08-04 16:50:30 +00002334//===----------------------------------------------------------------------===//
2335// Type transformation
2336//===----------------------------------------------------------------------===//
2337
2338template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002339QualType TreeTransform<Derived>::TransformType(QualType T,
2340 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341 if (getDerived().AlreadyTransformed(T))
2342 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002343
John McCall550e0c22009-10-21 00:40:46 +00002344 // Temporary workaround. All of these transformations should
2345 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002346 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002347 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002348
Douglas Gregorfe17d252010-02-16 19:09:40 +00002349 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002350
John McCall550e0c22009-10-21 00:40:46 +00002351 if (!NewDI)
2352 return QualType();
2353
2354 return NewDI->getType();
2355}
2356
2357template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002358TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2359 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002360 if (getDerived().AlreadyTransformed(DI->getType()))
2361 return DI;
2362
2363 TypeLocBuilder TLB;
2364
2365 TypeLoc TL = DI->getTypeLoc();
2366 TLB.reserve(TL.getFullDataSize());
2367
Douglas Gregorfe17d252010-02-16 19:09:40 +00002368 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002369 if (Result.isNull())
2370 return 0;
2371
John McCallbcd03502009-12-07 02:54:59 +00002372 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002373}
2374
2375template<typename Derived>
2376QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002377TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2378 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002379 switch (T.getTypeLocClass()) {
2380#define ABSTRACT_TYPELOC(CLASS, PARENT)
2381#define TYPELOC(CLASS, PARENT) \
2382 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002383 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2384 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002385#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386 }
Mike Stump11289f42009-09-09 15:08:12 +00002387
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002388 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002389 return QualType();
2390}
2391
2392/// FIXME: By default, this routine adds type qualifiers only to types
2393/// that can have qualifiers, and silently suppresses those qualifiers
2394/// that are not permitted (e.g., qualifiers on reference or function
2395/// types). This is the right thing for template instantiation, but
2396/// probably not for other clients.
2397template<typename Derived>
2398QualType
2399TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002400 QualifiedTypeLoc T,
2401 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002402 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002403
Douglas Gregorfe17d252010-02-16 19:09:40 +00002404 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2405 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002406 if (Result.isNull())
2407 return QualType();
2408
2409 // Silently suppress qualifiers if the result type can't be qualified.
2410 // FIXME: this is the right thing for template instantiation, but
2411 // probably not for other clients.
2412 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002413 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002414
John McCall550e0c22009-10-21 00:40:46 +00002415 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2416
2417 TLB.push<QualifiedTypeLoc>(Result);
2418
2419 // No location information to preserve.
2420
2421 return Result;
2422}
2423
2424template <class TyLoc> static inline
2425QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2426 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2427 NewT.setNameLoc(T.getNameLoc());
2428 return T.getType();
2429}
2430
John McCall550e0c22009-10-21 00:40:46 +00002431template<typename Derived>
2432QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002433 BuiltinTypeLoc T,
2434 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002435 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2436 NewT.setBuiltinLoc(T.getBuiltinLoc());
2437 if (T.needsExtraLocalData())
2438 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2439 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002440}
Mike Stump11289f42009-09-09 15:08:12 +00002441
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002443QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002444 ComplexTypeLoc T,
2445 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002446 // FIXME: recurse?
2447 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448}
Mike Stump11289f42009-09-09 15:08:12 +00002449
Douglas Gregord6ff3322009-08-04 16:50:30 +00002450template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002451QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002452 PointerTypeLoc TL,
2453 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002454 QualType PointeeType
2455 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2456 if (PointeeType.isNull())
2457 return QualType();
2458
2459 QualType Result = TL.getType();
2460 if (PointeeType->isObjCInterfaceType()) {
2461 // A dependent pointer type 'T *' has is being transformed such
2462 // that an Objective-C class type is being replaced for 'T'. The
2463 // resulting pointer type is an ObjCObjectPointerType, not a
2464 // PointerType.
2465 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2466 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2467 const_cast<ObjCProtocolDecl **>(
2468 IFace->qual_begin()),
2469 IFace->getNumProtocols());
2470
2471 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2472 NewT.setStarLoc(TL.getSigilLoc());
2473 NewT.setHasProtocolsAsWritten(false);
2474 NewT.setLAngleLoc(SourceLocation());
2475 NewT.setRAngleLoc(SourceLocation());
2476 NewT.setHasBaseTypeAsWritten(true);
2477 return Result;
2478 }
2479
2480 if (getDerived().AlwaysRebuild() ||
2481 PointeeType != TL.getPointeeLoc().getType()) {
2482 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2483 if (Result.isNull())
2484 return QualType();
2485 }
2486
2487 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2488 NewT.setSigilLoc(TL.getSigilLoc());
2489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002490}
Mike Stump11289f42009-09-09 15:08:12 +00002491
2492template<typename Derived>
2493QualType
John McCall550e0c22009-10-21 00:40:46 +00002494TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002495 BlockPointerTypeLoc TL,
2496 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002497 QualType PointeeType
2498 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2499 if (PointeeType.isNull())
2500 return QualType();
2501
2502 QualType Result = TL.getType();
2503 if (getDerived().AlwaysRebuild() ||
2504 PointeeType != TL.getPointeeLoc().getType()) {
2505 Result = getDerived().RebuildBlockPointerType(PointeeType,
2506 TL.getSigilLoc());
2507 if (Result.isNull())
2508 return QualType();
2509 }
2510
Douglas Gregor049211a2010-04-22 16:50:51 +00002511 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002512 NewT.setSigilLoc(TL.getSigilLoc());
2513 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002514}
2515
John McCall70dd5f62009-10-30 00:06:24 +00002516/// Transforms a reference type. Note that somewhat paradoxically we
2517/// don't care whether the type itself is an l-value type or an r-value
2518/// type; we only care if the type was *written* as an l-value type
2519/// or an r-value type.
2520template<typename Derived>
2521QualType
2522TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002523 ReferenceTypeLoc TL,
2524 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002525 const ReferenceType *T = TL.getTypePtr();
2526
2527 // Note that this works with the pointee-as-written.
2528 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2529 if (PointeeType.isNull())
2530 return QualType();
2531
2532 QualType Result = TL.getType();
2533 if (getDerived().AlwaysRebuild() ||
2534 PointeeType != T->getPointeeTypeAsWritten()) {
2535 Result = getDerived().RebuildReferenceType(PointeeType,
2536 T->isSpelledAsLValue(),
2537 TL.getSigilLoc());
2538 if (Result.isNull())
2539 return QualType();
2540 }
2541
2542 // r-value references can be rebuilt as l-value references.
2543 ReferenceTypeLoc NewTL;
2544 if (isa<LValueReferenceType>(Result))
2545 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2546 else
2547 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2548 NewTL.setSigilLoc(TL.getSigilLoc());
2549
2550 return Result;
2551}
2552
Mike Stump11289f42009-09-09 15:08:12 +00002553template<typename Derived>
2554QualType
John McCall550e0c22009-10-21 00:40:46 +00002555TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002556 LValueReferenceTypeLoc TL,
2557 QualType ObjectType) {
2558 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002559}
2560
Mike Stump11289f42009-09-09 15:08:12 +00002561template<typename Derived>
2562QualType
John McCall550e0c22009-10-21 00:40:46 +00002563TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002564 RValueReferenceTypeLoc TL,
2565 QualType ObjectType) {
2566 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567}
Mike Stump11289f42009-09-09 15:08:12 +00002568
Douglas Gregord6ff3322009-08-04 16:50:30 +00002569template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002570QualType
John McCall550e0c22009-10-21 00:40:46 +00002571TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002572 MemberPointerTypeLoc TL,
2573 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002574 MemberPointerType *T = TL.getTypePtr();
2575
2576 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577 if (PointeeType.isNull())
2578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002579
John McCall550e0c22009-10-21 00:40:46 +00002580 // TODO: preserve source information for this.
2581 QualType ClassType
2582 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583 if (ClassType.isNull())
2584 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002585
John McCall550e0c22009-10-21 00:40:46 +00002586 QualType Result = TL.getType();
2587 if (getDerived().AlwaysRebuild() ||
2588 PointeeType != T->getPointeeType() ||
2589 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002590 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2591 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002592 if (Result.isNull())
2593 return QualType();
2594 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595
John McCall550e0c22009-10-21 00:40:46 +00002596 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2597 NewTL.setSigilLoc(TL.getSigilLoc());
2598
2599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600}
2601
Mike Stump11289f42009-09-09 15:08:12 +00002602template<typename Derived>
2603QualType
John McCall550e0c22009-10-21 00:40:46 +00002604TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002605 ConstantArrayTypeLoc TL,
2606 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002607 ConstantArrayType *T = TL.getTypePtr();
2608 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002609 if (ElementType.isNull())
2610 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 ElementType != T->getElementType()) {
2615 Result = getDerived().RebuildConstantArrayType(ElementType,
2616 T->getSizeModifier(),
2617 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002618 T->getIndexTypeCVRQualifiers(),
2619 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002620 if (Result.isNull())
2621 return QualType();
2622 }
2623
2624 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2625 NewTL.setLBracketLoc(TL.getLBracketLoc());
2626 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002627
John McCall550e0c22009-10-21 00:40:46 +00002628 Expr *Size = TL.getSizeExpr();
2629 if (Size) {
2630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2631 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2632 }
2633 NewTL.setSizeExpr(Size);
2634
2635 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636}
Mike Stump11289f42009-09-09 15:08:12 +00002637
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002640 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002641 IncompleteArrayTypeLoc TL,
2642 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002643 IncompleteArrayType *T = TL.getTypePtr();
2644 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 if (ElementType.isNull())
2646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002647
John McCall550e0c22009-10-21 00:40:46 +00002648 QualType Result = TL.getType();
2649 if (getDerived().AlwaysRebuild() ||
2650 ElementType != T->getElementType()) {
2651 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002652 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002653 T->getIndexTypeCVRQualifiers(),
2654 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002655 if (Result.isNull())
2656 return QualType();
2657 }
2658
2659 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2660 NewTL.setLBracketLoc(TL.getLBracketLoc());
2661 NewTL.setRBracketLoc(TL.getRBracketLoc());
2662 NewTL.setSizeExpr(0);
2663
2664 return Result;
2665}
2666
2667template<typename Derived>
2668QualType
2669TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002670 VariableArrayTypeLoc TL,
2671 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002672 VariableArrayType *T = TL.getTypePtr();
2673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2674 if (ElementType.isNull())
2675 return QualType();
2676
2677 // Array bounds are not potentially evaluated contexts
2678 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2679
2680 Sema::OwningExprResult SizeResult
2681 = getDerived().TransformExpr(T->getSizeExpr());
2682 if (SizeResult.isInvalid())
2683 return QualType();
2684
2685 Expr *Size = static_cast<Expr*>(SizeResult.get());
2686
2687 QualType Result = TL.getType();
2688 if (getDerived().AlwaysRebuild() ||
2689 ElementType != T->getElementType() ||
2690 Size != T->getSizeExpr()) {
2691 Result = getDerived().RebuildVariableArrayType(ElementType,
2692 T->getSizeModifier(),
2693 move(SizeResult),
2694 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002695 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002696 if (Result.isNull())
2697 return QualType();
2698 }
2699 else SizeResult.take();
2700
2701 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2702 NewTL.setLBracketLoc(TL.getLBracketLoc());
2703 NewTL.setRBracketLoc(TL.getRBracketLoc());
2704 NewTL.setSizeExpr(Size);
2705
2706 return Result;
2707}
2708
2709template<typename Derived>
2710QualType
2711TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002712 DependentSizedArrayTypeLoc TL,
2713 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002714 DependentSizedArrayType *T = TL.getTypePtr();
2715 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2716 if (ElementType.isNull())
2717 return QualType();
2718
2719 // Array bounds are not potentially evaluated contexts
2720 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2721
2722 Sema::OwningExprResult SizeResult
2723 = getDerived().TransformExpr(T->getSizeExpr());
2724 if (SizeResult.isInvalid())
2725 return QualType();
2726
2727 Expr *Size = static_cast<Expr*>(SizeResult.get());
2728
2729 QualType Result = TL.getType();
2730 if (getDerived().AlwaysRebuild() ||
2731 ElementType != T->getElementType() ||
2732 Size != T->getSizeExpr()) {
2733 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2734 T->getSizeModifier(),
2735 move(SizeResult),
2736 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002737 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002738 if (Result.isNull())
2739 return QualType();
2740 }
2741 else SizeResult.take();
2742
2743 // We might have any sort of array type now, but fortunately they
2744 // all have the same location layout.
2745 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2746 NewTL.setLBracketLoc(TL.getLBracketLoc());
2747 NewTL.setRBracketLoc(TL.getRBracketLoc());
2748 NewTL.setSizeExpr(Size);
2749
2750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751}
Mike Stump11289f42009-09-09 15:08:12 +00002752
2753template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002754QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002755 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002756 DependentSizedExtVectorTypeLoc TL,
2757 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002758 DependentSizedExtVectorType *T = TL.getTypePtr();
2759
2760 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761 QualType ElementType = getDerived().TransformType(T->getElementType());
2762 if (ElementType.isNull())
2763 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002764
Douglas Gregore922c772009-08-04 22:27:00 +00002765 // Vector sizes are not potentially evaluated contexts
2766 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2767
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2769 if (Size.isInvalid())
2770 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002771
John McCall550e0c22009-10-21 00:40:46 +00002772 QualType Result = TL.getType();
2773 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002774 ElementType != T->getElementType() ||
2775 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002776 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002777 move(Size),
2778 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002779 if (Result.isNull())
2780 return QualType();
2781 }
2782 else Size.take();
2783
2784 // Result might be dependent or not.
2785 if (isa<DependentSizedExtVectorType>(Result)) {
2786 DependentSizedExtVectorTypeLoc NewTL
2787 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2788 NewTL.setNameLoc(TL.getNameLoc());
2789 } else {
2790 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2791 NewTL.setNameLoc(TL.getNameLoc());
2792 }
2793
2794 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002795}
Mike Stump11289f42009-09-09 15:08:12 +00002796
2797template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002798QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002799 VectorTypeLoc TL,
2800 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002801 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002802 QualType ElementType = getDerived().TransformType(T->getElementType());
2803 if (ElementType.isNull())
2804 return QualType();
2805
John McCall550e0c22009-10-21 00:40:46 +00002806 QualType Result = TL.getType();
2807 if (getDerived().AlwaysRebuild() ||
2808 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002809 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2810 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002811 if (Result.isNull())
2812 return QualType();
2813 }
2814
2815 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2816 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002817
John McCall550e0c22009-10-21 00:40:46 +00002818 return Result;
2819}
2820
2821template<typename Derived>
2822QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002823 ExtVectorTypeLoc TL,
2824 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002825 VectorType *T = TL.getTypePtr();
2826 QualType ElementType = getDerived().TransformType(T->getElementType());
2827 if (ElementType.isNull())
2828 return QualType();
2829
2830 QualType Result = TL.getType();
2831 if (getDerived().AlwaysRebuild() ||
2832 ElementType != T->getElementType()) {
2833 Result = getDerived().RebuildExtVectorType(ElementType,
2834 T->getNumElements(),
2835 /*FIXME*/ SourceLocation());
2836 if (Result.isNull())
2837 return QualType();
2838 }
2839
2840 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2841 NewTL.setNameLoc(TL.getNameLoc());
2842
2843 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002844}
Mike Stump11289f42009-09-09 15:08:12 +00002845
2846template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002847ParmVarDecl *
2848TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2849 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2850 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2851 if (!NewDI)
2852 return 0;
2853
2854 if (NewDI == OldDI)
2855 return OldParm;
2856 else
2857 return ParmVarDecl::Create(SemaRef.Context,
2858 OldParm->getDeclContext(),
2859 OldParm->getLocation(),
2860 OldParm->getIdentifier(),
2861 NewDI->getType(),
2862 NewDI,
2863 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002864 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002865 /* DefArg */ NULL);
2866}
2867
2868template<typename Derived>
2869bool TreeTransform<Derived>::
2870 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2871 llvm::SmallVectorImpl<QualType> &PTypes,
2872 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2873 FunctionProtoType *T = TL.getTypePtr();
2874
2875 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2876 ParmVarDecl *OldParm = TL.getArg(i);
2877
2878 QualType NewType;
2879 ParmVarDecl *NewParm;
2880
2881 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002882 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2883 if (!NewParm)
2884 return true;
2885 NewType = NewParm->getType();
2886
2887 // Deal with the possibility that we don't have a parameter
2888 // declaration for this parameter.
2889 } else {
2890 NewParm = 0;
2891
2892 QualType OldType = T->getArgType(i);
2893 NewType = getDerived().TransformType(OldType);
2894 if (NewType.isNull())
2895 return true;
2896 }
2897
2898 PTypes.push_back(NewType);
2899 PVars.push_back(NewParm);
2900 }
2901
2902 return false;
2903}
2904
2905template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002906QualType
John McCall550e0c22009-10-21 00:40:46 +00002907TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002908 FunctionProtoTypeLoc TL,
2909 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002910 FunctionProtoType *T = TL.getTypePtr();
2911 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002912 if (ResultType.isNull())
2913 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002914
John McCall550e0c22009-10-21 00:40:46 +00002915 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002917 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002918 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2919 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002920
John McCall550e0c22009-10-21 00:40:46 +00002921 QualType Result = TL.getType();
2922 if (getDerived().AlwaysRebuild() ||
2923 ResultType != T->getResultType() ||
2924 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2925 Result = getDerived().RebuildFunctionProtoType(ResultType,
2926 ParamTypes.data(),
2927 ParamTypes.size(),
2928 T->isVariadic(),
2929 T->getTypeQuals());
2930 if (Result.isNull())
2931 return QualType();
2932 }
Mike Stump11289f42009-09-09 15:08:12 +00002933
John McCall550e0c22009-10-21 00:40:46 +00002934 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2935 NewTL.setLParenLoc(TL.getLParenLoc());
2936 NewTL.setRParenLoc(TL.getRParenLoc());
2937 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2938 NewTL.setArg(i, ParamDecls[i]);
2939
2940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941}
Mike Stump11289f42009-09-09 15:08:12 +00002942
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943template<typename Derived>
2944QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002945 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002946 FunctionNoProtoTypeLoc TL,
2947 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002948 FunctionNoProtoType *T = TL.getTypePtr();
2949 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2950 if (ResultType.isNull())
2951 return QualType();
2952
2953 QualType Result = TL.getType();
2954 if (getDerived().AlwaysRebuild() ||
2955 ResultType != T->getResultType())
2956 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2957
2958 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2959 NewTL.setLParenLoc(TL.getLParenLoc());
2960 NewTL.setRParenLoc(TL.getRParenLoc());
2961
2962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002963}
Mike Stump11289f42009-09-09 15:08:12 +00002964
John McCallb96ec562009-12-04 22:46:56 +00002965template<typename Derived> QualType
2966TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002967 UnresolvedUsingTypeLoc TL,
2968 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002969 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002970 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002971 if (!D)
2972 return QualType();
2973
2974 QualType Result = TL.getType();
2975 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2976 Result = getDerived().RebuildUnresolvedUsingType(D);
2977 if (Result.isNull())
2978 return QualType();
2979 }
2980
2981 // We might get an arbitrary type spec type back. We should at
2982 // least always get a type spec type, though.
2983 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2984 NewTL.setNameLoc(TL.getNameLoc());
2985
2986 return Result;
2987}
2988
Douglas Gregord6ff3322009-08-04 16:50:30 +00002989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002990QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 TypedefTypeLoc TL,
2992 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002993 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002995 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2996 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002997 if (!Typedef)
2998 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002999
John McCall550e0c22009-10-21 00:40:46 +00003000 QualType Result = TL.getType();
3001 if (getDerived().AlwaysRebuild() ||
3002 Typedef != T->getDecl()) {
3003 Result = getDerived().RebuildTypedefType(Typedef);
3004 if (Result.isNull())
3005 return QualType();
3006 }
Mike Stump11289f42009-09-09 15:08:12 +00003007
John McCall550e0c22009-10-21 00:40:46 +00003008 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3009 NewTL.setNameLoc(TL.getNameLoc());
3010
3011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012}
Mike Stump11289f42009-09-09 15:08:12 +00003013
Douglas Gregord6ff3322009-08-04 16:50:30 +00003014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003015QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003016 TypeOfExprTypeLoc TL,
3017 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003018 // typeof expressions are not potentially evaluated contexts
3019 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003020
John McCalle8595032010-01-13 20:03:27 +00003021 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 if (E.isInvalid())
3023 return QualType();
3024
John McCall550e0c22009-10-21 00:40:46 +00003025 QualType Result = TL.getType();
3026 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003027 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003028 Result = getDerived().RebuildTypeOfExprType(move(E));
3029 if (Result.isNull())
3030 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003031 }
John McCall550e0c22009-10-21 00:40:46 +00003032 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003033
John McCall550e0c22009-10-21 00:40:46 +00003034 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003035 NewTL.setTypeofLoc(TL.getTypeofLoc());
3036 NewTL.setLParenLoc(TL.getLParenLoc());
3037 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003038
3039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003040}
Mike Stump11289f42009-09-09 15:08:12 +00003041
3042template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003043QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003044 TypeOfTypeLoc TL,
3045 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003046 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3047 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3048 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003050
John McCall550e0c22009-10-21 00:40:46 +00003051 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003052 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3053 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003054 if (Result.isNull())
3055 return QualType();
3056 }
Mike Stump11289f42009-09-09 15:08:12 +00003057
John McCall550e0c22009-10-21 00:40:46 +00003058 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003059 NewTL.setTypeofLoc(TL.getTypeofLoc());
3060 NewTL.setLParenLoc(TL.getLParenLoc());
3061 NewTL.setRParenLoc(TL.getRParenLoc());
3062 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003063
3064 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003065}
Mike Stump11289f42009-09-09 15:08:12 +00003066
3067template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003068QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003069 DecltypeTypeLoc TL,
3070 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003071 DecltypeType *T = TL.getTypePtr();
3072
Douglas Gregore922c772009-08-04 22:27:00 +00003073 // decltype expressions are not potentially evaluated contexts
3074 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003075
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3077 if (E.isInvalid())
3078 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003079
John McCall550e0c22009-10-21 00:40:46 +00003080 QualType Result = TL.getType();
3081 if (getDerived().AlwaysRebuild() ||
3082 E.get() != T->getUnderlyingExpr()) {
3083 Result = getDerived().RebuildDecltypeType(move(E));
3084 if (Result.isNull())
3085 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003086 }
John McCall550e0c22009-10-21 00:40:46 +00003087 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003088
John McCall550e0c22009-10-21 00:40:46 +00003089 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3090 NewTL.setNameLoc(TL.getNameLoc());
3091
3092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
3094
3095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003097 RecordTypeLoc TL,
3098 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003099 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003101 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3102 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103 if (!Record)
3104 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003105
John McCall550e0c22009-10-21 00:40:46 +00003106 QualType Result = TL.getType();
3107 if (getDerived().AlwaysRebuild() ||
3108 Record != T->getDecl()) {
3109 Result = getDerived().RebuildRecordType(Record);
3110 if (Result.isNull())
3111 return QualType();
3112 }
Mike Stump11289f42009-09-09 15:08:12 +00003113
John McCall550e0c22009-10-21 00:40:46 +00003114 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3115 NewTL.setNameLoc(TL.getNameLoc());
3116
3117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118}
Mike Stump11289f42009-09-09 15:08:12 +00003119
3120template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003121QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003122 EnumTypeLoc TL,
3123 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003124 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003126 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3127 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 if (!Enum)
3129 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003130
John McCall550e0c22009-10-21 00:40:46 +00003131 QualType Result = TL.getType();
3132 if (getDerived().AlwaysRebuild() ||
3133 Enum != T->getDecl()) {
3134 Result = getDerived().RebuildEnumType(Enum);
3135 if (Result.isNull())
3136 return QualType();
3137 }
Mike Stump11289f42009-09-09 15:08:12 +00003138
John McCall550e0c22009-10-21 00:40:46 +00003139 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3140 NewTL.setNameLoc(TL.getNameLoc());
3141
3142 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143}
John McCallfcc33b02009-09-05 00:15:47 +00003144
3145template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003146QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003147 ElaboratedTypeLoc TL,
3148 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003149 ElaboratedType *T = TL.getTypePtr();
3150
3151 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003152 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3153 if (Underlying.isNull())
3154 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003155
John McCall550e0c22009-10-21 00:40:46 +00003156 QualType Result = TL.getType();
3157 if (getDerived().AlwaysRebuild() ||
3158 Underlying != T->getUnderlyingType()) {
3159 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3160 if (Result.isNull())
3161 return QualType();
3162 }
Mike Stump11289f42009-09-09 15:08:12 +00003163
John McCall550e0c22009-10-21 00:40:46 +00003164 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3165 NewTL.setNameLoc(TL.getNameLoc());
3166
3167 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003168}
Mike Stump11289f42009-09-09 15:08:12 +00003169
John McCalle78aac42010-03-10 03:28:59 +00003170template<typename Derived>
3171QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3172 TypeLocBuilder &TLB,
3173 InjectedClassNameTypeLoc TL,
3174 QualType ObjectType) {
3175 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3176 TL.getTypePtr()->getDecl());
3177 if (!D) return QualType();
3178
3179 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3180 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3181 return T;
3182}
3183
Mike Stump11289f42009-09-09 15:08:12 +00003184
Douglas Gregord6ff3322009-08-04 16:50:30 +00003185template<typename Derived>
3186QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003187 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003188 TemplateTypeParmTypeLoc TL,
3189 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003190 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003191}
3192
Mike Stump11289f42009-09-09 15:08:12 +00003193template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003194QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003195 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003196 SubstTemplateTypeParmTypeLoc TL,
3197 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003198 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003199}
3200
3201template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003202QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3203 const TemplateSpecializationType *TST,
3204 QualType ObjectType) {
3205 // FIXME: this entire method is a temporary workaround; callers
3206 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003207
John McCall0ad16662009-10-29 08:12:44 +00003208 // Fake up a TemplateSpecializationTypeLoc.
3209 TypeLocBuilder TLB;
3210 TemplateSpecializationTypeLoc TL
3211 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3212
John McCall0d07eb32009-10-29 18:45:58 +00003213 SourceLocation BaseLoc = getDerived().getBaseLocation();
3214
3215 TL.setTemplateNameLoc(BaseLoc);
3216 TL.setLAngleLoc(BaseLoc);
3217 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003218 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3219 const TemplateArgument &TA = TST->getArg(i);
3220 TemplateArgumentLoc TAL;
3221 getDerived().InventTemplateArgumentLoc(TA, TAL);
3222 TL.setArgLocInfo(i, TAL.getLocInfo());
3223 }
3224
3225 TypeLocBuilder IgnoredTLB;
3226 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003227}
3228
3229template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003230QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003231 TypeLocBuilder &TLB,
3232 TemplateSpecializationTypeLoc TL,
3233 QualType ObjectType) {
3234 const TemplateSpecializationType *T = TL.getTypePtr();
3235
Mike Stump11289f42009-09-09 15:08:12 +00003236 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003237 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003238 if (Template.isNull())
3239 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003240
John McCall6b51f282009-11-23 01:53:49 +00003241 TemplateArgumentListInfo NewTemplateArgs;
3242 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3243 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3244
3245 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3246 TemplateArgumentLoc Loc;
3247 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003249 NewTemplateArgs.addArgument(Loc);
3250 }
Mike Stump11289f42009-09-09 15:08:12 +00003251
John McCall0ad16662009-10-29 08:12:44 +00003252 // FIXME: maybe don't rebuild if all the template arguments are the same.
3253
3254 QualType Result =
3255 getDerived().RebuildTemplateSpecializationType(Template,
3256 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003257 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003258
3259 if (!Result.isNull()) {
3260 TemplateSpecializationTypeLoc NewTL
3261 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3262 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3263 NewTL.setLAngleLoc(TL.getLAngleLoc());
3264 NewTL.setRAngleLoc(TL.getRAngleLoc());
3265 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3266 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003267 }
Mike Stump11289f42009-09-09 15:08:12 +00003268
John McCall0ad16662009-10-29 08:12:44 +00003269 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003270}
Mike Stump11289f42009-09-09 15:08:12 +00003271
3272template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003273QualType
3274TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003275 QualifiedNameTypeLoc TL,
3276 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003277 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003278 NestedNameSpecifier *NNS
3279 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003280 SourceRange(),
3281 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282 if (!NNS)
3283 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285 QualType Named = getDerived().TransformType(T->getNamedType());
3286 if (Named.isNull())
3287 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003288
John McCall550e0c22009-10-21 00:40:46 +00003289 QualType Result = TL.getType();
3290 if (getDerived().AlwaysRebuild() ||
3291 NNS != T->getQualifier() ||
3292 Named != T->getNamedType()) {
3293 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3294 if (Result.isNull())
3295 return QualType();
3296 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003297
John McCall550e0c22009-10-21 00:40:46 +00003298 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3299 NewTL.setNameLoc(TL.getNameLoc());
3300
3301 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003302}
Mike Stump11289f42009-09-09 15:08:12 +00003303
3304template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003305QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3306 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003307 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003308 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003309
3310 /* FIXME: preserve source information better than this */
3311 SourceRange SR(TL.getNameLoc());
3312
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003314 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003315 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316 if (!NNS)
3317 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003318
John McCall550e0c22009-10-21 00:40:46 +00003319 QualType Result;
3320
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003322 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323 = getDerived().TransformType(QualType(TemplateId, 0));
3324 if (NewTemplateId.isNull())
3325 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003326
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327 if (!getDerived().AlwaysRebuild() &&
3328 NNS == T->getQualifier() &&
3329 NewTemplateId == QualType(TemplateId, 0))
3330 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003331
Douglas Gregor02085352010-03-31 20:19:30 +00003332 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3333 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003334 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003335 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3336 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003337 }
John McCall550e0c22009-10-21 00:40:46 +00003338 if (Result.isNull())
3339 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003341 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003342 NewTL.setNameLoc(TL.getNameLoc());
3343
3344 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003345}
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregord6ff3322009-08-04 16:50:30 +00003347template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003348QualType
3349TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003350 ObjCInterfaceTypeLoc TL,
3351 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003352 // ObjCInterfaceType is never dependent.
3353 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003354}
Mike Stump11289f42009-09-09 15:08:12 +00003355
3356template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003357QualType
3358TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003359 ObjCObjectPointerTypeLoc TL,
3360 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003361 // ObjCObjectPointerType is never dependent.
3362 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003363}
3364
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003366// Statement transformation
3367//===----------------------------------------------------------------------===//
3368template<typename Derived>
3369Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003370TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3371 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003372}
3373
3374template<typename Derived>
3375Sema::OwningStmtResult
3376TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3377 return getDerived().TransformCompoundStmt(S, false);
3378}
3379
3380template<typename Derived>
3381Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003382TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003383 bool IsStmtExpr) {
3384 bool SubStmtChanged = false;
3385 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3386 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3387 B != BEnd; ++B) {
3388 OwningStmtResult Result = getDerived().TransformStmt(*B);
3389 if (Result.isInvalid())
3390 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003391
Douglas Gregorebe10102009-08-20 07:17:43 +00003392 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3393 Statements.push_back(Result.takeAs<Stmt>());
3394 }
Mike Stump11289f42009-09-09 15:08:12 +00003395
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 if (!getDerived().AlwaysRebuild() &&
3397 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003398 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003399
3400 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3401 move_arg(Statements),
3402 S->getRBracLoc(),
3403 IsStmtExpr);
3404}
Mike Stump11289f42009-09-09 15:08:12 +00003405
Douglas Gregorebe10102009-08-20 07:17:43 +00003406template<typename Derived>
3407Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003408TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003409 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3410 {
3411 // The case value expressions are not potentially evaluated.
3412 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003413
Eli Friedman06577382009-11-19 03:14:00 +00003414 // Transform the left-hand case value.
3415 LHS = getDerived().TransformExpr(S->getLHS());
3416 if (LHS.isInvalid())
3417 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003418
Eli Friedman06577382009-11-19 03:14:00 +00003419 // Transform the right-hand case value (for the GNU case-range extension).
3420 RHS = getDerived().TransformExpr(S->getRHS());
3421 if (RHS.isInvalid())
3422 return SemaRef.StmtError();
3423 }
Mike Stump11289f42009-09-09 15:08:12 +00003424
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 // Build the case statement.
3426 // Case statements are always rebuilt so that they will attached to their
3427 // transformed switch statement.
3428 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3429 move(LHS),
3430 S->getEllipsisLoc(),
3431 move(RHS),
3432 S->getColonLoc());
3433 if (Case.isInvalid())
3434 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 // Transform the statement following the case
3437 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3438 if (SubStmt.isInvalid())
3439 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregorebe10102009-08-20 07:17:43 +00003441 // Attach the body to the case statement
3442 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3443}
3444
3445template<typename Derived>
3446Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003447TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003448 // Transform the statement following the default case
3449 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3450 if (SubStmt.isInvalid())
3451 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 // Default statements are always rebuilt
3454 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3455 move(SubStmt));
3456}
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458template<typename Derived>
3459Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003460TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3462 if (SubStmt.isInvalid())
3463 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003464
Douglas Gregorebe10102009-08-20 07:17:43 +00003465 // FIXME: Pass the real colon location in.
3466 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3467 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3468 move(SubStmt));
3469}
Mike Stump11289f42009-09-09 15:08:12 +00003470
Douglas Gregorebe10102009-08-20 07:17:43 +00003471template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003472Sema::OwningStmtResult
3473TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003474 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003475 OwningExprResult Cond(SemaRef);
3476 VarDecl *ConditionVar = 0;
3477 if (S->getConditionVariable()) {
3478 ConditionVar
3479 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003480 getDerived().TransformDefinition(
3481 S->getConditionVariable()->getLocation(),
3482 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003483 if (!ConditionVar)
3484 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003485 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003486 Cond = getDerived().TransformExpr(S->getCond());
3487
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003488 if (Cond.isInvalid())
3489 return SemaRef.StmtError();
3490 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003491
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003492 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003493
Douglas Gregorebe10102009-08-20 07:17:43 +00003494 // Transform the "then" branch.
3495 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3496 if (Then.isInvalid())
3497 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003498
Douglas Gregorebe10102009-08-20 07:17:43 +00003499 // Transform the "else" branch.
3500 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3501 if (Else.isInvalid())
3502 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003503
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 if (!getDerived().AlwaysRebuild() &&
3505 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003506 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 Then.get() == S->getThen() &&
3508 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003509 return SemaRef.Owned(S->Retain());
3510
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003511 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3512 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003513 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003514}
3515
3516template<typename Derived>
3517Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003520 OwningExprResult Cond(SemaRef);
3521 VarDecl *ConditionVar = 0;
3522 if (S->getConditionVariable()) {
3523 ConditionVar
3524 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003525 getDerived().TransformDefinition(
3526 S->getConditionVariable()->getLocation(),
3527 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003528 if (!ConditionVar)
3529 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003530 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003531 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003532
3533 if (Cond.isInvalid())
3534 return SemaRef.StmtError();
3535 }
Mike Stump11289f42009-09-09 15:08:12 +00003536
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003537 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003540 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3541 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003542 if (Switch.isInvalid())
3543 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the body of the switch statement.
3546 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3547 if (Body.isInvalid())
3548 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003549
Douglas Gregorebe10102009-08-20 07:17:43 +00003550 // Complete the switch statement.
3551 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3552 move(Body));
3553}
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555template<typename Derived>
3556Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003557TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003559 OwningExprResult Cond(SemaRef);
3560 VarDecl *ConditionVar = 0;
3561 if (S->getConditionVariable()) {
3562 ConditionVar
3563 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003564 getDerived().TransformDefinition(
3565 S->getConditionVariable()->getLocation(),
3566 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003567 if (!ConditionVar)
3568 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003569 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003570 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003571
3572 if (Cond.isInvalid())
3573 return SemaRef.StmtError();
3574 }
Mike Stump11289f42009-09-09 15:08:12 +00003575
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003576 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 // Transform the body
3579 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3580 if (Body.isInvalid())
3581 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 if (!getDerived().AlwaysRebuild() &&
3584 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003586 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003587 return SemaRef.Owned(S->Retain());
3588
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003589 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3590 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003591}
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregorebe10102009-08-20 07:17:43 +00003593template<typename Derived>
3594Sema::OwningStmtResult
3595TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3596 // Transform the condition
3597 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3598 if (Cond.isInvalid())
3599 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 // Transform the body
3602 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3603 if (Body.isInvalid())
3604 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 if (!getDerived().AlwaysRebuild() &&
3607 Cond.get() == S->getCond() &&
3608 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003609 return SemaRef.Owned(S->Retain());
3610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3612 /*FIXME:*/S->getWhileLoc(), move(Cond),
3613 S->getRParenLoc());
3614}
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616template<typename Derived>
3617Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003618TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003619 // Transform the initialization statement
3620 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3621 if (Init.isInvalid())
3622 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003623
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003625 OwningExprResult Cond(SemaRef);
3626 VarDecl *ConditionVar = 0;
3627 if (S->getConditionVariable()) {
3628 ConditionVar
3629 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003630 getDerived().TransformDefinition(
3631 S->getConditionVariable()->getLocation(),
3632 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003633 if (!ConditionVar)
3634 return SemaRef.StmtError();
3635 } else {
3636 Cond = getDerived().TransformExpr(S->getCond());
3637
3638 if (Cond.isInvalid())
3639 return SemaRef.StmtError();
3640 }
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 // Transform the increment
3643 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3644 if (Inc.isInvalid())
3645 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003646
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 // Transform the body
3648 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3649 if (Body.isInvalid())
3650 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregorebe10102009-08-20 07:17:43 +00003652 if (!getDerived().AlwaysRebuild() &&
3653 Init.get() == S->getInit() &&
3654 Cond.get() == S->getCond() &&
3655 Inc.get() == S->getInc() &&
3656 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003657 return SemaRef.Owned(S->Retain());
3658
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003660 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003661 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003662 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003663 S->getRParenLoc(), move(Body));
3664}
3665
3666template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003667Sema::OwningStmtResult
3668TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003669 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003670 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003671 S->getLabel());
3672}
3673
3674template<typename Derived>
3675Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003676TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3678 if (Target.isInvalid())
3679 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003680
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 if (!getDerived().AlwaysRebuild() &&
3682 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003683 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003684
3685 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3686 move(Target));
3687}
3688
3689template<typename Derived>
3690Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003691TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3692 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003693}
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregorebe10102009-08-20 07:17:43 +00003695template<typename Derived>
3696Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003697TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3698 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003699}
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701template<typename Derived>
3702Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003703TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3705 if (Result.isInvalid())
3706 return SemaRef.StmtError();
3707
Mike Stump11289f42009-09-09 15:08:12 +00003708 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 // to tell whether the return type of the function has changed.
3710 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3711}
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregorebe10102009-08-20 07:17:43 +00003713template<typename Derived>
3714Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003715TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003716 bool DeclChanged = false;
3717 llvm::SmallVector<Decl *, 4> Decls;
3718 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3719 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003720 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3721 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 if (!Transformed)
3723 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003724
Douglas Gregorebe10102009-08-20 07:17:43 +00003725 if (Transformed != *D)
3726 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregorebe10102009-08-20 07:17:43 +00003728 Decls.push_back(Transformed);
3729 }
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003732 return SemaRef.Owned(S->Retain());
3733
3734 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003735 S->getStartLoc(), S->getEndLoc());
3736}
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregorebe10102009-08-20 07:17:43 +00003738template<typename Derived>
3739Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003740TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003741 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003742 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003743}
3744
3745template<typename Derived>
3746Sema::OwningStmtResult
3747TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003748
3749 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3750 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003751 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003752
Anders Carlssonaaeef072010-01-24 05:50:09 +00003753 OwningExprResult AsmString(SemaRef);
3754 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3755
3756 bool ExprsChanged = false;
3757
3758 // Go through the outputs.
3759 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003760 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003761
Anders Carlssonaaeef072010-01-24 05:50:09 +00003762 // No need to transform the constraint literal.
3763 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3764
3765 // Transform the output expr.
3766 Expr *OutputExpr = S->getOutputExpr(I);
3767 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3768 if (Result.isInvalid())
3769 return SemaRef.StmtError();
3770
3771 ExprsChanged |= Result.get() != OutputExpr;
3772
3773 Exprs.push_back(Result.takeAs<Expr>());
3774 }
3775
3776 // Go through the inputs.
3777 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003778 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003779
Anders Carlssonaaeef072010-01-24 05:50:09 +00003780 // No need to transform the constraint literal.
3781 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3782
3783 // Transform the input expr.
3784 Expr *InputExpr = S->getInputExpr(I);
3785 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3786 if (Result.isInvalid())
3787 return SemaRef.StmtError();
3788
3789 ExprsChanged |= Result.get() != InputExpr;
3790
3791 Exprs.push_back(Result.takeAs<Expr>());
3792 }
3793
3794 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3795 return SemaRef.Owned(S->Retain());
3796
3797 // Go through the clobbers.
3798 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3799 Clobbers.push_back(S->getClobber(I)->Retain());
3800
3801 // No need to transform the asm string literal.
3802 AsmString = SemaRef.Owned(S->getAsmString());
3803
3804 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3805 S->isSimple(),
3806 S->isVolatile(),
3807 S->getNumOutputs(),
3808 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003809 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003810 move_arg(Constraints),
3811 move_arg(Exprs),
3812 move(AsmString),
3813 move_arg(Clobbers),
3814 S->getRParenLoc(),
3815 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003816}
3817
3818
3819template<typename Derived>
3820Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003821TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003822 // Transform the body of the @try.
3823 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3824 if (TryBody.isInvalid())
3825 return SemaRef.StmtError();
3826
Douglas Gregor96c79492010-04-23 22:50:49 +00003827 // Transform the @catch statements (if present).
3828 bool AnyCatchChanged = false;
3829 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3830 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3831 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003832 if (Catch.isInvalid())
3833 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003834 if (Catch.get() != S->getCatchStmt(I))
3835 AnyCatchChanged = true;
3836 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003837 }
3838
3839 // Transform the @finally statement (if present).
3840 OwningStmtResult Finally(SemaRef);
3841 if (S->getFinallyStmt()) {
3842 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3843 if (Finally.isInvalid())
3844 return SemaRef.StmtError();
3845 }
3846
3847 // If nothing changed, just retain this statement.
3848 if (!getDerived().AlwaysRebuild() &&
3849 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003850 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003851 Finally.get() == S->getFinallyStmt())
3852 return SemaRef.Owned(S->Retain());
3853
3854 // Build a new statement.
3855 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003856 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003857}
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregorebe10102009-08-20 07:17:43 +00003859template<typename Derived>
3860Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003861TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003862 // Transform the @catch parameter, if there is one.
3863 VarDecl *Var = 0;
3864 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3865 TypeSourceInfo *TSInfo = 0;
3866 if (FromVar->getTypeSourceInfo()) {
3867 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3868 if (!TSInfo)
3869 return SemaRef.StmtError();
3870 }
3871
3872 QualType T;
3873 if (TSInfo)
3874 T = TSInfo->getType();
3875 else {
3876 T = getDerived().TransformType(FromVar->getType());
3877 if (T.isNull())
3878 return SemaRef.StmtError();
3879 }
3880
3881 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3882 if (!Var)
3883 return SemaRef.StmtError();
3884 }
3885
3886 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3887 if (Body.isInvalid())
3888 return SemaRef.StmtError();
3889
3890 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
3891 S->getRParenLoc(),
3892 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003893}
Mike Stump11289f42009-09-09 15:08:12 +00003894
Douglas Gregorebe10102009-08-20 07:17:43 +00003895template<typename Derived>
3896Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003897TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003898 // Transform the body.
3899 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3900 if (Body.isInvalid())
3901 return SemaRef.StmtError();
3902
3903 // If nothing changed, just retain this statement.
3904 if (!getDerived().AlwaysRebuild() &&
3905 Body.get() == S->getFinallyBody())
3906 return SemaRef.Owned(S->Retain());
3907
3908 // Build a new statement.
3909 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3910 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregorebe10102009-08-20 07:17:43 +00003913template<typename Derived>
3914Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003915TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003916 OwningExprResult Operand(SemaRef);
3917 if (S->getThrowExpr()) {
3918 Operand = getDerived().TransformExpr(S->getThrowExpr());
3919 if (Operand.isInvalid())
3920 return getSema().StmtError();
3921 }
3922
3923 if (!getDerived().AlwaysRebuild() &&
3924 Operand.get() == S->getThrowExpr())
3925 return getSema().Owned(S->Retain());
3926
3927 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003928}
Mike Stump11289f42009-09-09 15:08:12 +00003929
Douglas Gregorebe10102009-08-20 07:17:43 +00003930template<typename Derived>
3931Sema::OwningStmtResult
3932TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003933 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003934 // Transform the object we are locking.
3935 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3936 if (Object.isInvalid())
3937 return SemaRef.StmtError();
3938
3939 // Transform the body.
3940 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3941 if (Body.isInvalid())
3942 return SemaRef.StmtError();
3943
3944 // If nothing change, just retain the current statement.
3945 if (!getDerived().AlwaysRebuild() &&
3946 Object.get() == S->getSynchExpr() &&
3947 Body.get() == S->getSynchBody())
3948 return SemaRef.Owned(S->Retain());
3949
3950 // Build a new statement.
3951 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3952 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003953}
3954
3955template<typename Derived>
3956Sema::OwningStmtResult
3957TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003958 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003959 // Transform the element statement.
3960 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3961 if (Element.isInvalid())
3962 return SemaRef.StmtError();
3963
3964 // Transform the collection expression.
3965 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3966 if (Collection.isInvalid())
3967 return SemaRef.StmtError();
3968
3969 // Transform the body.
3970 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3971 if (Body.isInvalid())
3972 return SemaRef.StmtError();
3973
3974 // If nothing changed, just retain this statement.
3975 if (!getDerived().AlwaysRebuild() &&
3976 Element.get() == S->getElement() &&
3977 Collection.get() == S->getCollection() &&
3978 Body.get() == S->getBody())
3979 return SemaRef.Owned(S->Retain());
3980
3981 // Build a new statement.
3982 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3983 /*FIXME:*/S->getForLoc(),
3984 move(Element),
3985 move(Collection),
3986 S->getRParenLoc(),
3987 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003988}
3989
3990
3991template<typename Derived>
3992Sema::OwningStmtResult
3993TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3994 // Transform the exception declaration, if any.
3995 VarDecl *Var = 0;
3996 if (S->getExceptionDecl()) {
3997 VarDecl *ExceptionDecl = S->getExceptionDecl();
3998 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3999 ExceptionDecl->getDeclName());
4000
4001 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4002 if (T.isNull())
4003 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregorebe10102009-08-20 07:17:43 +00004005 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4006 T,
John McCallbcd03502009-12-07 02:54:59 +00004007 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004008 ExceptionDecl->getIdentifier(),
4009 ExceptionDecl->getLocation(),
4010 /*FIXME: Inaccurate*/
4011 SourceRange(ExceptionDecl->getLocation()));
4012 if (!Var || Var->isInvalidDecl()) {
4013 if (Var)
4014 Var->Destroy(SemaRef.Context);
4015 return SemaRef.StmtError();
4016 }
4017 }
Mike Stump11289f42009-09-09 15:08:12 +00004018
Douglas Gregorebe10102009-08-20 07:17:43 +00004019 // Transform the actual exception handler.
4020 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4021 if (Handler.isInvalid()) {
4022 if (Var)
4023 Var->Destroy(SemaRef.Context);
4024 return SemaRef.StmtError();
4025 }
Mike Stump11289f42009-09-09 15:08:12 +00004026
Douglas Gregorebe10102009-08-20 07:17:43 +00004027 if (!getDerived().AlwaysRebuild() &&
4028 !Var &&
4029 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004030 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004031
4032 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4033 Var,
4034 move(Handler));
4035}
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037template<typename Derived>
4038Sema::OwningStmtResult
4039TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4040 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004041 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004042 = getDerived().TransformCompoundStmt(S->getTryBlock());
4043 if (TryBlock.isInvalid())
4044 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregorebe10102009-08-20 07:17:43 +00004046 // Transform the handlers.
4047 bool HandlerChanged = false;
4048 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4049 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004050 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004051 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4052 if (Handler.isInvalid())
4053 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregorebe10102009-08-20 07:17:43 +00004055 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4056 Handlers.push_back(Handler.takeAs<Stmt>());
4057 }
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregorebe10102009-08-20 07:17:43 +00004059 if (!getDerived().AlwaysRebuild() &&
4060 TryBlock.get() == S->getTryBlock() &&
4061 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004062 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004063
4064 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004065 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregorebe10102009-08-20 07:17:43 +00004068//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004069// Expression transformation
4070//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004071template<typename Derived>
4072Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004073TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004074 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004075}
Mike Stump11289f42009-09-09 15:08:12 +00004076
4077template<typename Derived>
4078Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004079TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004080 NestedNameSpecifier *Qualifier = 0;
4081 if (E->getQualifier()) {
4082 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004083 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004084 if (!Qualifier)
4085 return SemaRef.ExprError();
4086 }
John McCallce546572009-12-08 09:08:17 +00004087
4088 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004089 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4090 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 if (!ND)
4092 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004094 if (!getDerived().AlwaysRebuild() &&
4095 Qualifier == E->getQualifier() &&
4096 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004097 !E->hasExplicitTemplateArgumentList()) {
4098
4099 // Mark it referenced in the new context regardless.
4100 // FIXME: this is a bit instantiation-specific.
4101 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4102
Mike Stump11289f42009-09-09 15:08:12 +00004103 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004104 }
John McCallce546572009-12-08 09:08:17 +00004105
4106 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4107 if (E->hasExplicitTemplateArgumentList()) {
4108 TemplateArgs = &TransArgs;
4109 TransArgs.setLAngleLoc(E->getLAngleLoc());
4110 TransArgs.setRAngleLoc(E->getRAngleLoc());
4111 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4112 TemplateArgumentLoc Loc;
4113 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4114 return SemaRef.ExprError();
4115 TransArgs.addArgument(Loc);
4116 }
4117 }
4118
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004119 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004120 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004121}
Mike Stump11289f42009-09-09 15:08:12 +00004122
Douglas Gregora16548e2009-08-11 05:31:07 +00004123template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004125TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004126 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004127}
Mike Stump11289f42009-09-09 15:08:12 +00004128
Douglas Gregora16548e2009-08-11 05:31:07 +00004129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004130Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004131TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004132 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004133}
Mike Stump11289f42009-09-09 15:08:12 +00004134
Douglas Gregora16548e2009-08-11 05:31:07 +00004135template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004136Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004137TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004138 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004139}
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregora16548e2009-08-11 05:31:07 +00004141template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004142Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004143TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004144 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004145}
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004148Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004149TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004150 return SemaRef.Owned(E->Retain());
4151}
4152
4153template<typename Derived>
4154Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004155TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004156 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4157 if (SubExpr.isInvalid())
4158 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004161 return SemaRef.Owned(E->Retain());
4162
4163 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 E->getRParen());
4165}
4166
Mike Stump11289f42009-09-09 15:08:12 +00004167template<typename Derived>
4168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004169TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4170 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 if (SubExpr.isInvalid())
4172 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004175 return SemaRef.Owned(E->Retain());
4176
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4178 E->getOpcode(),
4179 move(SubExpr));
4180}
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregora16548e2009-08-11 05:31:07 +00004182template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004183Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004184TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4185 // Transform the type.
4186 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4187 if (!Type)
4188 return getSema().ExprError();
4189
4190 // Transform all of the components into components similar to what the
4191 // parser uses.
4192 // FIXME: It would be slightly more efficient in the non-dependent case to
4193 // just map FieldDecls, rather than requiring the rebuilder to look for
4194 // the fields again. However, __builtin_offsetof is rare enough in
4195 // template code that we don't care.
4196 bool ExprChanged = false;
4197 typedef Action::OffsetOfComponent Component;
4198 typedef OffsetOfExpr::OffsetOfNode Node;
4199 llvm::SmallVector<Component, 4> Components;
4200 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4201 const Node &ON = E->getComponent(I);
4202 Component Comp;
4203 Comp.LocStart = ON.getRange().getBegin();
4204 Comp.LocEnd = ON.getRange().getEnd();
4205 switch (ON.getKind()) {
4206 case Node::Array: {
4207 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4208 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4209 if (Index.isInvalid())
4210 return getSema().ExprError();
4211
4212 ExprChanged = ExprChanged || Index.get() != FromIndex;
4213 Comp.isBrackets = true;
4214 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4215 break;
4216 }
4217
4218 case Node::Field:
4219 case Node::Identifier:
4220 Comp.isBrackets = false;
4221 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004222 if (!Comp.U.IdentInfo)
4223 continue;
4224
Douglas Gregor882211c2010-04-28 22:16:22 +00004225 break;
Douglas Gregord1702062010-04-29 00:18:15 +00004226
4227 case Node::Base:
4228 // Will be recomputed during the rebuild.
4229 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004230 }
4231
4232 Components.push_back(Comp);
4233 }
4234
4235 // If nothing changed, retain the existing expression.
4236 if (!getDerived().AlwaysRebuild() &&
4237 Type == E->getTypeSourceInfo() &&
4238 !ExprChanged)
4239 return SemaRef.Owned(E->Retain());
4240
4241 // Build a new offsetof expression.
4242 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4243 Components.data(), Components.size(),
4244 E->getRParenLoc());
4245}
4246
4247template<typename Derived>
4248Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004249TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004250 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004251 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004252
John McCallbcd03502009-12-07 02:54:59 +00004253 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004254 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004255 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004256
John McCall4c98fd82009-11-04 07:28:41 +00004257 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004259
John McCall4c98fd82009-11-04 07:28:41 +00004260 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004261 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 E->getSourceRange());
4263 }
Mike Stump11289f42009-09-09 15:08:12 +00004264
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004266 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 // C++0x [expr.sizeof]p1:
4268 // The operand is either an expression, which is an unevaluated operand
4269 // [...]
4270 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4273 if (SubExpr.isInvalid())
4274 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4277 return SemaRef.Owned(E->Retain());
4278 }
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4281 E->isSizeOf(),
4282 E->getSourceRange());
4283}
Mike Stump11289f42009-09-09 15:08:12 +00004284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004286Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004287TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4289 if (LHS.isInvalid())
4290 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004291
Douglas Gregora16548e2009-08-11 05:31:07 +00004292 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4293 if (RHS.isInvalid())
4294 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004295
4296
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 if (!getDerived().AlwaysRebuild() &&
4298 LHS.get() == E->getLHS() &&
4299 RHS.get() == E->getRHS())
4300 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004301
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4303 /*FIXME:*/E->getLHS()->getLocStart(),
4304 move(RHS),
4305 E->getRBracketLoc());
4306}
Mike Stump11289f42009-09-09 15:08:12 +00004307
4308template<typename Derived>
4309Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004310TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 // Transform the callee.
4312 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4313 if (Callee.isInvalid())
4314 return SemaRef.ExprError();
4315
4316 // Transform arguments.
4317 bool ArgChanged = false;
4318 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4319 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4320 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4321 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4322 if (Arg.isInvalid())
4323 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 // FIXME: Wrong source location information for the ','.
4326 FakeCommaLocs.push_back(
4327 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004328
4329 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 Args.push_back(Arg.takeAs<Expr>());
4331 }
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 if (!getDerived().AlwaysRebuild() &&
4334 Callee.get() == E->getCallee() &&
4335 !ArgChanged)
4336 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004339 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004340 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4341 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4342 move_arg(Args),
4343 FakeCommaLocs.data(),
4344 E->getRParenLoc());
4345}
Mike Stump11289f42009-09-09 15:08:12 +00004346
4347template<typename Derived>
4348Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004349TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4351 if (Base.isInvalid())
4352 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004354 NestedNameSpecifier *Qualifier = 0;
4355 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004356 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004357 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004358 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004359 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004360 return SemaRef.ExprError();
4361 }
Mike Stump11289f42009-09-09 15:08:12 +00004362
Eli Friedman2cfcef62009-12-04 06:40:45 +00004363 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004364 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4365 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004366 if (!Member)
4367 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004368
John McCall16df1e52010-03-30 21:47:33 +00004369 NamedDecl *FoundDecl = E->getFoundDecl();
4370 if (FoundDecl == E->getMemberDecl()) {
4371 FoundDecl = Member;
4372 } else {
4373 FoundDecl = cast_or_null<NamedDecl>(
4374 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4375 if (!FoundDecl)
4376 return SemaRef.ExprError();
4377 }
4378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 if (!getDerived().AlwaysRebuild() &&
4380 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004381 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004382 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004383 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004384 !E->hasExplicitTemplateArgumentList()) {
4385
4386 // Mark it referenced in the new context regardless.
4387 // FIXME: this is a bit instantiation-specific.
4388 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004389 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004390 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004391
John McCall6b51f282009-11-23 01:53:49 +00004392 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004393 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004394 TransArgs.setLAngleLoc(E->getLAngleLoc());
4395 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004396 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004397 TemplateArgumentLoc Loc;
4398 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004399 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004400 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004401 }
4402 }
4403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 // FIXME: Bogus source location for the operator
4405 SourceLocation FakeOperatorLoc
4406 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4407
John McCall38836f02010-01-15 08:34:02 +00004408 // FIXME: to do this check properly, we will need to preserve the
4409 // first-qualifier-in-scope here, just in case we had a dependent
4410 // base (and therefore couldn't do the check) and a
4411 // nested-name-qualifier (and therefore could do the lookup).
4412 NamedDecl *FirstQualifierInScope = 0;
4413
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4415 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004416 Qualifier,
4417 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004419 Member,
John McCall16df1e52010-03-30 21:47:33 +00004420 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004421 (E->hasExplicitTemplateArgumentList()
4422 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004423 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004424}
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregora16548e2009-08-11 05:31:07 +00004426template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004427Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004428TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4430 if (LHS.isInvalid())
4431 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4434 if (RHS.isInvalid())
4435 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 if (!getDerived().AlwaysRebuild() &&
4438 LHS.get() == E->getLHS() &&
4439 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004440 return SemaRef.Owned(E->Retain());
4441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4443 move(LHS), move(RHS));
4444}
4445
Mike Stump11289f42009-09-09 15:08:12 +00004446template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004447Sema::OwningExprResult
4448TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004449 CompoundAssignOperator *E) {
4450 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004451}
Mike Stump11289f42009-09-09 15:08:12 +00004452
Douglas Gregora16548e2009-08-11 05:31:07 +00004453template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004454Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4457 if (Cond.isInvalid())
4458 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004459
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4461 if (LHS.isInvalid())
4462 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4465 if (RHS.isInvalid())
4466 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 if (!getDerived().AlwaysRebuild() &&
4469 Cond.get() == E->getCond() &&
4470 LHS.get() == E->getLHS() &&
4471 RHS.get() == E->getRHS())
4472 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004473
4474 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004475 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004476 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004477 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 move(RHS));
4479}
Mike Stump11289f42009-09-09 15:08:12 +00004480
4481template<typename Derived>
4482Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004483TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004484 // Implicit casts are eliminated during transformation, since they
4485 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004486 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004487}
Mike Stump11289f42009-09-09 15:08:12 +00004488
Douglas Gregora16548e2009-08-11 05:31:07 +00004489template<typename Derived>
4490Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004491TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004492 TypeSourceInfo *OldT;
4493 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 {
4495 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004496 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4498 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004499
John McCall97513962010-01-15 18:39:57 +00004500 OldT = E->getTypeInfoAsWritten();
4501 NewT = getDerived().TransformType(OldT);
4502 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 return SemaRef.ExprError();
4504 }
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregor6131b442009-12-12 18:16:41 +00004506 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004507 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 if (SubExpr.isInvalid())
4509 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004512 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004514 return SemaRef.Owned(E->Retain());
4515
John McCall97513962010-01-15 18:39:57 +00004516 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4517 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004518 E->getRParenLoc(),
4519 move(SubExpr));
4520}
Mike Stump11289f42009-09-09 15:08:12 +00004521
Douglas Gregora16548e2009-08-11 05:31:07 +00004522template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004523Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004524TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004525 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4526 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4527 if (!NewT)
4528 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4531 if (Init.isInvalid())
4532 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004535 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004537 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004538
John McCall5d7aa7f2010-01-19 22:33:45 +00004539 // Note: the expression type doesn't necessarily match the
4540 // type-as-written, but that's okay, because it should always be
4541 // derivable from the initializer.
4542
John McCalle15bbff2010-01-18 19:35:47 +00004543 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 /*FIXME:*/E->getInitializer()->getLocEnd(),
4545 move(Init));
4546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548template<typename Derived>
4549Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004550TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4552 if (Base.isInvalid())
4553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 if (!getDerived().AlwaysRebuild() &&
4556 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004557 return SemaRef.Owned(E->Retain());
4558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004560 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4562 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4563 E->getAccessorLoc(),
4564 E->getAccessor());
4565}
Mike Stump11289f42009-09-09 15:08:12 +00004566
Douglas Gregora16548e2009-08-11 05:31:07 +00004567template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004568Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004569TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4573 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4574 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4575 if (Init.isInvalid())
4576 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 InitChanged = InitChanged || Init.get() != E->getInit(I);
4579 Inits.push_back(Init.takeAs<Expr>());
4580 }
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004583 return SemaRef.Owned(E->Retain());
4584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004586 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004587}
Mike Stump11289f42009-09-09 15:08:12 +00004588
Douglas Gregora16548e2009-08-11 05:31:07 +00004589template<typename Derived>
4590Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004591TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregorebe10102009-08-20 07:17:43 +00004594 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4596 if (Init.isInvalid())
4597 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004598
Douglas Gregorebe10102009-08-20 07:17:43 +00004599 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004600 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4601 bool ExprChanged = false;
4602 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4603 DEnd = E->designators_end();
4604 D != DEnd; ++D) {
4605 if (D->isFieldDesignator()) {
4606 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4607 D->getDotLoc(),
4608 D->getFieldLoc()));
4609 continue;
4610 }
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612 if (D->isArrayDesignator()) {
4613 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4614 if (Index.isInvalid())
4615 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004616
4617 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4621 ArrayExprs.push_back(Index.release());
4622 continue;
4623 }
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004626 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4628 if (Start.isInvalid())
4629 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4632 if (End.isInvalid())
4633 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004634
4635 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 End.get(),
4637 D->getLBracketLoc(),
4638 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4641 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 ArrayExprs.push_back(Start.release());
4644 ArrayExprs.push_back(End.release());
4645 }
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 if (!getDerived().AlwaysRebuild() &&
4648 Init.get() == E->getInit() &&
4649 !ExprChanged)
4650 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4653 E->getEqualOrColonLoc(),
4654 E->usesGNUSyntax(), move(Init));
4655}
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregora16548e2009-08-11 05:31:07 +00004657template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004658Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004659TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004660 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004661 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4662
4663 // FIXME: Will we ever have proper type location here? Will we actually
4664 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 QualType T = getDerived().TransformType(E->getType());
4666 if (T.isNull())
4667 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 if (!getDerived().AlwaysRebuild() &&
4670 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004671 return SemaRef.Owned(E->Retain());
4672
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 return getDerived().RebuildImplicitValueInitExpr(T);
4674}
Mike Stump11289f42009-09-09 15:08:12 +00004675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004677Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004678TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004679 // FIXME: Do we want the type as written?
4680 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 {
4683 // FIXME: Source location isn't quite accurate.
4684 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4685 T = getDerived().TransformType(E->getType());
4686 if (T.isNull())
4687 return SemaRef.ExprError();
4688 }
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4691 if (SubExpr.isInvalid())
4692 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004693
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 if (!getDerived().AlwaysRebuild() &&
4695 T == E->getType() &&
4696 SubExpr.get() == E->getSubExpr())
4697 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4700 T, E->getRParenLoc());
4701}
4702
4703template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004704Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004705TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 bool ArgumentChanged = false;
4707 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4708 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4709 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4710 if (Init.isInvalid())
4711 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4714 Inits.push_back(Init.takeAs<Expr>());
4715 }
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4718 move_arg(Inits),
4719 E->getRParenLoc());
4720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722/// \brief Transform an address-of-label expression.
4723///
4724/// By default, the transformation of an address-of-label expression always
4725/// rebuilds the expression, so that the label identifier can be resolved to
4726/// the corresponding label statement by semantic analysis.
4727template<typename Derived>
4728Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004729TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4731 E->getLabel());
4732}
Mike Stump11289f42009-09-09 15:08:12 +00004733
4734template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004735Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004736TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004737 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4739 if (SubStmt.isInvalid())
4740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 if (!getDerived().AlwaysRebuild() &&
4743 SubStmt.get() == E->getSubStmt())
4744 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004745
4746 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 move(SubStmt),
4748 E->getRParenLoc());
4749}
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregora16548e2009-08-11 05:31:07 +00004751template<typename Derived>
4752Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004753TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 QualType T1, T2;
4755 {
4756 // FIXME: Source location isn't quite accurate.
4757 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 T1 = getDerived().TransformType(E->getArgType1());
4760 if (T1.isNull())
4761 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 T2 = getDerived().TransformType(E->getArgType2());
4764 if (T2.isNull())
4765 return SemaRef.ExprError();
4766 }
4767
4768 if (!getDerived().AlwaysRebuild() &&
4769 T1 == E->getArgType1() &&
4770 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004771 return SemaRef.Owned(E->Retain());
4772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4774 T1, T2, E->getRParenLoc());
4775}
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregora16548e2009-08-11 05:31:07 +00004777template<typename Derived>
4778Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004779TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4781 if (Cond.isInvalid())
4782 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4785 if (LHS.isInvalid())
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4789 if (RHS.isInvalid())
4790 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 if (!getDerived().AlwaysRebuild() &&
4793 Cond.get() == E->getCond() &&
4794 LHS.get() == E->getLHS() &&
4795 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004796 return SemaRef.Owned(E->Retain());
4797
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4799 move(Cond), move(LHS), move(RHS),
4800 E->getRParenLoc());
4801}
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004804Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004805TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004806 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004807}
4808
4809template<typename Derived>
4810Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004811TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004812 switch (E->getOperator()) {
4813 case OO_New:
4814 case OO_Delete:
4815 case OO_Array_New:
4816 case OO_Array_Delete:
4817 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4818 return SemaRef.ExprError();
4819
4820 case OO_Call: {
4821 // This is a call to an object's operator().
4822 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4823
4824 // Transform the object itself.
4825 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4826 if (Object.isInvalid())
4827 return SemaRef.ExprError();
4828
4829 // FIXME: Poor location information
4830 SourceLocation FakeLParenLoc
4831 = SemaRef.PP.getLocForEndOfToken(
4832 static_cast<Expr *>(Object.get())->getLocEnd());
4833
4834 // Transform the call arguments.
4835 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4836 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4837 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004838 if (getDerived().DropCallArgument(E->getArg(I)))
4839 break;
4840
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004841 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4842 if (Arg.isInvalid())
4843 return SemaRef.ExprError();
4844
4845 // FIXME: Poor source location information.
4846 SourceLocation FakeCommaLoc
4847 = SemaRef.PP.getLocForEndOfToken(
4848 static_cast<Expr *>(Arg.get())->getLocEnd());
4849 FakeCommaLocs.push_back(FakeCommaLoc);
4850 Args.push_back(Arg.release());
4851 }
4852
4853 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4854 move_arg(Args),
4855 FakeCommaLocs.data(),
4856 E->getLocEnd());
4857 }
4858
4859#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4860 case OO_##Name:
4861#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4862#include "clang/Basic/OperatorKinds.def"
4863 case OO_Subscript:
4864 // Handled below.
4865 break;
4866
4867 case OO_Conditional:
4868 llvm_unreachable("conditional operator is not actually overloadable");
4869 return SemaRef.ExprError();
4870
4871 case OO_None:
4872 case NUM_OVERLOADED_OPERATORS:
4873 llvm_unreachable("not an overloaded operator?");
4874 return SemaRef.ExprError();
4875 }
4876
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4878 if (Callee.isInvalid())
4879 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004880
John McCall47f29ea2009-12-08 09:21:05 +00004881 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 if (First.isInvalid())
4883 return SemaRef.ExprError();
4884
4885 OwningExprResult Second(SemaRef);
4886 if (E->getNumArgs() == 2) {
4887 Second = getDerived().TransformExpr(E->getArg(1));
4888 if (Second.isInvalid())
4889 return SemaRef.ExprError();
4890 }
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregora16548e2009-08-11 05:31:07 +00004892 if (!getDerived().AlwaysRebuild() &&
4893 Callee.get() == E->getCallee() &&
4894 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004895 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4896 return SemaRef.Owned(E->Retain());
4897
Douglas Gregora16548e2009-08-11 05:31:07 +00004898 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4899 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004900 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 move(First),
4902 move(Second));
4903}
Mike Stump11289f42009-09-09 15:08:12 +00004904
Douglas Gregora16548e2009-08-11 05:31:07 +00004905template<typename Derived>
4906Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004907TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4908 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004909}
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregora16548e2009-08-11 05:31:07 +00004911template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004912Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004913TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004914 TypeSourceInfo *OldT;
4915 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 {
4917 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004918 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4920 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004921
John McCall97513962010-01-15 18:39:57 +00004922 OldT = E->getTypeInfoAsWritten();
4923 NewT = getDerived().TransformType(OldT);
4924 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 return SemaRef.ExprError();
4926 }
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregor6131b442009-12-12 18:16:41 +00004928 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004929 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004930 if (SubExpr.isInvalid())
4931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004932
Douglas Gregora16548e2009-08-11 05:31:07 +00004933 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004934 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004936 return SemaRef.Owned(E->Retain());
4937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004939 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004940 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4941 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4942 SourceLocation FakeRParenLoc
4943 = SemaRef.PP.getLocForEndOfToken(
4944 E->getSubExpr()->getSourceRange().getEnd());
4945 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004946 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004948 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 FakeRAngleLoc,
4950 FakeRAngleLoc,
4951 move(SubExpr),
4952 FakeRParenLoc);
4953}
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregora16548e2009-08-11 05:31:07 +00004955template<typename Derived>
4956Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004957TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4958 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004959}
Mike Stump11289f42009-09-09 15:08:12 +00004960
4961template<typename Derived>
4962Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004963TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4964 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004965}
4966
Douglas Gregora16548e2009-08-11 05:31:07 +00004967template<typename Derived>
4968Sema::OwningExprResult
4969TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004970 CXXReinterpretCastExpr *E) {
4971 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004972}
Mike Stump11289f42009-09-09 15:08:12 +00004973
Douglas Gregora16548e2009-08-11 05:31:07 +00004974template<typename Derived>
4975Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004976TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4977 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004978}
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregora16548e2009-08-11 05:31:07 +00004980template<typename Derived>
4981Sema::OwningExprResult
4982TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004983 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004984 TypeSourceInfo *OldT;
4985 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 {
4987 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004988
John McCall97513962010-01-15 18:39:57 +00004989 OldT = E->getTypeInfoAsWritten();
4990 NewT = getDerived().TransformType(OldT);
4991 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 return SemaRef.ExprError();
4993 }
Mike Stump11289f42009-09-09 15:08:12 +00004994
Douglas Gregor6131b442009-12-12 18:16:41 +00004995 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004996 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004997 if (SubExpr.isInvalid())
4998 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005001 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005002 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005003 return SemaRef.Owned(E->Retain());
5004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 // FIXME: The end of the type's source range is wrong
5006 return getDerived().RebuildCXXFunctionalCastExpr(
5007 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005008 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005009 /*FIXME:*/E->getSubExpr()->getLocStart(),
5010 move(SubExpr),
5011 E->getRParenLoc());
5012}
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014template<typename Derived>
5015Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005016TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005018 TypeSourceInfo *TInfo
5019 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5020 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005024 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregor9da64192010-04-26 22:37:10 +00005027 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5028 E->getLocStart(),
5029 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005030 E->getLocEnd());
5031 }
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 // We don't know whether the expression is potentially evaluated until
5034 // after we perform semantic analysis, so the expression is potentially
5035 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005036 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregora16548e2009-08-11 05:31:07 +00005039 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5040 if (SubExpr.isInvalid())
5041 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005042
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 if (!getDerived().AlwaysRebuild() &&
5044 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
5046
Douglas Gregor9da64192010-04-26 22:37:10 +00005047 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5048 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005049 move(SubExpr),
5050 E->getLocEnd());
5051}
5052
5053template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005054Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005055TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005056 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005057}
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregora16548e2009-08-11 05:31:07 +00005059template<typename Derived>
5060Sema::OwningExprResult
5061TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005062 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005063 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005064}
Mike Stump11289f42009-09-09 15:08:12 +00005065
Douglas Gregora16548e2009-08-11 05:31:07 +00005066template<typename Derived>
5067Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005068TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005069 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 QualType T = getDerived().TransformType(E->getType());
5072 if (T.isNull())
5073 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075 if (!getDerived().AlwaysRebuild() &&
5076 T == E->getType())
5077 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005078
Douglas Gregorb15af892010-01-07 23:12:05 +00005079 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5086 if (SubExpr.isInvalid())
5087 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 if (!getDerived().AlwaysRebuild() &&
5090 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005091 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005092
5093 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096template<typename Derived>
5097Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005098TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005099 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005100 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5101 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 if (!Param)
5103 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005104
Chandler Carruth794da4c2010-02-08 06:42:49 +00005105 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 Param == E->getParam())
5107 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregor033f6752009-12-23 23:03:06 +00005109 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005110}
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112template<typename Derived>
5113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5116
5117 QualType T = getDerived().TransformType(E->getType());
5118 if (T.isNull())
5119 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 if (!getDerived().AlwaysRebuild() &&
5122 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005123 return SemaRef.Owned(E->Retain());
5124
5125 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 /*FIXME:*/E->getTypeBeginLoc(),
5127 T,
5128 E->getRParenLoc());
5129}
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregora16548e2009-08-11 05:31:07 +00005131template<typename Derived>
5132Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005133TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 // Transform the type that we're allocating
5135 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5136 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5137 if (AllocType.isNull())
5138 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 // Transform the size of the array we're allocating (if any).
5141 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5142 if (ArraySize.isInvalid())
5143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 // Transform the placement arguments (if any).
5146 bool ArgumentChanged = false;
5147 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5148 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5149 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5150 if (Arg.isInvalid())
5151 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5154 PlacementArgs.push_back(Arg.take());
5155 }
Mike Stump11289f42009-09-09 15:08:12 +00005156
Douglas Gregorebe10102009-08-20 07:17:43 +00005157 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005158 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5159 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5160 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5161 if (Arg.isInvalid())
5162 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5165 ConstructorArgs.push_back(Arg.take());
5166 }
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregord2d9da02010-02-26 00:38:10 +00005168 // Transform constructor, new operator, and delete operator.
5169 CXXConstructorDecl *Constructor = 0;
5170 if (E->getConstructor()) {
5171 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005172 getDerived().TransformDecl(E->getLocStart(),
5173 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005174 if (!Constructor)
5175 return SemaRef.ExprError();
5176 }
5177
5178 FunctionDecl *OperatorNew = 0;
5179 if (E->getOperatorNew()) {
5180 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005181 getDerived().TransformDecl(E->getLocStart(),
5182 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005183 if (!OperatorNew)
5184 return SemaRef.ExprError();
5185 }
5186
5187 FunctionDecl *OperatorDelete = 0;
5188 if (E->getOperatorDelete()) {
5189 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005190 getDerived().TransformDecl(E->getLocStart(),
5191 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005192 if (!OperatorDelete)
5193 return SemaRef.ExprError();
5194 }
5195
Douglas Gregora16548e2009-08-11 05:31:07 +00005196 if (!getDerived().AlwaysRebuild() &&
5197 AllocType == E->getAllocatedType() &&
5198 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005199 Constructor == E->getConstructor() &&
5200 OperatorNew == E->getOperatorNew() &&
5201 OperatorDelete == E->getOperatorDelete() &&
5202 !ArgumentChanged) {
5203 // Mark any declarations we need as referenced.
5204 // FIXME: instantiation-specific.
5205 if (Constructor)
5206 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5207 if (OperatorNew)
5208 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5209 if (OperatorDelete)
5210 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005211 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005212 }
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005214 if (!ArraySize.get()) {
5215 // If no array size was specified, but the new expression was
5216 // instantiated with an array type (e.g., "new T" where T is
5217 // instantiated with "int[4]"), extract the outer bound from the
5218 // array type as our array size. We do this with constant and
5219 // dependently-sized array types.
5220 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5221 if (!ArrayT) {
5222 // Do nothing
5223 } else if (const ConstantArrayType *ConsArrayT
5224 = dyn_cast<ConstantArrayType>(ArrayT)) {
5225 ArraySize
5226 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
5227 ConsArrayT->getSize(),
5228 SemaRef.Context.getSizeType(),
5229 /*FIXME:*/E->getLocStart()));
5230 AllocType = ConsArrayT->getElementType();
5231 } else if (const DependentSizedArrayType *DepArrayT
5232 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5233 if (DepArrayT->getSizeExpr()) {
5234 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5235 AllocType = DepArrayT->getElementType();
5236 }
5237 }
5238 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5240 E->isGlobalNew(),
5241 /*FIXME:*/E->getLocStart(),
5242 move_arg(PlacementArgs),
5243 /*FIXME:*/E->getLocStart(),
5244 E->isParenTypeId(),
5245 AllocType,
5246 /*FIXME:*/E->getLocStart(),
5247 /*FIXME:*/SourceRange(),
5248 move(ArraySize),
5249 /*FIXME:*/E->getLocStart(),
5250 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005251 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254template<typename Derived>
5255Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005256TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5258 if (Operand.isInvalid())
5259 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregord2d9da02010-02-26 00:38:10 +00005261 // Transform the delete operator, if known.
5262 FunctionDecl *OperatorDelete = 0;
5263 if (E->getOperatorDelete()) {
5264 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005265 getDerived().TransformDecl(E->getLocStart(),
5266 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005267 if (!OperatorDelete)
5268 return SemaRef.ExprError();
5269 }
5270
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005272 Operand.get() == E->getArgument() &&
5273 OperatorDelete == E->getOperatorDelete()) {
5274 // Mark any declarations we need as referenced.
5275 // FIXME: instantiation-specific.
5276 if (OperatorDelete)
5277 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005278 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005279 }
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregora16548e2009-08-11 05:31:07 +00005281 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5282 E->isGlobalDelete(),
5283 E->isArrayForm(),
5284 move(Operand));
5285}
Mike Stump11289f42009-09-09 15:08:12 +00005286
Douglas Gregora16548e2009-08-11 05:31:07 +00005287template<typename Derived>
5288Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005289TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005290 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005291 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5292 if (Base.isInvalid())
5293 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregor678f90d2010-02-25 01:56:36 +00005295 Sema::TypeTy *ObjectTypePtr = 0;
5296 bool MayBePseudoDestructor = false;
5297 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5298 E->getOperatorLoc(),
5299 E->isArrow()? tok::arrow : tok::period,
5300 ObjectTypePtr,
5301 MayBePseudoDestructor);
5302 if (Base.isInvalid())
5303 return SemaRef.ExprError();
5304
5305 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005306 NestedNameSpecifier *Qualifier
5307 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005308 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005309 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005310 if (E->getQualifier() && !Qualifier)
5311 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregor678f90d2010-02-25 01:56:36 +00005313 PseudoDestructorTypeStorage Destroyed;
5314 if (E->getDestroyedTypeInfo()) {
5315 TypeSourceInfo *DestroyedTypeInfo
5316 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5317 if (!DestroyedTypeInfo)
5318 return SemaRef.ExprError();
5319 Destroyed = DestroyedTypeInfo;
5320 } else if (ObjectType->isDependentType()) {
5321 // We aren't likely to be able to resolve the identifier down to a type
5322 // now anyway, so just retain the identifier.
5323 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5324 E->getDestroyedTypeLoc());
5325 } else {
5326 // Look for a destructor known with the given name.
5327 CXXScopeSpec SS;
5328 if (Qualifier) {
5329 SS.setScopeRep(Qualifier);
5330 SS.setRange(E->getQualifierRange());
5331 }
5332
5333 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5334 *E->getDestroyedTypeIdentifier(),
5335 E->getDestroyedTypeLoc(),
5336 /*Scope=*/0,
5337 SS, ObjectTypePtr,
5338 false);
5339 if (!T)
5340 return SemaRef.ExprError();
5341
5342 Destroyed
5343 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5344 E->getDestroyedTypeLoc());
5345 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005346
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005347 TypeSourceInfo *ScopeTypeInfo = 0;
5348 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005349 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5350 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005351 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005352 return SemaRef.ExprError();
5353 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005354
Douglas Gregorad8a3362009-09-04 17:36:40 +00005355 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5356 E->getOperatorLoc(),
5357 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005358 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005359 E->getQualifierRange(),
5360 ScopeTypeInfo,
5361 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005362 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005363 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregorad8a3362009-09-04 17:36:40 +00005366template<typename Derived>
5367Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005368TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005369 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005370 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5371
5372 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5373 Sema::LookupOrdinaryName);
5374
5375 // Transform all the decls.
5376 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5377 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005378 NamedDecl *InstD = static_cast<NamedDecl*>(
5379 getDerived().TransformDecl(Old->getNameLoc(),
5380 *I));
John McCall84d87672009-12-10 09:41:52 +00005381 if (!InstD) {
5382 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5383 // This can happen because of dependent hiding.
5384 if (isa<UsingShadowDecl>(*I))
5385 continue;
5386 else
5387 return SemaRef.ExprError();
5388 }
John McCalle66edc12009-11-24 19:00:30 +00005389
5390 // Expand using declarations.
5391 if (isa<UsingDecl>(InstD)) {
5392 UsingDecl *UD = cast<UsingDecl>(InstD);
5393 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5394 E = UD->shadow_end(); I != E; ++I)
5395 R.addDecl(*I);
5396 continue;
5397 }
5398
5399 R.addDecl(InstD);
5400 }
5401
5402 // Resolve a kind, but don't do any further analysis. If it's
5403 // ambiguous, the callee needs to deal with it.
5404 R.resolveKind();
5405
5406 // Rebuild the nested-name qualifier, if present.
5407 CXXScopeSpec SS;
5408 NestedNameSpecifier *Qualifier = 0;
5409 if (Old->getQualifier()) {
5410 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005411 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005412 if (!Qualifier)
5413 return SemaRef.ExprError();
5414
5415 SS.setScopeRep(Qualifier);
5416 SS.setRange(Old->getQualifierRange());
Douglas Gregor9262f472010-04-27 18:19:34 +00005417 }
5418
5419 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005420 CXXRecordDecl *NamingClass
5421 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5422 Old->getNameLoc(),
5423 Old->getNamingClass()));
5424 if (!NamingClass)
5425 return SemaRef.ExprError();
Douglas Gregor9262f472010-04-27 18:19:34 +00005426
Douglas Gregorda7be082010-04-27 16:10:10 +00005427 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005428 }
5429
5430 // If we have no template arguments, it's a normal declaration name.
5431 if (!Old->hasExplicitTemplateArgs())
5432 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5433
5434 // If we have template arguments, rebuild them, then rebuild the
5435 // templateid expression.
5436 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5437 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5438 TemplateArgumentLoc Loc;
5439 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5440 return SemaRef.ExprError();
5441 TransArgs.addArgument(Loc);
5442 }
5443
5444 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5445 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005446}
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregora16548e2009-08-11 05:31:07 +00005448template<typename Derived>
5449Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005450TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005451 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 QualType T = getDerived().TransformType(E->getQueriedType());
5454 if (T.isNull())
5455 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 if (!getDerived().AlwaysRebuild() &&
5458 T == E->getQueriedType())
5459 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 // FIXME: Bad location information
5462 SourceLocation FakeLParenLoc
5463 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005464
5465 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005466 E->getLocStart(),
5467 /*FIXME:*/FakeLParenLoc,
5468 T,
5469 E->getLocEnd());
5470}
Mike Stump11289f42009-09-09 15:08:12 +00005471
Douglas Gregora16548e2009-08-11 05:31:07 +00005472template<typename Derived>
5473Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005474TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005475 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005477 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005478 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005479 if (!NNS)
5480 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005481
5482 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005483 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5484 if (!Name)
5485 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
John McCalle66edc12009-11-24 19:00:30 +00005487 if (!E->hasExplicitTemplateArgs()) {
5488 if (!getDerived().AlwaysRebuild() &&
5489 NNS == E->getQualifier() &&
5490 Name == E->getDeclName())
5491 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005492
John McCalle66edc12009-11-24 19:00:30 +00005493 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5494 E->getQualifierRange(),
5495 Name, E->getLocation(),
5496 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005497 }
John McCall6b51f282009-11-23 01:53:49 +00005498
5499 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005500 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005501 TemplateArgumentLoc Loc;
5502 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005503 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005504 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005505 }
5506
John McCalle66edc12009-11-24 19:00:30 +00005507 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5508 E->getQualifierRange(),
5509 Name, E->getLocation(),
5510 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005511}
5512
5513template<typename Derived>
5514Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005515TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005516 // CXXConstructExprs are always implicit, so when we have a
5517 // 1-argument construction we just transform that argument.
5518 if (E->getNumArgs() == 1 ||
5519 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5520 return getDerived().TransformExpr(E->getArg(0));
5521
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5523
5524 QualType T = getDerived().TransformType(E->getType());
5525 if (T.isNull())
5526 return SemaRef.ExprError();
5527
5528 CXXConstructorDecl *Constructor
5529 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005530 getDerived().TransformDecl(E->getLocStart(),
5531 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005532 if (!Constructor)
5533 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 bool ArgumentChanged = false;
5536 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005537 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 ArgEnd = E->arg_end();
5539 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005540 if (getDerived().DropCallArgument(*Arg)) {
5541 ArgumentChanged = true;
5542 break;
5543 }
5544
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5546 if (TransArg.isInvalid())
5547 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5550 Args.push_back(TransArg.takeAs<Expr>());
5551 }
5552
5553 if (!getDerived().AlwaysRebuild() &&
5554 T == E->getType() &&
5555 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005556 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005557 // Mark the constructor as referenced.
5558 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005559 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005561 }
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregordb121ba2009-12-14 16:27:04 +00005563 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5564 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005565 move_arg(Args));
5566}
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568/// \brief Transform a C++ temporary-binding expression.
5569///
Douglas Gregor363b1512009-12-24 18:51:59 +00005570/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5571/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005572template<typename Derived>
5573Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005574TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005575 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005576}
Mike Stump11289f42009-09-09 15:08:12 +00005577
Anders Carlssonba6c4372010-01-29 02:39:32 +00005578/// \brief Transform a C++ reference-binding expression.
5579///
5580/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5581/// transform the subexpression and return that.
5582template<typename Derived>
5583Sema::OwningExprResult
5584TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5585 return getDerived().TransformExpr(E->getSubExpr());
5586}
5587
Mike Stump11289f42009-09-09 15:08:12 +00005588/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005589/// be destroyed after the expression is evaluated.
5590///
Douglas Gregor363b1512009-12-24 18:51:59 +00005591/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5592/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005593template<typename Derived>
5594Sema::OwningExprResult
5595TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005596 CXXExprWithTemporaries *E) {
5597 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005598}
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregora16548e2009-08-11 05:31:07 +00005600template<typename Derived>
5601Sema::OwningExprResult
5602TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005603 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5605 QualType T = getDerived().TransformType(E->getType());
5606 if (T.isNull())
5607 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 CXXConstructorDecl *Constructor
5610 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005611 getDerived().TransformDecl(E->getLocStart(),
5612 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 if (!Constructor)
5614 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616 bool ArgumentChanged = false;
5617 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5618 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005619 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 ArgEnd = E->arg_end();
5621 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005622 if (getDerived().DropCallArgument(*Arg)) {
5623 ArgumentChanged = true;
5624 break;
5625 }
5626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5628 if (TransArg.isInvalid())
5629 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005630
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5632 Args.push_back((Expr *)TransArg.release());
5633 }
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 if (!getDerived().AlwaysRebuild() &&
5636 T == E->getType() &&
5637 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005638 !ArgumentChanged) {
5639 // FIXME: Instantiation-specific
5640 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005641 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005642 }
Mike Stump11289f42009-09-09 15:08:12 +00005643
Douglas Gregora16548e2009-08-11 05:31:07 +00005644 // FIXME: Bogus location information
5645 SourceLocation CommaLoc;
5646 if (Args.size() > 1) {
5647 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005648 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5650 }
5651 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5652 T,
5653 /*FIXME:*/E->getTypeBeginLoc(),
5654 move_arg(Args),
5655 &CommaLoc,
5656 E->getLocEnd());
5657}
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregora16548e2009-08-11 05:31:07 +00005659template<typename Derived>
5660Sema::OwningExprResult
5661TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005662 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5664 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5665 if (T.isNull())
5666 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005667
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 bool ArgumentChanged = false;
5669 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5670 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5671 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5672 ArgEnd = E->arg_end();
5673 Arg != ArgEnd; ++Arg) {
5674 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5675 if (TransArg.isInvalid())
5676 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5679 FakeCommaLocs.push_back(
5680 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5681 Args.push_back(TransArg.takeAs<Expr>());
5682 }
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 if (!getDerived().AlwaysRebuild() &&
5685 T == E->getTypeAsWritten() &&
5686 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005687 return SemaRef.Owned(E->Retain());
5688
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 // FIXME: we're faking the locations of the commas
5690 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5691 T,
5692 E->getLParenLoc(),
5693 move_arg(Args),
5694 FakeCommaLocs.data(),
5695 E->getRParenLoc());
5696}
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregora16548e2009-08-11 05:31:07 +00005698template<typename Derived>
5699Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005700TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005701 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005702 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005703 OwningExprResult Base(SemaRef, (Expr*) 0);
5704 Expr *OldBase;
5705 QualType BaseType;
5706 QualType ObjectType;
5707 if (!E->isImplicitAccess()) {
5708 OldBase = E->getBase();
5709 Base = getDerived().TransformExpr(OldBase);
5710 if (Base.isInvalid())
5711 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
John McCall2d74de92009-12-01 22:10:20 +00005713 // Start the member reference and compute the object's type.
5714 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005715 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005716 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5717 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005718 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005719 ObjectTy,
5720 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005721 if (Base.isInvalid())
5722 return SemaRef.ExprError();
5723
5724 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5725 BaseType = ((Expr*) Base.get())->getType();
5726 } else {
5727 OldBase = 0;
5728 BaseType = getDerived().TransformType(E->getBaseType());
5729 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5730 }
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005732 // Transform the first part of the nested-name-specifier that qualifies
5733 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005734 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005735 = getDerived().TransformFirstQualifierInScope(
5736 E->getFirstQualifierFoundInScope(),
5737 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005738
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005739 NestedNameSpecifier *Qualifier = 0;
5740 if (E->getQualifier()) {
5741 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5742 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005743 ObjectType,
5744 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005745 if (!Qualifier)
5746 return SemaRef.ExprError();
5747 }
Mike Stump11289f42009-09-09 15:08:12 +00005748
5749 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005750 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005751 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005752 if (!Name)
5753 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005754
John McCall2d74de92009-12-01 22:10:20 +00005755 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005756 // This is a reference to a member without an explicitly-specified
5757 // template argument list. Optimize for this common case.
5758 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005759 Base.get() == OldBase &&
5760 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005761 Qualifier == E->getQualifier() &&
5762 Name == E->getMember() &&
5763 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005764 return SemaRef.Owned(E->Retain());
5765
John McCall8cd78132009-11-19 22:55:06 +00005766 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005767 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005768 E->isArrow(),
5769 E->getOperatorLoc(),
5770 Qualifier,
5771 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005772 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005773 Name,
5774 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005775 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005776 }
5777
John McCall6b51f282009-11-23 01:53:49 +00005778 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005779 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005780 TemplateArgumentLoc Loc;
5781 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005782 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005783 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005784 }
Mike Stump11289f42009-09-09 15:08:12 +00005785
John McCall8cd78132009-11-19 22:55:06 +00005786 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005787 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 E->isArrow(),
5789 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005790 Qualifier,
5791 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005792 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005793 Name,
5794 E->getMemberLoc(),
5795 &TransArgs);
5796}
5797
5798template<typename Derived>
5799Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005800TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005801 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005802 OwningExprResult Base(SemaRef, (Expr*) 0);
5803 QualType BaseType;
5804 if (!Old->isImplicitAccess()) {
5805 Base = getDerived().TransformExpr(Old->getBase());
5806 if (Base.isInvalid())
5807 return SemaRef.ExprError();
5808 BaseType = ((Expr*) Base.get())->getType();
5809 } else {
5810 BaseType = getDerived().TransformType(Old->getBaseType());
5811 }
John McCall10eae182009-11-30 22:42:35 +00005812
5813 NestedNameSpecifier *Qualifier = 0;
5814 if (Old->getQualifier()) {
5815 Qualifier
5816 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005817 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005818 if (Qualifier == 0)
5819 return SemaRef.ExprError();
5820 }
5821
5822 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5823 Sema::LookupOrdinaryName);
5824
5825 // Transform all the decls.
5826 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5827 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005828 NamedDecl *InstD = static_cast<NamedDecl*>(
5829 getDerived().TransformDecl(Old->getMemberLoc(),
5830 *I));
John McCall84d87672009-12-10 09:41:52 +00005831 if (!InstD) {
5832 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5833 // This can happen because of dependent hiding.
5834 if (isa<UsingShadowDecl>(*I))
5835 continue;
5836 else
5837 return SemaRef.ExprError();
5838 }
John McCall10eae182009-11-30 22:42:35 +00005839
5840 // Expand using declarations.
5841 if (isa<UsingDecl>(InstD)) {
5842 UsingDecl *UD = cast<UsingDecl>(InstD);
5843 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5844 E = UD->shadow_end(); I != E; ++I)
5845 R.addDecl(*I);
5846 continue;
5847 }
5848
5849 R.addDecl(InstD);
5850 }
5851
5852 R.resolveKind();
5853
Douglas Gregor9262f472010-04-27 18:19:34 +00005854 // Determine the naming class.
5855 if (!Old->getNamingClass()) {
5856 CXXRecordDecl *NamingClass
5857 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005858 Old->getMemberLoc(),
5859 Old->getNamingClass()));
5860 if (!NamingClass)
5861 return SemaRef.ExprError();
Douglas Gregor9262f472010-04-27 18:19:34 +00005862
Douglas Gregorda7be082010-04-27 16:10:10 +00005863 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005864 }
Douglas Gregorda7be082010-04-27 16:10:10 +00005865
John McCall10eae182009-11-30 22:42:35 +00005866 TemplateArgumentListInfo TransArgs;
5867 if (Old->hasExplicitTemplateArgs()) {
5868 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5869 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5870 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5871 TemplateArgumentLoc Loc;
5872 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5873 Loc))
5874 return SemaRef.ExprError();
5875 TransArgs.addArgument(Loc);
5876 }
5877 }
John McCall38836f02010-01-15 08:34:02 +00005878
5879 // FIXME: to do this check properly, we will need to preserve the
5880 // first-qualifier-in-scope here, just in case we had a dependent
5881 // base (and therefore couldn't do the check) and a
5882 // nested-name-qualifier (and therefore could do the lookup).
5883 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005884
5885 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005886 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005887 Old->getOperatorLoc(),
5888 Old->isArrow(),
5889 Qualifier,
5890 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005891 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005892 R,
5893 (Old->hasExplicitTemplateArgs()
5894 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005895}
5896
5897template<typename Derived>
5898Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005899TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005900 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005901}
5902
Mike Stump11289f42009-09-09 15:08:12 +00005903template<typename Derived>
5904Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005905TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005906 TypeSourceInfo *EncodedTypeInfo
5907 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5908 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005910
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005912 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005913 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005914
5915 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005916 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 E->getRParenLoc());
5918}
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregora16548e2009-08-11 05:31:07 +00005920template<typename Derived>
5921Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005923 // Transform arguments.
5924 bool ArgChanged = false;
5925 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5926 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5927 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5928 if (Arg.isInvalid())
5929 return SemaRef.ExprError();
5930
5931 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5932 Args.push_back(Arg.takeAs<Expr>());
5933 }
5934
5935 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5936 // Class message: transform the receiver type.
5937 TypeSourceInfo *ReceiverTypeInfo
5938 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5939 if (!ReceiverTypeInfo)
5940 return SemaRef.ExprError();
5941
5942 // If nothing changed, just retain the existing message send.
5943 if (!getDerived().AlwaysRebuild() &&
5944 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5945 return SemaRef.Owned(E->Retain());
5946
5947 // Build a new class message send.
5948 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5949 E->getSelector(),
5950 E->getMethodDecl(),
5951 E->getLeftLoc(),
5952 move_arg(Args),
5953 E->getRightLoc());
5954 }
5955
5956 // Instance message: transform the receiver
5957 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5958 "Only class and instance messages may be instantiated");
5959 OwningExprResult Receiver
5960 = getDerived().TransformExpr(E->getInstanceReceiver());
5961 if (Receiver.isInvalid())
5962 return SemaRef.ExprError();
5963
5964 // If nothing changed, just retain the existing message send.
5965 if (!getDerived().AlwaysRebuild() &&
5966 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5967 return SemaRef.Owned(E->Retain());
5968
5969 // Build a new instance message send.
5970 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5971 E->getSelector(),
5972 E->getMethodDecl(),
5973 E->getLeftLoc(),
5974 move_arg(Args),
5975 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005976}
5977
Mike Stump11289f42009-09-09 15:08:12 +00005978template<typename Derived>
5979Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005980TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005981 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005982}
5983
Mike Stump11289f42009-09-09 15:08:12 +00005984template<typename Derived>
5985Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005986TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005987 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005988}
5989
Mike Stump11289f42009-09-09 15:08:12 +00005990template<typename Derived>
5991Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005992TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005993 // Transform the base expression.
5994 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5995 if (Base.isInvalid())
5996 return SemaRef.ExprError();
5997
5998 // We don't need to transform the ivar; it will never change.
5999
6000 // If nothing changed, just retain the existing expression.
6001 if (!getDerived().AlwaysRebuild() &&
6002 Base.get() == E->getBase())
6003 return SemaRef.Owned(E->Retain());
6004
6005 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6006 E->getLocation(),
6007 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006008}
6009
Mike Stump11289f42009-09-09 15:08:12 +00006010template<typename Derived>
6011Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006012TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006013 // Transform the base expression.
6014 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6015 if (Base.isInvalid())
6016 return SemaRef.ExprError();
6017
6018 // We don't need to transform the property; it will never change.
6019
6020 // If nothing changed, just retain the existing expression.
6021 if (!getDerived().AlwaysRebuild() &&
6022 Base.get() == E->getBase())
6023 return SemaRef.Owned(E->Retain());
6024
6025 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6026 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006027}
6028
Mike Stump11289f42009-09-09 15:08:12 +00006029template<typename Derived>
6030Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006031TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006032 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006033 // If this implicit setter/getter refers to class methods, it cannot have any
6034 // dependent parts. Just retain the existing declaration.
6035 if (E->getInterfaceDecl())
6036 return SemaRef.Owned(E->Retain());
6037
6038 // Transform the base expression.
6039 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6040 if (Base.isInvalid())
6041 return SemaRef.ExprError();
6042
6043 // We don't need to transform the getters/setters; they will never change.
6044
6045 // If nothing changed, just retain the existing expression.
6046 if (!getDerived().AlwaysRebuild() &&
6047 Base.get() == E->getBase())
6048 return SemaRef.Owned(E->Retain());
6049
6050 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6051 E->getGetterMethod(),
6052 E->getType(),
6053 E->getSetterMethod(),
6054 E->getLocation(),
6055 move(Base));
6056
Douglas Gregora16548e2009-08-11 05:31:07 +00006057}
6058
Mike Stump11289f42009-09-09 15:08:12 +00006059template<typename Derived>
6060Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006061TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006062 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006063 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006064}
6065
Mike Stump11289f42009-09-09 15:08:12 +00006066template<typename Derived>
6067Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006068TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006069 // Transform the base expression.
6070 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6071 if (Base.isInvalid())
6072 return SemaRef.ExprError();
6073
6074 // If nothing changed, just retain the existing expression.
6075 if (!getDerived().AlwaysRebuild() &&
6076 Base.get() == E->getBase())
6077 return SemaRef.Owned(E->Retain());
6078
6079 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6080 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006081}
6082
Mike Stump11289f42009-09-09 15:08:12 +00006083template<typename Derived>
6084Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006085TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006086 bool ArgumentChanged = false;
6087 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6088 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6089 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6090 if (SubExpr.isInvalid())
6091 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006092
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6094 SubExprs.push_back(SubExpr.takeAs<Expr>());
6095 }
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 if (!getDerived().AlwaysRebuild() &&
6098 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006099 return SemaRef.Owned(E->Retain());
6100
Douglas Gregora16548e2009-08-11 05:31:07 +00006101 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6102 move_arg(SubExprs),
6103 E->getRParenLoc());
6104}
6105
Mike Stump11289f42009-09-09 15:08:12 +00006106template<typename Derived>
6107Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006108TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 // FIXME: Implement this!
6110 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006111 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006112}
6113
Mike Stump11289f42009-09-09 15:08:12 +00006114template<typename Derived>
6115Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 // FIXME: Implement this!
6118 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006119 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006120}
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregora16548e2009-08-11 05:31:07 +00006122//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006123// Type reconstruction
6124//===----------------------------------------------------------------------===//
6125
Mike Stump11289f42009-09-09 15:08:12 +00006126template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006127QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6128 SourceLocation Star) {
6129 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006130 getDerived().getBaseEntity());
6131}
6132
Mike Stump11289f42009-09-09 15:08:12 +00006133template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006134QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6135 SourceLocation Star) {
6136 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006137 getDerived().getBaseEntity());
6138}
6139
Mike Stump11289f42009-09-09 15:08:12 +00006140template<typename Derived>
6141QualType
John McCall70dd5f62009-10-30 00:06:24 +00006142TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6143 bool WrittenAsLValue,
6144 SourceLocation Sigil) {
6145 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6146 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006147}
6148
6149template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006150QualType
John McCall70dd5f62009-10-30 00:06:24 +00006151TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6152 QualType ClassType,
6153 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006154 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006155 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006156}
6157
6158template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006159QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006160TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6161 ArrayType::ArraySizeModifier SizeMod,
6162 const llvm::APInt *Size,
6163 Expr *SizeExpr,
6164 unsigned IndexTypeQuals,
6165 SourceRange BracketsRange) {
6166 if (SizeExpr || !Size)
6167 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6168 IndexTypeQuals, BracketsRange,
6169 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006170
6171 QualType Types[] = {
6172 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6173 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6174 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006175 };
6176 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6177 QualType SizeType;
6178 for (unsigned I = 0; I != NumTypes; ++I)
6179 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6180 SizeType = Types[I];
6181 break;
6182 }
Mike Stump11289f42009-09-09 15:08:12 +00006183
Douglas Gregord6ff3322009-08-04 16:50:30 +00006184 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006185 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006186 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006187 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006188}
Mike Stump11289f42009-09-09 15:08:12 +00006189
Douglas Gregord6ff3322009-08-04 16:50:30 +00006190template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006191QualType
6192TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006193 ArrayType::ArraySizeModifier SizeMod,
6194 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006195 unsigned IndexTypeQuals,
6196 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006197 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006198 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006199}
6200
6201template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006202QualType
Mike Stump11289f42009-09-09 15:08:12 +00006203TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006204 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006205 unsigned IndexTypeQuals,
6206 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006207 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006208 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006209}
Mike Stump11289f42009-09-09 15:08:12 +00006210
Douglas Gregord6ff3322009-08-04 16:50:30 +00006211template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006212QualType
6213TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006214 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006216 unsigned IndexTypeQuals,
6217 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006218 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006219 SizeExpr.takeAs<Expr>(),
6220 IndexTypeQuals, BracketsRange);
6221}
6222
6223template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006224QualType
6225TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006226 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006228 unsigned IndexTypeQuals,
6229 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006230 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006231 SizeExpr.takeAs<Expr>(),
6232 IndexTypeQuals, BracketsRange);
6233}
6234
6235template<typename Derived>
6236QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006237 unsigned NumElements,
6238 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006239 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006240 return SemaRef.Context.getVectorType(ElementType, NumElements,
6241 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006242}
Mike Stump11289f42009-09-09 15:08:12 +00006243
Douglas Gregord6ff3322009-08-04 16:50:30 +00006244template<typename Derived>
6245QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6246 unsigned NumElements,
6247 SourceLocation AttributeLoc) {
6248 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6249 NumElements, true);
6250 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006251 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006252 AttributeLoc);
6253 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6254 AttributeLoc);
6255}
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregord6ff3322009-08-04 16:50:30 +00006257template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006258QualType
6259TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006261 SourceLocation AttributeLoc) {
6262 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6263}
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregord6ff3322009-08-04 16:50:30 +00006265template<typename Derived>
6266QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006267 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006268 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006269 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006270 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006271 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006272 Quals,
6273 getDerived().getBaseLocation(),
6274 getDerived().getBaseEntity());
6275}
Mike Stump11289f42009-09-09 15:08:12 +00006276
Douglas Gregord6ff3322009-08-04 16:50:30 +00006277template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006278QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6279 return SemaRef.Context.getFunctionNoProtoType(T);
6280}
6281
6282template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006283QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6284 assert(D && "no decl found");
6285 if (D->isInvalidDecl()) return QualType();
6286
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006287 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006288 TypeDecl *Ty;
6289 if (isa<UsingDecl>(D)) {
6290 UsingDecl *Using = cast<UsingDecl>(D);
6291 assert(Using->isTypeName() &&
6292 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6293
6294 // A valid resolved using typename decl points to exactly one type decl.
6295 assert(++Using->shadow_begin() == Using->shadow_end());
6296 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6297
6298 } else {
6299 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6300 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6301 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6302 }
6303
6304 return SemaRef.Context.getTypeDeclType(Ty);
6305}
6306
6307template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006308QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006309 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6310}
6311
6312template<typename Derived>
6313QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6314 return SemaRef.Context.getTypeOfType(Underlying);
6315}
6316
6317template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006318QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006319 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6320}
6321
6322template<typename Derived>
6323QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006324 TemplateName Template,
6325 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006326 const TemplateArgumentListInfo &TemplateArgs) {
6327 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006328}
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregor1135c352009-08-06 05:28:30 +00006330template<typename Derived>
6331NestedNameSpecifier *
6332TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6333 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006334 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006335 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006336 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006337 CXXScopeSpec SS;
6338 // FIXME: The source location information is all wrong.
6339 SS.setRange(Range);
6340 SS.setScopeRep(Prefix);
6341 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006342 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006343 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006344 ObjectType,
6345 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006346 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006347}
6348
6349template<typename Derived>
6350NestedNameSpecifier *
6351TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6352 SourceRange Range,
6353 NamespaceDecl *NS) {
6354 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6355}
6356
6357template<typename Derived>
6358NestedNameSpecifier *
6359TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6360 SourceRange Range,
6361 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006362 QualType T) {
6363 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006364 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006365 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006366 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6367 T.getTypePtr());
6368 }
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregor1135c352009-08-06 05:28:30 +00006370 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6371 return 0;
6372}
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregor71dc5092009-08-06 06:41:21 +00006374template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006375TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006376TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6377 bool TemplateKW,
6378 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006379 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006380 Template);
6381}
6382
6383template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006384TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006385TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006386 const IdentifierInfo &II,
6387 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006388 CXXScopeSpec SS;
6389 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006390 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006391 UnqualifiedId Name;
6392 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006393 return getSema().ActOnDependentTemplateName(
6394 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006395 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006396 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006397 ObjectType.getAsOpaquePtr(),
6398 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006399 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006400}
Mike Stump11289f42009-09-09 15:08:12 +00006401
Douglas Gregora16548e2009-08-11 05:31:07 +00006402template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006403TemplateName
6404TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6405 OverloadedOperatorKind Operator,
6406 QualType ObjectType) {
6407 CXXScopeSpec SS;
6408 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6409 SS.setScopeRep(Qualifier);
6410 UnqualifiedId Name;
6411 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6412 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6413 Operator, SymbolLocations);
6414 return getSema().ActOnDependentTemplateName(
6415 /*FIXME:*/getDerived().getBaseLocation(),
6416 SS,
6417 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006418 ObjectType.getAsOpaquePtr(),
6419 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006420 .template getAsVal<TemplateName>();
6421}
6422
6423template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006424Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006425TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6426 SourceLocation OpLoc,
6427 ExprArg Callee,
6428 ExprArg First,
6429 ExprArg Second) {
6430 Expr *FirstExpr = (Expr *)First.get();
6431 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006432 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006433 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregora16548e2009-08-11 05:31:07 +00006435 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006436 if (Op == OO_Subscript) {
6437 if (!FirstExpr->getType()->isOverloadableType() &&
6438 !SecondExpr->getType()->isOverloadableType())
6439 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006440 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006441 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006442 } else if (Op == OO_Arrow) {
6443 // -> is never a builtin operation.
6444 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006445 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 if (!FirstExpr->getType()->isOverloadableType()) {
6447 // The argument is not of overloadable type, so try to create a
6448 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006449 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006450 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006451
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6453 }
6454 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006455 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006456 !SecondExpr->getType()->isOverloadableType()) {
6457 // Neither of the arguments is an overloadable type, so try to
6458 // create a built-in binary operation.
6459 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006460 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6462 if (Result.isInvalid())
6463 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006464
Douglas Gregora16548e2009-08-11 05:31:07 +00006465 First.release();
6466 Second.release();
6467 return move(Result);
6468 }
6469 }
Mike Stump11289f42009-09-09 15:08:12 +00006470
6471 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006473 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006474
John McCalld14a8642009-11-21 08:51:07 +00006475 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6476 assert(ULE->requiresADL());
6477
6478 // FIXME: Do we have to check
6479 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006480 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006481 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006482 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006483 }
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 // Add any functions found via argument-dependent lookup.
6486 Expr *Args[2] = { FirstExpr, SecondExpr };
6487 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregora16548e2009-08-11 05:31:07 +00006489 // Create the overloaded operator invocation for unary operators.
6490 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006491 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6493 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6494 }
Mike Stump11289f42009-09-09 15:08:12 +00006495
Sebastian Redladba46e2009-10-29 20:17:01 +00006496 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006497 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6498 OpLoc,
6499 move(First),
6500 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006501
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006503 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006505 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6507 if (Result.isInvalid())
6508 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 First.release();
6511 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006512 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006513}
Mike Stump11289f42009-09-09 15:08:12 +00006514
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006515template<typename Derived>
6516Sema::OwningExprResult
6517TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6518 SourceLocation OperatorLoc,
6519 bool isArrow,
6520 NestedNameSpecifier *Qualifier,
6521 SourceRange QualifierRange,
6522 TypeSourceInfo *ScopeType,
6523 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006524 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006525 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006526 CXXScopeSpec SS;
6527 if (Qualifier) {
6528 SS.setRange(QualifierRange);
6529 SS.setScopeRep(Qualifier);
6530 }
6531
6532 Expr *BaseE = (Expr *)Base.get();
6533 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006534 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006535 (!isArrow && !BaseType->getAs<RecordType>()) ||
6536 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006537 !BaseType->getAs<PointerType>()->getPointeeType()
6538 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006539 // This pseudo-destructor expression is still a pseudo-destructor.
6540 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6541 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006542 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006543 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006544 /*FIXME?*/true);
6545 }
6546
Douglas Gregor678f90d2010-02-25 01:56:36 +00006547 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006548 DeclarationName Name
6549 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6550 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6551
6552 // FIXME: the ScopeType should be tacked onto SS.
6553
6554 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6555 OperatorLoc, isArrow,
6556 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006557 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006558 /*TemplateArgs*/ 0);
6559}
6560
Douglas Gregord6ff3322009-08-04 16:50:30 +00006561} // end namespace clang
6562
6563#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H