blob: 5ce268bd9eb4efca60a967b22c11e642abab7566 [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) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002910 // Transform the parameters. We do this first for the benefit of template
2911 // instantiations, so that the ParmVarDecls get/ placed into the template
2912 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002913 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002914 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002915 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2916 return QualType();
Douglas Gregor14cf7522010-04-30 18:55:50 +00002917
2918 FunctionProtoType *T = TL.getTypePtr();
2919 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2920 if (ResultType.isNull())
2921 return QualType();
2922
John McCall550e0c22009-10-21 00:40:46 +00002923 QualType Result = TL.getType();
2924 if (getDerived().AlwaysRebuild() ||
2925 ResultType != T->getResultType() ||
2926 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2927 Result = getDerived().RebuildFunctionProtoType(ResultType,
2928 ParamTypes.data(),
2929 ParamTypes.size(),
2930 T->isVariadic(),
2931 T->getTypeQuals());
2932 if (Result.isNull())
2933 return QualType();
2934 }
Mike Stump11289f42009-09-09 15:08:12 +00002935
John McCall550e0c22009-10-21 00:40:46 +00002936 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2937 NewTL.setLParenLoc(TL.getLParenLoc());
2938 NewTL.setRParenLoc(TL.getRParenLoc());
2939 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2940 NewTL.setArg(i, ParamDecls[i]);
2941
2942 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943}
Mike Stump11289f42009-09-09 15:08:12 +00002944
Douglas Gregord6ff3322009-08-04 16:50:30 +00002945template<typename Derived>
2946QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002947 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002948 FunctionNoProtoTypeLoc TL,
2949 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002950 FunctionNoProtoType *T = TL.getTypePtr();
2951 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2952 if (ResultType.isNull())
2953 return QualType();
2954
2955 QualType Result = TL.getType();
2956 if (getDerived().AlwaysRebuild() ||
2957 ResultType != T->getResultType())
2958 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2959
2960 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2961 NewTL.setLParenLoc(TL.getLParenLoc());
2962 NewTL.setRParenLoc(TL.getRParenLoc());
2963
2964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002965}
Mike Stump11289f42009-09-09 15:08:12 +00002966
John McCallb96ec562009-12-04 22:46:56 +00002967template<typename Derived> QualType
2968TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002969 UnresolvedUsingTypeLoc TL,
2970 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002971 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002972 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002973 if (!D)
2974 return QualType();
2975
2976 QualType Result = TL.getType();
2977 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2978 Result = getDerived().RebuildUnresolvedUsingType(D);
2979 if (Result.isNull())
2980 return QualType();
2981 }
2982
2983 // We might get an arbitrary type spec type back. We should at
2984 // least always get a type spec type, though.
2985 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2986 NewTL.setNameLoc(TL.getNameLoc());
2987
2988 return Result;
2989}
2990
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002992QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002993 TypedefTypeLoc TL,
2994 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002995 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002997 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2998 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002999 if (!Typedef)
3000 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003001
John McCall550e0c22009-10-21 00:40:46 +00003002 QualType Result = TL.getType();
3003 if (getDerived().AlwaysRebuild() ||
3004 Typedef != T->getDecl()) {
3005 Result = getDerived().RebuildTypedefType(Typedef);
3006 if (Result.isNull())
3007 return QualType();
3008 }
Mike Stump11289f42009-09-09 15:08:12 +00003009
John McCall550e0c22009-10-21 00:40:46 +00003010 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3011 NewTL.setNameLoc(TL.getNameLoc());
3012
3013 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003014}
Mike Stump11289f42009-09-09 15:08:12 +00003015
Douglas Gregord6ff3322009-08-04 16:50:30 +00003016template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003017QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003018 TypeOfExprTypeLoc TL,
3019 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003020 // typeof expressions are not potentially evaluated contexts
3021 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003022
John McCalle8595032010-01-13 20:03:27 +00003023 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024 if (E.isInvalid())
3025 return QualType();
3026
John McCall550e0c22009-10-21 00:40:46 +00003027 QualType Result = TL.getType();
3028 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003029 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003030 Result = getDerived().RebuildTypeOfExprType(move(E));
3031 if (Result.isNull())
3032 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033 }
John McCall550e0c22009-10-21 00:40:46 +00003034 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003035
John McCall550e0c22009-10-21 00:40:46 +00003036 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003037 NewTL.setTypeofLoc(TL.getTypeofLoc());
3038 NewTL.setLParenLoc(TL.getLParenLoc());
3039 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003040
3041 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003042}
Mike Stump11289f42009-09-09 15:08:12 +00003043
3044template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003045QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003046 TypeOfTypeLoc TL,
3047 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003048 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3049 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3050 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003051 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003052
John McCall550e0c22009-10-21 00:40:46 +00003053 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003054 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3055 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003056 if (Result.isNull())
3057 return QualType();
3058 }
Mike Stump11289f42009-09-09 15:08:12 +00003059
John McCall550e0c22009-10-21 00:40:46 +00003060 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003061 NewTL.setTypeofLoc(TL.getTypeofLoc());
3062 NewTL.setLParenLoc(TL.getLParenLoc());
3063 NewTL.setRParenLoc(TL.getRParenLoc());
3064 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003065
3066 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003067}
Mike Stump11289f42009-09-09 15:08:12 +00003068
3069template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003070QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003071 DecltypeTypeLoc TL,
3072 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003073 DecltypeType *T = TL.getTypePtr();
3074
Douglas Gregore922c772009-08-04 22:27:00 +00003075 // decltype expressions are not potentially evaluated contexts
3076 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003077
Douglas Gregord6ff3322009-08-04 16:50:30 +00003078 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3079 if (E.isInvalid())
3080 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003081
John McCall550e0c22009-10-21 00:40:46 +00003082 QualType Result = TL.getType();
3083 if (getDerived().AlwaysRebuild() ||
3084 E.get() != T->getUnderlyingExpr()) {
3085 Result = getDerived().RebuildDecltypeType(move(E));
3086 if (Result.isNull())
3087 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003088 }
John McCall550e0c22009-10-21 00:40:46 +00003089 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003090
John McCall550e0c22009-10-21 00:40:46 +00003091 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3092 NewTL.setNameLoc(TL.getNameLoc());
3093
3094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003095}
3096
3097template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003098QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003099 RecordTypeLoc TL,
3100 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003101 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003103 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3104 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 if (!Record)
3106 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003107
John McCall550e0c22009-10-21 00:40:46 +00003108 QualType Result = TL.getType();
3109 if (getDerived().AlwaysRebuild() ||
3110 Record != T->getDecl()) {
3111 Result = getDerived().RebuildRecordType(Record);
3112 if (Result.isNull())
3113 return QualType();
3114 }
Mike Stump11289f42009-09-09 15:08:12 +00003115
John McCall550e0c22009-10-21 00:40:46 +00003116 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3117 NewTL.setNameLoc(TL.getNameLoc());
3118
3119 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003120}
Mike Stump11289f42009-09-09 15:08:12 +00003121
3122template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003123QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003124 EnumTypeLoc TL,
3125 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003126 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003128 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3129 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003130 if (!Enum)
3131 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003132
John McCall550e0c22009-10-21 00:40:46 +00003133 QualType Result = TL.getType();
3134 if (getDerived().AlwaysRebuild() ||
3135 Enum != T->getDecl()) {
3136 Result = getDerived().RebuildEnumType(Enum);
3137 if (Result.isNull())
3138 return QualType();
3139 }
Mike Stump11289f42009-09-09 15:08:12 +00003140
John McCall550e0c22009-10-21 00:40:46 +00003141 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3142 NewTL.setNameLoc(TL.getNameLoc());
3143
3144 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145}
John McCallfcc33b02009-09-05 00:15:47 +00003146
3147template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003148QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003149 ElaboratedTypeLoc TL,
3150 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003151 ElaboratedType *T = TL.getTypePtr();
3152
3153 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003154 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3155 if (Underlying.isNull())
3156 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003157
John McCall550e0c22009-10-21 00:40:46 +00003158 QualType Result = TL.getType();
3159 if (getDerived().AlwaysRebuild() ||
3160 Underlying != T->getUnderlyingType()) {
3161 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3162 if (Result.isNull())
3163 return QualType();
3164 }
Mike Stump11289f42009-09-09 15:08:12 +00003165
John McCall550e0c22009-10-21 00:40:46 +00003166 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3167 NewTL.setNameLoc(TL.getNameLoc());
3168
3169 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003170}
Mike Stump11289f42009-09-09 15:08:12 +00003171
John McCalle78aac42010-03-10 03:28:59 +00003172template<typename Derived>
3173QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3174 TypeLocBuilder &TLB,
3175 InjectedClassNameTypeLoc TL,
3176 QualType ObjectType) {
3177 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3178 TL.getTypePtr()->getDecl());
3179 if (!D) return QualType();
3180
3181 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3182 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3183 return T;
3184}
3185
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregord6ff3322009-08-04 16:50:30 +00003187template<typename Derived>
3188QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003189 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003190 TemplateTypeParmTypeLoc TL,
3191 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003192 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003193}
3194
Mike Stump11289f42009-09-09 15:08:12 +00003195template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003196QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003197 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003198 SubstTemplateTypeParmTypeLoc TL,
3199 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003200 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003201}
3202
3203template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003204QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3205 const TemplateSpecializationType *TST,
3206 QualType ObjectType) {
3207 // FIXME: this entire method is a temporary workaround; callers
3208 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003209
John McCall0ad16662009-10-29 08:12:44 +00003210 // Fake up a TemplateSpecializationTypeLoc.
3211 TypeLocBuilder TLB;
3212 TemplateSpecializationTypeLoc TL
3213 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3214
John McCall0d07eb32009-10-29 18:45:58 +00003215 SourceLocation BaseLoc = getDerived().getBaseLocation();
3216
3217 TL.setTemplateNameLoc(BaseLoc);
3218 TL.setLAngleLoc(BaseLoc);
3219 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003220 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3221 const TemplateArgument &TA = TST->getArg(i);
3222 TemplateArgumentLoc TAL;
3223 getDerived().InventTemplateArgumentLoc(TA, TAL);
3224 TL.setArgLocInfo(i, TAL.getLocInfo());
3225 }
3226
3227 TypeLocBuilder IgnoredTLB;
3228 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003229}
3230
3231template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003232QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003233 TypeLocBuilder &TLB,
3234 TemplateSpecializationTypeLoc TL,
3235 QualType ObjectType) {
3236 const TemplateSpecializationType *T = TL.getTypePtr();
3237
Mike Stump11289f42009-09-09 15:08:12 +00003238 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003239 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003240 if (Template.isNull())
3241 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall6b51f282009-11-23 01:53:49 +00003243 TemplateArgumentListInfo NewTemplateArgs;
3244 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3245 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3246
3247 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3248 TemplateArgumentLoc Loc;
3249 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003250 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003251 NewTemplateArgs.addArgument(Loc);
3252 }
Mike Stump11289f42009-09-09 15:08:12 +00003253
John McCall0ad16662009-10-29 08:12:44 +00003254 // FIXME: maybe don't rebuild if all the template arguments are the same.
3255
3256 QualType Result =
3257 getDerived().RebuildTemplateSpecializationType(Template,
3258 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003259 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003260
3261 if (!Result.isNull()) {
3262 TemplateSpecializationTypeLoc NewTL
3263 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3264 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3265 NewTL.setLAngleLoc(TL.getLAngleLoc());
3266 NewTL.setRAngleLoc(TL.getRAngleLoc());
3267 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3268 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269 }
Mike Stump11289f42009-09-09 15:08:12 +00003270
John McCall0ad16662009-10-29 08:12:44 +00003271 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272}
Mike Stump11289f42009-09-09 15:08:12 +00003273
3274template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003275QualType
3276TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003277 QualifiedNameTypeLoc TL,
3278 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003279 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003280 NestedNameSpecifier *NNS
3281 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003282 SourceRange(),
3283 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003284 if (!NNS)
3285 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003286
Douglas Gregord6ff3322009-08-04 16:50:30 +00003287 QualType Named = getDerived().TransformType(T->getNamedType());
3288 if (Named.isNull())
3289 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003290
John McCall550e0c22009-10-21 00:40:46 +00003291 QualType Result = TL.getType();
3292 if (getDerived().AlwaysRebuild() ||
3293 NNS != T->getQualifier() ||
3294 Named != T->getNamedType()) {
3295 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3296 if (Result.isNull())
3297 return QualType();
3298 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003299
John McCall550e0c22009-10-21 00:40:46 +00003300 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3301 NewTL.setNameLoc(TL.getNameLoc());
3302
3303 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304}
Mike Stump11289f42009-09-09 15:08:12 +00003305
3306template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003307QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3308 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003309 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003310 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003311
3312 /* FIXME: preserve source information better than this */
3313 SourceRange SR(TL.getNameLoc());
3314
Douglas Gregord6ff3322009-08-04 16:50:30 +00003315 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003316 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003317 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003318 if (!NNS)
3319 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003320
John McCall550e0c22009-10-21 00:40:46 +00003321 QualType Result;
3322
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003324 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325 = getDerived().TransformType(QualType(TemplateId, 0));
3326 if (NewTemplateId.isNull())
3327 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003328
Douglas Gregord6ff3322009-08-04 16:50:30 +00003329 if (!getDerived().AlwaysRebuild() &&
3330 NNS == T->getQualifier() &&
3331 NewTemplateId == QualType(TemplateId, 0))
3332 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregor02085352010-03-31 20:19:30 +00003334 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3335 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003336 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003337 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3338 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003339 }
John McCall550e0c22009-10-21 00:40:46 +00003340 if (Result.isNull())
3341 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003342
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003343 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003344 NewTL.setNameLoc(TL.getNameLoc());
3345
3346 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003347}
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003350QualType
3351TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003352 ObjCInterfaceTypeLoc TL,
3353 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003354 // ObjCInterfaceType is never dependent.
3355 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003356}
Mike Stump11289f42009-09-09 15:08:12 +00003357
3358template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003359QualType
3360TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003361 ObjCObjectPointerTypeLoc TL,
3362 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003363 // ObjCObjectPointerType is never dependent.
3364 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003365}
3366
Douglas Gregord6ff3322009-08-04 16:50:30 +00003367//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003368// Statement transformation
3369//===----------------------------------------------------------------------===//
3370template<typename Derived>
3371Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003372TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3373 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003374}
3375
3376template<typename Derived>
3377Sema::OwningStmtResult
3378TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3379 return getDerived().TransformCompoundStmt(S, false);
3380}
3381
3382template<typename Derived>
3383Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003384TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003385 bool IsStmtExpr) {
3386 bool SubStmtChanged = false;
3387 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3388 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3389 B != BEnd; ++B) {
3390 OwningStmtResult Result = getDerived().TransformStmt(*B);
3391 if (Result.isInvalid())
3392 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003393
Douglas Gregorebe10102009-08-20 07:17:43 +00003394 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3395 Statements.push_back(Result.takeAs<Stmt>());
3396 }
Mike Stump11289f42009-09-09 15:08:12 +00003397
Douglas Gregorebe10102009-08-20 07:17:43 +00003398 if (!getDerived().AlwaysRebuild() &&
3399 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003400 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003401
3402 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3403 move_arg(Statements),
3404 S->getRBracLoc(),
3405 IsStmtExpr);
3406}
Mike Stump11289f42009-09-09 15:08:12 +00003407
Douglas Gregorebe10102009-08-20 07:17:43 +00003408template<typename Derived>
3409Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003410TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003411 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3412 {
3413 // The case value expressions are not potentially evaluated.
3414 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003415
Eli Friedman06577382009-11-19 03:14:00 +00003416 // Transform the left-hand case value.
3417 LHS = getDerived().TransformExpr(S->getLHS());
3418 if (LHS.isInvalid())
3419 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003420
Eli Friedman06577382009-11-19 03:14:00 +00003421 // Transform the right-hand case value (for the GNU case-range extension).
3422 RHS = getDerived().TransformExpr(S->getRHS());
3423 if (RHS.isInvalid())
3424 return SemaRef.StmtError();
3425 }
Mike Stump11289f42009-09-09 15:08:12 +00003426
Douglas Gregorebe10102009-08-20 07:17:43 +00003427 // Build the case statement.
3428 // Case statements are always rebuilt so that they will attached to their
3429 // transformed switch statement.
3430 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3431 move(LHS),
3432 S->getEllipsisLoc(),
3433 move(RHS),
3434 S->getColonLoc());
3435 if (Case.isInvalid())
3436 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003437
Douglas Gregorebe10102009-08-20 07:17:43 +00003438 // Transform the statement following the case
3439 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3440 if (SubStmt.isInvalid())
3441 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003442
Douglas Gregorebe10102009-08-20 07:17:43 +00003443 // Attach the body to the case statement
3444 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3445}
3446
3447template<typename Derived>
3448Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003449TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003450 // Transform the statement following the default case
3451 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3452 if (SubStmt.isInvalid())
3453 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003454
Douglas Gregorebe10102009-08-20 07:17:43 +00003455 // Default statements are always rebuilt
3456 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3457 move(SubStmt));
3458}
Mike Stump11289f42009-09-09 15:08:12 +00003459
Douglas Gregorebe10102009-08-20 07:17:43 +00003460template<typename Derived>
3461Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003462TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003463 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3464 if (SubStmt.isInvalid())
3465 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 // FIXME: Pass the real colon location in.
3468 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3469 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3470 move(SubStmt));
3471}
Mike Stump11289f42009-09-09 15:08:12 +00003472
Douglas Gregorebe10102009-08-20 07:17:43 +00003473template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003474Sema::OwningStmtResult
3475TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003476 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003477 OwningExprResult Cond(SemaRef);
3478 VarDecl *ConditionVar = 0;
3479 if (S->getConditionVariable()) {
3480 ConditionVar
3481 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003482 getDerived().TransformDefinition(
3483 S->getConditionVariable()->getLocation(),
3484 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003485 if (!ConditionVar)
3486 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003487 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003488 Cond = getDerived().TransformExpr(S->getCond());
3489
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003490 if (Cond.isInvalid())
3491 return SemaRef.StmtError();
3492 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003493
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003494 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // Transform the "then" branch.
3497 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3498 if (Then.isInvalid())
3499 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003500
Douglas Gregorebe10102009-08-20 07:17:43 +00003501 // Transform the "else" branch.
3502 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3503 if (Else.isInvalid())
3504 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003505
Douglas Gregorebe10102009-08-20 07:17:43 +00003506 if (!getDerived().AlwaysRebuild() &&
3507 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003508 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 Then.get() == S->getThen() &&
3510 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003511 return SemaRef.Owned(S->Retain());
3512
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003513 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3514 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003515 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003516}
3517
3518template<typename Derived>
3519Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003520TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003522 OwningExprResult Cond(SemaRef);
3523 VarDecl *ConditionVar = 0;
3524 if (S->getConditionVariable()) {
3525 ConditionVar
3526 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003527 getDerived().TransformDefinition(
3528 S->getConditionVariable()->getLocation(),
3529 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003530 if (!ConditionVar)
3531 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003532 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003533 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003534
3535 if (Cond.isInvalid())
3536 return SemaRef.StmtError();
3537 }
Mike Stump11289f42009-09-09 15:08:12 +00003538
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003539 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003540
Douglas Gregorebe10102009-08-20 07:17:43 +00003541 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003542 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3543 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003544 if (Switch.isInvalid())
3545 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003546
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 // Transform the body of the switch statement.
3548 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3549 if (Body.isInvalid())
3550 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 // Complete the switch statement.
3553 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3554 move(Body));
3555}
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregorebe10102009-08-20 07:17:43 +00003557template<typename Derived>
3558Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003559TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003560 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003561 OwningExprResult Cond(SemaRef);
3562 VarDecl *ConditionVar = 0;
3563 if (S->getConditionVariable()) {
3564 ConditionVar
3565 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003566 getDerived().TransformDefinition(
3567 S->getConditionVariable()->getLocation(),
3568 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003569 if (!ConditionVar)
3570 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003571 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003572 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003573
3574 if (Cond.isInvalid())
3575 return SemaRef.StmtError();
3576 }
Mike Stump11289f42009-09-09 15:08:12 +00003577
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003578 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003579
Douglas Gregorebe10102009-08-20 07:17:43 +00003580 // Transform the body
3581 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3582 if (Body.isInvalid())
3583 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003584
Douglas Gregorebe10102009-08-20 07:17:43 +00003585 if (!getDerived().AlwaysRebuild() &&
3586 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003587 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003589 return SemaRef.Owned(S->Retain());
3590
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003591 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3592 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003593}
Mike Stump11289f42009-09-09 15:08:12 +00003594
Douglas Gregorebe10102009-08-20 07:17:43 +00003595template<typename Derived>
3596Sema::OwningStmtResult
3597TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3598 // Transform the condition
3599 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3600 if (Cond.isInvalid())
3601 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003602
Douglas Gregorebe10102009-08-20 07:17:43 +00003603 // Transform the body
3604 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3605 if (Body.isInvalid())
3606 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003607
Douglas Gregorebe10102009-08-20 07:17:43 +00003608 if (!getDerived().AlwaysRebuild() &&
3609 Cond.get() == S->getCond() &&
3610 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003611 return SemaRef.Owned(S->Retain());
3612
Douglas Gregorebe10102009-08-20 07:17:43 +00003613 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3614 /*FIXME:*/S->getWhileLoc(), move(Cond),
3615 S->getRParenLoc());
3616}
Mike Stump11289f42009-09-09 15:08:12 +00003617
Douglas Gregorebe10102009-08-20 07:17:43 +00003618template<typename Derived>
3619Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003620TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 // Transform the initialization statement
3622 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3623 if (Init.isInvalid())
3624 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003625
Douglas Gregorebe10102009-08-20 07:17:43 +00003626 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003627 OwningExprResult Cond(SemaRef);
3628 VarDecl *ConditionVar = 0;
3629 if (S->getConditionVariable()) {
3630 ConditionVar
3631 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003632 getDerived().TransformDefinition(
3633 S->getConditionVariable()->getLocation(),
3634 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003635 if (!ConditionVar)
3636 return SemaRef.StmtError();
3637 } else {
3638 Cond = getDerived().TransformExpr(S->getCond());
3639
3640 if (Cond.isInvalid())
3641 return SemaRef.StmtError();
3642 }
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregorebe10102009-08-20 07:17:43 +00003644 // Transform the increment
3645 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3646 if (Inc.isInvalid())
3647 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregorebe10102009-08-20 07:17:43 +00003649 // Transform the body
3650 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3651 if (Body.isInvalid())
3652 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 if (!getDerived().AlwaysRebuild() &&
3655 Init.get() == S->getInit() &&
3656 Cond.get() == S->getCond() &&
3657 Inc.get() == S->getInc() &&
3658 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003659 return SemaRef.Owned(S->Retain());
3660
Douglas Gregorebe10102009-08-20 07:17:43 +00003661 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003662 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003663 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003664 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003665 S->getRParenLoc(), move(Body));
3666}
3667
3668template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003669Sema::OwningStmtResult
3670TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003671 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003672 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003673 S->getLabel());
3674}
3675
3676template<typename Derived>
3677Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003678TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003679 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3680 if (Target.isInvalid())
3681 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregorebe10102009-08-20 07:17:43 +00003683 if (!getDerived().AlwaysRebuild() &&
3684 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003685 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003686
3687 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3688 move(Target));
3689}
3690
3691template<typename Derived>
3692Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003693TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3694 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003695}
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregorebe10102009-08-20 07:17:43 +00003697template<typename Derived>
3698Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003699TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3700 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003701}
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregorebe10102009-08-20 07:17:43 +00003703template<typename Derived>
3704Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003705TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003706 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3707 if (Result.isInvalid())
3708 return SemaRef.StmtError();
3709
Mike Stump11289f42009-09-09 15:08:12 +00003710 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003711 // to tell whether the return type of the function has changed.
3712 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3713}
Mike Stump11289f42009-09-09 15:08:12 +00003714
Douglas Gregorebe10102009-08-20 07:17:43 +00003715template<typename Derived>
3716Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003717TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003718 bool DeclChanged = false;
3719 llvm::SmallVector<Decl *, 4> Decls;
3720 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3721 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003722 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3723 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003724 if (!Transformed)
3725 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003726
Douglas Gregorebe10102009-08-20 07:17:43 +00003727 if (Transformed != *D)
3728 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003729
Douglas Gregorebe10102009-08-20 07:17:43 +00003730 Decls.push_back(Transformed);
3731 }
Mike Stump11289f42009-09-09 15:08:12 +00003732
Douglas Gregorebe10102009-08-20 07:17:43 +00003733 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003734 return SemaRef.Owned(S->Retain());
3735
3736 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003737 S->getStartLoc(), S->getEndLoc());
3738}
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740template<typename Derived>
3741Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003742TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003743 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003744 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003745}
3746
3747template<typename Derived>
3748Sema::OwningStmtResult
3749TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003750
3751 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3752 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003753 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003754
Anders Carlssonaaeef072010-01-24 05:50:09 +00003755 OwningExprResult AsmString(SemaRef);
3756 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3757
3758 bool ExprsChanged = false;
3759
3760 // Go through the outputs.
3761 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003762 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003763
Anders Carlssonaaeef072010-01-24 05:50:09 +00003764 // No need to transform the constraint literal.
3765 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3766
3767 // Transform the output expr.
3768 Expr *OutputExpr = S->getOutputExpr(I);
3769 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3770 if (Result.isInvalid())
3771 return SemaRef.StmtError();
3772
3773 ExprsChanged |= Result.get() != OutputExpr;
3774
3775 Exprs.push_back(Result.takeAs<Expr>());
3776 }
3777
3778 // Go through the inputs.
3779 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003780 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003781
Anders Carlssonaaeef072010-01-24 05:50:09 +00003782 // No need to transform the constraint literal.
3783 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3784
3785 // Transform the input expr.
3786 Expr *InputExpr = S->getInputExpr(I);
3787 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3788 if (Result.isInvalid())
3789 return SemaRef.StmtError();
3790
3791 ExprsChanged |= Result.get() != InputExpr;
3792
3793 Exprs.push_back(Result.takeAs<Expr>());
3794 }
3795
3796 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3797 return SemaRef.Owned(S->Retain());
3798
3799 // Go through the clobbers.
3800 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3801 Clobbers.push_back(S->getClobber(I)->Retain());
3802
3803 // No need to transform the asm string literal.
3804 AsmString = SemaRef.Owned(S->getAsmString());
3805
3806 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3807 S->isSimple(),
3808 S->isVolatile(),
3809 S->getNumOutputs(),
3810 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003811 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003812 move_arg(Constraints),
3813 move_arg(Exprs),
3814 move(AsmString),
3815 move_arg(Clobbers),
3816 S->getRParenLoc(),
3817 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003818}
3819
3820
3821template<typename Derived>
3822Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003823TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003824 // Transform the body of the @try.
3825 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3826 if (TryBody.isInvalid())
3827 return SemaRef.StmtError();
3828
Douglas Gregor96c79492010-04-23 22:50:49 +00003829 // Transform the @catch statements (if present).
3830 bool AnyCatchChanged = false;
3831 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3832 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3833 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003834 if (Catch.isInvalid())
3835 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003836 if (Catch.get() != S->getCatchStmt(I))
3837 AnyCatchChanged = true;
3838 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003839 }
3840
3841 // Transform the @finally statement (if present).
3842 OwningStmtResult Finally(SemaRef);
3843 if (S->getFinallyStmt()) {
3844 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3845 if (Finally.isInvalid())
3846 return SemaRef.StmtError();
3847 }
3848
3849 // If nothing changed, just retain this statement.
3850 if (!getDerived().AlwaysRebuild() &&
3851 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003852 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003853 Finally.get() == S->getFinallyStmt())
3854 return SemaRef.Owned(S->Retain());
3855
3856 // Build a new statement.
3857 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003858 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003859}
Mike Stump11289f42009-09-09 15:08:12 +00003860
Douglas Gregorebe10102009-08-20 07:17:43 +00003861template<typename Derived>
3862Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003863TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003864 // Transform the @catch parameter, if there is one.
3865 VarDecl *Var = 0;
3866 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3867 TypeSourceInfo *TSInfo = 0;
3868 if (FromVar->getTypeSourceInfo()) {
3869 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3870 if (!TSInfo)
3871 return SemaRef.StmtError();
3872 }
3873
3874 QualType T;
3875 if (TSInfo)
3876 T = TSInfo->getType();
3877 else {
3878 T = getDerived().TransformType(FromVar->getType());
3879 if (T.isNull())
3880 return SemaRef.StmtError();
3881 }
3882
3883 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3884 if (!Var)
3885 return SemaRef.StmtError();
3886 }
3887
3888 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3889 if (Body.isInvalid())
3890 return SemaRef.StmtError();
3891
3892 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
3893 S->getRParenLoc(),
3894 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003895}
Mike Stump11289f42009-09-09 15:08:12 +00003896
Douglas Gregorebe10102009-08-20 07:17:43 +00003897template<typename Derived>
3898Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003899TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003900 // Transform the body.
3901 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3902 if (Body.isInvalid())
3903 return SemaRef.StmtError();
3904
3905 // If nothing changed, just retain this statement.
3906 if (!getDerived().AlwaysRebuild() &&
3907 Body.get() == S->getFinallyBody())
3908 return SemaRef.Owned(S->Retain());
3909
3910 // Build a new statement.
3911 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3912 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003913}
Mike Stump11289f42009-09-09 15:08:12 +00003914
Douglas Gregorebe10102009-08-20 07:17:43 +00003915template<typename Derived>
3916Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003917TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003918 OwningExprResult Operand(SemaRef);
3919 if (S->getThrowExpr()) {
3920 Operand = getDerived().TransformExpr(S->getThrowExpr());
3921 if (Operand.isInvalid())
3922 return getSema().StmtError();
3923 }
3924
3925 if (!getDerived().AlwaysRebuild() &&
3926 Operand.get() == S->getThrowExpr())
3927 return getSema().Owned(S->Retain());
3928
3929 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003930}
Mike Stump11289f42009-09-09 15:08:12 +00003931
Douglas Gregorebe10102009-08-20 07:17:43 +00003932template<typename Derived>
3933Sema::OwningStmtResult
3934TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003935 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003936 // Transform the object we are locking.
3937 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3938 if (Object.isInvalid())
3939 return SemaRef.StmtError();
3940
3941 // Transform the body.
3942 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3943 if (Body.isInvalid())
3944 return SemaRef.StmtError();
3945
3946 // If nothing change, just retain the current statement.
3947 if (!getDerived().AlwaysRebuild() &&
3948 Object.get() == S->getSynchExpr() &&
3949 Body.get() == S->getSynchBody())
3950 return SemaRef.Owned(S->Retain());
3951
3952 // Build a new statement.
3953 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3954 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003955}
3956
3957template<typename Derived>
3958Sema::OwningStmtResult
3959TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003960 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003961 // Transform the element statement.
3962 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3963 if (Element.isInvalid())
3964 return SemaRef.StmtError();
3965
3966 // Transform the collection expression.
3967 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3968 if (Collection.isInvalid())
3969 return SemaRef.StmtError();
3970
3971 // Transform the body.
3972 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3973 if (Body.isInvalid())
3974 return SemaRef.StmtError();
3975
3976 // If nothing changed, just retain this statement.
3977 if (!getDerived().AlwaysRebuild() &&
3978 Element.get() == S->getElement() &&
3979 Collection.get() == S->getCollection() &&
3980 Body.get() == S->getBody())
3981 return SemaRef.Owned(S->Retain());
3982
3983 // Build a new statement.
3984 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3985 /*FIXME:*/S->getForLoc(),
3986 move(Element),
3987 move(Collection),
3988 S->getRParenLoc(),
3989 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003990}
3991
3992
3993template<typename Derived>
3994Sema::OwningStmtResult
3995TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3996 // Transform the exception declaration, if any.
3997 VarDecl *Var = 0;
3998 if (S->getExceptionDecl()) {
3999 VarDecl *ExceptionDecl = S->getExceptionDecl();
4000 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4001 ExceptionDecl->getDeclName());
4002
4003 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4004 if (T.isNull())
4005 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregorebe10102009-08-20 07:17:43 +00004007 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4008 T,
John McCallbcd03502009-12-07 02:54:59 +00004009 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004010 ExceptionDecl->getIdentifier(),
4011 ExceptionDecl->getLocation(),
4012 /*FIXME: Inaccurate*/
4013 SourceRange(ExceptionDecl->getLocation()));
4014 if (!Var || Var->isInvalidDecl()) {
4015 if (Var)
4016 Var->Destroy(SemaRef.Context);
4017 return SemaRef.StmtError();
4018 }
4019 }
Mike Stump11289f42009-09-09 15:08:12 +00004020
Douglas Gregorebe10102009-08-20 07:17:43 +00004021 // Transform the actual exception handler.
4022 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4023 if (Handler.isInvalid()) {
4024 if (Var)
4025 Var->Destroy(SemaRef.Context);
4026 return SemaRef.StmtError();
4027 }
Mike Stump11289f42009-09-09 15:08:12 +00004028
Douglas Gregorebe10102009-08-20 07:17:43 +00004029 if (!getDerived().AlwaysRebuild() &&
4030 !Var &&
4031 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004032 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004033
4034 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4035 Var,
4036 move(Handler));
4037}
Mike Stump11289f42009-09-09 15:08:12 +00004038
Douglas Gregorebe10102009-08-20 07:17:43 +00004039template<typename Derived>
4040Sema::OwningStmtResult
4041TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4042 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004043 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004044 = getDerived().TransformCompoundStmt(S->getTryBlock());
4045 if (TryBlock.isInvalid())
4046 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004047
Douglas Gregorebe10102009-08-20 07:17:43 +00004048 // Transform the handlers.
4049 bool HandlerChanged = false;
4050 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4051 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004052 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004053 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4054 if (Handler.isInvalid())
4055 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregorebe10102009-08-20 07:17:43 +00004057 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4058 Handlers.push_back(Handler.takeAs<Stmt>());
4059 }
Mike Stump11289f42009-09-09 15:08:12 +00004060
Douglas Gregorebe10102009-08-20 07:17:43 +00004061 if (!getDerived().AlwaysRebuild() &&
4062 TryBlock.get() == S->getTryBlock() &&
4063 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004064 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004065
4066 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004067 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004068}
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregorebe10102009-08-20 07:17:43 +00004070//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004071// Expression transformation
4072//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004073template<typename Derived>
4074Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004075TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004076 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004077}
Mike Stump11289f42009-09-09 15:08:12 +00004078
4079template<typename Derived>
4080Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004081TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004082 NestedNameSpecifier *Qualifier = 0;
4083 if (E->getQualifier()) {
4084 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004085 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004086 if (!Qualifier)
4087 return SemaRef.ExprError();
4088 }
John McCallce546572009-12-08 09:08:17 +00004089
4090 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004091 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4092 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 if (!ND)
4094 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004096 if (!getDerived().AlwaysRebuild() &&
4097 Qualifier == E->getQualifier() &&
4098 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004099 !E->hasExplicitTemplateArgumentList()) {
4100
4101 // Mark it referenced in the new context regardless.
4102 // FIXME: this is a bit instantiation-specific.
4103 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4104
Mike Stump11289f42009-09-09 15:08:12 +00004105 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004106 }
John McCallce546572009-12-08 09:08:17 +00004107
4108 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4109 if (E->hasExplicitTemplateArgumentList()) {
4110 TemplateArgs = &TransArgs;
4111 TransArgs.setLAngleLoc(E->getLAngleLoc());
4112 TransArgs.setRAngleLoc(E->getRAngleLoc());
4113 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4114 TemplateArgumentLoc Loc;
4115 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4116 return SemaRef.ExprError();
4117 TransArgs.addArgument(Loc);
4118 }
4119 }
4120
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004121 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004122 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004123}
Mike Stump11289f42009-09-09 15:08:12 +00004124
Douglas Gregora16548e2009-08-11 05:31:07 +00004125template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004126Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004127TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004128 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004129}
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregora16548e2009-08-11 05:31:07 +00004131template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004132Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004133TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004134 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004135}
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregora16548e2009-08-11 05:31:07 +00004137template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004138Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004139TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004140 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregora16548e2009-08-11 05:31:07 +00004143template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004144Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004145TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004146 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004147}
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregora16548e2009-08-11 05:31:07 +00004149template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004150Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004151TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004152 return SemaRef.Owned(E->Retain());
4153}
4154
4155template<typename Derived>
4156Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004157TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4159 if (SubExpr.isInvalid())
4160 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004161
Douglas Gregora16548e2009-08-11 05:31:07 +00004162 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004163 return SemaRef.Owned(E->Retain());
4164
4165 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004166 E->getRParen());
4167}
4168
Mike Stump11289f42009-09-09 15:08:12 +00004169template<typename Derived>
4170Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004171TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4172 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004173 if (SubExpr.isInvalid())
4174 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004175
Douglas Gregora16548e2009-08-11 05:31:07 +00004176 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
4178
Douglas Gregora16548e2009-08-11 05:31:07 +00004179 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4180 E->getOpcode(),
4181 move(SubExpr));
4182}
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregora16548e2009-08-11 05:31:07 +00004184template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004185Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004186TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4187 // Transform the type.
4188 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4189 if (!Type)
4190 return getSema().ExprError();
4191
4192 // Transform all of the components into components similar to what the
4193 // parser uses.
4194 // FIXME: It would be slightly more efficient in the non-dependent case to
4195 // just map FieldDecls, rather than requiring the rebuilder to look for
4196 // the fields again. However, __builtin_offsetof is rare enough in
4197 // template code that we don't care.
4198 bool ExprChanged = false;
4199 typedef Action::OffsetOfComponent Component;
4200 typedef OffsetOfExpr::OffsetOfNode Node;
4201 llvm::SmallVector<Component, 4> Components;
4202 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4203 const Node &ON = E->getComponent(I);
4204 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004205 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004206 Comp.LocStart = ON.getRange().getBegin();
4207 Comp.LocEnd = ON.getRange().getEnd();
4208 switch (ON.getKind()) {
4209 case Node::Array: {
4210 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4211 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4212 if (Index.isInvalid())
4213 return getSema().ExprError();
4214
4215 ExprChanged = ExprChanged || Index.get() != FromIndex;
4216 Comp.isBrackets = true;
4217 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4218 break;
4219 }
4220
4221 case Node::Field:
4222 case Node::Identifier:
4223 Comp.isBrackets = false;
4224 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004225 if (!Comp.U.IdentInfo)
4226 continue;
4227
Douglas Gregor882211c2010-04-28 22:16:22 +00004228 break;
Douglas Gregord1702062010-04-29 00:18:15 +00004229
4230 case Node::Base:
4231 // Will be recomputed during the rebuild.
4232 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004233 }
4234
4235 Components.push_back(Comp);
4236 }
4237
4238 // If nothing changed, retain the existing expression.
4239 if (!getDerived().AlwaysRebuild() &&
4240 Type == E->getTypeSourceInfo() &&
4241 !ExprChanged)
4242 return SemaRef.Owned(E->Retain());
4243
4244 // Build a new offsetof expression.
4245 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4246 Components.data(), Components.size(),
4247 E->getRParenLoc());
4248}
4249
4250template<typename Derived>
4251Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004252TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004254 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004255
John McCallbcd03502009-12-07 02:54:59 +00004256 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004257 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004259
John McCall4c98fd82009-11-04 07:28:41 +00004260 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004262
John McCall4c98fd82009-11-04 07:28:41 +00004263 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004264 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 E->getSourceRange());
4266 }
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004269 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004270 // C++0x [expr.sizeof]p1:
4271 // The operand is either an expression, which is an unevaluated operand
4272 // [...]
4273 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004274
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4276 if (SubExpr.isInvalid())
4277 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004278
Douglas Gregora16548e2009-08-11 05:31:07 +00004279 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4280 return SemaRef.Owned(E->Retain());
4281 }
Mike Stump11289f42009-09-09 15:08:12 +00004282
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4284 E->isSizeOf(),
4285 E->getSourceRange());
4286}
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004289Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4292 if (LHS.isInvalid())
4293 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4296 if (RHS.isInvalid())
4297 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004298
4299
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 if (!getDerived().AlwaysRebuild() &&
4301 LHS.get() == E->getLHS() &&
4302 RHS.get() == E->getRHS())
4303 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4306 /*FIXME:*/E->getLHS()->getLocStart(),
4307 move(RHS),
4308 E->getRBracketLoc());
4309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
4311template<typename Derived>
4312Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004313TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004314 // Transform the callee.
4315 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4316 if (Callee.isInvalid())
4317 return SemaRef.ExprError();
4318
4319 // Transform arguments.
4320 bool ArgChanged = false;
4321 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4322 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4323 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4324 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4325 if (Arg.isInvalid())
4326 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004327
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 // FIXME: Wrong source location information for the ','.
4329 FakeCommaLocs.push_back(
4330 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004331
4332 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 Args.push_back(Arg.takeAs<Expr>());
4334 }
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 if (!getDerived().AlwaysRebuild() &&
4337 Callee.get() == E->getCallee() &&
4338 !ArgChanged)
4339 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004342 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4344 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4345 move_arg(Args),
4346 FakeCommaLocs.data(),
4347 E->getRParenLoc());
4348}
Mike Stump11289f42009-09-09 15:08:12 +00004349
4350template<typename Derived>
4351Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4354 if (Base.isInvalid())
4355 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004357 NestedNameSpecifier *Qualifier = 0;
4358 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004359 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004360 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004361 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004362 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004363 return SemaRef.ExprError();
4364 }
Mike Stump11289f42009-09-09 15:08:12 +00004365
Eli Friedman2cfcef62009-12-04 06:40:45 +00004366 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004367 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4368 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 if (!Member)
4370 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall16df1e52010-03-30 21:47:33 +00004372 NamedDecl *FoundDecl = E->getFoundDecl();
4373 if (FoundDecl == E->getMemberDecl()) {
4374 FoundDecl = Member;
4375 } else {
4376 FoundDecl = cast_or_null<NamedDecl>(
4377 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4378 if (!FoundDecl)
4379 return SemaRef.ExprError();
4380 }
4381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 if (!getDerived().AlwaysRebuild() &&
4383 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004384 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004385 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004386 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004387 !E->hasExplicitTemplateArgumentList()) {
4388
4389 // Mark it referenced in the new context regardless.
4390 // FIXME: this is a bit instantiation-specific.
4391 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004392 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004393 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004394
John McCall6b51f282009-11-23 01:53:49 +00004395 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004396 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004397 TransArgs.setLAngleLoc(E->getLAngleLoc());
4398 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004399 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004400 TemplateArgumentLoc Loc;
4401 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004402 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004403 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004404 }
4405 }
4406
Douglas Gregora16548e2009-08-11 05:31:07 +00004407 // FIXME: Bogus source location for the operator
4408 SourceLocation FakeOperatorLoc
4409 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4410
John McCall38836f02010-01-15 08:34:02 +00004411 // FIXME: to do this check properly, we will need to preserve the
4412 // first-qualifier-in-scope here, just in case we had a dependent
4413 // base (and therefore couldn't do the check) and a
4414 // nested-name-qualifier (and therefore could do the lookup).
4415 NamedDecl *FirstQualifierInScope = 0;
4416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4418 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004419 Qualifier,
4420 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004422 Member,
John McCall16df1e52010-03-30 21:47:33 +00004423 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004424 (E->hasExplicitTemplateArgumentList()
4425 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004426 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004427}
Mike Stump11289f42009-09-09 15:08:12 +00004428
Douglas Gregora16548e2009-08-11 05:31:07 +00004429template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004430Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004431TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4433 if (LHS.isInvalid())
4434 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4437 if (RHS.isInvalid())
4438 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 if (!getDerived().AlwaysRebuild() &&
4441 LHS.get() == E->getLHS() &&
4442 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004443 return SemaRef.Owned(E->Retain());
4444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4446 move(LHS), move(RHS));
4447}
4448
Mike Stump11289f42009-09-09 15:08:12 +00004449template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004450Sema::OwningExprResult
4451TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004452 CompoundAssignOperator *E) {
4453 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004454}
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004457Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004458TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4460 if (Cond.isInvalid())
4461 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4464 if (LHS.isInvalid())
4465 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4468 if (RHS.isInvalid())
4469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 if (!getDerived().AlwaysRebuild() &&
4472 Cond.get() == E->getCond() &&
4473 LHS.get() == E->getLHS() &&
4474 RHS.get() == E->getRHS())
4475 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004476
4477 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004478 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004479 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004480 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 move(RHS));
4482}
Mike Stump11289f42009-09-09 15:08:12 +00004483
4484template<typename Derived>
4485Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004486TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004487 // Implicit casts are eliminated during transformation, since they
4488 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004489 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004490}
Mike Stump11289f42009-09-09 15:08:12 +00004491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492template<typename Derived>
4493Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004494TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004495 TypeSourceInfo *OldT;
4496 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 {
4498 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004499 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4501 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004502
John McCall97513962010-01-15 18:39:57 +00004503 OldT = E->getTypeInfoAsWritten();
4504 NewT = getDerived().TransformType(OldT);
4505 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 return SemaRef.ExprError();
4507 }
Mike Stump11289f42009-09-09 15:08:12 +00004508
Douglas Gregor6131b442009-12-12 18:16:41 +00004509 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004510 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 if (SubExpr.isInvalid())
4512 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004513
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004515 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004516 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004517 return SemaRef.Owned(E->Retain());
4518
John McCall97513962010-01-15 18:39:57 +00004519 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4520 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 E->getRParenLoc(),
4522 move(SubExpr));
4523}
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregora16548e2009-08-11 05:31:07 +00004525template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004526Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004527TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004528 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4529 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4530 if (!NewT)
4531 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4534 if (Init.isInvalid())
4535 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004536
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004538 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004540 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004541
John McCall5d7aa7f2010-01-19 22:33:45 +00004542 // Note: the expression type doesn't necessarily match the
4543 // type-as-written, but that's okay, because it should always be
4544 // derivable from the initializer.
4545
John McCalle15bbff2010-01-18 19:35:47 +00004546 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 /*FIXME:*/E->getInitializer()->getLocEnd(),
4548 move(Init));
4549}
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregora16548e2009-08-11 05:31:07 +00004551template<typename Derived>
4552Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004553TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4555 if (Base.isInvalid())
4556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 if (!getDerived().AlwaysRebuild() &&
4559 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004560 return SemaRef.Owned(E->Retain());
4561
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004563 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4565 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4566 E->getAccessorLoc(),
4567 E->getAccessor());
4568}
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004571Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004572TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4576 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4577 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4578 if (Init.isInvalid())
4579 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004580
Douglas Gregora16548e2009-08-11 05:31:07 +00004581 InitChanged = InitChanged || Init.get() != E->getInit(I);
4582 Inits.push_back(Init.takeAs<Expr>());
4583 }
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004586 return SemaRef.Owned(E->Retain());
4587
Douglas Gregora16548e2009-08-11 05:31:07 +00004588 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004589 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregora16548e2009-08-11 05:31:07 +00004592template<typename Derived>
4593Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004594TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregorebe10102009-08-20 07:17:43 +00004597 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004598 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4599 if (Init.isInvalid())
4600 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregorebe10102009-08-20 07:17:43 +00004602 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004603 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4604 bool ExprChanged = false;
4605 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4606 DEnd = E->designators_end();
4607 D != DEnd; ++D) {
4608 if (D->isFieldDesignator()) {
4609 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4610 D->getDotLoc(),
4611 D->getFieldLoc()));
4612 continue;
4613 }
Mike Stump11289f42009-09-09 15:08:12 +00004614
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 if (D->isArrayDesignator()) {
4616 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4617 if (Index.isInvalid())
4618 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004619
4620 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004622
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4624 ArrayExprs.push_back(Index.release());
4625 continue;
4626 }
Mike Stump11289f42009-09-09 15:08:12 +00004627
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004629 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4631 if (Start.isInvalid())
4632 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4635 if (End.isInvalid())
4636 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004637
4638 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 End.get(),
4640 D->getLBracketLoc(),
4641 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4644 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 ArrayExprs.push_back(Start.release());
4647 ArrayExprs.push_back(End.release());
4648 }
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 if (!getDerived().AlwaysRebuild() &&
4651 Init.get() == E->getInit() &&
4652 !ExprChanged)
4653 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004654
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4656 E->getEqualOrColonLoc(),
4657 E->usesGNUSyntax(), move(Init));
4658}
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004661Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004662TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004663 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004664 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4665
4666 // FIXME: Will we ever have proper type location here? Will we actually
4667 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 QualType T = getDerived().TransformType(E->getType());
4669 if (T.isNull())
4670 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 if (!getDerived().AlwaysRebuild() &&
4673 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004674 return SemaRef.Owned(E->Retain());
4675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 return getDerived().RebuildImplicitValueInitExpr(T);
4677}
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregora16548e2009-08-11 05:31:07 +00004679template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004680Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004681TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 // FIXME: Do we want the type as written?
4683 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 {
4686 // FIXME: Source location isn't quite accurate.
4687 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4688 T = getDerived().TransformType(E->getType());
4689 if (T.isNull())
4690 return SemaRef.ExprError();
4691 }
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4694 if (SubExpr.isInvalid())
4695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 if (!getDerived().AlwaysRebuild() &&
4698 T == E->getType() &&
4699 SubExpr.get() == E->getSubExpr())
4700 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4703 T, E->getRParenLoc());
4704}
4705
4706template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004707Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004708TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 bool ArgumentChanged = false;
4710 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4711 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4712 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4713 if (Init.isInvalid())
4714 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4717 Inits.push_back(Init.takeAs<Expr>());
4718 }
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4721 move_arg(Inits),
4722 E->getRParenLoc());
4723}
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregora16548e2009-08-11 05:31:07 +00004725/// \brief Transform an address-of-label expression.
4726///
4727/// By default, the transformation of an address-of-label expression always
4728/// rebuilds the expression, so that the label identifier can be resolved to
4729/// the corresponding label statement by semantic analysis.
4730template<typename Derived>
4731Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004732TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4734 E->getLabel());
4735}
Mike Stump11289f42009-09-09 15:08:12 +00004736
4737template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004738Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004739TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004740 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4742 if (SubStmt.isInvalid())
4743 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004744
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 if (!getDerived().AlwaysRebuild() &&
4746 SubStmt.get() == E->getSubStmt())
4747 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004748
4749 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 move(SubStmt),
4751 E->getRParenLoc());
4752}
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754template<typename Derived>
4755Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004756TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 QualType T1, T2;
4758 {
4759 // FIXME: Source location isn't quite accurate.
4760 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 T1 = getDerived().TransformType(E->getArgType1());
4763 if (T1.isNull())
4764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 T2 = getDerived().TransformType(E->getArgType2());
4767 if (T2.isNull())
4768 return SemaRef.ExprError();
4769 }
4770
4771 if (!getDerived().AlwaysRebuild() &&
4772 T1 == E->getArgType1() &&
4773 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004774 return SemaRef.Owned(E->Retain());
4775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4777 T1, T2, E->getRParenLoc());
4778}
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780template<typename Derived>
4781Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4784 if (Cond.isInvalid())
4785 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4788 if (LHS.isInvalid())
4789 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4792 if (RHS.isInvalid())
4793 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 if (!getDerived().AlwaysRebuild() &&
4796 Cond.get() == E->getCond() &&
4797 LHS.get() == E->getLHS() &&
4798 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004799 return SemaRef.Owned(E->Retain());
4800
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4802 move(Cond), move(LHS), move(RHS),
4803 E->getRParenLoc());
4804}
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004807Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004808TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004809 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004810}
4811
4812template<typename Derived>
4813Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004814TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004815 switch (E->getOperator()) {
4816 case OO_New:
4817 case OO_Delete:
4818 case OO_Array_New:
4819 case OO_Array_Delete:
4820 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4821 return SemaRef.ExprError();
4822
4823 case OO_Call: {
4824 // This is a call to an object's operator().
4825 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4826
4827 // Transform the object itself.
4828 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4829 if (Object.isInvalid())
4830 return SemaRef.ExprError();
4831
4832 // FIXME: Poor location information
4833 SourceLocation FakeLParenLoc
4834 = SemaRef.PP.getLocForEndOfToken(
4835 static_cast<Expr *>(Object.get())->getLocEnd());
4836
4837 // Transform the call arguments.
4838 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4839 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4840 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004841 if (getDerived().DropCallArgument(E->getArg(I)))
4842 break;
4843
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004844 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4845 if (Arg.isInvalid())
4846 return SemaRef.ExprError();
4847
4848 // FIXME: Poor source location information.
4849 SourceLocation FakeCommaLoc
4850 = SemaRef.PP.getLocForEndOfToken(
4851 static_cast<Expr *>(Arg.get())->getLocEnd());
4852 FakeCommaLocs.push_back(FakeCommaLoc);
4853 Args.push_back(Arg.release());
4854 }
4855
4856 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4857 move_arg(Args),
4858 FakeCommaLocs.data(),
4859 E->getLocEnd());
4860 }
4861
4862#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4863 case OO_##Name:
4864#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4865#include "clang/Basic/OperatorKinds.def"
4866 case OO_Subscript:
4867 // Handled below.
4868 break;
4869
4870 case OO_Conditional:
4871 llvm_unreachable("conditional operator is not actually overloadable");
4872 return SemaRef.ExprError();
4873
4874 case OO_None:
4875 case NUM_OVERLOADED_OPERATORS:
4876 llvm_unreachable("not an overloaded operator?");
4877 return SemaRef.ExprError();
4878 }
4879
Douglas Gregora16548e2009-08-11 05:31:07 +00004880 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4881 if (Callee.isInvalid())
4882 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004883
John McCall47f29ea2009-12-08 09:21:05 +00004884 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004885 if (First.isInvalid())
4886 return SemaRef.ExprError();
4887
4888 OwningExprResult Second(SemaRef);
4889 if (E->getNumArgs() == 2) {
4890 Second = getDerived().TransformExpr(E->getArg(1));
4891 if (Second.isInvalid())
4892 return SemaRef.ExprError();
4893 }
Mike Stump11289f42009-09-09 15:08:12 +00004894
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 if (!getDerived().AlwaysRebuild() &&
4896 Callee.get() == E->getCallee() &&
4897 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004898 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4899 return SemaRef.Owned(E->Retain());
4900
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4902 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004903 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004904 move(First),
4905 move(Second));
4906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908template<typename Derived>
4909Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004910TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4911 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004912}
Mike Stump11289f42009-09-09 15:08:12 +00004913
Douglas Gregora16548e2009-08-11 05:31:07 +00004914template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004915Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004916TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004917 TypeSourceInfo *OldT;
4918 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 {
4920 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004921 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004922 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4923 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004924
John McCall97513962010-01-15 18:39:57 +00004925 OldT = E->getTypeInfoAsWritten();
4926 NewT = getDerived().TransformType(OldT);
4927 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 return SemaRef.ExprError();
4929 }
Mike Stump11289f42009-09-09 15:08:12 +00004930
Douglas Gregor6131b442009-12-12 18:16:41 +00004931 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004932 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004933 if (SubExpr.isInvalid())
4934 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004935
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004937 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004939 return SemaRef.Owned(E->Retain());
4940
Douglas Gregora16548e2009-08-11 05:31:07 +00004941 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004942 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4944 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4945 SourceLocation FakeRParenLoc
4946 = SemaRef.PP.getLocForEndOfToken(
4947 E->getSubExpr()->getSourceRange().getEnd());
4948 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004949 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004950 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004951 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 FakeRAngleLoc,
4953 FakeRAngleLoc,
4954 move(SubExpr),
4955 FakeRParenLoc);
4956}
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregora16548e2009-08-11 05:31:07 +00004958template<typename Derived>
4959Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004960TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4961 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004962}
Mike Stump11289f42009-09-09 15:08:12 +00004963
4964template<typename Derived>
4965Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004966TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4967 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004968}
4969
Douglas Gregora16548e2009-08-11 05:31:07 +00004970template<typename Derived>
4971Sema::OwningExprResult
4972TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004973 CXXReinterpretCastExpr *E) {
4974 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004975}
Mike Stump11289f42009-09-09 15:08:12 +00004976
Douglas Gregora16548e2009-08-11 05:31:07 +00004977template<typename Derived>
4978Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004979TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4980 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004981}
Mike Stump11289f42009-09-09 15:08:12 +00004982
Douglas Gregora16548e2009-08-11 05:31:07 +00004983template<typename Derived>
4984Sema::OwningExprResult
4985TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004986 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004987 TypeSourceInfo *OldT;
4988 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 {
4990 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004991
John McCall97513962010-01-15 18:39:57 +00004992 OldT = E->getTypeInfoAsWritten();
4993 NewT = getDerived().TransformType(OldT);
4994 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004995 return SemaRef.ExprError();
4996 }
Mike Stump11289f42009-09-09 15:08:12 +00004997
Douglas Gregor6131b442009-12-12 18:16:41 +00004998 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004999 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 if (SubExpr.isInvalid())
5001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005002
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005004 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005006 return SemaRef.Owned(E->Retain());
5007
Douglas Gregora16548e2009-08-11 05:31:07 +00005008 // FIXME: The end of the type's source range is wrong
5009 return getDerived().RebuildCXXFunctionalCastExpr(
5010 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005011 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005012 /*FIXME:*/E->getSubExpr()->getLocStart(),
5013 move(SubExpr),
5014 E->getRParenLoc());
5015}
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017template<typename Derived>
5018Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005019TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005021 TypeSourceInfo *TInfo
5022 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5023 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005027 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregor9da64192010-04-26 22:37:10 +00005030 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5031 E->getLocStart(),
5032 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 E->getLocEnd());
5034 }
Mike Stump11289f42009-09-09 15:08:12 +00005035
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 // We don't know whether the expression is potentially evaluated until
5037 // after we perform semantic analysis, so the expression is potentially
5038 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005039 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005041
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5043 if (SubExpr.isInvalid())
5044 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 if (!getDerived().AlwaysRebuild() &&
5047 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005048 return SemaRef.Owned(E->Retain());
5049
Douglas Gregor9da64192010-04-26 22:37:10 +00005050 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5051 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 move(SubExpr),
5053 E->getLocEnd());
5054}
5055
5056template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005057Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005058TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005059 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005060}
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062template<typename Derived>
5063Sema::OwningExprResult
5064TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005065 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005066 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005067}
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069template<typename Derived>
5070Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005071TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005072 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 QualType T = getDerived().TransformType(E->getType());
5075 if (T.isNull())
5076 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078 if (!getDerived().AlwaysRebuild() &&
5079 T == E->getType())
5080 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregorb15af892010-01-07 23:12:05 +00005082 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005083}
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085template<typename Derived>
5086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005087TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5089 if (SubExpr.isInvalid())
5090 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005091
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 if (!getDerived().AlwaysRebuild() &&
5093 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005094 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005095
5096 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5097}
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregora16548e2009-08-11 05:31:07 +00005099template<typename Derived>
5100Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005101TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005102 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005103 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5104 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 if (!Param)
5106 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005107
Chandler Carruth794da4c2010-02-08 06:42:49 +00005108 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 Param == E->getParam())
5110 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregor033f6752009-12-23 23:03:06 +00005112 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005113}
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregora16548e2009-08-11 05:31:07 +00005115template<typename Derived>
5116Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005117TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5119
5120 QualType T = getDerived().TransformType(E->getType());
5121 if (T.isNull())
5122 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005123
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 if (!getDerived().AlwaysRebuild() &&
5125 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005126 return SemaRef.Owned(E->Retain());
5127
5128 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 /*FIXME:*/E->getTypeBeginLoc(),
5130 T,
5131 E->getRParenLoc());
5132}
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134template<typename Derived>
5135Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005136TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 // Transform the type that we're allocating
5138 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5139 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5140 if (AllocType.isNull())
5141 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005142
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 // Transform the size of the array we're allocating (if any).
5144 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5145 if (ArraySize.isInvalid())
5146 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 // Transform the placement arguments (if any).
5149 bool ArgumentChanged = false;
5150 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5151 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5152 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5153 if (Arg.isInvalid())
5154 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005155
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5157 PlacementArgs.push_back(Arg.take());
5158 }
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregorebe10102009-08-20 07:17:43 +00005160 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5162 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5163 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5164 if (Arg.isInvalid())
5165 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5168 ConstructorArgs.push_back(Arg.take());
5169 }
Mike Stump11289f42009-09-09 15:08:12 +00005170
Douglas Gregord2d9da02010-02-26 00:38:10 +00005171 // Transform constructor, new operator, and delete operator.
5172 CXXConstructorDecl *Constructor = 0;
5173 if (E->getConstructor()) {
5174 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005175 getDerived().TransformDecl(E->getLocStart(),
5176 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005177 if (!Constructor)
5178 return SemaRef.ExprError();
5179 }
5180
5181 FunctionDecl *OperatorNew = 0;
5182 if (E->getOperatorNew()) {
5183 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005184 getDerived().TransformDecl(E->getLocStart(),
5185 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005186 if (!OperatorNew)
5187 return SemaRef.ExprError();
5188 }
5189
5190 FunctionDecl *OperatorDelete = 0;
5191 if (E->getOperatorDelete()) {
5192 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005193 getDerived().TransformDecl(E->getLocStart(),
5194 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005195 if (!OperatorDelete)
5196 return SemaRef.ExprError();
5197 }
5198
Douglas Gregora16548e2009-08-11 05:31:07 +00005199 if (!getDerived().AlwaysRebuild() &&
5200 AllocType == E->getAllocatedType() &&
5201 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005202 Constructor == E->getConstructor() &&
5203 OperatorNew == E->getOperatorNew() &&
5204 OperatorDelete == E->getOperatorDelete() &&
5205 !ArgumentChanged) {
5206 // Mark any declarations we need as referenced.
5207 // FIXME: instantiation-specific.
5208 if (Constructor)
5209 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5210 if (OperatorNew)
5211 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5212 if (OperatorDelete)
5213 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005214 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005215 }
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005217 if (!ArraySize.get()) {
5218 // If no array size was specified, but the new expression was
5219 // instantiated with an array type (e.g., "new T" where T is
5220 // instantiated with "int[4]"), extract the outer bound from the
5221 // array type as our array size. We do this with constant and
5222 // dependently-sized array types.
5223 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5224 if (!ArrayT) {
5225 // Do nothing
5226 } else if (const ConstantArrayType *ConsArrayT
5227 = dyn_cast<ConstantArrayType>(ArrayT)) {
5228 ArraySize
5229 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
5230 ConsArrayT->getSize(),
5231 SemaRef.Context.getSizeType(),
5232 /*FIXME:*/E->getLocStart()));
5233 AllocType = ConsArrayT->getElementType();
5234 } else if (const DependentSizedArrayType *DepArrayT
5235 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5236 if (DepArrayT->getSizeExpr()) {
5237 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5238 AllocType = DepArrayT->getElementType();
5239 }
5240 }
5241 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5243 E->isGlobalNew(),
5244 /*FIXME:*/E->getLocStart(),
5245 move_arg(PlacementArgs),
5246 /*FIXME:*/E->getLocStart(),
5247 E->isParenTypeId(),
5248 AllocType,
5249 /*FIXME:*/E->getLocStart(),
5250 /*FIXME:*/SourceRange(),
5251 move(ArraySize),
5252 /*FIXME:*/E->getLocStart(),
5253 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005254 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005255}
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregora16548e2009-08-11 05:31:07 +00005257template<typename Derived>
5258Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005259TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5261 if (Operand.isInvalid())
5262 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregord2d9da02010-02-26 00:38:10 +00005264 // Transform the delete operator, if known.
5265 FunctionDecl *OperatorDelete = 0;
5266 if (E->getOperatorDelete()) {
5267 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005268 getDerived().TransformDecl(E->getLocStart(),
5269 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005270 if (!OperatorDelete)
5271 return SemaRef.ExprError();
5272 }
5273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005275 Operand.get() == E->getArgument() &&
5276 OperatorDelete == E->getOperatorDelete()) {
5277 // Mark any declarations we need as referenced.
5278 // FIXME: instantiation-specific.
5279 if (OperatorDelete)
5280 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005281 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005282 }
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregora16548e2009-08-11 05:31:07 +00005284 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5285 E->isGlobalDelete(),
5286 E->isArrayForm(),
5287 move(Operand));
5288}
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregora16548e2009-08-11 05:31:07 +00005290template<typename Derived>
5291Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005292TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005293 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005294 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5295 if (Base.isInvalid())
5296 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005297
Douglas Gregor678f90d2010-02-25 01:56:36 +00005298 Sema::TypeTy *ObjectTypePtr = 0;
5299 bool MayBePseudoDestructor = false;
5300 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5301 E->getOperatorLoc(),
5302 E->isArrow()? tok::arrow : tok::period,
5303 ObjectTypePtr,
5304 MayBePseudoDestructor);
5305 if (Base.isInvalid())
5306 return SemaRef.ExprError();
5307
5308 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005309 NestedNameSpecifier *Qualifier
5310 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005311 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005312 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005313 if (E->getQualifier() && !Qualifier)
5314 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregor678f90d2010-02-25 01:56:36 +00005316 PseudoDestructorTypeStorage Destroyed;
5317 if (E->getDestroyedTypeInfo()) {
5318 TypeSourceInfo *DestroyedTypeInfo
5319 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5320 if (!DestroyedTypeInfo)
5321 return SemaRef.ExprError();
5322 Destroyed = DestroyedTypeInfo;
5323 } else if (ObjectType->isDependentType()) {
5324 // We aren't likely to be able to resolve the identifier down to a type
5325 // now anyway, so just retain the identifier.
5326 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5327 E->getDestroyedTypeLoc());
5328 } else {
5329 // Look for a destructor known with the given name.
5330 CXXScopeSpec SS;
5331 if (Qualifier) {
5332 SS.setScopeRep(Qualifier);
5333 SS.setRange(E->getQualifierRange());
5334 }
5335
5336 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5337 *E->getDestroyedTypeIdentifier(),
5338 E->getDestroyedTypeLoc(),
5339 /*Scope=*/0,
5340 SS, ObjectTypePtr,
5341 false);
5342 if (!T)
5343 return SemaRef.ExprError();
5344
5345 Destroyed
5346 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5347 E->getDestroyedTypeLoc());
5348 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005349
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005350 TypeSourceInfo *ScopeTypeInfo = 0;
5351 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005352 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5353 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005354 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005355 return SemaRef.ExprError();
5356 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005357
Douglas Gregorad8a3362009-09-04 17:36:40 +00005358 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5359 E->getOperatorLoc(),
5360 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005361 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005362 E->getQualifierRange(),
5363 ScopeTypeInfo,
5364 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005365 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005366 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005367}
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregorad8a3362009-09-04 17:36:40 +00005369template<typename Derived>
5370Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005371TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005372 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005373 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5374
5375 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5376 Sema::LookupOrdinaryName);
5377
5378 // Transform all the decls.
5379 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5380 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005381 NamedDecl *InstD = static_cast<NamedDecl*>(
5382 getDerived().TransformDecl(Old->getNameLoc(),
5383 *I));
John McCall84d87672009-12-10 09:41:52 +00005384 if (!InstD) {
5385 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5386 // This can happen because of dependent hiding.
5387 if (isa<UsingShadowDecl>(*I))
5388 continue;
5389 else
5390 return SemaRef.ExprError();
5391 }
John McCalle66edc12009-11-24 19:00:30 +00005392
5393 // Expand using declarations.
5394 if (isa<UsingDecl>(InstD)) {
5395 UsingDecl *UD = cast<UsingDecl>(InstD);
5396 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5397 E = UD->shadow_end(); I != E; ++I)
5398 R.addDecl(*I);
5399 continue;
5400 }
5401
5402 R.addDecl(InstD);
5403 }
5404
5405 // Resolve a kind, but don't do any further analysis. If it's
5406 // ambiguous, the callee needs to deal with it.
5407 R.resolveKind();
5408
5409 // Rebuild the nested-name qualifier, if present.
5410 CXXScopeSpec SS;
5411 NestedNameSpecifier *Qualifier = 0;
5412 if (Old->getQualifier()) {
5413 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005414 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005415 if (!Qualifier)
5416 return SemaRef.ExprError();
5417
5418 SS.setScopeRep(Qualifier);
5419 SS.setRange(Old->getQualifierRange());
Douglas Gregor9262f472010-04-27 18:19:34 +00005420 }
5421
5422 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005423 CXXRecordDecl *NamingClass
5424 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5425 Old->getNameLoc(),
5426 Old->getNamingClass()));
5427 if (!NamingClass)
5428 return SemaRef.ExprError();
Douglas Gregor9262f472010-04-27 18:19:34 +00005429
Douglas Gregorda7be082010-04-27 16:10:10 +00005430 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005431 }
5432
5433 // If we have no template arguments, it's a normal declaration name.
5434 if (!Old->hasExplicitTemplateArgs())
5435 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5436
5437 // If we have template arguments, rebuild them, then rebuild the
5438 // templateid expression.
5439 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5440 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5441 TemplateArgumentLoc Loc;
5442 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5443 return SemaRef.ExprError();
5444 TransArgs.addArgument(Loc);
5445 }
5446
5447 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5448 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005449}
Mike Stump11289f42009-09-09 15:08:12 +00005450
Douglas Gregora16548e2009-08-11 05:31:07 +00005451template<typename Derived>
5452Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005453TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005454 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregora16548e2009-08-11 05:31:07 +00005456 QualType T = getDerived().TransformType(E->getQueriedType());
5457 if (T.isNull())
5458 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005459
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 if (!getDerived().AlwaysRebuild() &&
5461 T == E->getQueriedType())
5462 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregora16548e2009-08-11 05:31:07 +00005464 // FIXME: Bad location information
5465 SourceLocation FakeLParenLoc
5466 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005467
5468 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005469 E->getLocStart(),
5470 /*FIXME:*/FakeLParenLoc,
5471 T,
5472 E->getLocEnd());
5473}
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregora16548e2009-08-11 05:31:07 +00005475template<typename Derived>
5476Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005477TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005478 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005479 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005480 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005481 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005482 if (!NNS)
5483 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005484
5485 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005486 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5487 if (!Name)
5488 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005489
John McCalle66edc12009-11-24 19:00:30 +00005490 if (!E->hasExplicitTemplateArgs()) {
5491 if (!getDerived().AlwaysRebuild() &&
5492 NNS == E->getQualifier() &&
5493 Name == E->getDeclName())
5494 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005495
John McCalle66edc12009-11-24 19:00:30 +00005496 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5497 E->getQualifierRange(),
5498 Name, E->getLocation(),
5499 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005500 }
John McCall6b51f282009-11-23 01:53:49 +00005501
5502 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005503 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005504 TemplateArgumentLoc Loc;
5505 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005507 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 }
5509
John McCalle66edc12009-11-24 19:00:30 +00005510 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5511 E->getQualifierRange(),
5512 Name, E->getLocation(),
5513 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005514}
5515
5516template<typename Derived>
5517Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005518TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005519 // CXXConstructExprs are always implicit, so when we have a
5520 // 1-argument construction we just transform that argument.
5521 if (E->getNumArgs() == 1 ||
5522 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5523 return getDerived().TransformExpr(E->getArg(0));
5524
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5526
5527 QualType T = getDerived().TransformType(E->getType());
5528 if (T.isNull())
5529 return SemaRef.ExprError();
5530
5531 CXXConstructorDecl *Constructor
5532 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005533 getDerived().TransformDecl(E->getLocStart(),
5534 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 if (!Constructor)
5536 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005537
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 bool ArgumentChanged = false;
5539 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005540 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 ArgEnd = E->arg_end();
5542 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005543 if (getDerived().DropCallArgument(*Arg)) {
5544 ArgumentChanged = true;
5545 break;
5546 }
5547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5549 if (TransArg.isInvalid())
5550 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5553 Args.push_back(TransArg.takeAs<Expr>());
5554 }
5555
5556 if (!getDerived().AlwaysRebuild() &&
5557 T == E->getType() &&
5558 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005559 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005560 // Mark the constructor as referenced.
5561 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005562 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005563 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005564 }
Mike Stump11289f42009-09-09 15:08:12 +00005565
Douglas Gregordb121ba2009-12-14 16:27:04 +00005566 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5567 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 move_arg(Args));
5569}
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571/// \brief Transform a C++ temporary-binding expression.
5572///
Douglas Gregor363b1512009-12-24 18:51:59 +00005573/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5574/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005575template<typename Derived>
5576Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005577TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005578 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005579}
Mike Stump11289f42009-09-09 15:08:12 +00005580
Anders Carlssonba6c4372010-01-29 02:39:32 +00005581/// \brief Transform a C++ reference-binding expression.
5582///
5583/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5584/// transform the subexpression and return that.
5585template<typename Derived>
5586Sema::OwningExprResult
5587TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5588 return getDerived().TransformExpr(E->getSubExpr());
5589}
5590
Mike Stump11289f42009-09-09 15:08:12 +00005591/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005592/// be destroyed after the expression is evaluated.
5593///
Douglas Gregor363b1512009-12-24 18:51:59 +00005594/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5595/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005596template<typename Derived>
5597Sema::OwningExprResult
5598TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005599 CXXExprWithTemporaries *E) {
5600 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005601}
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregora16548e2009-08-11 05:31:07 +00005603template<typename Derived>
5604Sema::OwningExprResult
5605TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005606 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005607 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5608 QualType T = getDerived().TransformType(E->getType());
5609 if (T.isNull())
5610 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 CXXConstructorDecl *Constructor
5613 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005614 getDerived().TransformDecl(E->getLocStart(),
5615 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005616 if (!Constructor)
5617 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 bool ArgumentChanged = false;
5620 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5621 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005622 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 ArgEnd = E->arg_end();
5624 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005625 if (getDerived().DropCallArgument(*Arg)) {
5626 ArgumentChanged = true;
5627 break;
5628 }
5629
Douglas Gregora16548e2009-08-11 05:31:07 +00005630 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5631 if (TransArg.isInvalid())
5632 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5635 Args.push_back((Expr *)TransArg.release());
5636 }
Mike Stump11289f42009-09-09 15:08:12 +00005637
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 if (!getDerived().AlwaysRebuild() &&
5639 T == E->getType() &&
5640 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005641 !ArgumentChanged) {
5642 // FIXME: Instantiation-specific
5643 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005644 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005645 }
Mike Stump11289f42009-09-09 15:08:12 +00005646
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 // FIXME: Bogus location information
5648 SourceLocation CommaLoc;
5649 if (Args.size() > 1) {
5650 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005651 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5653 }
5654 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5655 T,
5656 /*FIXME:*/E->getTypeBeginLoc(),
5657 move_arg(Args),
5658 &CommaLoc,
5659 E->getLocEnd());
5660}
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregora16548e2009-08-11 05:31:07 +00005662template<typename Derived>
5663Sema::OwningExprResult
5664TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005665 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5667 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5668 if (T.isNull())
5669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 bool ArgumentChanged = false;
5672 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5673 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5674 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5675 ArgEnd = E->arg_end();
5676 Arg != ArgEnd; ++Arg) {
5677 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5678 if (TransArg.isInvalid())
5679 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5682 FakeCommaLocs.push_back(
5683 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5684 Args.push_back(TransArg.takeAs<Expr>());
5685 }
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 if (!getDerived().AlwaysRebuild() &&
5688 T == E->getTypeAsWritten() &&
5689 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005690 return SemaRef.Owned(E->Retain());
5691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 // FIXME: we're faking the locations of the commas
5693 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5694 T,
5695 E->getLParenLoc(),
5696 move_arg(Args),
5697 FakeCommaLocs.data(),
5698 E->getRParenLoc());
5699}
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701template<typename Derived>
5702Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005703TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005704 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005706 OwningExprResult Base(SemaRef, (Expr*) 0);
5707 Expr *OldBase;
5708 QualType BaseType;
5709 QualType ObjectType;
5710 if (!E->isImplicitAccess()) {
5711 OldBase = E->getBase();
5712 Base = getDerived().TransformExpr(OldBase);
5713 if (Base.isInvalid())
5714 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005715
John McCall2d74de92009-12-01 22:10:20 +00005716 // Start the member reference and compute the object's type.
5717 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005718 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005719 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5720 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005721 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005722 ObjectTy,
5723 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005724 if (Base.isInvalid())
5725 return SemaRef.ExprError();
5726
5727 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5728 BaseType = ((Expr*) Base.get())->getType();
5729 } else {
5730 OldBase = 0;
5731 BaseType = getDerived().TransformType(E->getBaseType());
5732 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5733 }
Mike Stump11289f42009-09-09 15:08:12 +00005734
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005735 // Transform the first part of the nested-name-specifier that qualifies
5736 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005737 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005738 = getDerived().TransformFirstQualifierInScope(
5739 E->getFirstQualifierFoundInScope(),
5740 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005741
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005742 NestedNameSpecifier *Qualifier = 0;
5743 if (E->getQualifier()) {
5744 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5745 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005746 ObjectType,
5747 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005748 if (!Qualifier)
5749 return SemaRef.ExprError();
5750 }
Mike Stump11289f42009-09-09 15:08:12 +00005751
5752 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005753 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005754 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005755 if (!Name)
5756 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005757
John McCall2d74de92009-12-01 22:10:20 +00005758 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005759 // This is a reference to a member without an explicitly-specified
5760 // template argument list. Optimize for this common case.
5761 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005762 Base.get() == OldBase &&
5763 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005764 Qualifier == E->getQualifier() &&
5765 Name == E->getMember() &&
5766 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005767 return SemaRef.Owned(E->Retain());
5768
John McCall8cd78132009-11-19 22:55:06 +00005769 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005770 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005771 E->isArrow(),
5772 E->getOperatorLoc(),
5773 Qualifier,
5774 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005775 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005776 Name,
5777 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005778 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005779 }
5780
John McCall6b51f282009-11-23 01:53:49 +00005781 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005782 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005783 TemplateArgumentLoc Loc;
5784 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005785 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005786 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005787 }
Mike Stump11289f42009-09-09 15:08:12 +00005788
John McCall8cd78132009-11-19 22:55:06 +00005789 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005790 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 E->isArrow(),
5792 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005793 Qualifier,
5794 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005795 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005796 Name,
5797 E->getMemberLoc(),
5798 &TransArgs);
5799}
5800
5801template<typename Derived>
5802Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005803TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005804 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005805 OwningExprResult Base(SemaRef, (Expr*) 0);
5806 QualType BaseType;
5807 if (!Old->isImplicitAccess()) {
5808 Base = getDerived().TransformExpr(Old->getBase());
5809 if (Base.isInvalid())
5810 return SemaRef.ExprError();
5811 BaseType = ((Expr*) Base.get())->getType();
5812 } else {
5813 BaseType = getDerived().TransformType(Old->getBaseType());
5814 }
John McCall10eae182009-11-30 22:42:35 +00005815
5816 NestedNameSpecifier *Qualifier = 0;
5817 if (Old->getQualifier()) {
5818 Qualifier
5819 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005820 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005821 if (Qualifier == 0)
5822 return SemaRef.ExprError();
5823 }
5824
5825 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5826 Sema::LookupOrdinaryName);
5827
5828 // Transform all the decls.
5829 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5830 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005831 NamedDecl *InstD = static_cast<NamedDecl*>(
5832 getDerived().TransformDecl(Old->getMemberLoc(),
5833 *I));
John McCall84d87672009-12-10 09:41:52 +00005834 if (!InstD) {
5835 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5836 // This can happen because of dependent hiding.
5837 if (isa<UsingShadowDecl>(*I))
5838 continue;
5839 else
5840 return SemaRef.ExprError();
5841 }
John McCall10eae182009-11-30 22:42:35 +00005842
5843 // Expand using declarations.
5844 if (isa<UsingDecl>(InstD)) {
5845 UsingDecl *UD = cast<UsingDecl>(InstD);
5846 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5847 E = UD->shadow_end(); I != E; ++I)
5848 R.addDecl(*I);
5849 continue;
5850 }
5851
5852 R.addDecl(InstD);
5853 }
5854
5855 R.resolveKind();
5856
Douglas Gregor9262f472010-04-27 18:19:34 +00005857 // Determine the naming class.
5858 if (!Old->getNamingClass()) {
5859 CXXRecordDecl *NamingClass
5860 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005861 Old->getMemberLoc(),
5862 Old->getNamingClass()));
5863 if (!NamingClass)
5864 return SemaRef.ExprError();
Douglas Gregor9262f472010-04-27 18:19:34 +00005865
Douglas Gregorda7be082010-04-27 16:10:10 +00005866 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005867 }
Douglas Gregorda7be082010-04-27 16:10:10 +00005868
John McCall10eae182009-11-30 22:42:35 +00005869 TemplateArgumentListInfo TransArgs;
5870 if (Old->hasExplicitTemplateArgs()) {
5871 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5872 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5873 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5874 TemplateArgumentLoc Loc;
5875 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5876 Loc))
5877 return SemaRef.ExprError();
5878 TransArgs.addArgument(Loc);
5879 }
5880 }
John McCall38836f02010-01-15 08:34:02 +00005881
5882 // FIXME: to do this check properly, we will need to preserve the
5883 // first-qualifier-in-scope here, just in case we had a dependent
5884 // base (and therefore couldn't do the check) and a
5885 // nested-name-qualifier (and therefore could do the lookup).
5886 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005887
5888 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005889 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005890 Old->getOperatorLoc(),
5891 Old->isArrow(),
5892 Qualifier,
5893 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005894 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005895 R,
5896 (Old->hasExplicitTemplateArgs()
5897 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005898}
5899
5900template<typename Derived>
5901Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005902TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005903 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005904}
5905
Mike Stump11289f42009-09-09 15:08:12 +00005906template<typename Derived>
5907Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005908TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005909 TypeSourceInfo *EncodedTypeInfo
5910 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5911 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005913
Douglas Gregora16548e2009-08-11 05:31:07 +00005914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005915 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005916 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005917
5918 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005919 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 E->getRParenLoc());
5921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923template<typename Derived>
5924Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005925TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005926 // Transform arguments.
5927 bool ArgChanged = false;
5928 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5929 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5930 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5931 if (Arg.isInvalid())
5932 return SemaRef.ExprError();
5933
5934 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5935 Args.push_back(Arg.takeAs<Expr>());
5936 }
5937
5938 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5939 // Class message: transform the receiver type.
5940 TypeSourceInfo *ReceiverTypeInfo
5941 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5942 if (!ReceiverTypeInfo)
5943 return SemaRef.ExprError();
5944
5945 // If nothing changed, just retain the existing message send.
5946 if (!getDerived().AlwaysRebuild() &&
5947 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5948 return SemaRef.Owned(E->Retain());
5949
5950 // Build a new class message send.
5951 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5952 E->getSelector(),
5953 E->getMethodDecl(),
5954 E->getLeftLoc(),
5955 move_arg(Args),
5956 E->getRightLoc());
5957 }
5958
5959 // Instance message: transform the receiver
5960 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5961 "Only class and instance messages may be instantiated");
5962 OwningExprResult Receiver
5963 = getDerived().TransformExpr(E->getInstanceReceiver());
5964 if (Receiver.isInvalid())
5965 return SemaRef.ExprError();
5966
5967 // If nothing changed, just retain the existing message send.
5968 if (!getDerived().AlwaysRebuild() &&
5969 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5970 return SemaRef.Owned(E->Retain());
5971
5972 // Build a new instance message send.
5973 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5974 E->getSelector(),
5975 E->getMethodDecl(),
5976 E->getLeftLoc(),
5977 move_arg(Args),
5978 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005979}
5980
Mike Stump11289f42009-09-09 15:08:12 +00005981template<typename Derived>
5982Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005983TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005984 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985}
5986
Mike Stump11289f42009-09-09 15:08:12 +00005987template<typename Derived>
5988Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005989TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005990 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991}
5992
Mike Stump11289f42009-09-09 15:08:12 +00005993template<typename Derived>
5994Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005995TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005996 // Transform the base expression.
5997 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5998 if (Base.isInvalid())
5999 return SemaRef.ExprError();
6000
6001 // We don't need to transform the ivar; it will never change.
6002
6003 // If nothing changed, just retain the existing expression.
6004 if (!getDerived().AlwaysRebuild() &&
6005 Base.get() == E->getBase())
6006 return SemaRef.Owned(E->Retain());
6007
6008 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6009 E->getLocation(),
6010 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006011}
6012
Mike Stump11289f42009-09-09 15:08:12 +00006013template<typename Derived>
6014Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006015TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006016 // Transform the base expression.
6017 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6018 if (Base.isInvalid())
6019 return SemaRef.ExprError();
6020
6021 // We don't need to transform the property; it will never change.
6022
6023 // If nothing changed, just retain the existing expression.
6024 if (!getDerived().AlwaysRebuild() &&
6025 Base.get() == E->getBase())
6026 return SemaRef.Owned(E->Retain());
6027
6028 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6029 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006030}
6031
Mike Stump11289f42009-09-09 15:08:12 +00006032template<typename Derived>
6033Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006034TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006035 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006036 // If this implicit setter/getter refers to class methods, it cannot have any
6037 // dependent parts. Just retain the existing declaration.
6038 if (E->getInterfaceDecl())
6039 return SemaRef.Owned(E->Retain());
6040
6041 // Transform the base expression.
6042 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6043 if (Base.isInvalid())
6044 return SemaRef.ExprError();
6045
6046 // We don't need to transform the getters/setters; they will never change.
6047
6048 // If nothing changed, just retain the existing expression.
6049 if (!getDerived().AlwaysRebuild() &&
6050 Base.get() == E->getBase())
6051 return SemaRef.Owned(E->Retain());
6052
6053 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6054 E->getGetterMethod(),
6055 E->getType(),
6056 E->getSetterMethod(),
6057 E->getLocation(),
6058 move(Base));
6059
Douglas Gregora16548e2009-08-11 05:31:07 +00006060}
6061
Mike Stump11289f42009-09-09 15:08:12 +00006062template<typename Derived>
6063Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006065 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006066 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006067}
6068
Mike Stump11289f42009-09-09 15:08:12 +00006069template<typename Derived>
6070Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006072 // Transform the base expression.
6073 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6074 if (Base.isInvalid())
6075 return SemaRef.ExprError();
6076
6077 // If nothing changed, just retain the existing expression.
6078 if (!getDerived().AlwaysRebuild() &&
6079 Base.get() == E->getBase())
6080 return SemaRef.Owned(E->Retain());
6081
6082 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6083 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006084}
6085
Mike Stump11289f42009-09-09 15:08:12 +00006086template<typename Derived>
6087Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 bool ArgumentChanged = false;
6090 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6091 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6092 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6093 if (SubExpr.isInvalid())
6094 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006095
Douglas Gregora16548e2009-08-11 05:31:07 +00006096 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6097 SubExprs.push_back(SubExpr.takeAs<Expr>());
6098 }
Mike Stump11289f42009-09-09 15:08:12 +00006099
Douglas Gregora16548e2009-08-11 05:31:07 +00006100 if (!getDerived().AlwaysRebuild() &&
6101 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006102 return SemaRef.Owned(E->Retain());
6103
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6105 move_arg(SubExprs),
6106 E->getRParenLoc());
6107}
6108
Mike Stump11289f42009-09-09 15:08:12 +00006109template<typename Derived>
6110Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 // FIXME: Implement this!
6113 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006114 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006115}
6116
Mike Stump11289f42009-09-09 15:08:12 +00006117template<typename Derived>
6118Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 // FIXME: Implement this!
6121 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006122 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006123}
Mike Stump11289f42009-09-09 15:08:12 +00006124
Douglas Gregora16548e2009-08-11 05:31:07 +00006125//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006126// Type reconstruction
6127//===----------------------------------------------------------------------===//
6128
Mike Stump11289f42009-09-09 15:08:12 +00006129template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006130QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6131 SourceLocation Star) {
6132 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006133 getDerived().getBaseEntity());
6134}
6135
Mike Stump11289f42009-09-09 15:08:12 +00006136template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006137QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6138 SourceLocation Star) {
6139 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006140 getDerived().getBaseEntity());
6141}
6142
Mike Stump11289f42009-09-09 15:08:12 +00006143template<typename Derived>
6144QualType
John McCall70dd5f62009-10-30 00:06:24 +00006145TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6146 bool WrittenAsLValue,
6147 SourceLocation Sigil) {
6148 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6149 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006150}
6151
6152template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006153QualType
John McCall70dd5f62009-10-30 00:06:24 +00006154TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6155 QualType ClassType,
6156 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006157 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006158 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006159}
6160
6161template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006162QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006163TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6164 ArrayType::ArraySizeModifier SizeMod,
6165 const llvm::APInt *Size,
6166 Expr *SizeExpr,
6167 unsigned IndexTypeQuals,
6168 SourceRange BracketsRange) {
6169 if (SizeExpr || !Size)
6170 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6171 IndexTypeQuals, BracketsRange,
6172 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006173
6174 QualType Types[] = {
6175 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6176 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6177 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006178 };
6179 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6180 QualType SizeType;
6181 for (unsigned I = 0; I != NumTypes; ++I)
6182 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6183 SizeType = Types[I];
6184 break;
6185 }
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregord6ff3322009-08-04 16:50:30 +00006187 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006188 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006189 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006190 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006191}
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregord6ff3322009-08-04 16:50:30 +00006193template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006194QualType
6195TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006196 ArrayType::ArraySizeModifier SizeMod,
6197 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006198 unsigned IndexTypeQuals,
6199 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006200 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006201 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006202}
6203
6204template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006205QualType
Mike Stump11289f42009-09-09 15:08:12 +00006206TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006207 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006208 unsigned IndexTypeQuals,
6209 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006210 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006211 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006212}
Mike Stump11289f42009-09-09 15:08:12 +00006213
Douglas Gregord6ff3322009-08-04 16:50:30 +00006214template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006215QualType
6216TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006217 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006219 unsigned IndexTypeQuals,
6220 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006221 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006222 SizeExpr.takeAs<Expr>(),
6223 IndexTypeQuals, BracketsRange);
6224}
6225
6226template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006227QualType
6228TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006229 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006231 unsigned IndexTypeQuals,
6232 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006233 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006234 SizeExpr.takeAs<Expr>(),
6235 IndexTypeQuals, BracketsRange);
6236}
6237
6238template<typename Derived>
6239QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006240 unsigned NumElements,
6241 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006242 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006243 return SemaRef.Context.getVectorType(ElementType, NumElements,
6244 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006245}
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregord6ff3322009-08-04 16:50:30 +00006247template<typename Derived>
6248QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6249 unsigned NumElements,
6250 SourceLocation AttributeLoc) {
6251 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6252 NumElements, true);
6253 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006254 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006255 AttributeLoc);
6256 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6257 AttributeLoc);
6258}
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregord6ff3322009-08-04 16:50:30 +00006260template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006261QualType
6262TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006263 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006264 SourceLocation AttributeLoc) {
6265 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6266}
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregord6ff3322009-08-04 16:50:30 +00006268template<typename Derived>
6269QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006270 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006271 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006272 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006273 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006274 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006275 Quals,
6276 getDerived().getBaseLocation(),
6277 getDerived().getBaseEntity());
6278}
Mike Stump11289f42009-09-09 15:08:12 +00006279
Douglas Gregord6ff3322009-08-04 16:50:30 +00006280template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006281QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6282 return SemaRef.Context.getFunctionNoProtoType(T);
6283}
6284
6285template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006286QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6287 assert(D && "no decl found");
6288 if (D->isInvalidDecl()) return QualType();
6289
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006290 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006291 TypeDecl *Ty;
6292 if (isa<UsingDecl>(D)) {
6293 UsingDecl *Using = cast<UsingDecl>(D);
6294 assert(Using->isTypeName() &&
6295 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6296
6297 // A valid resolved using typename decl points to exactly one type decl.
6298 assert(++Using->shadow_begin() == Using->shadow_end());
6299 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6300
6301 } else {
6302 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6303 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6304 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6305 }
6306
6307 return SemaRef.Context.getTypeDeclType(Ty);
6308}
6309
6310template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006311QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006312 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6313}
6314
6315template<typename Derived>
6316QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6317 return SemaRef.Context.getTypeOfType(Underlying);
6318}
6319
6320template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006321QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006322 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6323}
6324
6325template<typename Derived>
6326QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006327 TemplateName Template,
6328 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006329 const TemplateArgumentListInfo &TemplateArgs) {
6330 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006331}
Mike Stump11289f42009-09-09 15:08:12 +00006332
Douglas Gregor1135c352009-08-06 05:28:30 +00006333template<typename Derived>
6334NestedNameSpecifier *
6335TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6336 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006337 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006338 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006339 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006340 CXXScopeSpec SS;
6341 // FIXME: The source location information is all wrong.
6342 SS.setRange(Range);
6343 SS.setScopeRep(Prefix);
6344 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006345 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006346 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006347 ObjectType,
6348 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006349 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006350}
6351
6352template<typename Derived>
6353NestedNameSpecifier *
6354TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6355 SourceRange Range,
6356 NamespaceDecl *NS) {
6357 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6358}
6359
6360template<typename Derived>
6361NestedNameSpecifier *
6362TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6363 SourceRange Range,
6364 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006365 QualType T) {
6366 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006367 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006368 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006369 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6370 T.getTypePtr());
6371 }
Mike Stump11289f42009-09-09 15:08:12 +00006372
Douglas Gregor1135c352009-08-06 05:28:30 +00006373 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6374 return 0;
6375}
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregor71dc5092009-08-06 06:41:21 +00006377template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006378TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006379TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6380 bool TemplateKW,
6381 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006382 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006383 Template);
6384}
6385
6386template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006387TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006388TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006389 const IdentifierInfo &II,
6390 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006391 CXXScopeSpec SS;
6392 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006393 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006394 UnqualifiedId Name;
6395 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006396 return getSema().ActOnDependentTemplateName(
6397 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006398 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006399 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006400 ObjectType.getAsOpaquePtr(),
6401 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006402 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006403}
Mike Stump11289f42009-09-09 15:08:12 +00006404
Douglas Gregora16548e2009-08-11 05:31:07 +00006405template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006406TemplateName
6407TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6408 OverloadedOperatorKind Operator,
6409 QualType ObjectType) {
6410 CXXScopeSpec SS;
6411 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6412 SS.setScopeRep(Qualifier);
6413 UnqualifiedId Name;
6414 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6415 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6416 Operator, SymbolLocations);
6417 return getSema().ActOnDependentTemplateName(
6418 /*FIXME:*/getDerived().getBaseLocation(),
6419 SS,
6420 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006421 ObjectType.getAsOpaquePtr(),
6422 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006423 .template getAsVal<TemplateName>();
6424}
6425
6426template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006427Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006428TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6429 SourceLocation OpLoc,
6430 ExprArg Callee,
6431 ExprArg First,
6432 ExprArg Second) {
6433 Expr *FirstExpr = (Expr *)First.get();
6434 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006435 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006439 if (Op == OO_Subscript) {
6440 if (!FirstExpr->getType()->isOverloadableType() &&
6441 !SecondExpr->getType()->isOverloadableType())
6442 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006443 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006444 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006445 } else if (Op == OO_Arrow) {
6446 // -> is never a builtin operation.
6447 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006448 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006449 if (!FirstExpr->getType()->isOverloadableType()) {
6450 // The argument is not of overloadable type, so try to create a
6451 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006452 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006453 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregora16548e2009-08-11 05:31:07 +00006455 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6456 }
6457 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006458 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006459 !SecondExpr->getType()->isOverloadableType()) {
6460 // Neither of the arguments is an overloadable type, so try to
6461 // create a built-in binary operation.
6462 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006463 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6465 if (Result.isInvalid())
6466 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregora16548e2009-08-11 05:31:07 +00006468 First.release();
6469 Second.release();
6470 return move(Result);
6471 }
6472 }
Mike Stump11289f42009-09-09 15:08:12 +00006473
6474 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006475 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006476 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006477
John McCalld14a8642009-11-21 08:51:07 +00006478 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6479 assert(ULE->requiresADL());
6480
6481 // FIXME: Do we have to check
6482 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006483 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006484 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006485 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006486 }
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 // Add any functions found via argument-dependent lookup.
6489 Expr *Args[2] = { FirstExpr, SecondExpr };
6490 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006491
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 // Create the overloaded operator invocation for unary operators.
6493 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006494 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6496 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6497 }
Mike Stump11289f42009-09-09 15:08:12 +00006498
Sebastian Redladba46e2009-10-29 20:17:01 +00006499 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006500 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6501 OpLoc,
6502 move(First),
6503 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006504
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006506 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006507 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006508 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006509 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6510 if (Result.isInvalid())
6511 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006512
Douglas Gregora16548e2009-08-11 05:31:07 +00006513 First.release();
6514 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006515 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006516}
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006518template<typename Derived>
6519Sema::OwningExprResult
6520TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6521 SourceLocation OperatorLoc,
6522 bool isArrow,
6523 NestedNameSpecifier *Qualifier,
6524 SourceRange QualifierRange,
6525 TypeSourceInfo *ScopeType,
6526 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006527 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006528 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006529 CXXScopeSpec SS;
6530 if (Qualifier) {
6531 SS.setRange(QualifierRange);
6532 SS.setScopeRep(Qualifier);
6533 }
6534
6535 Expr *BaseE = (Expr *)Base.get();
6536 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006537 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006538 (!isArrow && !BaseType->getAs<RecordType>()) ||
6539 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006540 !BaseType->getAs<PointerType>()->getPointeeType()
6541 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006542 // This pseudo-destructor expression is still a pseudo-destructor.
6543 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6544 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006545 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006546 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006547 /*FIXME?*/true);
6548 }
6549
Douglas Gregor678f90d2010-02-25 01:56:36 +00006550 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006551 DeclarationName Name
6552 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6553 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6554
6555 // FIXME: the ScopeType should be tacked onto SS.
6556
6557 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6558 OperatorLoc, isArrow,
6559 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006560 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006561 /*TemplateArgs*/ 0);
6562}
6563
Douglas Gregord6ff3322009-08-04 16:50:30 +00006564} // end namespace clang
6565
6566#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H