blob: f80747b69f10491f599daaefe26eba19e0045124 [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 Gregora16548e2009-08-11 05:31:07 +00001070 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001071 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// By default, performs semantic analysis to build the new expression.
1073 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001074 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001075 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001077 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 }
1079
Mike Stump11289f42009-09-09 15:08:12 +00001080 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001081 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001082 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 /// By default, performs semantic analysis to build the new expression.
1084 /// Subclasses may override this routine to provide different behavior.
1085 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1086 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001087 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1089 OpLoc, isSizeOf, R);
1090 if (Result.isInvalid())
1091 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 SubExpr.release();
1094 return move(Result);
1095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, performs semantic analysis to build the new expression.
1100 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001101 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 SourceLocation LBracketLoc,
1103 ExprArg RHS,
1104 SourceLocation RBracketLoc) {
1105 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001106 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 RBracketLoc);
1108 }
1109
1110 /// \brief Build a new call 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.
1114 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1115 MultiExprArg Args,
1116 SourceLocation *CommaLocs,
1117 SourceLocation RParenLoc) {
1118 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1119 move(Args), CommaLocs, RParenLoc);
1120 }
1121
1122 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001123 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// By default, performs semantic analysis to build the new expression.
1125 /// Subclasses may override this routine to provide different behavior.
1126 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001127 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001128 NestedNameSpecifier *Qualifier,
1129 SourceRange QualifierRange,
1130 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001131 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001132 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001133 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001134 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001135 if (!Member->getDeclName()) {
1136 // We have a reference to an unnamed field.
1137 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001139 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001140 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1141 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001142 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001143
Mike Stump11289f42009-09-09 15:08:12 +00001144 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001145 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001146 Member, MemberLoc,
1147 cast<FieldDecl>(Member)->getType());
1148 return getSema().Owned(ME);
1149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001151 CXXScopeSpec SS;
1152 if (Qualifier) {
1153 SS.setRange(QualifierRange);
1154 SS.setScopeRep(Qualifier);
1155 }
1156
John McCall2d74de92009-12-01 22:10:20 +00001157 QualType BaseType = ((Expr*) Base.get())->getType();
1158
John McCall16df1e52010-03-30 21:47:33 +00001159 // FIXME: this involves duplicating earlier analysis in a lot of
1160 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001161 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1162 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001163 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001164 R.resolveKind();
1165
John McCall2d74de92009-12-01 22:10:20 +00001166 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1167 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001168 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001169 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregora16548e2009-08-11 05:31:07 +00001172 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001173 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001174 /// By default, performs semantic analysis to build the new expression.
1175 /// Subclasses may override this routine to provide different behavior.
1176 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1177 BinaryOperator::Opcode Opc,
1178 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001179 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1180 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
1182
1183 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
1187 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1188 SourceLocation QuestionLoc,
1189 ExprArg LHS,
1190 SourceLocation ColonLoc,
1191 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001192 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 move(LHS), move(RHS));
1194 }
1195
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// \brief Build a new C-style cast 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.
John McCall97513962010-01-15 18:39:57 +00001200 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1201 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 SourceLocation RParenLoc,
1203 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001204 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1205 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 }
Mike Stump11289f42009-09-09 15:08:12 +00001207
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001209 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// By default, performs semantic analysis to build the new expression.
1211 /// Subclasses may override this routine to provide different behavior.
1212 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001213 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 SourceLocation RParenLoc,
1215 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001216 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1217 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001224 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 SourceLocation OpLoc,
1226 SourceLocation AccessorLoc,
1227 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001228
John McCall10eae182009-11-30 22:42:35 +00001229 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001230 QualType BaseType = ((Expr*) Base.get())->getType();
1231 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001232 OpLoc, /*IsArrow*/ false,
1233 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001234 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001235 AccessorLoc,
1236 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 }
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001240 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
1243 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1244 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001245 SourceLocation RBraceLoc,
1246 QualType ResultTy) {
1247 OwningExprResult Result
1248 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1249 if (Result.isInvalid() || ResultTy->isDependentType())
1250 return move(Result);
1251
1252 // Patch in the result type we were given, which may have been computed
1253 // when the initial InitListExpr was built.
1254 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1255 ILE->setType(ResultTy);
1256 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1264 MultiExprArg ArrayExprs,
1265 SourceLocation EqualOrColonLoc,
1266 bool GNUSyntax,
1267 ExprArg Init) {
1268 OwningExprResult Result
1269 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1270 move(Init));
1271 if (Result.isInvalid())
1272 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001273
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 ArrayExprs.release();
1275 return move(Result);
1276 }
Mike Stump11289f42009-09-09 15:08:12 +00001277
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001279 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// By default, builds the implicit value initialization without performing
1281 /// any semantic analysis. Subclasses may override this routine to provide
1282 /// different behavior.
1283 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1284 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
1291 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1292 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001293 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 RParenLoc);
1295 }
1296
1297 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001298 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
1301 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1302 MultiExprArg SubExprs,
1303 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001304 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1305 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
Mike Stump11289f42009-09-09 15:08:12 +00001307
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
1310 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// rather than attempting to map the label statement itself.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1314 SourceLocation LabelLoc,
1315 LabelStmt *Label) {
1316 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1324 StmtArg SubStmt,
1325 SourceLocation RParenLoc) {
1326 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1327 }
Mike Stump11289f42009-09-09 15:08:12 +00001328
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// \brief Build a new __builtin_types_compatible_p expression.
1330 ///
1331 /// By default, performs semantic analysis to build the new expression.
1332 /// Subclasses may override this routine to provide different behavior.
1333 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1334 QualType T1, QualType T2,
1335 SourceLocation RParenLoc) {
1336 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1337 T1.getAsOpaquePtr(),
1338 T2.getAsOpaquePtr(),
1339 RParenLoc);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_choose_expr 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 RebuildChooseExpr(SourceLocation BuiltinLoc,
1347 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1348 SourceLocation RParenLoc) {
1349 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1350 move(Cond), move(LHS), move(RHS),
1351 RParenLoc);
1352 }
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new overloaded operator call expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// The semantic analysis provides the behavior of template instantiation,
1358 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001359 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 /// argument-dependent lookup, etc. Subclasses may override this routine to
1361 /// provide different behavior.
1362 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1363 SourceLocation OpLoc,
1364 ExprArg Callee,
1365 ExprArg First,
1366 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001367
1368 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// reinterpret_cast.
1370 ///
1371 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// Subclasses may override this routine to provide different behavior.
1374 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1375 Stmt::StmtClass Class,
1376 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001377 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 SourceLocation RAngleLoc,
1379 SourceLocation LParenLoc,
1380 ExprArg SubExpr,
1381 SourceLocation RParenLoc) {
1382 switch (Class) {
1383 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001384 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001385 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 move(SubExpr), RParenLoc);
1387
1388 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001389 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001390 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001392
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001394 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001395 RAngleLoc, LParenLoc,
1396 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 default:
1405 assert(false && "Invalid C++ named cast");
1406 break;
1407 }
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 return getSema().ExprError();
1410 }
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// \brief Build a new C++ static_cast expression.
1413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
1416 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1417 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001418 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 SourceLocation RAngleLoc,
1420 SourceLocation LParenLoc,
1421 ExprArg SubExpr,
1422 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001423 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1424 TInfo, move(SubExpr),
1425 SourceRange(LAngleLoc, RAngleLoc),
1426 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 }
1428
1429 /// \brief Build a new C++ dynamic_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1434 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
1438 ExprArg SubExpr,
1439 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1441 TInfo, move(SubExpr),
1442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ reinterpret_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1451 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
1455 ExprArg SubExpr,
1456 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1458 TInfo, move(SubExpr),
1459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ const_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1468 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
1472 ExprArg SubExpr,
1473 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1475 TInfo, move(SubExpr),
1476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
Mike Stump11289f42009-09-09 15:08:12 +00001479
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// \brief Build a new C++ functional-style cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
1484 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001485 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation LParenLoc,
1487 ExprArg SubExpr,
1488 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001489 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001491 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001493 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001494 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 RParenLoc);
1496 }
Mike Stump11289f42009-09-09 15:08:12 +00001497
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// \brief Build a new C++ typeid(type) expression.
1499 ///
1500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001502 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1503 SourceLocation TypeidLoc,
1504 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001506 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1507 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(expr) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001514 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1515 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 ExprArg Operand,
1517 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001518 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1519 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001520 }
1521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new C++ "this" expression.
1523 ///
1524 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001525 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001527 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001528 QualType ThisType,
1529 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001531 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1532 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 }
1534
1535 /// \brief Build a new C++ throw expression.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
1539 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1540 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1541 }
1542
1543 /// \brief Build a new C++ default-argument expression.
1544 ///
1545 /// By default, builds a new default-argument expression, which does not
1546 /// require any semantic analysis. Subclasses may override this routine to
1547 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001548 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1549 ParmVarDecl *Param) {
1550 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1551 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 }
1553
1554 /// \brief Build a new C++ zero-initialization expression.
1555 ///
1556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001558 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 SourceLocation LParenLoc,
1560 QualType T,
1561 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001562 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1563 T.getAsOpaquePtr(), LParenLoc,
1564 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 0, RParenLoc);
1566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new C++ "new" expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001572 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 bool UseGlobal,
1574 SourceLocation PlacementLParen,
1575 MultiExprArg PlacementArgs,
1576 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001577 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 QualType AllocType,
1579 SourceLocation TypeLoc,
1580 SourceRange TypeRange,
1581 ExprArg ArraySize,
1582 SourceLocation ConstructorLParen,
1583 MultiExprArg ConstructorArgs,
1584 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001585 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 PlacementLParen,
1587 move(PlacementArgs),
1588 PlacementRParen,
1589 ParenTypeId,
1590 AllocType,
1591 TypeLoc,
1592 TypeRange,
1593 move(ArraySize),
1594 ConstructorLParen,
1595 move(ConstructorArgs),
1596 ConstructorRParen);
1597 }
Mike Stump11289f42009-09-09 15:08:12 +00001598
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// \brief Build a new C++ "delete" expression.
1600 ///
1601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
1603 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1604 bool IsGlobalDelete,
1605 bool IsArrayForm,
1606 ExprArg Operand) {
1607 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1608 move(Operand));
1609 }
Mike Stump11289f42009-09-09 15:08:12 +00001610
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// \brief Build a new unary type trait expression.
1612 ///
1613 /// By default, performs semantic analysis to build the new expression.
1614 /// Subclasses may override this routine to provide different behavior.
1615 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1616 SourceLocation StartLoc,
1617 SourceLocation LParenLoc,
1618 QualType T,
1619 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001620 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 T.getAsOpaquePtr(), RParenLoc);
1622 }
1623
Mike Stump11289f42009-09-09 15:08:12 +00001624 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 /// expression.
1626 ///
1627 /// By default, performs semantic analysis to build the new expression.
1628 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001629 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 SourceRange QualifierRange,
1631 DeclarationName Name,
1632 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001633 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 CXXScopeSpec SS;
1635 SS.setRange(QualifierRange);
1636 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001637
1638 if (TemplateArgs)
1639 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1640 *TemplateArgs);
1641
1642 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 }
1644
1645 /// \brief Build a new template-id expression.
1646 ///
1647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001649 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1650 LookupResult &R,
1651 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001652 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001653 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 }
1655
1656 /// \brief Build a new object-construction expression.
1657 ///
1658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
1660 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001661 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 CXXConstructorDecl *Constructor,
1663 bool IsElidable,
1664 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001665 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1666 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1667 ConvertedArgs))
1668 return getSema().ExprError();
1669
1670 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1671 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new object-construction expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
1678 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1679 QualType T,
1680 SourceLocation LParenLoc,
1681 MultiExprArg Args,
1682 SourceLocation *Commas,
1683 SourceLocation RParenLoc) {
1684 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1685 T.getAsOpaquePtr(),
1686 LParenLoc,
1687 move(Args),
1688 Commas,
1689 RParenLoc);
1690 }
1691
1692 /// \brief Build a new object-construction expression.
1693 ///
1694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1697 QualType T,
1698 SourceLocation LParenLoc,
1699 MultiExprArg Args,
1700 SourceLocation *Commas,
1701 SourceLocation RParenLoc) {
1702 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1703 /*FIXME*/LParenLoc),
1704 T.getAsOpaquePtr(),
1705 LParenLoc,
1706 move(Args),
1707 Commas,
1708 RParenLoc);
1709 }
Mike Stump11289f42009-09-09 15:08:12 +00001710
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 /// \brief Build a new member reference expression.
1712 ///
1713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001715 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001716 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 bool IsArrow,
1718 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001719 NestedNameSpecifier *Qualifier,
1720 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001721 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001723 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001724 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001726 SS.setRange(QualifierRange);
1727 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001728
John McCall2d74de92009-12-01 22:10:20 +00001729 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1730 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001731 SS, FirstQualifierInScope,
1732 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 }
1734
John McCall10eae182009-11-30 22:42:35 +00001735 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001739 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001740 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001741 SourceLocation OperatorLoc,
1742 bool IsArrow,
1743 NestedNameSpecifier *Qualifier,
1744 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001745 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001746 LookupResult &R,
1747 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001748 CXXScopeSpec SS;
1749 SS.setRange(QualifierRange);
1750 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001751
John McCall2d74de92009-12-01 22:10:20 +00001752 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1753 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001754 SS, FirstQualifierInScope,
1755 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001756 }
Mike Stump11289f42009-09-09 15:08:12 +00001757
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 /// \brief Build a new Objective-C @encode expression.
1759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
1762 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001763 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001765 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001767 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001768
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001769 /// \brief Build a new Objective-C class message.
1770 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1771 Selector Sel,
1772 ObjCMethodDecl *Method,
1773 SourceLocation LBracLoc,
1774 MultiExprArg Args,
1775 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001776 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1777 ReceiverTypeInfo->getType(),
1778 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001779 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001780 move(Args));
1781 }
1782
1783 /// \brief Build a new Objective-C instance message.
1784 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1785 Selector Sel,
1786 ObjCMethodDecl *Method,
1787 SourceLocation LBracLoc,
1788 MultiExprArg Args,
1789 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001790 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1791 return SemaRef.BuildInstanceMessage(move(Receiver),
1792 ReceiverType,
1793 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001794 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001795 move(Args));
1796 }
1797
Douglas Gregord51d90d2010-04-26 20:11:03 +00001798 /// \brief Build a new Objective-C ivar reference expression.
1799 ///
1800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
1802 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1803 SourceLocation IvarLoc,
1804 bool IsArrow, bool IsFreeIvar) {
1805 // FIXME: We lose track of the IsFreeIvar bit.
1806 CXXScopeSpec SS;
1807 Expr *Base = BaseArg.takeAs<Expr>();
1808 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1809 Sema::LookupMemberName);
1810 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1811 /*FIME:*/IvarLoc,
1812 SS, DeclPtrTy());
1813 if (Result.isInvalid())
1814 return getSema().ExprError();
1815
1816 if (Result.get())
1817 return move(Result);
1818
1819 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1820 Base->getType(),
1821 /*FIXME:*/IvarLoc, IsArrow, SS,
1822 /*FirstQualifierInScope=*/0,
1823 R,
1824 /*TemplateArgs=*/0);
1825 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001826
1827 /// \brief Build a new Objective-C property reference expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
1831 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
1832 ObjCPropertyDecl *Property,
1833 SourceLocation PropertyLoc) {
1834 CXXScopeSpec SS;
1835 Expr *Base = BaseArg.takeAs<Expr>();
1836 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1837 Sema::LookupMemberName);
1838 bool IsArrow = false;
1839 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1840 /*FIME:*/PropertyLoc,
1841 SS, DeclPtrTy());
1842 if (Result.isInvalid())
1843 return getSema().ExprError();
1844
1845 if (Result.get())
1846 return move(Result);
1847
1848 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1849 Base->getType(),
1850 /*FIXME:*/PropertyLoc, IsArrow,
1851 SS,
1852 /*FirstQualifierInScope=*/0,
1853 R,
1854 /*TemplateArgs=*/0);
1855 }
1856
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001857 /// \brief Build a new Objective-C implicit setter/getter reference
1858 /// expression.
1859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// Subclasses may override this routine to provide different behavior.
1862 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1863 ObjCMethodDecl *Getter,
1864 QualType T,
1865 ObjCMethodDecl *Setter,
1866 SourceLocation NameLoc,
1867 ExprArg Base) {
1868 // Since these expressions can only be value-dependent, we do not need to
1869 // perform semantic analysis again.
1870 return getSema().Owned(
1871 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1872 Setter,
1873 NameLoc,
1874 Base.takeAs<Expr>()));
1875 }
1876
Douglas Gregord51d90d2010-04-26 20:11:03 +00001877 /// \brief Build a new Objective-C "isa" expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
1881 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1882 bool IsArrow) {
1883 CXXScopeSpec SS;
1884 Expr *Base = BaseArg.takeAs<Expr>();
1885 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1886 Sema::LookupMemberName);
1887 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1888 /*FIME:*/IsaLoc,
1889 SS, DeclPtrTy());
1890 if (Result.isInvalid())
1891 return getSema().ExprError();
1892
1893 if (Result.get())
1894 return move(Result);
1895
1896 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1897 Base->getType(),
1898 /*FIXME:*/IsaLoc, IsArrow, SS,
1899 /*FirstQualifierInScope=*/0,
1900 R,
1901 /*TemplateArgs=*/0);
1902 }
1903
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 /// \brief Build a new shuffle vector expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
1908 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1909 MultiExprArg SubExprs,
1910 SourceLocation RParenLoc) {
1911 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001912 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1914 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1915 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1916 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001917
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 // Build a reference to the __builtin_shufflevector builtin
1919 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001920 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001922 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001924
1925 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 unsigned NumSubExprs = SubExprs.size();
1927 Expr **Subs = (Expr **)SubExprs.release();
1928 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1929 Subs, NumSubExprs,
1930 Builtin->getResultType(),
1931 RParenLoc);
1932 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001933
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 // Type-check the __builtin_shufflevector expression.
1935 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1936 if (Result.isInvalid())
1937 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001940 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001942};
Douglas Gregora16548e2009-08-11 05:31:07 +00001943
Douglas Gregorebe10102009-08-20 07:17:43 +00001944template<typename Derived>
1945Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1946 if (!S)
1947 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregorebe10102009-08-20 07:17:43 +00001949 switch (S->getStmtClass()) {
1950 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregorebe10102009-08-20 07:17:43 +00001952 // Transform individual statement nodes
1953#define STMT(Node, Parent) \
1954 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1955#define EXPR(Node, Parent)
1956#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregorebe10102009-08-20 07:17:43 +00001958 // Transform expressions by calling TransformExpr.
1959#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001960#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001961#define EXPR(Node, Parent) case Stmt::Node##Class:
1962#include "clang/AST/StmtNodes.def"
1963 {
1964 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1965 if (E.isInvalid())
1966 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001967
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001968 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970 }
1971
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 return SemaRef.Owned(S->Retain());
1973}
Mike Stump11289f42009-09-09 15:08:12 +00001974
1975
Douglas Gregore922c772009-08-04 22:27:00 +00001976template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001977Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 if (!E)
1979 return SemaRef.Owned(E);
1980
1981 switch (E->getStmtClass()) {
1982 case Stmt::NoStmtClass: break;
1983#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001984#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001985#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001986 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001987#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001988 }
1989
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001991}
1992
1993template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001994NestedNameSpecifier *
1995TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001996 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001997 QualType ObjectType,
1998 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001999 if (!NNS)
2000 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002001
Douglas Gregorebe10102009-08-20 07:17:43 +00002002 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002003 NestedNameSpecifier *Prefix = NNS->getPrefix();
2004 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002005 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002006 ObjectType,
2007 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002008 if (!Prefix)
2009 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002010
2011 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002012 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002013 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002014 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002015 }
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregor1135c352009-08-06 05:28:30 +00002017 switch (NNS->getKind()) {
2018 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002019 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002020 "Identifier nested-name-specifier with no prefix or object type");
2021 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2022 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002023 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002024
2025 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002026 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002027 ObjectType,
2028 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002029
Douglas Gregor1135c352009-08-06 05:28:30 +00002030 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002031 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002033 getDerived().TransformDecl(Range.getBegin(),
2034 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002035 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002036 Prefix == NNS->getPrefix() &&
2037 NS == NNS->getAsNamespace())
2038 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregor1135c352009-08-06 05:28:30 +00002040 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2041 }
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 case NestedNameSpecifier::Global:
2044 // There is no meaningful transformation that one could perform on the
2045 // global scope.
2046 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregor1135c352009-08-06 05:28:30 +00002048 case NestedNameSpecifier::TypeSpecWithTemplate:
2049 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002050 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002051 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2052 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002053 if (T.isNull())
2054 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002055
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 if (!getDerived().AlwaysRebuild() &&
2057 Prefix == NNS->getPrefix() &&
2058 T == QualType(NNS->getAsType(), 0))
2059 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002060
2061 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2062 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002063 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002064 }
2065 }
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregor1135c352009-08-06 05:28:30 +00002067 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002068 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002069}
2070
2071template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002072DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002073TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002074 SourceLocation Loc,
2075 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002076 if (!Name)
2077 return Name;
2078
2079 switch (Name.getNameKind()) {
2080 case DeclarationName::Identifier:
2081 case DeclarationName::ObjCZeroArgSelector:
2082 case DeclarationName::ObjCOneArgSelector:
2083 case DeclarationName::ObjCMultiArgSelector:
2084 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002085 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002086 case DeclarationName::CXXUsingDirective:
2087 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002088
Douglas Gregorf816bd72009-09-03 22:13:48 +00002089 case DeclarationName::CXXConstructorName:
2090 case DeclarationName::CXXDestructorName:
2091 case DeclarationName::CXXConversionFunctionName: {
2092 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00002093 QualType T = getDerived().TransformType(Name.getCXXNameType(),
2094 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002095 if (T.isNull())
2096 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002097
Douglas Gregorf816bd72009-09-03 22:13:48 +00002098 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002099 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002100 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 }
Mike Stump11289f42009-09-09 15:08:12 +00002102 }
2103
Douglas Gregorf816bd72009-09-03 22:13:48 +00002104 return DeclarationName();
2105}
2106
2107template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002108TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002109TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2110 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002111 SourceLocation Loc = getDerived().getBaseLocation();
2112
Douglas Gregor71dc5092009-08-06 06:41:21 +00002113 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002114 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002115 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002116 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2117 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002118 if (!NNS)
2119 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002120
Douglas Gregor71dc5092009-08-06 06:41:21 +00002121 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002122 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002123 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002124 if (!TransTemplate)
2125 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002126
Douglas Gregor71dc5092009-08-06 06:41:21 +00002127 if (!getDerived().AlwaysRebuild() &&
2128 NNS == QTN->getQualifier() &&
2129 TransTemplate == Template)
2130 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregor71dc5092009-08-06 06:41:21 +00002132 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2133 TransTemplate);
2134 }
Mike Stump11289f42009-09-09 15:08:12 +00002135
John McCalle66edc12009-11-24 19:00:30 +00002136 // These should be getting filtered out before they make it into the AST.
2137 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002138 }
Mike Stump11289f42009-09-09 15:08:12 +00002139
Douglas Gregor71dc5092009-08-06 06:41:21 +00002140 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002141 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002142 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002143 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2144 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002145 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002146 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002147
Douglas Gregor71dc5092009-08-06 06:41:21 +00002148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002149 NNS == DTN->getQualifier() &&
2150 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregor71395fa2009-11-04 00:56:37 +00002153 if (DTN->isIdentifier())
2154 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2155 ObjectType);
2156
2157 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2158 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 }
Mike Stump11289f42009-09-09 15:08:12 +00002160
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002162 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002163 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002164 if (!TransTemplate)
2165 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 if (!getDerived().AlwaysRebuild() &&
2168 TransTemplate == Template)
2169 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 return TemplateName(TransTemplate);
2172 }
Mike Stump11289f42009-09-09 15:08:12 +00002173
John McCalle66edc12009-11-24 19:00:30 +00002174 // These should be getting filtered out before they reach the AST.
2175 assert(false && "overloaded function decl survived to here");
2176 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177}
2178
2179template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002180void TreeTransform<Derived>::InventTemplateArgumentLoc(
2181 const TemplateArgument &Arg,
2182 TemplateArgumentLoc &Output) {
2183 SourceLocation Loc = getDerived().getBaseLocation();
2184 switch (Arg.getKind()) {
2185 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002186 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002187 break;
2188
2189 case TemplateArgument::Type:
2190 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002191 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002192
2193 break;
2194
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002195 case TemplateArgument::Template:
2196 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2197 break;
2198
John McCall0ad16662009-10-29 08:12:44 +00002199 case TemplateArgument::Expression:
2200 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2201 break;
2202
2203 case TemplateArgument::Declaration:
2204 case TemplateArgument::Integral:
2205 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002206 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002207 break;
2208 }
2209}
2210
2211template<typename Derived>
2212bool TreeTransform<Derived>::TransformTemplateArgument(
2213 const TemplateArgumentLoc &Input,
2214 TemplateArgumentLoc &Output) {
2215 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002216 switch (Arg.getKind()) {
2217 case TemplateArgument::Null:
2218 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002219 Output = Input;
2220 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregore922c772009-08-04 22:27:00 +00002222 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002223 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002224 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002225 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002226
2227 DI = getDerived().TransformType(DI);
2228 if (!DI) return true;
2229
2230 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2231 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002232 }
Mike Stump11289f42009-09-09 15:08:12 +00002233
Douglas Gregore922c772009-08-04 22:27:00 +00002234 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002235 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002236 DeclarationName Name;
2237 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2238 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002239 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002240 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002241 if (!D) return true;
2242
John McCall0d07eb32009-10-29 18:45:58 +00002243 Expr *SourceExpr = Input.getSourceDeclExpression();
2244 if (SourceExpr) {
2245 EnterExpressionEvaluationContext Unevaluated(getSema(),
2246 Action::Unevaluated);
2247 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2248 if (E.isInvalid())
2249 SourceExpr = NULL;
2250 else {
2251 SourceExpr = E.takeAs<Expr>();
2252 SourceExpr->Retain();
2253 }
2254 }
2255
2256 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002257 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002258 }
Mike Stump11289f42009-09-09 15:08:12 +00002259
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002260 case TemplateArgument::Template: {
2261 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2262 TemplateName Template
2263 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2264 if (Template.isNull())
2265 return true;
2266
2267 Output = TemplateArgumentLoc(TemplateArgument(Template),
2268 Input.getTemplateQualifierRange(),
2269 Input.getTemplateNameLoc());
2270 return false;
2271 }
2272
Douglas Gregore922c772009-08-04 22:27:00 +00002273 case TemplateArgument::Expression: {
2274 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002275 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002276 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002277
John McCall0ad16662009-10-29 08:12:44 +00002278 Expr *InputExpr = Input.getSourceExpression();
2279 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2280
2281 Sema::OwningExprResult E
2282 = getDerived().TransformExpr(InputExpr);
2283 if (E.isInvalid()) return true;
2284
2285 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002286 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002287 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2288 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregore922c772009-08-04 22:27:00 +00002291 case TemplateArgument::Pack: {
2292 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2293 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002294 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002295 AEnd = Arg.pack_end();
2296 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002297
John McCall0ad16662009-10-29 08:12:44 +00002298 // FIXME: preserve source information here when we start
2299 // caring about parameter packs.
2300
John McCall0d07eb32009-10-29 18:45:58 +00002301 TemplateArgumentLoc InputArg;
2302 TemplateArgumentLoc OutputArg;
2303 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2304 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002305 return true;
2306
John McCall0d07eb32009-10-29 18:45:58 +00002307 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002308 }
2309 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002310 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002311 true);
John McCall0d07eb32009-10-29 18:45:58 +00002312 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002313 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002314 }
2315 }
Mike Stump11289f42009-09-09 15:08:12 +00002316
Douglas Gregore922c772009-08-04 22:27:00 +00002317 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002318 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002319}
2320
Douglas Gregord6ff3322009-08-04 16:50:30 +00002321//===----------------------------------------------------------------------===//
2322// Type transformation
2323//===----------------------------------------------------------------------===//
2324
2325template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002326QualType TreeTransform<Derived>::TransformType(QualType T,
2327 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002328 if (getDerived().AlreadyTransformed(T))
2329 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002330
John McCall550e0c22009-10-21 00:40:46 +00002331 // Temporary workaround. All of these transformations should
2332 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002333 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002334 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002335
Douglas Gregorfe17d252010-02-16 19:09:40 +00002336 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002337
John McCall550e0c22009-10-21 00:40:46 +00002338 if (!NewDI)
2339 return QualType();
2340
2341 return NewDI->getType();
2342}
2343
2344template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002345TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2346 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002347 if (getDerived().AlreadyTransformed(DI->getType()))
2348 return DI;
2349
2350 TypeLocBuilder TLB;
2351
2352 TypeLoc TL = DI->getTypeLoc();
2353 TLB.reserve(TL.getFullDataSize());
2354
Douglas Gregorfe17d252010-02-16 19:09:40 +00002355 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002356 if (Result.isNull())
2357 return 0;
2358
John McCallbcd03502009-12-07 02:54:59 +00002359 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002360}
2361
2362template<typename Derived>
2363QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002364TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2365 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002366 switch (T.getTypeLocClass()) {
2367#define ABSTRACT_TYPELOC(CLASS, PARENT)
2368#define TYPELOC(CLASS, PARENT) \
2369 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002370 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2371 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002372#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002373 }
Mike Stump11289f42009-09-09 15:08:12 +00002374
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002375 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002376 return QualType();
2377}
2378
2379/// FIXME: By default, this routine adds type qualifiers only to types
2380/// that can have qualifiers, and silently suppresses those qualifiers
2381/// that are not permitted (e.g., qualifiers on reference or function
2382/// types). This is the right thing for template instantiation, but
2383/// probably not for other clients.
2384template<typename Derived>
2385QualType
2386TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002387 QualifiedTypeLoc T,
2388 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002389 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002390
Douglas Gregorfe17d252010-02-16 19:09:40 +00002391 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2392 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002393 if (Result.isNull())
2394 return QualType();
2395
2396 // Silently suppress qualifiers if the result type can't be qualified.
2397 // FIXME: this is the right thing for template instantiation, but
2398 // probably not for other clients.
2399 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002400 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002401
John McCall550e0c22009-10-21 00:40:46 +00002402 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2403
2404 TLB.push<QualifiedTypeLoc>(Result);
2405
2406 // No location information to preserve.
2407
2408 return Result;
2409}
2410
2411template <class TyLoc> static inline
2412QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2413 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2414 NewT.setNameLoc(T.getNameLoc());
2415 return T.getType();
2416}
2417
John McCall550e0c22009-10-21 00:40:46 +00002418template<typename Derived>
2419QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002420 BuiltinTypeLoc T,
2421 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002422 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2423 NewT.setBuiltinLoc(T.getBuiltinLoc());
2424 if (T.needsExtraLocalData())
2425 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2426 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002427}
Mike Stump11289f42009-09-09 15:08:12 +00002428
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002430QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002431 ComplexTypeLoc T,
2432 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002433 // FIXME: recurse?
2434 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002435}
Mike Stump11289f42009-09-09 15:08:12 +00002436
Douglas Gregord6ff3322009-08-04 16:50:30 +00002437template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002438QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002439 PointerTypeLoc TL,
2440 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002441 QualType PointeeType
2442 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2443 if (PointeeType.isNull())
2444 return QualType();
2445
2446 QualType Result = TL.getType();
2447 if (PointeeType->isObjCInterfaceType()) {
2448 // A dependent pointer type 'T *' has is being transformed such
2449 // that an Objective-C class type is being replaced for 'T'. The
2450 // resulting pointer type is an ObjCObjectPointerType, not a
2451 // PointerType.
2452 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2453 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2454 const_cast<ObjCProtocolDecl **>(
2455 IFace->qual_begin()),
2456 IFace->getNumProtocols());
2457
2458 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2459 NewT.setStarLoc(TL.getSigilLoc());
2460 NewT.setHasProtocolsAsWritten(false);
2461 NewT.setLAngleLoc(SourceLocation());
2462 NewT.setRAngleLoc(SourceLocation());
2463 NewT.setHasBaseTypeAsWritten(true);
2464 return Result;
2465 }
2466
2467 if (getDerived().AlwaysRebuild() ||
2468 PointeeType != TL.getPointeeLoc().getType()) {
2469 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2470 if (Result.isNull())
2471 return QualType();
2472 }
2473
2474 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2475 NewT.setSigilLoc(TL.getSigilLoc());
2476 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002477}
Mike Stump11289f42009-09-09 15:08:12 +00002478
2479template<typename Derived>
2480QualType
John McCall550e0c22009-10-21 00:40:46 +00002481TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002482 BlockPointerTypeLoc TL,
2483 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002484 QualType PointeeType
2485 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2486 if (PointeeType.isNull())
2487 return QualType();
2488
2489 QualType Result = TL.getType();
2490 if (getDerived().AlwaysRebuild() ||
2491 PointeeType != TL.getPointeeLoc().getType()) {
2492 Result = getDerived().RebuildBlockPointerType(PointeeType,
2493 TL.getSigilLoc());
2494 if (Result.isNull())
2495 return QualType();
2496 }
2497
Douglas Gregor049211a2010-04-22 16:50:51 +00002498 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002499 NewT.setSigilLoc(TL.getSigilLoc());
2500 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002501}
2502
John McCall70dd5f62009-10-30 00:06:24 +00002503/// Transforms a reference type. Note that somewhat paradoxically we
2504/// don't care whether the type itself is an l-value type or an r-value
2505/// type; we only care if the type was *written* as an l-value type
2506/// or an r-value type.
2507template<typename Derived>
2508QualType
2509TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002510 ReferenceTypeLoc TL,
2511 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002512 const ReferenceType *T = TL.getTypePtr();
2513
2514 // Note that this works with the pointee-as-written.
2515 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2516 if (PointeeType.isNull())
2517 return QualType();
2518
2519 QualType Result = TL.getType();
2520 if (getDerived().AlwaysRebuild() ||
2521 PointeeType != T->getPointeeTypeAsWritten()) {
2522 Result = getDerived().RebuildReferenceType(PointeeType,
2523 T->isSpelledAsLValue(),
2524 TL.getSigilLoc());
2525 if (Result.isNull())
2526 return QualType();
2527 }
2528
2529 // r-value references can be rebuilt as l-value references.
2530 ReferenceTypeLoc NewTL;
2531 if (isa<LValueReferenceType>(Result))
2532 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2533 else
2534 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2535 NewTL.setSigilLoc(TL.getSigilLoc());
2536
2537 return Result;
2538}
2539
Mike Stump11289f42009-09-09 15:08:12 +00002540template<typename Derived>
2541QualType
John McCall550e0c22009-10-21 00:40:46 +00002542TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002543 LValueReferenceTypeLoc TL,
2544 QualType ObjectType) {
2545 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002546}
2547
Mike Stump11289f42009-09-09 15:08:12 +00002548template<typename Derived>
2549QualType
John McCall550e0c22009-10-21 00:40:46 +00002550TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002551 RValueReferenceTypeLoc TL,
2552 QualType ObjectType) {
2553 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002554}
Mike Stump11289f42009-09-09 15:08:12 +00002555
Douglas Gregord6ff3322009-08-04 16:50:30 +00002556template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002557QualType
John McCall550e0c22009-10-21 00:40:46 +00002558TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002559 MemberPointerTypeLoc TL,
2560 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002561 MemberPointerType *T = TL.getTypePtr();
2562
2563 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002564 if (PointeeType.isNull())
2565 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002566
John McCall550e0c22009-10-21 00:40:46 +00002567 // TODO: preserve source information for this.
2568 QualType ClassType
2569 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002570 if (ClassType.isNull())
2571 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002572
John McCall550e0c22009-10-21 00:40:46 +00002573 QualType Result = TL.getType();
2574 if (getDerived().AlwaysRebuild() ||
2575 PointeeType != T->getPointeeType() ||
2576 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002577 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2578 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002579 if (Result.isNull())
2580 return QualType();
2581 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582
John McCall550e0c22009-10-21 00:40:46 +00002583 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2584 NewTL.setSigilLoc(TL.getSigilLoc());
2585
2586 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002587}
2588
Mike Stump11289f42009-09-09 15:08:12 +00002589template<typename Derived>
2590QualType
John McCall550e0c22009-10-21 00:40:46 +00002591TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002592 ConstantArrayTypeLoc TL,
2593 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002594 ConstantArrayType *T = TL.getTypePtr();
2595 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002596 if (ElementType.isNull())
2597 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002598
John McCall550e0c22009-10-21 00:40:46 +00002599 QualType Result = TL.getType();
2600 if (getDerived().AlwaysRebuild() ||
2601 ElementType != T->getElementType()) {
2602 Result = getDerived().RebuildConstantArrayType(ElementType,
2603 T->getSizeModifier(),
2604 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002605 T->getIndexTypeCVRQualifiers(),
2606 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002607 if (Result.isNull())
2608 return QualType();
2609 }
2610
2611 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2612 NewTL.setLBracketLoc(TL.getLBracketLoc());
2613 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002614
John McCall550e0c22009-10-21 00:40:46 +00002615 Expr *Size = TL.getSizeExpr();
2616 if (Size) {
2617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2618 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2619 }
2620 NewTL.setSizeExpr(Size);
2621
2622 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002623}
Mike Stump11289f42009-09-09 15:08:12 +00002624
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002627 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002628 IncompleteArrayTypeLoc TL,
2629 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002630 IncompleteArrayType *T = TL.getTypePtr();
2631 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632 if (ElementType.isNull())
2633 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002634
John McCall550e0c22009-10-21 00:40:46 +00002635 QualType Result = TL.getType();
2636 if (getDerived().AlwaysRebuild() ||
2637 ElementType != T->getElementType()) {
2638 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002640 T->getIndexTypeCVRQualifiers(),
2641 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002642 if (Result.isNull())
2643 return QualType();
2644 }
2645
2646 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2647 NewTL.setLBracketLoc(TL.getLBracketLoc());
2648 NewTL.setRBracketLoc(TL.getRBracketLoc());
2649 NewTL.setSizeExpr(0);
2650
2651 return Result;
2652}
2653
2654template<typename Derived>
2655QualType
2656TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002657 VariableArrayTypeLoc TL,
2658 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002659 VariableArrayType *T = TL.getTypePtr();
2660 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2661 if (ElementType.isNull())
2662 return QualType();
2663
2664 // Array bounds are not potentially evaluated contexts
2665 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2666
2667 Sema::OwningExprResult SizeResult
2668 = getDerived().TransformExpr(T->getSizeExpr());
2669 if (SizeResult.isInvalid())
2670 return QualType();
2671
2672 Expr *Size = static_cast<Expr*>(SizeResult.get());
2673
2674 QualType Result = TL.getType();
2675 if (getDerived().AlwaysRebuild() ||
2676 ElementType != T->getElementType() ||
2677 Size != T->getSizeExpr()) {
2678 Result = getDerived().RebuildVariableArrayType(ElementType,
2679 T->getSizeModifier(),
2680 move(SizeResult),
2681 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002682 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002683 if (Result.isNull())
2684 return QualType();
2685 }
2686 else SizeResult.take();
2687
2688 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2689 NewTL.setLBracketLoc(TL.getLBracketLoc());
2690 NewTL.setRBracketLoc(TL.getRBracketLoc());
2691 NewTL.setSizeExpr(Size);
2692
2693 return Result;
2694}
2695
2696template<typename Derived>
2697QualType
2698TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002699 DependentSizedArrayTypeLoc TL,
2700 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002701 DependentSizedArrayType *T = TL.getTypePtr();
2702 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2703 if (ElementType.isNull())
2704 return QualType();
2705
2706 // Array bounds are not potentially evaluated contexts
2707 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2708
2709 Sema::OwningExprResult SizeResult
2710 = getDerived().TransformExpr(T->getSizeExpr());
2711 if (SizeResult.isInvalid())
2712 return QualType();
2713
2714 Expr *Size = static_cast<Expr*>(SizeResult.get());
2715
2716 QualType Result = TL.getType();
2717 if (getDerived().AlwaysRebuild() ||
2718 ElementType != T->getElementType() ||
2719 Size != T->getSizeExpr()) {
2720 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2721 T->getSizeModifier(),
2722 move(SizeResult),
2723 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002724 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002725 if (Result.isNull())
2726 return QualType();
2727 }
2728 else SizeResult.take();
2729
2730 // We might have any sort of array type now, but fortunately they
2731 // all have the same location layout.
2732 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2733 NewTL.setLBracketLoc(TL.getLBracketLoc());
2734 NewTL.setRBracketLoc(TL.getRBracketLoc());
2735 NewTL.setSizeExpr(Size);
2736
2737 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002738}
Mike Stump11289f42009-09-09 15:08:12 +00002739
2740template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002742 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002743 DependentSizedExtVectorTypeLoc TL,
2744 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002745 DependentSizedExtVectorType *T = TL.getTypePtr();
2746
2747 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002748 QualType ElementType = getDerived().TransformType(T->getElementType());
2749 if (ElementType.isNull())
2750 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002751
Douglas Gregore922c772009-08-04 22:27:00 +00002752 // Vector sizes are not potentially evaluated contexts
2753 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2754
Douglas Gregord6ff3322009-08-04 16:50:30 +00002755 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2756 if (Size.isInvalid())
2757 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002758
John McCall550e0c22009-10-21 00:40:46 +00002759 QualType Result = TL.getType();
2760 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002761 ElementType != T->getElementType() ||
2762 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002763 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764 move(Size),
2765 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002766 if (Result.isNull())
2767 return QualType();
2768 }
2769 else Size.take();
2770
2771 // Result might be dependent or not.
2772 if (isa<DependentSizedExtVectorType>(Result)) {
2773 DependentSizedExtVectorTypeLoc NewTL
2774 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2775 NewTL.setNameLoc(TL.getNameLoc());
2776 } else {
2777 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2778 NewTL.setNameLoc(TL.getNameLoc());
2779 }
2780
2781 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002782}
Mike Stump11289f42009-09-09 15:08:12 +00002783
2784template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002785QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002786 VectorTypeLoc TL,
2787 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002788 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002789 QualType ElementType = getDerived().TransformType(T->getElementType());
2790 if (ElementType.isNull())
2791 return QualType();
2792
John McCall550e0c22009-10-21 00:40:46 +00002793 QualType Result = TL.getType();
2794 if (getDerived().AlwaysRebuild() ||
2795 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002796 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2797 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002798 if (Result.isNull())
2799 return QualType();
2800 }
2801
2802 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2803 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002804
John McCall550e0c22009-10-21 00:40:46 +00002805 return Result;
2806}
2807
2808template<typename Derived>
2809QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002810 ExtVectorTypeLoc TL,
2811 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002812 VectorType *T = TL.getTypePtr();
2813 QualType ElementType = getDerived().TransformType(T->getElementType());
2814 if (ElementType.isNull())
2815 return QualType();
2816
2817 QualType Result = TL.getType();
2818 if (getDerived().AlwaysRebuild() ||
2819 ElementType != T->getElementType()) {
2820 Result = getDerived().RebuildExtVectorType(ElementType,
2821 T->getNumElements(),
2822 /*FIXME*/ SourceLocation());
2823 if (Result.isNull())
2824 return QualType();
2825 }
2826
2827 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2828 NewTL.setNameLoc(TL.getNameLoc());
2829
2830 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002831}
Mike Stump11289f42009-09-09 15:08:12 +00002832
2833template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002834ParmVarDecl *
2835TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2836 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2837 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2838 if (!NewDI)
2839 return 0;
2840
2841 if (NewDI == OldDI)
2842 return OldParm;
2843 else
2844 return ParmVarDecl::Create(SemaRef.Context,
2845 OldParm->getDeclContext(),
2846 OldParm->getLocation(),
2847 OldParm->getIdentifier(),
2848 NewDI->getType(),
2849 NewDI,
2850 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002851 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002852 /* DefArg */ NULL);
2853}
2854
2855template<typename Derived>
2856bool TreeTransform<Derived>::
2857 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2858 llvm::SmallVectorImpl<QualType> &PTypes,
2859 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2860 FunctionProtoType *T = TL.getTypePtr();
2861
2862 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2863 ParmVarDecl *OldParm = TL.getArg(i);
2864
2865 QualType NewType;
2866 ParmVarDecl *NewParm;
2867
2868 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002869 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2870 if (!NewParm)
2871 return true;
2872 NewType = NewParm->getType();
2873
2874 // Deal with the possibility that we don't have a parameter
2875 // declaration for this parameter.
2876 } else {
2877 NewParm = 0;
2878
2879 QualType OldType = T->getArgType(i);
2880 NewType = getDerived().TransformType(OldType);
2881 if (NewType.isNull())
2882 return true;
2883 }
2884
2885 PTypes.push_back(NewType);
2886 PVars.push_back(NewParm);
2887 }
2888
2889 return false;
2890}
2891
2892template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002893QualType
John McCall550e0c22009-10-21 00:40:46 +00002894TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002895 FunctionProtoTypeLoc TL,
2896 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002897 FunctionProtoType *T = TL.getTypePtr();
2898 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899 if (ResultType.isNull())
2900 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002901
John McCall550e0c22009-10-21 00:40:46 +00002902 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002903 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002904 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002905 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2906 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002907
John McCall550e0c22009-10-21 00:40:46 +00002908 QualType Result = TL.getType();
2909 if (getDerived().AlwaysRebuild() ||
2910 ResultType != T->getResultType() ||
2911 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2912 Result = getDerived().RebuildFunctionProtoType(ResultType,
2913 ParamTypes.data(),
2914 ParamTypes.size(),
2915 T->isVariadic(),
2916 T->getTypeQuals());
2917 if (Result.isNull())
2918 return QualType();
2919 }
Mike Stump11289f42009-09-09 15:08:12 +00002920
John McCall550e0c22009-10-21 00:40:46 +00002921 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2922 NewTL.setLParenLoc(TL.getLParenLoc());
2923 NewTL.setRParenLoc(TL.getRParenLoc());
2924 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2925 NewTL.setArg(i, ParamDecls[i]);
2926
2927 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928}
Mike Stump11289f42009-09-09 15:08:12 +00002929
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930template<typename Derived>
2931QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002932 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002933 FunctionNoProtoTypeLoc TL,
2934 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002935 FunctionNoProtoType *T = TL.getTypePtr();
2936 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2937 if (ResultType.isNull())
2938 return QualType();
2939
2940 QualType Result = TL.getType();
2941 if (getDerived().AlwaysRebuild() ||
2942 ResultType != T->getResultType())
2943 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2944
2945 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2946 NewTL.setLParenLoc(TL.getLParenLoc());
2947 NewTL.setRParenLoc(TL.getRParenLoc());
2948
2949 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002950}
Mike Stump11289f42009-09-09 15:08:12 +00002951
John McCallb96ec562009-12-04 22:46:56 +00002952template<typename Derived> QualType
2953TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002954 UnresolvedUsingTypeLoc TL,
2955 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002956 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002957 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002958 if (!D)
2959 return QualType();
2960
2961 QualType Result = TL.getType();
2962 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2963 Result = getDerived().RebuildUnresolvedUsingType(D);
2964 if (Result.isNull())
2965 return QualType();
2966 }
2967
2968 // We might get an arbitrary type spec type back. We should at
2969 // least always get a type spec type, though.
2970 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2971 NewTL.setNameLoc(TL.getNameLoc());
2972
2973 return Result;
2974}
2975
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002977QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002978 TypedefTypeLoc TL,
2979 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002980 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002981 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002982 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2983 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002984 if (!Typedef)
2985 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002986
John McCall550e0c22009-10-21 00:40:46 +00002987 QualType Result = TL.getType();
2988 if (getDerived().AlwaysRebuild() ||
2989 Typedef != T->getDecl()) {
2990 Result = getDerived().RebuildTypedefType(Typedef);
2991 if (Result.isNull())
2992 return QualType();
2993 }
Mike Stump11289f42009-09-09 15:08:12 +00002994
John McCall550e0c22009-10-21 00:40:46 +00002995 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2996 NewTL.setNameLoc(TL.getNameLoc());
2997
2998 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002999}
Mike Stump11289f42009-09-09 15:08:12 +00003000
Douglas Gregord6ff3322009-08-04 16:50:30 +00003001template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003002QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003003 TypeOfExprTypeLoc TL,
3004 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003005 // typeof expressions are not potentially evaluated contexts
3006 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003007
John McCalle8595032010-01-13 20:03:27 +00003008 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003009 if (E.isInvalid())
3010 return QualType();
3011
John McCall550e0c22009-10-21 00:40:46 +00003012 QualType Result = TL.getType();
3013 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003014 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003015 Result = getDerived().RebuildTypeOfExprType(move(E));
3016 if (Result.isNull())
3017 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018 }
John McCall550e0c22009-10-21 00:40:46 +00003019 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003020
John McCall550e0c22009-10-21 00:40:46 +00003021 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003022 NewTL.setTypeofLoc(TL.getTypeofLoc());
3023 NewTL.setLParenLoc(TL.getLParenLoc());
3024 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003025
3026 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003027}
Mike Stump11289f42009-09-09 15:08:12 +00003028
3029template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003030QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003031 TypeOfTypeLoc TL,
3032 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003033 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3034 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3035 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003037
John McCall550e0c22009-10-21 00:40:46 +00003038 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003039 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3040 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003041 if (Result.isNull())
3042 return QualType();
3043 }
Mike Stump11289f42009-09-09 15:08:12 +00003044
John McCall550e0c22009-10-21 00:40:46 +00003045 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003046 NewTL.setTypeofLoc(TL.getTypeofLoc());
3047 NewTL.setLParenLoc(TL.getLParenLoc());
3048 NewTL.setRParenLoc(TL.getRParenLoc());
3049 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003050
3051 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003052}
Mike Stump11289f42009-09-09 15:08:12 +00003053
3054template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003055QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003056 DecltypeTypeLoc TL,
3057 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003058 DecltypeType *T = TL.getTypePtr();
3059
Douglas Gregore922c772009-08-04 22:27:00 +00003060 // decltype expressions are not potentially evaluated contexts
3061 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003062
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3064 if (E.isInvalid())
3065 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003066
John McCall550e0c22009-10-21 00:40:46 +00003067 QualType Result = TL.getType();
3068 if (getDerived().AlwaysRebuild() ||
3069 E.get() != T->getUnderlyingExpr()) {
3070 Result = getDerived().RebuildDecltypeType(move(E));
3071 if (Result.isNull())
3072 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073 }
John McCall550e0c22009-10-21 00:40:46 +00003074 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003075
John McCall550e0c22009-10-21 00:40:46 +00003076 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3077 NewTL.setNameLoc(TL.getNameLoc());
3078
3079 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003080}
3081
3082template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003083QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003084 RecordTypeLoc TL,
3085 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003086 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003087 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003088 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3089 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003090 if (!Record)
3091 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003092
John McCall550e0c22009-10-21 00:40:46 +00003093 QualType Result = TL.getType();
3094 if (getDerived().AlwaysRebuild() ||
3095 Record != T->getDecl()) {
3096 Result = getDerived().RebuildRecordType(Record);
3097 if (Result.isNull())
3098 return QualType();
3099 }
Mike Stump11289f42009-09-09 15:08:12 +00003100
John McCall550e0c22009-10-21 00:40:46 +00003101 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3102 NewTL.setNameLoc(TL.getNameLoc());
3103
3104 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105}
Mike Stump11289f42009-09-09 15:08:12 +00003106
3107template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003108QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003109 EnumTypeLoc TL,
3110 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003111 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003113 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3114 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115 if (!Enum)
3116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003117
John McCall550e0c22009-10-21 00:40:46 +00003118 QualType Result = TL.getType();
3119 if (getDerived().AlwaysRebuild() ||
3120 Enum != T->getDecl()) {
3121 Result = getDerived().RebuildEnumType(Enum);
3122 if (Result.isNull())
3123 return QualType();
3124 }
Mike Stump11289f42009-09-09 15:08:12 +00003125
John McCall550e0c22009-10-21 00:40:46 +00003126 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3127 NewTL.setNameLoc(TL.getNameLoc());
3128
3129 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003130}
John McCallfcc33b02009-09-05 00:15:47 +00003131
3132template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003133QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003134 ElaboratedTypeLoc TL,
3135 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003136 ElaboratedType *T = TL.getTypePtr();
3137
3138 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003139 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3140 if (Underlying.isNull())
3141 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003142
John McCall550e0c22009-10-21 00:40:46 +00003143 QualType Result = TL.getType();
3144 if (getDerived().AlwaysRebuild() ||
3145 Underlying != T->getUnderlyingType()) {
3146 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3147 if (Result.isNull())
3148 return QualType();
3149 }
Mike Stump11289f42009-09-09 15:08:12 +00003150
John McCall550e0c22009-10-21 00:40:46 +00003151 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3152 NewTL.setNameLoc(TL.getNameLoc());
3153
3154 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003155}
Mike Stump11289f42009-09-09 15:08:12 +00003156
John McCalle78aac42010-03-10 03:28:59 +00003157template<typename Derived>
3158QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3159 TypeLocBuilder &TLB,
3160 InjectedClassNameTypeLoc TL,
3161 QualType ObjectType) {
3162 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3163 TL.getTypePtr()->getDecl());
3164 if (!D) return QualType();
3165
3166 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3167 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3168 return T;
3169}
3170
Mike Stump11289f42009-09-09 15:08:12 +00003171
Douglas Gregord6ff3322009-08-04 16:50:30 +00003172template<typename Derived>
3173QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003174 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003175 TemplateTypeParmTypeLoc TL,
3176 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003177 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003178}
3179
Mike Stump11289f42009-09-09 15:08:12 +00003180template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003181QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003182 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003183 SubstTemplateTypeParmTypeLoc TL,
3184 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003185 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003186}
3187
3188template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003189QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3190 const TemplateSpecializationType *TST,
3191 QualType ObjectType) {
3192 // FIXME: this entire method is a temporary workaround; callers
3193 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003194
John McCall0ad16662009-10-29 08:12:44 +00003195 // Fake up a TemplateSpecializationTypeLoc.
3196 TypeLocBuilder TLB;
3197 TemplateSpecializationTypeLoc TL
3198 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3199
John McCall0d07eb32009-10-29 18:45:58 +00003200 SourceLocation BaseLoc = getDerived().getBaseLocation();
3201
3202 TL.setTemplateNameLoc(BaseLoc);
3203 TL.setLAngleLoc(BaseLoc);
3204 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003205 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3206 const TemplateArgument &TA = TST->getArg(i);
3207 TemplateArgumentLoc TAL;
3208 getDerived().InventTemplateArgumentLoc(TA, TAL);
3209 TL.setArgLocInfo(i, TAL.getLocInfo());
3210 }
3211
3212 TypeLocBuilder IgnoredTLB;
3213 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003214}
3215
3216template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003217QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003218 TypeLocBuilder &TLB,
3219 TemplateSpecializationTypeLoc TL,
3220 QualType ObjectType) {
3221 const TemplateSpecializationType *T = TL.getTypePtr();
3222
Mike Stump11289f42009-09-09 15:08:12 +00003223 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003224 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003225 if (Template.isNull())
3226 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall6b51f282009-11-23 01:53:49 +00003228 TemplateArgumentListInfo NewTemplateArgs;
3229 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3230 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3231
3232 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3233 TemplateArgumentLoc Loc;
3234 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003235 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003236 NewTemplateArgs.addArgument(Loc);
3237 }
Mike Stump11289f42009-09-09 15:08:12 +00003238
John McCall0ad16662009-10-29 08:12:44 +00003239 // FIXME: maybe don't rebuild if all the template arguments are the same.
3240
3241 QualType Result =
3242 getDerived().RebuildTemplateSpecializationType(Template,
3243 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003244 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003245
3246 if (!Result.isNull()) {
3247 TemplateSpecializationTypeLoc NewTL
3248 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3249 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3250 NewTL.setLAngleLoc(TL.getLAngleLoc());
3251 NewTL.setRAngleLoc(TL.getRAngleLoc());
3252 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3253 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003254 }
Mike Stump11289f42009-09-09 15:08:12 +00003255
John McCall0ad16662009-10-29 08:12:44 +00003256 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003257}
Mike Stump11289f42009-09-09 15:08:12 +00003258
3259template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003260QualType
3261TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003262 QualifiedNameTypeLoc TL,
3263 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003264 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003265 NestedNameSpecifier *NNS
3266 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003267 SourceRange(),
3268 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269 if (!NNS)
3270 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003271
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272 QualType Named = getDerived().TransformType(T->getNamedType());
3273 if (Named.isNull())
3274 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003275
John McCall550e0c22009-10-21 00:40:46 +00003276 QualType Result = TL.getType();
3277 if (getDerived().AlwaysRebuild() ||
3278 NNS != T->getQualifier() ||
3279 Named != T->getNamedType()) {
3280 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3281 if (Result.isNull())
3282 return QualType();
3283 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003284
John McCall550e0c22009-10-21 00:40:46 +00003285 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3286 NewTL.setNameLoc(TL.getNameLoc());
3287
3288 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003289}
Mike Stump11289f42009-09-09 15:08:12 +00003290
3291template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003292QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3293 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003294 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003295 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003296
3297 /* FIXME: preserve source information better than this */
3298 SourceRange SR(TL.getNameLoc());
3299
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003301 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003302 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003303 if (!NNS)
3304 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003305
John McCall550e0c22009-10-21 00:40:46 +00003306 QualType Result;
3307
Douglas Gregord6ff3322009-08-04 16:50:30 +00003308 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003309 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310 = getDerived().TransformType(QualType(TemplateId, 0));
3311 if (NewTemplateId.isNull())
3312 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314 if (!getDerived().AlwaysRebuild() &&
3315 NNS == T->getQualifier() &&
3316 NewTemplateId == QualType(TemplateId, 0))
3317 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003318
Douglas Gregor02085352010-03-31 20:19:30 +00003319 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3320 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003321 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003322 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3323 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324 }
John McCall550e0c22009-10-21 00:40:46 +00003325 if (Result.isNull())
3326 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003328 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003329 NewTL.setNameLoc(TL.getNameLoc());
3330
3331 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332}
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003335QualType
3336TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003337 ObjCInterfaceTypeLoc TL,
3338 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003339 // ObjCInterfaceType is never dependent.
3340 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341}
Mike Stump11289f42009-09-09 15:08:12 +00003342
3343template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003344QualType
3345TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003346 ObjCObjectPointerTypeLoc TL,
3347 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003348 // ObjCObjectPointerType is never dependent.
3349 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003350}
3351
Douglas Gregord6ff3322009-08-04 16:50:30 +00003352//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003353// Statement transformation
3354//===----------------------------------------------------------------------===//
3355template<typename Derived>
3356Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003357TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3358 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003359}
3360
3361template<typename Derived>
3362Sema::OwningStmtResult
3363TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3364 return getDerived().TransformCompoundStmt(S, false);
3365}
3366
3367template<typename Derived>
3368Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003369TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003370 bool IsStmtExpr) {
3371 bool SubStmtChanged = false;
3372 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3373 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3374 B != BEnd; ++B) {
3375 OwningStmtResult Result = getDerived().TransformStmt(*B);
3376 if (Result.isInvalid())
3377 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003378
Douglas Gregorebe10102009-08-20 07:17:43 +00003379 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3380 Statements.push_back(Result.takeAs<Stmt>());
3381 }
Mike Stump11289f42009-09-09 15:08:12 +00003382
Douglas Gregorebe10102009-08-20 07:17:43 +00003383 if (!getDerived().AlwaysRebuild() &&
3384 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003385 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003386
3387 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3388 move_arg(Statements),
3389 S->getRBracLoc(),
3390 IsStmtExpr);
3391}
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregorebe10102009-08-20 07:17:43 +00003393template<typename Derived>
3394Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003395TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003396 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3397 {
3398 // The case value expressions are not potentially evaluated.
3399 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003400
Eli Friedman06577382009-11-19 03:14:00 +00003401 // Transform the left-hand case value.
3402 LHS = getDerived().TransformExpr(S->getLHS());
3403 if (LHS.isInvalid())
3404 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003405
Eli Friedman06577382009-11-19 03:14:00 +00003406 // Transform the right-hand case value (for the GNU case-range extension).
3407 RHS = getDerived().TransformExpr(S->getRHS());
3408 if (RHS.isInvalid())
3409 return SemaRef.StmtError();
3410 }
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregorebe10102009-08-20 07:17:43 +00003412 // Build the case statement.
3413 // Case statements are always rebuilt so that they will attached to their
3414 // transformed switch statement.
3415 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3416 move(LHS),
3417 S->getEllipsisLoc(),
3418 move(RHS),
3419 S->getColonLoc());
3420 if (Case.isInvalid())
3421 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423 // Transform the statement following the case
3424 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3425 if (SubStmt.isInvalid())
3426 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003427
Douglas Gregorebe10102009-08-20 07:17:43 +00003428 // Attach the body to the case statement
3429 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3430}
3431
3432template<typename Derived>
3433Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003434TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003435 // Transform the statement following the default case
3436 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3437 if (SubStmt.isInvalid())
3438 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregorebe10102009-08-20 07:17:43 +00003440 // Default statements are always rebuilt
3441 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3442 move(SubStmt));
3443}
Mike Stump11289f42009-09-09 15:08:12 +00003444
Douglas Gregorebe10102009-08-20 07:17:43 +00003445template<typename Derived>
3446Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003447TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003448 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3449 if (SubStmt.isInvalid())
3450 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003451
Douglas Gregorebe10102009-08-20 07:17:43 +00003452 // FIXME: Pass the real colon location in.
3453 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3454 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3455 move(SubStmt));
3456}
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003459Sema::OwningStmtResult
3460TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003462 OwningExprResult Cond(SemaRef);
3463 VarDecl *ConditionVar = 0;
3464 if (S->getConditionVariable()) {
3465 ConditionVar
3466 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003467 getDerived().TransformDefinition(
3468 S->getConditionVariable()->getLocation(),
3469 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003470 if (!ConditionVar)
3471 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003472 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003473 Cond = getDerived().TransformExpr(S->getCond());
3474
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003475 if (Cond.isInvalid())
3476 return SemaRef.StmtError();
3477 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003478
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003479 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003480
Douglas Gregorebe10102009-08-20 07:17:43 +00003481 // Transform the "then" branch.
3482 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3483 if (Then.isInvalid())
3484 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003485
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 // Transform the "else" branch.
3487 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3488 if (Else.isInvalid())
3489 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003490
Douglas Gregorebe10102009-08-20 07:17:43 +00003491 if (!getDerived().AlwaysRebuild() &&
3492 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003493 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003494 Then.get() == S->getThen() &&
3495 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003496 return SemaRef.Owned(S->Retain());
3497
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003498 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3499 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003500 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003501}
3502
3503template<typename Derived>
3504Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003505TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003506 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003507 OwningExprResult Cond(SemaRef);
3508 VarDecl *ConditionVar = 0;
3509 if (S->getConditionVariable()) {
3510 ConditionVar
3511 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003512 getDerived().TransformDefinition(
3513 S->getConditionVariable()->getLocation(),
3514 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003515 if (!ConditionVar)
3516 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003517 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003518 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003519
3520 if (Cond.isInvalid())
3521 return SemaRef.StmtError();
3522 }
Mike Stump11289f42009-09-09 15:08:12 +00003523
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003524 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003525
Douglas Gregorebe10102009-08-20 07:17:43 +00003526 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003527 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3528 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003529 if (Switch.isInvalid())
3530 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003531
Douglas Gregorebe10102009-08-20 07:17:43 +00003532 // Transform the body of the switch statement.
3533 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3534 if (Body.isInvalid())
3535 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003536
Douglas Gregorebe10102009-08-20 07:17:43 +00003537 // Complete the switch statement.
3538 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3539 move(Body));
3540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregorebe10102009-08-20 07:17:43 +00003542template<typename Derived>
3543Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003544TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003546 OwningExprResult Cond(SemaRef);
3547 VarDecl *ConditionVar = 0;
3548 if (S->getConditionVariable()) {
3549 ConditionVar
3550 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003551 getDerived().TransformDefinition(
3552 S->getConditionVariable()->getLocation(),
3553 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003554 if (!ConditionVar)
3555 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003556 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003557 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003558
3559 if (Cond.isInvalid())
3560 return SemaRef.StmtError();
3561 }
Mike Stump11289f42009-09-09 15:08:12 +00003562
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003563 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003564
Douglas Gregorebe10102009-08-20 07:17:43 +00003565 // Transform the body
3566 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3567 if (Body.isInvalid())
3568 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregorebe10102009-08-20 07:17:43 +00003570 if (!getDerived().AlwaysRebuild() &&
3571 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003572 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003574 return SemaRef.Owned(S->Retain());
3575
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003576 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3577 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003578}
Mike Stump11289f42009-09-09 15:08:12 +00003579
Douglas Gregorebe10102009-08-20 07:17:43 +00003580template<typename Derived>
3581Sema::OwningStmtResult
3582TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3583 // Transform the condition
3584 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3585 if (Cond.isInvalid())
3586 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 // Transform the body
3589 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3590 if (Body.isInvalid())
3591 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregorebe10102009-08-20 07:17:43 +00003593 if (!getDerived().AlwaysRebuild() &&
3594 Cond.get() == S->getCond() &&
3595 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003596 return SemaRef.Owned(S->Retain());
3597
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3599 /*FIXME:*/S->getWhileLoc(), move(Cond),
3600 S->getRParenLoc());
3601}
Mike Stump11289f42009-09-09 15:08:12 +00003602
Douglas Gregorebe10102009-08-20 07:17:43 +00003603template<typename Derived>
3604Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003605TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 // Transform the initialization statement
3607 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3608 if (Init.isInvalid())
3609 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003612 OwningExprResult Cond(SemaRef);
3613 VarDecl *ConditionVar = 0;
3614 if (S->getConditionVariable()) {
3615 ConditionVar
3616 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003617 getDerived().TransformDefinition(
3618 S->getConditionVariable()->getLocation(),
3619 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003620 if (!ConditionVar)
3621 return SemaRef.StmtError();
3622 } else {
3623 Cond = getDerived().TransformExpr(S->getCond());
3624
3625 if (Cond.isInvalid())
3626 return SemaRef.StmtError();
3627 }
Mike Stump11289f42009-09-09 15:08:12 +00003628
Douglas Gregorebe10102009-08-20 07:17:43 +00003629 // Transform the increment
3630 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3631 if (Inc.isInvalid())
3632 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003633
Douglas Gregorebe10102009-08-20 07:17:43 +00003634 // Transform the body
3635 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3636 if (Body.isInvalid())
3637 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregorebe10102009-08-20 07:17:43 +00003639 if (!getDerived().AlwaysRebuild() &&
3640 Init.get() == S->getInit() &&
3641 Cond.get() == S->getCond() &&
3642 Inc.get() == S->getInc() &&
3643 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003644 return SemaRef.Owned(S->Retain());
3645
Douglas Gregorebe10102009-08-20 07:17:43 +00003646 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003647 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003648 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003649 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003650 S->getRParenLoc(), move(Body));
3651}
3652
3653template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003654Sema::OwningStmtResult
3655TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003656 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003657 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003658 S->getLabel());
3659}
3660
3661template<typename Derived>
3662Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003663TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003664 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3665 if (Target.isInvalid())
3666 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregorebe10102009-08-20 07:17:43 +00003668 if (!getDerived().AlwaysRebuild() &&
3669 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003670 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003671
3672 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3673 move(Target));
3674}
3675
3676template<typename Derived>
3677Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003678TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3679 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003680}
Mike Stump11289f42009-09-09 15:08:12 +00003681
Douglas Gregorebe10102009-08-20 07:17:43 +00003682template<typename Derived>
3683Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003684TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3685 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003686}
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregorebe10102009-08-20 07:17:43 +00003688template<typename Derived>
3689Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003690TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3692 if (Result.isInvalid())
3693 return SemaRef.StmtError();
3694
Mike Stump11289f42009-09-09 15:08:12 +00003695 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003696 // to tell whether the return type of the function has changed.
3697 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3698}
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregorebe10102009-08-20 07:17:43 +00003700template<typename Derived>
3701Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003702TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003703 bool DeclChanged = false;
3704 llvm::SmallVector<Decl *, 4> Decls;
3705 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3706 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003707 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3708 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 if (!Transformed)
3710 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003711
Douglas Gregorebe10102009-08-20 07:17:43 +00003712 if (Transformed != *D)
3713 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003714
Douglas Gregorebe10102009-08-20 07:17:43 +00003715 Decls.push_back(Transformed);
3716 }
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregorebe10102009-08-20 07:17:43 +00003718 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003719 return SemaRef.Owned(S->Retain());
3720
3721 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 S->getStartLoc(), S->getEndLoc());
3723}
Mike Stump11289f42009-09-09 15:08:12 +00003724
Douglas Gregorebe10102009-08-20 07:17:43 +00003725template<typename Derived>
3726Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003727TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003728 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003729 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003730}
3731
3732template<typename Derived>
3733Sema::OwningStmtResult
3734TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003735
3736 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3737 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003738 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003739
Anders Carlssonaaeef072010-01-24 05:50:09 +00003740 OwningExprResult AsmString(SemaRef);
3741 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3742
3743 bool ExprsChanged = false;
3744
3745 // Go through the outputs.
3746 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003747 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003748
Anders Carlssonaaeef072010-01-24 05:50:09 +00003749 // No need to transform the constraint literal.
3750 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3751
3752 // Transform the output expr.
3753 Expr *OutputExpr = S->getOutputExpr(I);
3754 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3755 if (Result.isInvalid())
3756 return SemaRef.StmtError();
3757
3758 ExprsChanged |= Result.get() != OutputExpr;
3759
3760 Exprs.push_back(Result.takeAs<Expr>());
3761 }
3762
3763 // Go through the inputs.
3764 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003765 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003766
Anders Carlssonaaeef072010-01-24 05:50:09 +00003767 // No need to transform the constraint literal.
3768 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3769
3770 // Transform the input expr.
3771 Expr *InputExpr = S->getInputExpr(I);
3772 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3773 if (Result.isInvalid())
3774 return SemaRef.StmtError();
3775
3776 ExprsChanged |= Result.get() != InputExpr;
3777
3778 Exprs.push_back(Result.takeAs<Expr>());
3779 }
3780
3781 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3782 return SemaRef.Owned(S->Retain());
3783
3784 // Go through the clobbers.
3785 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3786 Clobbers.push_back(S->getClobber(I)->Retain());
3787
3788 // No need to transform the asm string literal.
3789 AsmString = SemaRef.Owned(S->getAsmString());
3790
3791 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3792 S->isSimple(),
3793 S->isVolatile(),
3794 S->getNumOutputs(),
3795 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003796 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003797 move_arg(Constraints),
3798 move_arg(Exprs),
3799 move(AsmString),
3800 move_arg(Clobbers),
3801 S->getRParenLoc(),
3802 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003803}
3804
3805
3806template<typename Derived>
3807Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003808TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003809 // Transform the body of the @try.
3810 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3811 if (TryBody.isInvalid())
3812 return SemaRef.StmtError();
3813
Douglas Gregor96c79492010-04-23 22:50:49 +00003814 // Transform the @catch statements (if present).
3815 bool AnyCatchChanged = false;
3816 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3817 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3818 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003819 if (Catch.isInvalid())
3820 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003821 if (Catch.get() != S->getCatchStmt(I))
3822 AnyCatchChanged = true;
3823 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003824 }
3825
3826 // Transform the @finally statement (if present).
3827 OwningStmtResult Finally(SemaRef);
3828 if (S->getFinallyStmt()) {
3829 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3830 if (Finally.isInvalid())
3831 return SemaRef.StmtError();
3832 }
3833
3834 // If nothing changed, just retain this statement.
3835 if (!getDerived().AlwaysRebuild() &&
3836 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003837 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003838 Finally.get() == S->getFinallyStmt())
3839 return SemaRef.Owned(S->Retain());
3840
3841 // Build a new statement.
3842 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003843 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003844}
Mike Stump11289f42009-09-09 15:08:12 +00003845
Douglas Gregorebe10102009-08-20 07:17:43 +00003846template<typename Derived>
3847Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003848TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003849 // Transform the @catch parameter, if there is one.
3850 VarDecl *Var = 0;
3851 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3852 TypeSourceInfo *TSInfo = 0;
3853 if (FromVar->getTypeSourceInfo()) {
3854 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3855 if (!TSInfo)
3856 return SemaRef.StmtError();
3857 }
3858
3859 QualType T;
3860 if (TSInfo)
3861 T = TSInfo->getType();
3862 else {
3863 T = getDerived().TransformType(FromVar->getType());
3864 if (T.isNull())
3865 return SemaRef.StmtError();
3866 }
3867
3868 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3869 if (!Var)
3870 return SemaRef.StmtError();
3871 }
3872
3873 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3874 if (Body.isInvalid())
3875 return SemaRef.StmtError();
3876
3877 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
3878 S->getRParenLoc(),
3879 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregorebe10102009-08-20 07:17:43 +00003882template<typename Derived>
3883Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003884TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003885 // Transform the body.
3886 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3887 if (Body.isInvalid())
3888 return SemaRef.StmtError();
3889
3890 // If nothing changed, just retain this statement.
3891 if (!getDerived().AlwaysRebuild() &&
3892 Body.get() == S->getFinallyBody())
3893 return SemaRef.Owned(S->Retain());
3894
3895 // Build a new statement.
3896 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3897 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003898}
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregorebe10102009-08-20 07:17:43 +00003900template<typename Derived>
3901Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003902TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003903 OwningExprResult Operand(SemaRef);
3904 if (S->getThrowExpr()) {
3905 Operand = getDerived().TransformExpr(S->getThrowExpr());
3906 if (Operand.isInvalid())
3907 return getSema().StmtError();
3908 }
3909
3910 if (!getDerived().AlwaysRebuild() &&
3911 Operand.get() == S->getThrowExpr())
3912 return getSema().Owned(S->Retain());
3913
3914 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003915}
Mike Stump11289f42009-09-09 15:08:12 +00003916
Douglas Gregorebe10102009-08-20 07:17:43 +00003917template<typename Derived>
3918Sema::OwningStmtResult
3919TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003920 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003921 // Transform the object we are locking.
3922 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3923 if (Object.isInvalid())
3924 return SemaRef.StmtError();
3925
3926 // Transform the body.
3927 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3928 if (Body.isInvalid())
3929 return SemaRef.StmtError();
3930
3931 // If nothing change, just retain the current statement.
3932 if (!getDerived().AlwaysRebuild() &&
3933 Object.get() == S->getSynchExpr() &&
3934 Body.get() == S->getSynchBody())
3935 return SemaRef.Owned(S->Retain());
3936
3937 // Build a new statement.
3938 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3939 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003940}
3941
3942template<typename Derived>
3943Sema::OwningStmtResult
3944TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003945 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003946 // Transform the element statement.
3947 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3948 if (Element.isInvalid())
3949 return SemaRef.StmtError();
3950
3951 // Transform the collection expression.
3952 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3953 if (Collection.isInvalid())
3954 return SemaRef.StmtError();
3955
3956 // Transform the body.
3957 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3958 if (Body.isInvalid())
3959 return SemaRef.StmtError();
3960
3961 // If nothing changed, just retain this statement.
3962 if (!getDerived().AlwaysRebuild() &&
3963 Element.get() == S->getElement() &&
3964 Collection.get() == S->getCollection() &&
3965 Body.get() == S->getBody())
3966 return SemaRef.Owned(S->Retain());
3967
3968 // Build a new statement.
3969 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3970 /*FIXME:*/S->getForLoc(),
3971 move(Element),
3972 move(Collection),
3973 S->getRParenLoc(),
3974 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003975}
3976
3977
3978template<typename Derived>
3979Sema::OwningStmtResult
3980TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3981 // Transform the exception declaration, if any.
3982 VarDecl *Var = 0;
3983 if (S->getExceptionDecl()) {
3984 VarDecl *ExceptionDecl = S->getExceptionDecl();
3985 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3986 ExceptionDecl->getDeclName());
3987
3988 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3989 if (T.isNull())
3990 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003991
Douglas Gregorebe10102009-08-20 07:17:43 +00003992 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3993 T,
John McCallbcd03502009-12-07 02:54:59 +00003994 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003995 ExceptionDecl->getIdentifier(),
3996 ExceptionDecl->getLocation(),
3997 /*FIXME: Inaccurate*/
3998 SourceRange(ExceptionDecl->getLocation()));
3999 if (!Var || Var->isInvalidDecl()) {
4000 if (Var)
4001 Var->Destroy(SemaRef.Context);
4002 return SemaRef.StmtError();
4003 }
4004 }
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregorebe10102009-08-20 07:17:43 +00004006 // Transform the actual exception handler.
4007 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4008 if (Handler.isInvalid()) {
4009 if (Var)
4010 Var->Destroy(SemaRef.Context);
4011 return SemaRef.StmtError();
4012 }
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregorebe10102009-08-20 07:17:43 +00004014 if (!getDerived().AlwaysRebuild() &&
4015 !Var &&
4016 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004017 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004018
4019 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4020 Var,
4021 move(Handler));
4022}
Mike Stump11289f42009-09-09 15:08:12 +00004023
Douglas Gregorebe10102009-08-20 07:17:43 +00004024template<typename Derived>
4025Sema::OwningStmtResult
4026TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4027 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004028 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004029 = getDerived().TransformCompoundStmt(S->getTryBlock());
4030 if (TryBlock.isInvalid())
4031 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregorebe10102009-08-20 07:17:43 +00004033 // Transform the handlers.
4034 bool HandlerChanged = false;
4035 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4036 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004037 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004038 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4039 if (Handler.isInvalid())
4040 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004041
Douglas Gregorebe10102009-08-20 07:17:43 +00004042 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4043 Handlers.push_back(Handler.takeAs<Stmt>());
4044 }
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregorebe10102009-08-20 07:17:43 +00004046 if (!getDerived().AlwaysRebuild() &&
4047 TryBlock.get() == S->getTryBlock() &&
4048 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004049 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004050
4051 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004052 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004053}
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregorebe10102009-08-20 07:17:43 +00004055//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004056// Expression transformation
4057//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004058template<typename Derived>
4059Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004060TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004061 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004062}
Mike Stump11289f42009-09-09 15:08:12 +00004063
4064template<typename Derived>
4065Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004066TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004067 NestedNameSpecifier *Qualifier = 0;
4068 if (E->getQualifier()) {
4069 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004070 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004071 if (!Qualifier)
4072 return SemaRef.ExprError();
4073 }
John McCallce546572009-12-08 09:08:17 +00004074
4075 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004076 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4077 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004078 if (!ND)
4079 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004081 if (!getDerived().AlwaysRebuild() &&
4082 Qualifier == E->getQualifier() &&
4083 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004084 !E->hasExplicitTemplateArgumentList()) {
4085
4086 // Mark it referenced in the new context regardless.
4087 // FIXME: this is a bit instantiation-specific.
4088 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4089
Mike Stump11289f42009-09-09 15:08:12 +00004090 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004091 }
John McCallce546572009-12-08 09:08:17 +00004092
4093 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4094 if (E->hasExplicitTemplateArgumentList()) {
4095 TemplateArgs = &TransArgs;
4096 TransArgs.setLAngleLoc(E->getLAngleLoc());
4097 TransArgs.setRAngleLoc(E->getRAngleLoc());
4098 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4099 TemplateArgumentLoc Loc;
4100 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4101 return SemaRef.ExprError();
4102 TransArgs.addArgument(Loc);
4103 }
4104 }
4105
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004106 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004107 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
Douglas Gregora16548e2009-08-11 05:31:07 +00004110template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004112TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004113 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004114}
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004117Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004118TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004119 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004120}
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004123Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004124TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004125 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004126}
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004129Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004130TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004131 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregora16548e2009-08-11 05:31:07 +00004134template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004135Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004136TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004137 return SemaRef.Owned(E->Retain());
4138}
4139
4140template<typename Derived>
4141Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004142TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004143 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4144 if (SubExpr.isInvalid())
4145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004148 return SemaRef.Owned(E->Retain());
4149
4150 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004151 E->getRParen());
4152}
4153
Mike Stump11289f42009-09-09 15:08:12 +00004154template<typename Derived>
4155Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004156TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4157 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 if (SubExpr.isInvalid())
4159 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregora16548e2009-08-11 05:31:07 +00004161 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004162 return SemaRef.Owned(E->Retain());
4163
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4165 E->getOpcode(),
4166 move(SubExpr));
4167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregora16548e2009-08-11 05:31:07 +00004169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004170Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004171TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004172 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004173 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004174
John McCallbcd03502009-12-07 02:54:59 +00004175 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004176 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004178
John McCall4c98fd82009-11-04 07:28:41 +00004179 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004180 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004181
John McCall4c98fd82009-11-04 07:28:41 +00004182 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004183 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004184 E->getSourceRange());
4185 }
Mike Stump11289f42009-09-09 15:08:12 +00004186
Douglas Gregora16548e2009-08-11 05:31:07 +00004187 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004188 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004189 // C++0x [expr.sizeof]p1:
4190 // The operand is either an expression, which is an unevaluated operand
4191 // [...]
4192 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004193
Douglas Gregora16548e2009-08-11 05:31:07 +00004194 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4195 if (SubExpr.isInvalid())
4196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004197
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4199 return SemaRef.Owned(E->Retain());
4200 }
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4203 E->isSizeOf(),
4204 E->getSourceRange());
4205}
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004208Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004209TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4211 if (LHS.isInvalid())
4212 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregora16548e2009-08-11 05:31:07 +00004214 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4215 if (RHS.isInvalid())
4216 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004217
4218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 if (!getDerived().AlwaysRebuild() &&
4220 LHS.get() == E->getLHS() &&
4221 RHS.get() == E->getRHS())
4222 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004223
Douglas Gregora16548e2009-08-11 05:31:07 +00004224 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4225 /*FIXME:*/E->getLHS()->getLocStart(),
4226 move(RHS),
4227 E->getRBracketLoc());
4228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
4230template<typename Derived>
4231Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004232TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004233 // Transform the callee.
4234 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4235 if (Callee.isInvalid())
4236 return SemaRef.ExprError();
4237
4238 // Transform arguments.
4239 bool ArgChanged = false;
4240 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4241 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4242 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4243 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4244 if (Arg.isInvalid())
4245 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004246
Douglas Gregora16548e2009-08-11 05:31:07 +00004247 // FIXME: Wrong source location information for the ','.
4248 FakeCommaLocs.push_back(
4249 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004250
4251 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004252 Args.push_back(Arg.takeAs<Expr>());
4253 }
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregora16548e2009-08-11 05:31:07 +00004255 if (!getDerived().AlwaysRebuild() &&
4256 Callee.get() == E->getCallee() &&
4257 !ArgChanged)
4258 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004259
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004261 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4263 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4264 move_arg(Args),
4265 FakeCommaLocs.data(),
4266 E->getRParenLoc());
4267}
Mike Stump11289f42009-09-09 15:08:12 +00004268
4269template<typename Derived>
4270Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004271TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4273 if (Base.isInvalid())
4274 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004276 NestedNameSpecifier *Qualifier = 0;
4277 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004278 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004279 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004280 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004281 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004282 return SemaRef.ExprError();
4283 }
Mike Stump11289f42009-09-09 15:08:12 +00004284
Eli Friedman2cfcef62009-12-04 06:40:45 +00004285 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004286 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4287 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 if (!Member)
4289 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004290
John McCall16df1e52010-03-30 21:47:33 +00004291 NamedDecl *FoundDecl = E->getFoundDecl();
4292 if (FoundDecl == E->getMemberDecl()) {
4293 FoundDecl = Member;
4294 } else {
4295 FoundDecl = cast_or_null<NamedDecl>(
4296 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4297 if (!FoundDecl)
4298 return SemaRef.ExprError();
4299 }
4300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 if (!getDerived().AlwaysRebuild() &&
4302 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004303 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004304 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004305 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004306 !E->hasExplicitTemplateArgumentList()) {
4307
4308 // Mark it referenced in the new context regardless.
4309 // FIXME: this is a bit instantiation-specific.
4310 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004311 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004312 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004313
John McCall6b51f282009-11-23 01:53:49 +00004314 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004315 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004316 TransArgs.setLAngleLoc(E->getLAngleLoc());
4317 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004318 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004319 TemplateArgumentLoc Loc;
4320 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004321 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004322 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004323 }
4324 }
4325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 // FIXME: Bogus source location for the operator
4327 SourceLocation FakeOperatorLoc
4328 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4329
John McCall38836f02010-01-15 08:34:02 +00004330 // FIXME: to do this check properly, we will need to preserve the
4331 // first-qualifier-in-scope here, just in case we had a dependent
4332 // base (and therefore couldn't do the check) and a
4333 // nested-name-qualifier (and therefore could do the lookup).
4334 NamedDecl *FirstQualifierInScope = 0;
4335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4337 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004338 Qualifier,
4339 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004340 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004341 Member,
John McCall16df1e52010-03-30 21:47:33 +00004342 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004343 (E->hasExplicitTemplateArgumentList()
4344 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004345 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004346}
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004349Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004350TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4352 if (LHS.isInvalid())
4353 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4356 if (RHS.isInvalid())
4357 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004358
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 if (!getDerived().AlwaysRebuild() &&
4360 LHS.get() == E->getLHS() &&
4361 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004362 return SemaRef.Owned(E->Retain());
4363
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4365 move(LHS), move(RHS));
4366}
4367
Mike Stump11289f42009-09-09 15:08:12 +00004368template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004369Sema::OwningExprResult
4370TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004371 CompoundAssignOperator *E) {
4372 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004373}
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregora16548e2009-08-11 05:31:07 +00004375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004376Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004377TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4379 if (Cond.isInvalid())
4380 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4383 if (LHS.isInvalid())
4384 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4387 if (RHS.isInvalid())
4388 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 if (!getDerived().AlwaysRebuild() &&
4391 Cond.get() == E->getCond() &&
4392 LHS.get() == E->getLHS() &&
4393 RHS.get() == E->getRHS())
4394 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004395
4396 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004397 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004398 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004399 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 move(RHS));
4401}
Mike Stump11289f42009-09-09 15:08:12 +00004402
4403template<typename Derived>
4404Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004405TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004406 // Implicit casts are eliminated during transformation, since they
4407 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004408 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004409}
Mike Stump11289f42009-09-09 15:08:12 +00004410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411template<typename Derived>
4412Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004413TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004414 TypeSourceInfo *OldT;
4415 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 {
4417 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004418 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4420 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004421
John McCall97513962010-01-15 18:39:57 +00004422 OldT = E->getTypeInfoAsWritten();
4423 NewT = getDerived().TransformType(OldT);
4424 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 return SemaRef.ExprError();
4426 }
Mike Stump11289f42009-09-09 15:08:12 +00004427
Douglas Gregor6131b442009-12-12 18:16:41 +00004428 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004429 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 if (SubExpr.isInvalid())
4431 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004434 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004436 return SemaRef.Owned(E->Retain());
4437
John McCall97513962010-01-15 18:39:57 +00004438 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4439 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 E->getRParenLoc(),
4441 move(SubExpr));
4442}
Mike Stump11289f42009-09-09 15:08:12 +00004443
Douglas Gregora16548e2009-08-11 05:31:07 +00004444template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004445Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004446TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004447 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4448 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4449 if (!NewT)
4450 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4453 if (Init.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004457 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004459 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004460
John McCall5d7aa7f2010-01-19 22:33:45 +00004461 // Note: the expression type doesn't necessarily match the
4462 // type-as-written, but that's okay, because it should always be
4463 // derivable from the initializer.
4464
John McCalle15bbff2010-01-18 19:35:47 +00004465 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004466 /*FIXME:*/E->getInitializer()->getLocEnd(),
4467 move(Init));
4468}
Mike Stump11289f42009-09-09 15:08:12 +00004469
Douglas Gregora16548e2009-08-11 05:31:07 +00004470template<typename Derived>
4471Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004472TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004473 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4474 if (Base.isInvalid())
4475 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004476
Douglas Gregora16548e2009-08-11 05:31:07 +00004477 if (!getDerived().AlwaysRebuild() &&
4478 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004479 return SemaRef.Owned(E->Retain());
4480
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004482 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4484 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4485 E->getAccessorLoc(),
4486 E->getAccessor());
4487}
Mike Stump11289f42009-09-09 15:08:12 +00004488
Douglas Gregora16548e2009-08-11 05:31:07 +00004489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004490Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004491TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4495 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4496 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4497 if (Init.isInvalid())
4498 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 InitChanged = InitChanged || Init.get() != E->getInit(I);
4501 Inits.push_back(Init.takeAs<Expr>());
4502 }
Mike Stump11289f42009-09-09 15:08:12 +00004503
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004505 return SemaRef.Owned(E->Retain());
4506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004508 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511template<typename Derived>
4512Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004513TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004515
Douglas Gregorebe10102009-08-20 07:17:43 +00004516 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004517 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4518 if (Init.isInvalid())
4519 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004520
Douglas Gregorebe10102009-08-20 07:17:43 +00004521 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004522 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4523 bool ExprChanged = false;
4524 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4525 DEnd = E->designators_end();
4526 D != DEnd; ++D) {
4527 if (D->isFieldDesignator()) {
4528 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4529 D->getDotLoc(),
4530 D->getFieldLoc()));
4531 continue;
4532 }
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 if (D->isArrayDesignator()) {
4535 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4536 if (Index.isInvalid())
4537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004538
4539 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4543 ArrayExprs.push_back(Index.release());
4544 continue;
4545 }
Mike Stump11289f42009-09-09 15:08:12 +00004546
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004548 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4550 if (Start.isInvalid())
4551 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4554 if (End.isInvalid())
4555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004556
4557 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 End.get(),
4559 D->getLBracketLoc(),
4560 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004561
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4563 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565 ArrayExprs.push_back(Start.release());
4566 ArrayExprs.push_back(End.release());
4567 }
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 if (!getDerived().AlwaysRebuild() &&
4570 Init.get() == E->getInit() &&
4571 !ExprChanged)
4572 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4575 E->getEqualOrColonLoc(),
4576 E->usesGNUSyntax(), move(Init));
4577}
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregora16548e2009-08-11 05:31:07 +00004579template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004580Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004581TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004582 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004583 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4584
4585 // FIXME: Will we ever have proper type location here? Will we actually
4586 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 QualType T = getDerived().TransformType(E->getType());
4588 if (T.isNull())
4589 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 if (!getDerived().AlwaysRebuild() &&
4592 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004593 return SemaRef.Owned(E->Retain());
4594
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 return getDerived().RebuildImplicitValueInitExpr(T);
4596}
Mike Stump11289f42009-09-09 15:08:12 +00004597
Douglas Gregora16548e2009-08-11 05:31:07 +00004598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004599Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004600TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 // FIXME: Do we want the type as written?
4602 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 {
4605 // FIXME: Source location isn't quite accurate.
4606 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4607 T = getDerived().TransformType(E->getType());
4608 if (T.isNull())
4609 return SemaRef.ExprError();
4610 }
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4613 if (SubExpr.isInvalid())
4614 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 if (!getDerived().AlwaysRebuild() &&
4617 T == E->getType() &&
4618 SubExpr.get() == E->getSubExpr())
4619 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4622 T, E->getRParenLoc());
4623}
4624
4625template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004626Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004627TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 bool ArgumentChanged = false;
4629 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4630 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4631 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4632 if (Init.isInvalid())
4633 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004634
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4636 Inits.push_back(Init.takeAs<Expr>());
4637 }
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4640 move_arg(Inits),
4641 E->getRParenLoc());
4642}
Mike Stump11289f42009-09-09 15:08:12 +00004643
Douglas Gregora16548e2009-08-11 05:31:07 +00004644/// \brief Transform an address-of-label expression.
4645///
4646/// By default, the transformation of an address-of-label expression always
4647/// rebuilds the expression, so that the label identifier can be resolved to
4648/// the corresponding label statement by semantic analysis.
4649template<typename Derived>
4650Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004651TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004652 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4653 E->getLabel());
4654}
Mike Stump11289f42009-09-09 15:08:12 +00004655
4656template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004657Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004658TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004659 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4661 if (SubStmt.isInvalid())
4662 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 if (!getDerived().AlwaysRebuild() &&
4665 SubStmt.get() == E->getSubStmt())
4666 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004667
4668 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 move(SubStmt),
4670 E->getRParenLoc());
4671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregora16548e2009-08-11 05:31:07 +00004673template<typename Derived>
4674Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004675TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 QualType T1, T2;
4677 {
4678 // FIXME: Source location isn't quite accurate.
4679 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 T1 = getDerived().TransformType(E->getArgType1());
4682 if (T1.isNull())
4683 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 T2 = getDerived().TransformType(E->getArgType2());
4686 if (T2.isNull())
4687 return SemaRef.ExprError();
4688 }
4689
4690 if (!getDerived().AlwaysRebuild() &&
4691 T1 == E->getArgType1() &&
4692 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004693 return SemaRef.Owned(E->Retain());
4694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4696 T1, T2, E->getRParenLoc());
4697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregora16548e2009-08-11 05:31:07 +00004699template<typename Derived>
4700Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004701TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4703 if (Cond.isInvalid())
4704 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4707 if (LHS.isInvalid())
4708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4711 if (RHS.isInvalid())
4712 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 if (!getDerived().AlwaysRebuild() &&
4715 Cond.get() == E->getCond() &&
4716 LHS.get() == E->getLHS() &&
4717 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004718 return SemaRef.Owned(E->Retain());
4719
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4721 move(Cond), move(LHS), move(RHS),
4722 E->getRParenLoc());
4723}
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregora16548e2009-08-11 05:31:07 +00004725template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004726Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004727TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004728 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004729}
4730
4731template<typename Derived>
4732Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004733TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004734 switch (E->getOperator()) {
4735 case OO_New:
4736 case OO_Delete:
4737 case OO_Array_New:
4738 case OO_Array_Delete:
4739 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4740 return SemaRef.ExprError();
4741
4742 case OO_Call: {
4743 // This is a call to an object's operator().
4744 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4745
4746 // Transform the object itself.
4747 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4748 if (Object.isInvalid())
4749 return SemaRef.ExprError();
4750
4751 // FIXME: Poor location information
4752 SourceLocation FakeLParenLoc
4753 = SemaRef.PP.getLocForEndOfToken(
4754 static_cast<Expr *>(Object.get())->getLocEnd());
4755
4756 // Transform the call arguments.
4757 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4758 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4759 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004760 if (getDerived().DropCallArgument(E->getArg(I)))
4761 break;
4762
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004763 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4764 if (Arg.isInvalid())
4765 return SemaRef.ExprError();
4766
4767 // FIXME: Poor source location information.
4768 SourceLocation FakeCommaLoc
4769 = SemaRef.PP.getLocForEndOfToken(
4770 static_cast<Expr *>(Arg.get())->getLocEnd());
4771 FakeCommaLocs.push_back(FakeCommaLoc);
4772 Args.push_back(Arg.release());
4773 }
4774
4775 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4776 move_arg(Args),
4777 FakeCommaLocs.data(),
4778 E->getLocEnd());
4779 }
4780
4781#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4782 case OO_##Name:
4783#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4784#include "clang/Basic/OperatorKinds.def"
4785 case OO_Subscript:
4786 // Handled below.
4787 break;
4788
4789 case OO_Conditional:
4790 llvm_unreachable("conditional operator is not actually overloadable");
4791 return SemaRef.ExprError();
4792
4793 case OO_None:
4794 case NUM_OVERLOADED_OPERATORS:
4795 llvm_unreachable("not an overloaded operator?");
4796 return SemaRef.ExprError();
4797 }
4798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4800 if (Callee.isInvalid())
4801 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004802
John McCall47f29ea2009-12-08 09:21:05 +00004803 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 if (First.isInvalid())
4805 return SemaRef.ExprError();
4806
4807 OwningExprResult Second(SemaRef);
4808 if (E->getNumArgs() == 2) {
4809 Second = getDerived().TransformExpr(E->getArg(1));
4810 if (Second.isInvalid())
4811 return SemaRef.ExprError();
4812 }
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 if (!getDerived().AlwaysRebuild() &&
4815 Callee.get() == E->getCallee() &&
4816 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004817 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4818 return SemaRef.Owned(E->Retain());
4819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4821 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004822 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 move(First),
4824 move(Second));
4825}
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregora16548e2009-08-11 05:31:07 +00004827template<typename Derived>
4828Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004829TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4830 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004831}
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004834Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004835TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004836 TypeSourceInfo *OldT;
4837 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 {
4839 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004840 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004841 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4842 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004843
John McCall97513962010-01-15 18:39:57 +00004844 OldT = E->getTypeInfoAsWritten();
4845 NewT = getDerived().TransformType(OldT);
4846 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 return SemaRef.ExprError();
4848 }
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregor6131b442009-12-12 18:16:41 +00004850 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004851 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 if (SubExpr.isInvalid())
4853 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004854
Douglas Gregora16548e2009-08-11 05:31:07 +00004855 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004856 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004857 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004858 return SemaRef.Owned(E->Retain());
4859
Douglas Gregora16548e2009-08-11 05:31:07 +00004860 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004861 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4863 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4864 SourceLocation FakeRParenLoc
4865 = SemaRef.PP.getLocForEndOfToken(
4866 E->getSubExpr()->getSourceRange().getEnd());
4867 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004868 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004869 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004870 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 FakeRAngleLoc,
4872 FakeRAngleLoc,
4873 move(SubExpr),
4874 FakeRParenLoc);
4875}
Mike Stump11289f42009-09-09 15:08:12 +00004876
Douglas Gregora16548e2009-08-11 05:31:07 +00004877template<typename Derived>
4878Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004879TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4880 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004881}
Mike Stump11289f42009-09-09 15:08:12 +00004882
4883template<typename Derived>
4884Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004885TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4886 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004887}
4888
Douglas Gregora16548e2009-08-11 05:31:07 +00004889template<typename Derived>
4890Sema::OwningExprResult
4891TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004892 CXXReinterpretCastExpr *E) {
4893 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004894}
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896template<typename Derived>
4897Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004898TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4899 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004900}
Mike Stump11289f42009-09-09 15:08:12 +00004901
Douglas Gregora16548e2009-08-11 05:31:07 +00004902template<typename Derived>
4903Sema::OwningExprResult
4904TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004905 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004906 TypeSourceInfo *OldT;
4907 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 {
4909 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004910
John McCall97513962010-01-15 18:39:57 +00004911 OldT = E->getTypeInfoAsWritten();
4912 NewT = getDerived().TransformType(OldT);
4913 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004914 return SemaRef.ExprError();
4915 }
Mike Stump11289f42009-09-09 15:08:12 +00004916
Douglas Gregor6131b442009-12-12 18:16:41 +00004917 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004918 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 if (SubExpr.isInvalid())
4920 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004921
Douglas Gregora16548e2009-08-11 05:31:07 +00004922 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004923 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004924 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004925 return SemaRef.Owned(E->Retain());
4926
Douglas Gregora16548e2009-08-11 05:31:07 +00004927 // FIXME: The end of the type's source range is wrong
4928 return getDerived().RebuildCXXFunctionalCastExpr(
4929 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004930 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004931 /*FIXME:*/E->getSubExpr()->getLocStart(),
4932 move(SubExpr),
4933 E->getRParenLoc());
4934}
Mike Stump11289f42009-09-09 15:08:12 +00004935
Douglas Gregora16548e2009-08-11 05:31:07 +00004936template<typename Derived>
4937Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004938TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004939 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00004940 TypeSourceInfo *TInfo
4941 = getDerived().TransformType(E->getTypeOperandSourceInfo());
4942 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00004946 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004948
Douglas Gregor9da64192010-04-26 22:37:10 +00004949 return getDerived().RebuildCXXTypeidExpr(E->getType(),
4950 E->getLocStart(),
4951 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 E->getLocEnd());
4953 }
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregora16548e2009-08-11 05:31:07 +00004955 // We don't know whether the expression is potentially evaluated until
4956 // after we perform semantic analysis, so the expression is potentially
4957 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004958 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004959 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregora16548e2009-08-11 05:31:07 +00004961 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4962 if (SubExpr.isInvalid())
4963 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004964
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 if (!getDerived().AlwaysRebuild() &&
4966 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004967 return SemaRef.Owned(E->Retain());
4968
Douglas Gregor9da64192010-04-26 22:37:10 +00004969 return getDerived().RebuildCXXTypeidExpr(E->getType(),
4970 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004971 move(SubExpr),
4972 E->getLocEnd());
4973}
4974
4975template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004976Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004977TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004978 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004979}
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregora16548e2009-08-11 05:31:07 +00004981template<typename Derived>
4982Sema::OwningExprResult
4983TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004984 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004985 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004986}
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregora16548e2009-08-11 05:31:07 +00004988template<typename Derived>
4989Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004990TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004991 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004992
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 QualType T = getDerived().TransformType(E->getType());
4994 if (T.isNull())
4995 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregora16548e2009-08-11 05:31:07 +00004997 if (!getDerived().AlwaysRebuild() &&
4998 T == E->getType())
4999 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregorb15af892010-01-07 23:12:05 +00005001 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005002}
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregora16548e2009-08-11 05:31:07 +00005004template<typename Derived>
5005Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005006TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5008 if (SubExpr.isInvalid())
5009 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (!getDerived().AlwaysRebuild() &&
5012 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005013 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005014
5015 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018template<typename Derived>
5019Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005020TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005021 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005022 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5023 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 if (!Param)
5025 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005026
Chandler Carruth794da4c2010-02-08 06:42:49 +00005027 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 Param == E->getParam())
5029 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregor033f6752009-12-23 23:03:06 +00005031 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005032}
Mike Stump11289f42009-09-09 15:08:12 +00005033
Douglas Gregora16548e2009-08-11 05:31:07 +00005034template<typename Derived>
5035Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005036TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5038
5039 QualType T = getDerived().TransformType(E->getType());
5040 if (T.isNull())
5041 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005042
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 if (!getDerived().AlwaysRebuild() &&
5044 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
5046
5047 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 /*FIXME:*/E->getTypeBeginLoc(),
5049 T,
5050 E->getRParenLoc());
5051}
Mike Stump11289f42009-09-09 15:08:12 +00005052
Douglas Gregora16548e2009-08-11 05:31:07 +00005053template<typename Derived>
5054Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005055TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 // Transform the type that we're allocating
5057 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5058 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5059 if (AllocType.isNull())
5060 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 // Transform the size of the array we're allocating (if any).
5063 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5064 if (ArraySize.isInvalid())
5065 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 // Transform the placement arguments (if any).
5068 bool ArgumentChanged = false;
5069 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5070 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5071 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5072 if (Arg.isInvalid())
5073 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5076 PlacementArgs.push_back(Arg.take());
5077 }
Mike Stump11289f42009-09-09 15:08:12 +00005078
Douglas Gregorebe10102009-08-20 07:17:43 +00005079 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005080 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5081 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5082 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5083 if (Arg.isInvalid())
5084 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5087 ConstructorArgs.push_back(Arg.take());
5088 }
Mike Stump11289f42009-09-09 15:08:12 +00005089
Douglas Gregord2d9da02010-02-26 00:38:10 +00005090 // Transform constructor, new operator, and delete operator.
5091 CXXConstructorDecl *Constructor = 0;
5092 if (E->getConstructor()) {
5093 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005094 getDerived().TransformDecl(E->getLocStart(),
5095 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005096 if (!Constructor)
5097 return SemaRef.ExprError();
5098 }
5099
5100 FunctionDecl *OperatorNew = 0;
5101 if (E->getOperatorNew()) {
5102 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005103 getDerived().TransformDecl(E->getLocStart(),
5104 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005105 if (!OperatorNew)
5106 return SemaRef.ExprError();
5107 }
5108
5109 FunctionDecl *OperatorDelete = 0;
5110 if (E->getOperatorDelete()) {
5111 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005112 getDerived().TransformDecl(E->getLocStart(),
5113 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005114 if (!OperatorDelete)
5115 return SemaRef.ExprError();
5116 }
5117
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 if (!getDerived().AlwaysRebuild() &&
5119 AllocType == E->getAllocatedType() &&
5120 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005121 Constructor == E->getConstructor() &&
5122 OperatorNew == E->getOperatorNew() &&
5123 OperatorDelete == E->getOperatorDelete() &&
5124 !ArgumentChanged) {
5125 // Mark any declarations we need as referenced.
5126 // FIXME: instantiation-specific.
5127 if (Constructor)
5128 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5129 if (OperatorNew)
5130 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5131 if (OperatorDelete)
5132 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005133 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005134 }
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005136 if (!ArraySize.get()) {
5137 // If no array size was specified, but the new expression was
5138 // instantiated with an array type (e.g., "new T" where T is
5139 // instantiated with "int[4]"), extract the outer bound from the
5140 // array type as our array size. We do this with constant and
5141 // dependently-sized array types.
5142 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5143 if (!ArrayT) {
5144 // Do nothing
5145 } else if (const ConstantArrayType *ConsArrayT
5146 = dyn_cast<ConstantArrayType>(ArrayT)) {
5147 ArraySize
5148 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
5149 ConsArrayT->getSize(),
5150 SemaRef.Context.getSizeType(),
5151 /*FIXME:*/E->getLocStart()));
5152 AllocType = ConsArrayT->getElementType();
5153 } else if (const DependentSizedArrayType *DepArrayT
5154 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5155 if (DepArrayT->getSizeExpr()) {
5156 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5157 AllocType = DepArrayT->getElementType();
5158 }
5159 }
5160 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5162 E->isGlobalNew(),
5163 /*FIXME:*/E->getLocStart(),
5164 move_arg(PlacementArgs),
5165 /*FIXME:*/E->getLocStart(),
5166 E->isParenTypeId(),
5167 AllocType,
5168 /*FIXME:*/E->getLocStart(),
5169 /*FIXME:*/SourceRange(),
5170 move(ArraySize),
5171 /*FIXME:*/E->getLocStart(),
5172 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005173 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005174}
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregora16548e2009-08-11 05:31:07 +00005176template<typename Derived>
5177Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005178TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005179 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5180 if (Operand.isInvalid())
5181 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregord2d9da02010-02-26 00:38:10 +00005183 // Transform the delete operator, if known.
5184 FunctionDecl *OperatorDelete = 0;
5185 if (E->getOperatorDelete()) {
5186 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005187 getDerived().TransformDecl(E->getLocStart(),
5188 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005189 if (!OperatorDelete)
5190 return SemaRef.ExprError();
5191 }
5192
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005194 Operand.get() == E->getArgument() &&
5195 OperatorDelete == E->getOperatorDelete()) {
5196 // Mark any declarations we need as referenced.
5197 // FIXME: instantiation-specific.
5198 if (OperatorDelete)
5199 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005200 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005201 }
Mike Stump11289f42009-09-09 15:08:12 +00005202
Douglas Gregora16548e2009-08-11 05:31:07 +00005203 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5204 E->isGlobalDelete(),
5205 E->isArrayForm(),
5206 move(Operand));
5207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
Douglas Gregora16548e2009-08-11 05:31:07 +00005209template<typename Derived>
5210Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005211TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005212 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005213 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5214 if (Base.isInvalid())
5215 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregor678f90d2010-02-25 01:56:36 +00005217 Sema::TypeTy *ObjectTypePtr = 0;
5218 bool MayBePseudoDestructor = false;
5219 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5220 E->getOperatorLoc(),
5221 E->isArrow()? tok::arrow : tok::period,
5222 ObjectTypePtr,
5223 MayBePseudoDestructor);
5224 if (Base.isInvalid())
5225 return SemaRef.ExprError();
5226
5227 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005228 NestedNameSpecifier *Qualifier
5229 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005230 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005231 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005232 if (E->getQualifier() && !Qualifier)
5233 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregor678f90d2010-02-25 01:56:36 +00005235 PseudoDestructorTypeStorage Destroyed;
5236 if (E->getDestroyedTypeInfo()) {
5237 TypeSourceInfo *DestroyedTypeInfo
5238 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5239 if (!DestroyedTypeInfo)
5240 return SemaRef.ExprError();
5241 Destroyed = DestroyedTypeInfo;
5242 } else if (ObjectType->isDependentType()) {
5243 // We aren't likely to be able to resolve the identifier down to a type
5244 // now anyway, so just retain the identifier.
5245 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5246 E->getDestroyedTypeLoc());
5247 } else {
5248 // Look for a destructor known with the given name.
5249 CXXScopeSpec SS;
5250 if (Qualifier) {
5251 SS.setScopeRep(Qualifier);
5252 SS.setRange(E->getQualifierRange());
5253 }
5254
5255 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5256 *E->getDestroyedTypeIdentifier(),
5257 E->getDestroyedTypeLoc(),
5258 /*Scope=*/0,
5259 SS, ObjectTypePtr,
5260 false);
5261 if (!T)
5262 return SemaRef.ExprError();
5263
5264 Destroyed
5265 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5266 E->getDestroyedTypeLoc());
5267 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005268
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005269 TypeSourceInfo *ScopeTypeInfo = 0;
5270 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005271 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5272 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005273 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005274 return SemaRef.ExprError();
5275 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005276
Douglas Gregorad8a3362009-09-04 17:36:40 +00005277 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5278 E->getOperatorLoc(),
5279 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005280 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005281 E->getQualifierRange(),
5282 ScopeTypeInfo,
5283 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005284 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005285 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005286}
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregorad8a3362009-09-04 17:36:40 +00005288template<typename Derived>
5289Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005290TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005291 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005292 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5293
5294 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5295 Sema::LookupOrdinaryName);
5296
5297 // Transform all the decls.
5298 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5299 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005300 NamedDecl *InstD = static_cast<NamedDecl*>(
5301 getDerived().TransformDecl(Old->getNameLoc(),
5302 *I));
John McCall84d87672009-12-10 09:41:52 +00005303 if (!InstD) {
5304 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5305 // This can happen because of dependent hiding.
5306 if (isa<UsingShadowDecl>(*I))
5307 continue;
5308 else
5309 return SemaRef.ExprError();
5310 }
John McCalle66edc12009-11-24 19:00:30 +00005311
5312 // Expand using declarations.
5313 if (isa<UsingDecl>(InstD)) {
5314 UsingDecl *UD = cast<UsingDecl>(InstD);
5315 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5316 E = UD->shadow_end(); I != E; ++I)
5317 R.addDecl(*I);
5318 continue;
5319 }
5320
5321 R.addDecl(InstD);
5322 }
5323
5324 // Resolve a kind, but don't do any further analysis. If it's
5325 // ambiguous, the callee needs to deal with it.
5326 R.resolveKind();
5327
5328 // Rebuild the nested-name qualifier, if present.
5329 CXXScopeSpec SS;
5330 NestedNameSpecifier *Qualifier = 0;
5331 if (Old->getQualifier()) {
5332 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005333 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005334 if (!Qualifier)
5335 return SemaRef.ExprError();
5336
5337 SS.setScopeRep(Qualifier);
5338 SS.setRange(Old->getQualifierRange());
5339 }
5340
5341 // If we have no template arguments, it's a normal declaration name.
5342 if (!Old->hasExplicitTemplateArgs())
5343 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5344
5345 // If we have template arguments, rebuild them, then rebuild the
5346 // templateid expression.
5347 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5348 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5349 TemplateArgumentLoc Loc;
5350 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5351 return SemaRef.ExprError();
5352 TransArgs.addArgument(Loc);
5353 }
5354
5355 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5356 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359template<typename Derived>
5360Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005361TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005362 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregora16548e2009-08-11 05:31:07 +00005364 QualType T = getDerived().TransformType(E->getQueriedType());
5365 if (T.isNull())
5366 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005367
Douglas Gregora16548e2009-08-11 05:31:07 +00005368 if (!getDerived().AlwaysRebuild() &&
5369 T == E->getQueriedType())
5370 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005371
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 // FIXME: Bad location information
5373 SourceLocation FakeLParenLoc
5374 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005375
5376 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005377 E->getLocStart(),
5378 /*FIXME:*/FakeLParenLoc,
5379 T,
5380 E->getLocEnd());
5381}
Mike Stump11289f42009-09-09 15:08:12 +00005382
Douglas Gregora16548e2009-08-11 05:31:07 +00005383template<typename Derived>
5384Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005385TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005386 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005388 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005389 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 if (!NNS)
5391 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005392
5393 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005394 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5395 if (!Name)
5396 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005397
John McCalle66edc12009-11-24 19:00:30 +00005398 if (!E->hasExplicitTemplateArgs()) {
5399 if (!getDerived().AlwaysRebuild() &&
5400 NNS == E->getQualifier() &&
5401 Name == E->getDeclName())
5402 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005403
John McCalle66edc12009-11-24 19:00:30 +00005404 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5405 E->getQualifierRange(),
5406 Name, E->getLocation(),
5407 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005408 }
John McCall6b51f282009-11-23 01:53:49 +00005409
5410 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005411 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005412 TemplateArgumentLoc Loc;
5413 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005415 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005416 }
5417
John McCalle66edc12009-11-24 19:00:30 +00005418 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5419 E->getQualifierRange(),
5420 Name, E->getLocation(),
5421 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005422}
5423
5424template<typename Derived>
5425Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005426TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005427 // CXXConstructExprs are always implicit, so when we have a
5428 // 1-argument construction we just transform that argument.
5429 if (E->getNumArgs() == 1 ||
5430 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5431 return getDerived().TransformExpr(E->getArg(0));
5432
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5434
5435 QualType T = getDerived().TransformType(E->getType());
5436 if (T.isNull())
5437 return SemaRef.ExprError();
5438
5439 CXXConstructorDecl *Constructor
5440 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005441 getDerived().TransformDecl(E->getLocStart(),
5442 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005443 if (!Constructor)
5444 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 bool ArgumentChanged = false;
5447 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005448 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005449 ArgEnd = E->arg_end();
5450 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005451 if (getDerived().DropCallArgument(*Arg)) {
5452 ArgumentChanged = true;
5453 break;
5454 }
5455
Douglas Gregora16548e2009-08-11 05:31:07 +00005456 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5457 if (TransArg.isInvalid())
5458 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005459
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5461 Args.push_back(TransArg.takeAs<Expr>());
5462 }
5463
5464 if (!getDerived().AlwaysRebuild() &&
5465 T == E->getType() &&
5466 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005467 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005468 // Mark the constructor as referenced.
5469 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005470 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005471 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005472 }
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregordb121ba2009-12-14 16:27:04 +00005474 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5475 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 move_arg(Args));
5477}
Mike Stump11289f42009-09-09 15:08:12 +00005478
Douglas Gregora16548e2009-08-11 05:31:07 +00005479/// \brief Transform a C++ temporary-binding expression.
5480///
Douglas Gregor363b1512009-12-24 18:51:59 +00005481/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5482/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005483template<typename Derived>
5484Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005485TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005486 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005487}
Mike Stump11289f42009-09-09 15:08:12 +00005488
Anders Carlssonba6c4372010-01-29 02:39:32 +00005489/// \brief Transform a C++ reference-binding expression.
5490///
5491/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5492/// transform the subexpression and return that.
5493template<typename Derived>
5494Sema::OwningExprResult
5495TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5496 return getDerived().TransformExpr(E->getSubExpr());
5497}
5498
Mike Stump11289f42009-09-09 15:08:12 +00005499/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005500/// be destroyed after the expression is evaluated.
5501///
Douglas Gregor363b1512009-12-24 18:51:59 +00005502/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5503/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005504template<typename Derived>
5505Sema::OwningExprResult
5506TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005507 CXXExprWithTemporaries *E) {
5508 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005509}
Mike Stump11289f42009-09-09 15:08:12 +00005510
Douglas Gregora16548e2009-08-11 05:31:07 +00005511template<typename Derived>
5512Sema::OwningExprResult
5513TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005514 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005515 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5516 QualType T = getDerived().TransformType(E->getType());
5517 if (T.isNull())
5518 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 CXXConstructorDecl *Constructor
5521 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005522 getDerived().TransformDecl(E->getLocStart(),
5523 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 if (!Constructor)
5525 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 bool ArgumentChanged = false;
5528 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5529 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005530 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 ArgEnd = E->arg_end();
5532 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005533 if (getDerived().DropCallArgument(*Arg)) {
5534 ArgumentChanged = true;
5535 break;
5536 }
5537
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5539 if (TransArg.isInvalid())
5540 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005541
Douglas Gregora16548e2009-08-11 05:31:07 +00005542 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5543 Args.push_back((Expr *)TransArg.release());
5544 }
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 if (!getDerived().AlwaysRebuild() &&
5547 T == E->getType() &&
5548 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005549 !ArgumentChanged) {
5550 // FIXME: Instantiation-specific
5551 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005552 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005553 }
Mike Stump11289f42009-09-09 15:08:12 +00005554
Douglas Gregora16548e2009-08-11 05:31:07 +00005555 // FIXME: Bogus location information
5556 SourceLocation CommaLoc;
5557 if (Args.size() > 1) {
5558 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005559 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5561 }
5562 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5563 T,
5564 /*FIXME:*/E->getTypeBeginLoc(),
5565 move_arg(Args),
5566 &CommaLoc,
5567 E->getLocEnd());
5568}
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregora16548e2009-08-11 05:31:07 +00005570template<typename Derived>
5571Sema::OwningExprResult
5572TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005573 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005574 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5575 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5576 if (T.isNull())
5577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 bool ArgumentChanged = false;
5580 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5581 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5582 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5583 ArgEnd = E->arg_end();
5584 Arg != ArgEnd; ++Arg) {
5585 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5586 if (TransArg.isInvalid())
5587 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5590 FakeCommaLocs.push_back(
5591 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5592 Args.push_back(TransArg.takeAs<Expr>());
5593 }
Mike Stump11289f42009-09-09 15:08:12 +00005594
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 if (!getDerived().AlwaysRebuild() &&
5596 T == E->getTypeAsWritten() &&
5597 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005598 return SemaRef.Owned(E->Retain());
5599
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 // FIXME: we're faking the locations of the commas
5601 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5602 T,
5603 E->getLParenLoc(),
5604 move_arg(Args),
5605 FakeCommaLocs.data(),
5606 E->getRParenLoc());
5607}
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregora16548e2009-08-11 05:31:07 +00005609template<typename Derived>
5610Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005611TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005612 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005614 OwningExprResult Base(SemaRef, (Expr*) 0);
5615 Expr *OldBase;
5616 QualType BaseType;
5617 QualType ObjectType;
5618 if (!E->isImplicitAccess()) {
5619 OldBase = E->getBase();
5620 Base = getDerived().TransformExpr(OldBase);
5621 if (Base.isInvalid())
5622 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005623
John McCall2d74de92009-12-01 22:10:20 +00005624 // Start the member reference and compute the object's type.
5625 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005626 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005627 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5628 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005629 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005630 ObjectTy,
5631 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005632 if (Base.isInvalid())
5633 return SemaRef.ExprError();
5634
5635 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5636 BaseType = ((Expr*) Base.get())->getType();
5637 } else {
5638 OldBase = 0;
5639 BaseType = getDerived().TransformType(E->getBaseType());
5640 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5641 }
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005643 // Transform the first part of the nested-name-specifier that qualifies
5644 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005645 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005646 = getDerived().TransformFirstQualifierInScope(
5647 E->getFirstQualifierFoundInScope(),
5648 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005650 NestedNameSpecifier *Qualifier = 0;
5651 if (E->getQualifier()) {
5652 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5653 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005654 ObjectType,
5655 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005656 if (!Qualifier)
5657 return SemaRef.ExprError();
5658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
5660 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005661 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005662 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005663 if (!Name)
5664 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
John McCall2d74de92009-12-01 22:10:20 +00005666 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005667 // This is a reference to a member without an explicitly-specified
5668 // template argument list. Optimize for this common case.
5669 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005670 Base.get() == OldBase &&
5671 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005672 Qualifier == E->getQualifier() &&
5673 Name == E->getMember() &&
5674 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005675 return SemaRef.Owned(E->Retain());
5676
John McCall8cd78132009-11-19 22:55:06 +00005677 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005678 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005679 E->isArrow(),
5680 E->getOperatorLoc(),
5681 Qualifier,
5682 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005683 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005684 Name,
5685 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005686 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005687 }
5688
John McCall6b51f282009-11-23 01:53:49 +00005689 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005690 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005691 TemplateArgumentLoc Loc;
5692 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005693 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005694 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
John McCall8cd78132009-11-19 22:55:06 +00005697 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005698 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 E->isArrow(),
5700 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005701 Qualifier,
5702 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005703 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005704 Name,
5705 E->getMemberLoc(),
5706 &TransArgs);
5707}
5708
5709template<typename Derived>
5710Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005711TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005712 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005713 OwningExprResult Base(SemaRef, (Expr*) 0);
5714 QualType BaseType;
5715 if (!Old->isImplicitAccess()) {
5716 Base = getDerived().TransformExpr(Old->getBase());
5717 if (Base.isInvalid())
5718 return SemaRef.ExprError();
5719 BaseType = ((Expr*) Base.get())->getType();
5720 } else {
5721 BaseType = getDerived().TransformType(Old->getBaseType());
5722 }
John McCall10eae182009-11-30 22:42:35 +00005723
5724 NestedNameSpecifier *Qualifier = 0;
5725 if (Old->getQualifier()) {
5726 Qualifier
5727 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005728 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005729 if (Qualifier == 0)
5730 return SemaRef.ExprError();
5731 }
5732
5733 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5734 Sema::LookupOrdinaryName);
5735
5736 // Transform all the decls.
5737 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5738 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005739 NamedDecl *InstD = static_cast<NamedDecl*>(
5740 getDerived().TransformDecl(Old->getMemberLoc(),
5741 *I));
John McCall84d87672009-12-10 09:41:52 +00005742 if (!InstD) {
5743 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5744 // This can happen because of dependent hiding.
5745 if (isa<UsingShadowDecl>(*I))
5746 continue;
5747 else
5748 return SemaRef.ExprError();
5749 }
John McCall10eae182009-11-30 22:42:35 +00005750
5751 // Expand using declarations.
5752 if (isa<UsingDecl>(InstD)) {
5753 UsingDecl *UD = cast<UsingDecl>(InstD);
5754 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5755 E = UD->shadow_end(); I != E; ++I)
5756 R.addDecl(*I);
5757 continue;
5758 }
5759
5760 R.addDecl(InstD);
5761 }
5762
5763 R.resolveKind();
5764
5765 TemplateArgumentListInfo TransArgs;
5766 if (Old->hasExplicitTemplateArgs()) {
5767 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5768 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5769 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5770 TemplateArgumentLoc Loc;
5771 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5772 Loc))
5773 return SemaRef.ExprError();
5774 TransArgs.addArgument(Loc);
5775 }
5776 }
John McCall38836f02010-01-15 08:34:02 +00005777
5778 // FIXME: to do this check properly, we will need to preserve the
5779 // first-qualifier-in-scope here, just in case we had a dependent
5780 // base (and therefore couldn't do the check) and a
5781 // nested-name-qualifier (and therefore could do the lookup).
5782 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005783
5784 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005785 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005786 Old->getOperatorLoc(),
5787 Old->isArrow(),
5788 Qualifier,
5789 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005790 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005791 R,
5792 (Old->hasExplicitTemplateArgs()
5793 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005794}
5795
5796template<typename Derived>
5797Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005798TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005799 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005800}
5801
Mike Stump11289f42009-09-09 15:08:12 +00005802template<typename Derived>
5803Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005804TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005805 TypeSourceInfo *EncodedTypeInfo
5806 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5807 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005809
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005811 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005812 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005813
5814 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005815 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005816 E->getRParenLoc());
5817}
Mike Stump11289f42009-09-09 15:08:12 +00005818
Douglas Gregora16548e2009-08-11 05:31:07 +00005819template<typename Derived>
5820Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005821TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005822 // Transform arguments.
5823 bool ArgChanged = false;
5824 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5825 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5826 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5827 if (Arg.isInvalid())
5828 return SemaRef.ExprError();
5829
5830 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5831 Args.push_back(Arg.takeAs<Expr>());
5832 }
5833
5834 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5835 // Class message: transform the receiver type.
5836 TypeSourceInfo *ReceiverTypeInfo
5837 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5838 if (!ReceiverTypeInfo)
5839 return SemaRef.ExprError();
5840
5841 // If nothing changed, just retain the existing message send.
5842 if (!getDerived().AlwaysRebuild() &&
5843 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5844 return SemaRef.Owned(E->Retain());
5845
5846 // Build a new class message send.
5847 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5848 E->getSelector(),
5849 E->getMethodDecl(),
5850 E->getLeftLoc(),
5851 move_arg(Args),
5852 E->getRightLoc());
5853 }
5854
5855 // Instance message: transform the receiver
5856 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5857 "Only class and instance messages may be instantiated");
5858 OwningExprResult Receiver
5859 = getDerived().TransformExpr(E->getInstanceReceiver());
5860 if (Receiver.isInvalid())
5861 return SemaRef.ExprError();
5862
5863 // If nothing changed, just retain the existing message send.
5864 if (!getDerived().AlwaysRebuild() &&
5865 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5866 return SemaRef.Owned(E->Retain());
5867
5868 // Build a new instance message send.
5869 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5870 E->getSelector(),
5871 E->getMethodDecl(),
5872 E->getLeftLoc(),
5873 move_arg(Args),
5874 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005875}
5876
Mike Stump11289f42009-09-09 15:08:12 +00005877template<typename Derived>
5878Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005879TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005880 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005881}
5882
Mike Stump11289f42009-09-09 15:08:12 +00005883template<typename Derived>
5884Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005885TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005886 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005887}
5888
Mike Stump11289f42009-09-09 15:08:12 +00005889template<typename Derived>
5890Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005891TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005892 // Transform the base expression.
5893 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5894 if (Base.isInvalid())
5895 return SemaRef.ExprError();
5896
5897 // We don't need to transform the ivar; it will never change.
5898
5899 // If nothing changed, just retain the existing expression.
5900 if (!getDerived().AlwaysRebuild() &&
5901 Base.get() == E->getBase())
5902 return SemaRef.Owned(E->Retain());
5903
5904 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
5905 E->getLocation(),
5906 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00005907}
5908
Mike Stump11289f42009-09-09 15:08:12 +00005909template<typename Derived>
5910Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005911TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00005912 // Transform the base expression.
5913 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5914 if (Base.isInvalid())
5915 return SemaRef.ExprError();
5916
5917 // We don't need to transform the property; it will never change.
5918
5919 // If nothing changed, just retain the existing expression.
5920 if (!getDerived().AlwaysRebuild() &&
5921 Base.get() == E->getBase())
5922 return SemaRef.Owned(E->Retain());
5923
5924 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
5925 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00005926}
5927
Mike Stump11289f42009-09-09 15:08:12 +00005928template<typename Derived>
5929Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005930TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005931 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00005932 // If this implicit setter/getter refers to class methods, it cannot have any
5933 // dependent parts. Just retain the existing declaration.
5934 if (E->getInterfaceDecl())
5935 return SemaRef.Owned(E->Retain());
5936
5937 // Transform the base expression.
5938 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5939 if (Base.isInvalid())
5940 return SemaRef.ExprError();
5941
5942 // We don't need to transform the getters/setters; they will never change.
5943
5944 // If nothing changed, just retain the existing expression.
5945 if (!getDerived().AlwaysRebuild() &&
5946 Base.get() == E->getBase())
5947 return SemaRef.Owned(E->Retain());
5948
5949 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
5950 E->getGetterMethod(),
5951 E->getType(),
5952 E->getSetterMethod(),
5953 E->getLocation(),
5954 move(Base));
5955
Douglas Gregora16548e2009-08-11 05:31:07 +00005956}
5957
Mike Stump11289f42009-09-09 15:08:12 +00005958template<typename Derived>
5959Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005960TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005961 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005962 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005963}
5964
Mike Stump11289f42009-09-09 15:08:12 +00005965template<typename Derived>
5966Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005967TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005968 // Transform the base expression.
5969 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5970 if (Base.isInvalid())
5971 return SemaRef.ExprError();
5972
5973 // If nothing changed, just retain the existing expression.
5974 if (!getDerived().AlwaysRebuild() &&
5975 Base.get() == E->getBase())
5976 return SemaRef.Owned(E->Retain());
5977
5978 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
5979 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00005980}
5981
Mike Stump11289f42009-09-09 15:08:12 +00005982template<typename Derived>
5983Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005984TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 bool ArgumentChanged = false;
5986 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5987 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5988 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5989 if (SubExpr.isInvalid())
5990 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005991
Douglas Gregora16548e2009-08-11 05:31:07 +00005992 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5993 SubExprs.push_back(SubExpr.takeAs<Expr>());
5994 }
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 if (!getDerived().AlwaysRebuild() &&
5997 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005998 return SemaRef.Owned(E->Retain());
5999
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6001 move_arg(SubExprs),
6002 E->getRParenLoc());
6003}
6004
Mike Stump11289f42009-09-09 15:08:12 +00006005template<typename Derived>
6006Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 // FIXME: Implement this!
6009 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006010 return SemaRef.Owned(E->Retain());
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>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 // FIXME: Implement this!
6017 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006018 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006019}
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006022// Type reconstruction
6023//===----------------------------------------------------------------------===//
6024
Mike Stump11289f42009-09-09 15:08:12 +00006025template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006026QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6027 SourceLocation Star) {
6028 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006029 getDerived().getBaseEntity());
6030}
6031
Mike Stump11289f42009-09-09 15:08:12 +00006032template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006033QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6034 SourceLocation Star) {
6035 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006036 getDerived().getBaseEntity());
6037}
6038
Mike Stump11289f42009-09-09 15:08:12 +00006039template<typename Derived>
6040QualType
John McCall70dd5f62009-10-30 00:06:24 +00006041TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6042 bool WrittenAsLValue,
6043 SourceLocation Sigil) {
6044 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6045 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006046}
6047
6048template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006049QualType
John McCall70dd5f62009-10-30 00:06:24 +00006050TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6051 QualType ClassType,
6052 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006053 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006054 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006055}
6056
6057template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006058QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006059TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6060 ArrayType::ArraySizeModifier SizeMod,
6061 const llvm::APInt *Size,
6062 Expr *SizeExpr,
6063 unsigned IndexTypeQuals,
6064 SourceRange BracketsRange) {
6065 if (SizeExpr || !Size)
6066 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6067 IndexTypeQuals, BracketsRange,
6068 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006069
6070 QualType Types[] = {
6071 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6072 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6073 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006074 };
6075 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6076 QualType SizeType;
6077 for (unsigned I = 0; I != NumTypes; ++I)
6078 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6079 SizeType = Types[I];
6080 break;
6081 }
Mike Stump11289f42009-09-09 15:08:12 +00006082
Douglas Gregord6ff3322009-08-04 16:50:30 +00006083 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006084 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006085 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006086 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006087}
Mike Stump11289f42009-09-09 15:08:12 +00006088
Douglas Gregord6ff3322009-08-04 16:50:30 +00006089template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006090QualType
6091TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006092 ArrayType::ArraySizeModifier SizeMod,
6093 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006094 unsigned IndexTypeQuals,
6095 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006096 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006097 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006098}
6099
6100template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006101QualType
Mike Stump11289f42009-09-09 15:08:12 +00006102TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006103 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006104 unsigned IndexTypeQuals,
6105 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006106 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006107 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006108}
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregord6ff3322009-08-04 16:50:30 +00006110template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006111QualType
6112TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006113 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006114 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006115 unsigned IndexTypeQuals,
6116 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006117 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006118 SizeExpr.takeAs<Expr>(),
6119 IndexTypeQuals, BracketsRange);
6120}
6121
6122template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006123QualType
6124TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006125 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006126 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006127 unsigned IndexTypeQuals,
6128 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006129 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006130 SizeExpr.takeAs<Expr>(),
6131 IndexTypeQuals, BracketsRange);
6132}
6133
6134template<typename Derived>
6135QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006136 unsigned NumElements,
6137 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006138 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006139 return SemaRef.Context.getVectorType(ElementType, NumElements,
6140 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006141}
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregord6ff3322009-08-04 16:50:30 +00006143template<typename Derived>
6144QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6145 unsigned NumElements,
6146 SourceLocation AttributeLoc) {
6147 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6148 NumElements, true);
6149 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006150 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006151 AttributeLoc);
6152 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6153 AttributeLoc);
6154}
Mike Stump11289f42009-09-09 15:08:12 +00006155
Douglas Gregord6ff3322009-08-04 16:50:30 +00006156template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006157QualType
6158TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006160 SourceLocation AttributeLoc) {
6161 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6162}
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregord6ff3322009-08-04 16:50:30 +00006164template<typename Derived>
6165QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006166 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006167 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006168 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006169 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006170 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006171 Quals,
6172 getDerived().getBaseLocation(),
6173 getDerived().getBaseEntity());
6174}
Mike Stump11289f42009-09-09 15:08:12 +00006175
Douglas Gregord6ff3322009-08-04 16:50:30 +00006176template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006177QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6178 return SemaRef.Context.getFunctionNoProtoType(T);
6179}
6180
6181template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006182QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6183 assert(D && "no decl found");
6184 if (D->isInvalidDecl()) return QualType();
6185
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006186 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006187 TypeDecl *Ty;
6188 if (isa<UsingDecl>(D)) {
6189 UsingDecl *Using = cast<UsingDecl>(D);
6190 assert(Using->isTypeName() &&
6191 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6192
6193 // A valid resolved using typename decl points to exactly one type decl.
6194 assert(++Using->shadow_begin() == Using->shadow_end());
6195 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6196
6197 } else {
6198 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6199 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6200 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6201 }
6202
6203 return SemaRef.Context.getTypeDeclType(Ty);
6204}
6205
6206template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006207QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006208 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6209}
6210
6211template<typename Derived>
6212QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6213 return SemaRef.Context.getTypeOfType(Underlying);
6214}
6215
6216template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006217QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006218 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6219}
6220
6221template<typename Derived>
6222QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006223 TemplateName Template,
6224 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006225 const TemplateArgumentListInfo &TemplateArgs) {
6226 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006227}
Mike Stump11289f42009-09-09 15:08:12 +00006228
Douglas Gregor1135c352009-08-06 05:28:30 +00006229template<typename Derived>
6230NestedNameSpecifier *
6231TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6232 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006233 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006234 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006235 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006236 CXXScopeSpec SS;
6237 // FIXME: The source location information is all wrong.
6238 SS.setRange(Range);
6239 SS.setScopeRep(Prefix);
6240 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006241 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006242 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006243 ObjectType,
6244 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006245 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006246}
6247
6248template<typename Derived>
6249NestedNameSpecifier *
6250TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6251 SourceRange Range,
6252 NamespaceDecl *NS) {
6253 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6254}
6255
6256template<typename Derived>
6257NestedNameSpecifier *
6258TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6259 SourceRange Range,
6260 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006261 QualType T) {
6262 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006263 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006264 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006265 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6266 T.getTypePtr());
6267 }
Mike Stump11289f42009-09-09 15:08:12 +00006268
Douglas Gregor1135c352009-08-06 05:28:30 +00006269 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6270 return 0;
6271}
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregor71dc5092009-08-06 06:41:21 +00006273template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006274TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006275TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6276 bool TemplateKW,
6277 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006278 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006279 Template);
6280}
6281
6282template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006283TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006284TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006285 const IdentifierInfo &II,
6286 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006287 CXXScopeSpec SS;
6288 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006289 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006290 UnqualifiedId Name;
6291 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006292 return getSema().ActOnDependentTemplateName(
6293 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006294 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006295 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006296 ObjectType.getAsOpaquePtr(),
6297 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006298 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006299}
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006302TemplateName
6303TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6304 OverloadedOperatorKind Operator,
6305 QualType ObjectType) {
6306 CXXScopeSpec SS;
6307 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6308 SS.setScopeRep(Qualifier);
6309 UnqualifiedId Name;
6310 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6311 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6312 Operator, SymbolLocations);
6313 return getSema().ActOnDependentTemplateName(
6314 /*FIXME:*/getDerived().getBaseLocation(),
6315 SS,
6316 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006317 ObjectType.getAsOpaquePtr(),
6318 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006319 .template getAsVal<TemplateName>();
6320}
6321
6322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006323Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006324TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6325 SourceLocation OpLoc,
6326 ExprArg Callee,
6327 ExprArg First,
6328 ExprArg Second) {
6329 Expr *FirstExpr = (Expr *)First.get();
6330 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006331 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006333
Douglas Gregora16548e2009-08-11 05:31:07 +00006334 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006335 if (Op == OO_Subscript) {
6336 if (!FirstExpr->getType()->isOverloadableType() &&
6337 !SecondExpr->getType()->isOverloadableType())
6338 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006339 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006340 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006341 } else if (Op == OO_Arrow) {
6342 // -> is never a builtin operation.
6343 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006344 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 if (!FirstExpr->getType()->isOverloadableType()) {
6346 // The argument is not of overloadable type, so try to create a
6347 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006348 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006349 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006350
Douglas Gregora16548e2009-08-11 05:31:07 +00006351 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6352 }
6353 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006354 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006355 !SecondExpr->getType()->isOverloadableType()) {
6356 // Neither of the arguments is an overloadable type, so try to
6357 // create a built-in binary operation.
6358 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006359 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006360 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6361 if (Result.isInvalid())
6362 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregora16548e2009-08-11 05:31:07 +00006364 First.release();
6365 Second.release();
6366 return move(Result);
6367 }
6368 }
Mike Stump11289f42009-09-09 15:08:12 +00006369
6370 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006371 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006372 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006373
John McCalld14a8642009-11-21 08:51:07 +00006374 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6375 assert(ULE->requiresADL());
6376
6377 // FIXME: Do we have to check
6378 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006379 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006380 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006381 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006382 }
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregora16548e2009-08-11 05:31:07 +00006384 // Add any functions found via argument-dependent lookup.
6385 Expr *Args[2] = { FirstExpr, SecondExpr };
6386 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006387
Douglas Gregora16548e2009-08-11 05:31:07 +00006388 // Create the overloaded operator invocation for unary operators.
6389 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006390 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6392 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6393 }
Mike Stump11289f42009-09-09 15:08:12 +00006394
Sebastian Redladba46e2009-10-29 20:17:01 +00006395 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006396 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6397 OpLoc,
6398 move(First),
6399 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006400
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006402 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006403 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006404 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006405 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6406 if (Result.isInvalid())
6407 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 First.release();
6410 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006411 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006414template<typename Derived>
6415Sema::OwningExprResult
6416TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6417 SourceLocation OperatorLoc,
6418 bool isArrow,
6419 NestedNameSpecifier *Qualifier,
6420 SourceRange QualifierRange,
6421 TypeSourceInfo *ScopeType,
6422 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006423 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006424 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006425 CXXScopeSpec SS;
6426 if (Qualifier) {
6427 SS.setRange(QualifierRange);
6428 SS.setScopeRep(Qualifier);
6429 }
6430
6431 Expr *BaseE = (Expr *)Base.get();
6432 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006433 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006434 (!isArrow && !BaseType->getAs<RecordType>()) ||
6435 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006436 !BaseType->getAs<PointerType>()->getPointeeType()
6437 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006438 // This pseudo-destructor expression is still a pseudo-destructor.
6439 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6440 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006441 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006442 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006443 /*FIXME?*/true);
6444 }
6445
Douglas Gregor678f90d2010-02-25 01:56:36 +00006446 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006447 DeclarationName Name
6448 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6449 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6450
6451 // FIXME: the ScopeType should be tacked onto SS.
6452
6453 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6454 OperatorLoc, isArrow,
6455 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006456 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006457 /*TemplateArgs*/ 0);
6458}
6459
Douglas Gregord6ff3322009-08-04 16:50:30 +00006460} // end namespace clang
6461
6462#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H