blob: 4e32897df62f1ec70ee053b03c5cb980e60e710a [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregore677daf2010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000577 // Fall through.
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 case ETK_Typename:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000579 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
Douglas Gregore677daf2010-03-31 22:19:08 +0000580
581 case ETK_Class: Kind = TagDecl::TK_class; break;
582 case ETK_Struct: Kind = TagDecl::TK_struct; break;
583 case ETK_Union: Kind = TagDecl::TK_union; break;
584 case ETK_Enum: Kind = TagDecl::TK_enum; break;
585 }
586
587 // We had a dependent elaborated-type-specifier that as been transformed
588 // into a non-dependent elaborated-type-specifier. Find the tag we're
589 // referring to.
590 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
591 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
592 if (!DC)
593 return QualType();
594
595 TagDecl *Tag = 0;
596 SemaRef.LookupQualifiedName(Result, DC);
597 switch (Result.getResultKind()) {
598 case LookupResult::NotFound:
599 case LookupResult::NotFoundInCurrentInstantiation:
600 break;
601
602 case LookupResult::Found:
603 Tag = Result.getAsSingle<TagDecl>();
604 break;
605
606 case LookupResult::FoundOverloaded:
607 case LookupResult::FoundUnresolvedValue:
608 llvm_unreachable("Tag lookup cannot find non-tags");
609 return QualType();
610
611 case LookupResult::Ambiguous:
612 // Let the LookupResult structure handle ambiguities.
613 return QualType();
614 }
615
616 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000617 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000619 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 return QualType();
621 }
622
623 // FIXME: Terrible location information
624 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
625 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
626 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
627 return QualType();
628 }
629
630 // Build the elaborated-type-specifier type.
631 QualType T = SemaRef.Context.getTypeDeclType(Tag);
632 T = SemaRef.Context.getQualifiedNameType(NNS, T);
633 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000634 }
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregor1135c352009-08-06 05:28:30 +0000636 /// \brief Build a new nested-name-specifier given the prefix and an
637 /// identifier that names the next step in the nested-name-specifier.
638 ///
639 /// By default, performs semantic analysis when building the new
640 /// nested-name-specifier. Subclasses may override this routine to provide
641 /// different behavior.
642 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
643 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000644 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000645 QualType ObjectType,
646 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000647
648 /// \brief Build a new nested-name-specifier given the prefix and the
649 /// namespace named in the next step in the nested-name-specifier.
650 ///
651 /// By default, performs semantic analysis when building the new
652 /// nested-name-specifier. Subclasses may override this routine to provide
653 /// different behavior.
654 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
655 SourceRange Range,
656 NamespaceDecl *NS);
657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// type named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000667 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000668
669 /// \brief Build a new template name given a nested name specifier, a flag
670 /// indicating whether the "template" keyword was provided, and the template
671 /// that the template name refers to.
672 ///
673 /// By default, builds the new template name directly. Subclasses may override
674 /// this routine to provide different behavior.
675 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
676 bool TemplateKW,
677 TemplateDecl *Template);
678
Douglas Gregor71dc5092009-08-06 06:41:21 +0000679 /// \brief Build a new template name given a nested name specifier and the
680 /// name that is referred to as a template.
681 ///
682 /// By default, performs semantic analysis to determine whether the name can
683 /// be resolved to a specific template, then builds the appropriate kind of
684 /// template name. Subclasses may override this routine to provide different
685 /// behavior.
686 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000687 const IdentifierInfo &II,
688 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregor71395fa2009-11-04 00:56:37 +0000690 /// \brief Build a new template name given a nested name specifier and the
691 /// overloaded operator name that is referred to as a template.
692 ///
693 /// By default, performs semantic analysis to determine whether the name can
694 /// be resolved to a specific template, then builds the appropriate kind of
695 /// template name. Subclasses may override this routine to provide different
696 /// behavior.
697 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
698 OverloadedOperatorKind Operator,
699 QualType ObjectType);
700
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 /// \brief Build a new compound statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
706 MultiStmtArg Statements,
707 SourceLocation RBraceLoc,
708 bool IsStmtExpr) {
709 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
710 IsStmtExpr);
711 }
712
713 /// \brief Build a new case statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
718 ExprArg LHS,
719 SourceLocation EllipsisLoc,
720 ExprArg RHS,
721 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000722 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 ColonLoc);
724 }
Mike Stump11289f42009-09-09 15:08:12 +0000725
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 /// \brief Attach the body to a new case statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
730 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
731 getSema().ActOnCaseStmtBody(S.get(), move(Body));
732 return move(S);
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new default statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000742 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /*CurScope=*/0);
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Build a new label statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 IdentifierInfo *Id,
752 SourceLocation ColonLoc,
753 StmtArg SubStmt) {
754 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
755 }
Mike Stump11289f42009-09-09 15:08:12 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new "if" statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000761 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000762 VarDecl *CondVar, StmtArg Then,
763 SourceLocation ElseLoc, StmtArg Else) {
764 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
765 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 }
Mike Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 /// \brief Start building a new switch statement.
769 ///
770 /// By default, performs semantic analysis to build the new statement.
771 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000772 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
773 VarDecl *CondVar) {
774 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 }
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 /// \brief Attach the body to the switch statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000781 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 StmtArg Switch, StmtArg Body) {
783 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
784 move(Body));
785 }
786
787 /// \brief Build a new while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
792 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000793 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000795 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
796 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
Mike Stump11289f42009-09-09 15:08:12 +0000798
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 /// \brief Build a new do-while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
803 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
804 SourceLocation WhileLoc,
805 SourceLocation LParenLoc,
806 ExprArg Cond,
807 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000808 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000809 move(Cond), RParenLoc);
810 }
811
812 /// \brief Build a new for statement.
813 ///
814 /// By default, performs semantic analysis to build the new statement.
815 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000816 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000818 StmtArg Init, Sema::FullExprArg Cond,
819 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000821 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
822 DeclPtrTy::make(CondVar),
823 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 }
Mike Stump11289f42009-09-09 15:08:12 +0000825
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 /// \brief Build a new goto statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
831 SourceLocation LabelLoc,
832 LabelStmt *Label) {
833 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
834 }
835
836 /// \brief Build a new indirect goto statement.
837 ///
838 /// By default, performs semantic analysis to build the new statement.
839 /// Subclasses may override this routine to provide different behavior.
840 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
841 SourceLocation StarLoc,
842 ExprArg Target) {
843 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
844 }
Mike Stump11289f42009-09-09 15:08:12 +0000845
Douglas Gregorebe10102009-08-20 07:17:43 +0000846 /// \brief Build a new return statement.
847 ///
848 /// By default, performs semantic analysis to build the new statement.
849 /// Subclasses may override this routine to provide different behavior.
850 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
851 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000852
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregorebe10102009-08-20 07:17:43 +0000856 /// \brief Build a new declaration statement.
857 ///
858 /// By default, performs semantic analysis to build the new statement.
859 /// Subclasses may override this routine to provide different behavior.
860 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000861 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 SourceLocation EndLoc) {
863 return getSema().Owned(
864 new (getSema().Context) DeclStmt(
865 DeclGroupRef::Create(getSema().Context,
866 Decls, NumDecls),
867 StartLoc, EndLoc));
868 }
Mike Stump11289f42009-09-09 15:08:12 +0000869
Anders Carlssonaaeef072010-01-24 05:50:09 +0000870 /// \brief Build a new inline asm statement.
871 ///
872 /// By default, performs semantic analysis to build the new statement.
873 /// Subclasses may override this routine to provide different behavior.
874 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
875 bool IsSimple,
876 bool IsVolatile,
877 unsigned NumOutputs,
878 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000879 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000880 MultiExprArg Constraints,
881 MultiExprArg Exprs,
882 ExprArg AsmString,
883 MultiExprArg Clobbers,
884 SourceLocation RParenLoc,
885 bool MSAsm) {
886 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
887 NumInputs, Names, move(Constraints),
888 move(Exprs), move(AsmString), move(Clobbers),
889 RParenLoc, MSAsm);
890 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000891
892 /// \brief Build a new Objective-C @try statement.
893 ///
894 /// By default, performs semantic analysis to build the new statement.
895 /// Subclasses may override this routine to provide different behavior.
896 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
897 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000898 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000899 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000900 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000901 move(Finally));
902 }
903
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000904 /// \brief Rebuild an Objective-C exception declaration.
905 ///
906 /// By default, performs semantic analysis to build the new declaration.
907 /// Subclasses may override this routine to provide different behavior.
908 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
909 TypeSourceInfo *TInfo, QualType T) {
910 return getSema().BuildObjCExceptionDecl(TInfo, T,
911 ExceptionDecl->getIdentifier(),
912 ExceptionDecl->getLocation());
913 }
914
915 /// \brief Build a new Objective-C @catch statement.
916 ///
917 /// By default, performs semantic analysis to build the new statement.
918 /// Subclasses may override this routine to provide different behavior.
919 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
920 SourceLocation RParenLoc,
921 VarDecl *Var,
922 StmtArg Body) {
923 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
924 Sema::DeclPtrTy::make(Var),
925 move(Body));
926 }
927
Douglas Gregor306de2f2010-04-22 23:59:56 +0000928 /// \brief Build a new Objective-C @finally statement.
929 ///
930 /// By default, performs semantic analysis to build the new statement.
931 /// Subclasses may override this routine to provide different behavior.
932 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
933 StmtArg Body) {
934 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
935 }
Anders Carlssonaaeef072010-01-24 05:50:09 +0000936
Douglas Gregor6148de72010-04-22 22:01:21 +0000937 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
942 ExprArg Operand) {
943 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
944 }
945
Douglas Gregor6148de72010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @synchronized statement.
947 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
951 ExprArg Object,
952 StmtArg Body) {
953 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
954 move(Body));
955 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000956
957 /// \brief Build a new Objective-C fast enumeration statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
961 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
962 SourceLocation LParenLoc,
963 StmtArg Element,
964 ExprArg Collection,
965 SourceLocation RParenLoc,
966 StmtArg Body) {
967 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
968 move(Element),
969 move(Collection),
970 RParenLoc,
971 move(Body));
972 }
Douglas Gregor6148de72010-04-22 22:01:21 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new C++ exception declaration.
975 ///
976 /// By default, performs semantic analysis to build the new decaration.
977 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000978 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000979 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 IdentifierInfo *Name,
981 SourceLocation Loc,
982 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000983 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 TypeRange);
985 }
986
987 /// \brief Build a new C++ catch statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
992 VarDecl *ExceptionDecl,
993 StmtArg Handler) {
994 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000995 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 Handler.takeAs<Stmt>()));
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /// \brief Build a new C++ try statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
1003 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1004 StmtArg TryBlock,
1005 MultiStmtArg Handlers) {
1006 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 /// \brief Build a new expression that references a declaration.
1010 ///
1011 /// By default, performs semantic analysis to build the new expression.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001013 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1014 LookupResult &R,
1015 bool RequiresADL) {
1016 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1017 }
1018
1019
1020 /// \brief Build a new expression that references a declaration.
1021 ///
1022 /// By default, performs semantic analysis to build the new expression.
1023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001024 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1025 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001026 ValueDecl *VD, SourceLocation Loc,
1027 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001028 CXXScopeSpec SS;
1029 SS.setScopeRep(Qualifier);
1030 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001031
1032 // FIXME: loses template args.
1033
1034 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1042 SourceLocation RParen) {
1043 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1044 }
1045
Douglas Gregorad8a3362009-09-04 17:36:40 +00001046 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001047 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// By default, performs semantic analysis to build the new expression.
1049 /// Subclasses may override this routine to provide different behavior.
1050 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1051 SourceLocation OperatorLoc,
1052 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001053 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001054 SourceRange QualifierRange,
1055 TypeSourceInfo *ScopeType,
1056 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001057 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001058 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001061 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1065 UnaryOperator::Opcode Opc,
1066 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001067 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregor882211c2010-04-28 22:16:22 +00001070 /// \brief Build a new builtin offsetof expression.
1071 ///
1072 /// By default, performs semantic analysis to build the new expression.
1073 /// Subclasses may override this routine to provide different behavior.
1074 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1075 TypeSourceInfo *Type,
1076 Action::OffsetOfComponent *Components,
1077 unsigned NumComponents,
1078 SourceLocation RParenLoc) {
1079 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1080 NumComponents, RParenLoc);
1081 }
1082
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001084 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// By default, performs semantic analysis to build the new expression.
1086 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001087 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001088 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001090 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 }
1092
Mike Stump11289f42009-09-09 15:08:12 +00001093 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001095 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// By default, performs semantic analysis to build the new expression.
1097 /// Subclasses may override this routine to provide different behavior.
1098 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1099 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001100 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1102 OpLoc, isSizeOf, R);
1103 if (Result.isInvalid())
1104 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001105
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 SubExpr.release();
1107 return move(Result);
1108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001114 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 SourceLocation LBracketLoc,
1116 ExprArg RHS,
1117 SourceLocation RBracketLoc) {
1118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001119 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 RBracketLoc);
1121 }
1122
1123 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
1127 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1128 MultiExprArg Args,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
1131 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1132 move(Args), CommaLocs, RParenLoc);
1133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
1139 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
1143 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001152 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001153 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1154 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001155 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001156
Mike Stump11289f42009-09-09 15:08:12 +00001157 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001158 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001159 Member, MemberLoc,
1160 cast<FieldDecl>(Member)->getType());
1161 return getSema().Owned(ME);
1162 }
Mike Stump11289f42009-09-09 15:08:12 +00001163
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001164 CXXScopeSpec SS;
1165 if (Qualifier) {
1166 SS.setRange(QualifierRange);
1167 SS.setScopeRep(Qualifier);
1168 }
1169
John McCall2d74de92009-12-01 22:10:20 +00001170 QualType BaseType = ((Expr*) Base.get())->getType();
1171
John McCall16df1e52010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001174 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1175 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001176 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001177 R.resolveKind();
1178
John McCall2d74de92009-12-01 22:10:20 +00001179 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1180 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001181 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001182 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001186 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
1189 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1190 BinaryOperator::Opcode Opc,
1191 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001192 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1193 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 }
1195
1196 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
1200 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1201 SourceLocation QuestionLoc,
1202 ExprArg LHS,
1203 SourceLocation ColonLoc,
1204 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001205 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 move(LHS), move(RHS));
1207 }
1208
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001210 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001213 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1214 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
1216 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001217 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1218 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
1225 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001226 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 SourceLocation RParenLoc,
1228 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001229 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1230 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001234 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001237 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 SourceLocation OpLoc,
1239 SourceLocation AccessorLoc,
1240 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001241
John McCall10eae182009-11-30 22:42:35 +00001242 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001243 QualType BaseType = ((Expr*) Base.get())->getType();
1244 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001245 OpLoc, /*IsArrow*/ false,
1246 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001247 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001248 AccessorLoc,
1249 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001253 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 /// By default, performs semantic analysis to build the new expression.
1255 /// Subclasses may override this routine to provide different behavior.
1256 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1257 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001258 SourceLocation RBraceLoc,
1259 QualType ResultTy) {
1260 OwningExprResult Result
1261 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1262 if (Result.isInvalid() || ResultTy->isDependentType())
1263 return move(Result);
1264
1265 // Patch in the result type we were given, which may have been computed
1266 // when the initial InitListExpr was built.
1267 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1268 ILE->setType(ResultTy);
1269 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 }
Mike Stump11289f42009-09-09 15:08:12 +00001271
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001273 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 /// By default, performs semantic analysis to build the new expression.
1275 /// Subclasses may override this routine to provide different behavior.
1276 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1277 MultiExprArg ArrayExprs,
1278 SourceLocation EqualOrColonLoc,
1279 bool GNUSyntax,
1280 ExprArg Init) {
1281 OwningExprResult Result
1282 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1283 move(Init));
1284 if (Result.isInvalid())
1285 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 ArrayExprs.release();
1288 return move(Result);
1289 }
Mike Stump11289f42009-09-09 15:08:12 +00001290
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001292 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 /// By default, builds the implicit value initialization without performing
1294 /// any semantic analysis. Subclasses may override this routine to provide
1295 /// different behavior.
1296 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1297 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
1304 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1305 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001306 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 RParenLoc);
1308 }
1309
1310 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1315 MultiExprArg SubExprs,
1316 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001317 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1318 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
1323 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// rather than attempting to map the label statement itself.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1327 SourceLocation LabelLoc,
1328 LabelStmt *Label) {
1329 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1337 StmtArg SubStmt,
1338 SourceLocation RParenLoc) {
1339 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_types_compatible_p expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1347 QualType T1, QualType T2,
1348 SourceLocation RParenLoc) {
1349 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1350 T1.getAsOpaquePtr(),
1351 T2.getAsOpaquePtr(),
1352 RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_choose_expr expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
1359 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1360 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1361 SourceLocation RParenLoc) {
1362 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1363 move(Cond), move(LHS), move(RHS),
1364 RParenLoc);
1365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new overloaded operator call expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// The semantic analysis provides the behavior of template instantiation,
1371 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// argument-dependent lookup, etc. Subclasses may override this routine to
1374 /// provide different behavior.
1375 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1376 SourceLocation OpLoc,
1377 ExprArg Callee,
1378 ExprArg First,
1379 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001380
1381 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// reinterpret_cast.
1383 ///
1384 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001385 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// Subclasses may override this routine to provide different behavior.
1387 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1388 Stmt::StmtClass Class,
1389 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001390 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 SourceLocation RAngleLoc,
1392 SourceLocation LParenLoc,
1393 ExprArg SubExpr,
1394 SourceLocation RParenLoc) {
1395 switch (Class) {
1396 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 move(SubExpr), RParenLoc);
1400
1401 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001402 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001403 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001405
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001407 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001408 RAngleLoc, LParenLoc,
1409 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001413 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001414 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 default:
1418 assert(false && "Invalid C++ named cast");
1419 break;
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 return getSema().ExprError();
1423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new C++ static_cast expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1430 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001431 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 SourceLocation RAngleLoc,
1433 SourceLocation LParenLoc,
1434 ExprArg SubExpr,
1435 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001436 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1437 TInfo, move(SubExpr),
1438 SourceRange(LAngleLoc, RAngleLoc),
1439 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
1441
1442 /// \brief Build a new C++ dynamic_cast expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1447 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001448 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 SourceLocation RAngleLoc,
1450 SourceLocation LParenLoc,
1451 ExprArg SubExpr,
1452 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001453 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1454 TInfo, move(SubExpr),
1455 SourceRange(LAngleLoc, RAngleLoc),
1456 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new C++ reinterpret_cast expression.
1460 ///
1461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
1463 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1464 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001465 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 SourceLocation RAngleLoc,
1467 SourceLocation LParenLoc,
1468 ExprArg SubExpr,
1469 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001470 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1471 TInfo, move(SubExpr),
1472 SourceRange(LAngleLoc, RAngleLoc),
1473 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 }
1475
1476 /// \brief Build a new C++ const_cast expression.
1477 ///
1478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1481 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001482 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 SourceLocation RAngleLoc,
1484 SourceLocation LParenLoc,
1485 ExprArg SubExpr,
1486 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001487 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1488 TInfo, move(SubExpr),
1489 SourceRange(LAngleLoc, RAngleLoc),
1490 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 }
Mike Stump11289f42009-09-09 15:08:12 +00001492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new C++ functional-style cast expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
1497 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001498 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 SourceLocation LParenLoc,
1500 ExprArg SubExpr,
1501 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001502 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001504 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001506 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001507 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 RParenLoc);
1509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new C++ typeid(type) expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001515 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1516 SourceLocation TypeidLoc,
1517 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1520 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 }
Mike Stump11289f42009-09-09 15:08:12 +00001522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new C++ typeid(expr) expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001527 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1528 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 ExprArg Operand,
1530 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001531 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1532 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001533 }
1534
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 /// \brief Build a new C++ "this" expression.
1536 ///
1537 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001538 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001540 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001541 QualType ThisType,
1542 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001544 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1545 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 }
1547
1548 /// \brief Build a new C++ throw expression.
1549 ///
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
1552 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1553 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1554 }
1555
1556 /// \brief Build a new C++ default-argument expression.
1557 ///
1558 /// By default, builds a new default-argument expression, which does not
1559 /// require any semantic analysis. Subclasses may override this routine to
1560 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001561 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1562 ParmVarDecl *Param) {
1563 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1564 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new C++ zero-initialization expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001571 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 SourceLocation LParenLoc,
1573 QualType T,
1574 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001575 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1576 T.getAsOpaquePtr(), LParenLoc,
1577 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 0, RParenLoc);
1579 }
Mike Stump11289f42009-09-09 15:08:12 +00001580
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// \brief Build a new C++ "new" expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001585 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 bool UseGlobal,
1587 SourceLocation PlacementLParen,
1588 MultiExprArg PlacementArgs,
1589 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001590 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 QualType AllocType,
1592 SourceLocation TypeLoc,
1593 SourceRange TypeRange,
1594 ExprArg ArraySize,
1595 SourceLocation ConstructorLParen,
1596 MultiExprArg ConstructorArgs,
1597 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001598 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 PlacementLParen,
1600 move(PlacementArgs),
1601 PlacementRParen,
1602 ParenTypeId,
1603 AllocType,
1604 TypeLoc,
1605 TypeRange,
1606 move(ArraySize),
1607 ConstructorLParen,
1608 move(ConstructorArgs),
1609 ConstructorRParen);
1610 }
Mike Stump11289f42009-09-09 15:08:12 +00001611
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// \brief Build a new C++ "delete" expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1617 bool IsGlobalDelete,
1618 bool IsArrayForm,
1619 ExprArg Operand) {
1620 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1621 move(Operand));
1622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new unary type trait expression.
1625 ///
1626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
1628 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1629 SourceLocation StartLoc,
1630 SourceLocation LParenLoc,
1631 QualType T,
1632 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001633 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 T.getAsOpaquePtr(), RParenLoc);
1635 }
1636
Mike Stump11289f42009-09-09 15:08:12 +00001637 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001642 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceRange QualifierRange,
1644 DeclarationName Name,
1645 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001646 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 CXXScopeSpec SS;
1648 SS.setRange(QualifierRange);
1649 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001650
1651 if (TemplateArgs)
1652 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1653 *TemplateArgs);
1654
1655 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
1657
1658 /// \brief Build a new template-id expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001662 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1663 LookupResult &R,
1664 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001665 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001666 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 }
1668
1669 /// \brief Build a new object-construction expression.
1670 ///
1671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001674 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 CXXConstructorDecl *Constructor,
1676 bool IsElidable,
1677 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001678 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1679 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1680 ConvertedArgs))
1681 return getSema().ExprError();
1682
1683 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1684 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new object-construction expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
1691 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1692 QualType T,
1693 SourceLocation LParenLoc,
1694 MultiExprArg Args,
1695 SourceLocation *Commas,
1696 SourceLocation RParenLoc) {
1697 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1698 T.getAsOpaquePtr(),
1699 LParenLoc,
1700 move(Args),
1701 Commas,
1702 RParenLoc);
1703 }
1704
1705 /// \brief Build a new object-construction expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
1709 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1710 QualType T,
1711 SourceLocation LParenLoc,
1712 MultiExprArg Args,
1713 SourceLocation *Commas,
1714 SourceLocation RParenLoc) {
1715 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1716 /*FIXME*/LParenLoc),
1717 T.getAsOpaquePtr(),
1718 LParenLoc,
1719 move(Args),
1720 Commas,
1721 RParenLoc);
1722 }
Mike Stump11289f42009-09-09 15:08:12 +00001723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// \brief Build a new member reference expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001728 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001729 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 bool IsArrow,
1731 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 NestedNameSpecifier *Qualifier,
1733 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001734 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001736 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001737 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001739 SS.setRange(QualifierRange);
1740 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001741
John McCall2d74de92009-12-01 22:10:20 +00001742 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1743 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001744 SS, FirstQualifierInScope,
1745 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
1747
John McCall10eae182009-11-30 22:42:35 +00001748 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001752 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001753 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001754 SourceLocation OperatorLoc,
1755 bool IsArrow,
1756 NestedNameSpecifier *Qualifier,
1757 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001758 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001759 LookupResult &R,
1760 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001761 CXXScopeSpec SS;
1762 SS.setRange(QualifierRange);
1763 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001764
John McCall2d74de92009-12-01 22:10:20 +00001765 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1766 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001767 SS, FirstQualifierInScope,
1768 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001769 }
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// \brief Build a new Objective-C @encode expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
1775 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001776 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001778 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001780 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001781
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001782 /// \brief Build a new Objective-C class message.
1783 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1784 Selector Sel,
1785 ObjCMethodDecl *Method,
1786 SourceLocation LBracLoc,
1787 MultiExprArg Args,
1788 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1790 ReceiverTypeInfo->getType(),
1791 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001792 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001793 move(Args));
1794 }
1795
1796 /// \brief Build a new Objective-C instance message.
1797 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1798 Selector Sel,
1799 ObjCMethodDecl *Method,
1800 SourceLocation LBracLoc,
1801 MultiExprArg Args,
1802 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001803 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1804 return SemaRef.BuildInstanceMessage(move(Receiver),
1805 ReceiverType,
1806 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001807 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001808 move(Args));
1809 }
1810
Douglas Gregord51d90d2010-04-26 20:11:03 +00001811 /// \brief Build a new Objective-C ivar reference expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
1815 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1816 SourceLocation IvarLoc,
1817 bool IsArrow, bool IsFreeIvar) {
1818 // FIXME: We lose track of the IsFreeIvar bit.
1819 CXXScopeSpec SS;
1820 Expr *Base = BaseArg.takeAs<Expr>();
1821 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1822 Sema::LookupMemberName);
1823 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1824 /*FIME:*/IvarLoc,
1825 SS, DeclPtrTy());
1826 if (Result.isInvalid())
1827 return getSema().ExprError();
1828
1829 if (Result.get())
1830 return move(Result);
1831
1832 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1833 Base->getType(),
1834 /*FIXME:*/IvarLoc, IsArrow, SS,
1835 /*FirstQualifierInScope=*/0,
1836 R,
1837 /*TemplateArgs=*/0);
1838 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001839
1840 /// \brief Build a new Objective-C property reference expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
1844 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
1845 ObjCPropertyDecl *Property,
1846 SourceLocation PropertyLoc) {
1847 CXXScopeSpec SS;
1848 Expr *Base = BaseArg.takeAs<Expr>();
1849 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1850 Sema::LookupMemberName);
1851 bool IsArrow = false;
1852 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1853 /*FIME:*/PropertyLoc,
1854 SS, DeclPtrTy());
1855 if (Result.isInvalid())
1856 return getSema().ExprError();
1857
1858 if (Result.get())
1859 return move(Result);
1860
1861 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1862 Base->getType(),
1863 /*FIXME:*/PropertyLoc, IsArrow,
1864 SS,
1865 /*FirstQualifierInScope=*/0,
1866 R,
1867 /*TemplateArgs=*/0);
1868 }
1869
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001870 /// \brief Build a new Objective-C implicit setter/getter reference
1871 /// expression.
1872 ///
1873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
1875 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1876 ObjCMethodDecl *Getter,
1877 QualType T,
1878 ObjCMethodDecl *Setter,
1879 SourceLocation NameLoc,
1880 ExprArg Base) {
1881 // Since these expressions can only be value-dependent, we do not need to
1882 // perform semantic analysis again.
1883 return getSema().Owned(
1884 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1885 Setter,
1886 NameLoc,
1887 Base.takeAs<Expr>()));
1888 }
1889
Douglas Gregord51d90d2010-04-26 20:11:03 +00001890 /// \brief Build a new Objective-C "isa" expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
1894 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1895 bool IsArrow) {
1896 CXXScopeSpec SS;
1897 Expr *Base = BaseArg.takeAs<Expr>();
1898 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1899 Sema::LookupMemberName);
1900 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1901 /*FIME:*/IsaLoc,
1902 SS, DeclPtrTy());
1903 if (Result.isInvalid())
1904 return getSema().ExprError();
1905
1906 if (Result.get())
1907 return move(Result);
1908
1909 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1910 Base->getType(),
1911 /*FIXME:*/IsaLoc, IsArrow, SS,
1912 /*FirstQualifierInScope=*/0,
1913 R,
1914 /*TemplateArgs=*/0);
1915 }
1916
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// \brief Build a new shuffle vector expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
1921 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1922 MultiExprArg SubExprs,
1923 SourceLocation RParenLoc) {
1924 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001925 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1927 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1928 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1929 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001930
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 // Build a reference to the __builtin_shufflevector builtin
1932 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001933 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001935 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001937
1938 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 unsigned NumSubExprs = SubExprs.size();
1940 Expr **Subs = (Expr **)SubExprs.release();
1941 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1942 Subs, NumSubExprs,
1943 Builtin->getResultType(),
1944 RParenLoc);
1945 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 // Type-check the __builtin_shufflevector expression.
1948 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1949 if (Result.isInvalid())
1950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001953 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001955};
Douglas Gregora16548e2009-08-11 05:31:07 +00001956
Douglas Gregorebe10102009-08-20 07:17:43 +00001957template<typename Derived>
1958Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1959 if (!S)
1960 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregorebe10102009-08-20 07:17:43 +00001962 switch (S->getStmtClass()) {
1963 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001964
Douglas Gregorebe10102009-08-20 07:17:43 +00001965 // Transform individual statement nodes
1966#define STMT(Node, Parent) \
1967 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1968#define EXPR(Node, Parent)
1969#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregorebe10102009-08-20 07:17:43 +00001971 // Transform expressions by calling TransformExpr.
1972#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001973#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001974#define EXPR(Node, Parent) case Stmt::Node##Class:
1975#include "clang/AST/StmtNodes.def"
1976 {
1977 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1978 if (E.isInvalid())
1979 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001980
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001981 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001982 }
Mike Stump11289f42009-09-09 15:08:12 +00001983 }
1984
Douglas Gregorebe10102009-08-20 07:17:43 +00001985 return SemaRef.Owned(S->Retain());
1986}
Mike Stump11289f42009-09-09 15:08:12 +00001987
1988
Douglas Gregore922c772009-08-04 22:27:00 +00001989template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001990Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 if (!E)
1992 return SemaRef.Owned(E);
1993
1994 switch (E->getStmtClass()) {
1995 case Stmt::NoStmtClass: break;
1996#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001997#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001998#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001999 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00002000#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00002001 }
2002
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002004}
2005
2006template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002007NestedNameSpecifier *
2008TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002009 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002010 QualType ObjectType,
2011 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002012 if (!NNS)
2013 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002014
Douglas Gregorebe10102009-08-20 07:17:43 +00002015 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002016 NestedNameSpecifier *Prefix = NNS->getPrefix();
2017 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002018 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002019 ObjectType,
2020 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002021 if (!Prefix)
2022 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002023
2024 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002025 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002026 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002027 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002028 }
Mike Stump11289f42009-09-09 15:08:12 +00002029
Douglas Gregor1135c352009-08-06 05:28:30 +00002030 switch (NNS->getKind()) {
2031 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002032 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002033 "Identifier nested-name-specifier with no prefix or object type");
2034 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2035 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002036 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002037
2038 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002039 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002040 ObjectType,
2041 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002044 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002045 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002046 getDerived().TransformDecl(Range.getBegin(),
2047 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 Prefix == NNS->getPrefix() &&
2050 NS == NNS->getAsNamespace())
2051 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2054 }
Mike Stump11289f42009-09-09 15:08:12 +00002055
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 case NestedNameSpecifier::Global:
2057 // There is no meaningful transformation that one could perform on the
2058 // global scope.
2059 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 case NestedNameSpecifier::TypeSpecWithTemplate:
2062 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002063 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002064 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2065 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002066 if (T.isNull())
2067 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregor1135c352009-08-06 05:28:30 +00002069 if (!getDerived().AlwaysRebuild() &&
2070 Prefix == NNS->getPrefix() &&
2071 T == QualType(NNS->getAsType(), 0))
2072 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002073
2074 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2075 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002076 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002077 }
2078 }
Mike Stump11289f42009-09-09 15:08:12 +00002079
Douglas Gregor1135c352009-08-06 05:28:30 +00002080 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002081 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002082}
2083
2084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002085DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002086TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002087 SourceLocation Loc,
2088 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002089 if (!Name)
2090 return Name;
2091
2092 switch (Name.getNameKind()) {
2093 case DeclarationName::Identifier:
2094 case DeclarationName::ObjCZeroArgSelector:
2095 case DeclarationName::ObjCOneArgSelector:
2096 case DeclarationName::ObjCMultiArgSelector:
2097 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002098 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002099 case DeclarationName::CXXUsingDirective:
2100 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002101
Douglas Gregorf816bd72009-09-03 22:13:48 +00002102 case DeclarationName::CXXConstructorName:
2103 case DeclarationName::CXXDestructorName:
2104 case DeclarationName::CXXConversionFunctionName: {
2105 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00002106 QualType T = getDerived().TransformType(Name.getCXXNameType(),
2107 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002108 if (T.isNull())
2109 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002110
Douglas Gregorf816bd72009-09-03 22:13:48 +00002111 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002112 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002113 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002114 }
Mike Stump11289f42009-09-09 15:08:12 +00002115 }
2116
Douglas Gregorf816bd72009-09-03 22:13:48 +00002117 return DeclarationName();
2118}
2119
2120template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002121TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002122TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2123 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002124 SourceLocation Loc = getDerived().getBaseLocation();
2125
Douglas Gregor71dc5092009-08-06 06:41:21 +00002126 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002127 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002128 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002129 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2130 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002131 if (!NNS)
2132 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002133
Douglas Gregor71dc5092009-08-06 06:41:21 +00002134 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002135 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002136 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002137 if (!TransTemplate)
2138 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002139
Douglas Gregor71dc5092009-08-06 06:41:21 +00002140 if (!getDerived().AlwaysRebuild() &&
2141 NNS == QTN->getQualifier() &&
2142 TransTemplate == Template)
2143 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002144
Douglas Gregor71dc5092009-08-06 06:41:21 +00002145 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2146 TransTemplate);
2147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
John McCalle66edc12009-11-24 19:00:30 +00002149 // These should be getting filtered out before they make it into the AST.
2150 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 }
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregor71dc5092009-08-06 06:41:21 +00002153 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002154 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002155 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002156 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2157 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002158 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002160
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002162 NNS == DTN->getQualifier() &&
2163 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002164 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregor71395fa2009-11-04 00:56:37 +00002166 if (DTN->isIdentifier())
2167 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2168 ObjectType);
2169
2170 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2171 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002172 }
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002175 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002176 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 if (!TransTemplate)
2178 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180 if (!getDerived().AlwaysRebuild() &&
2181 TransTemplate == Template)
2182 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 return TemplateName(TransTemplate);
2185 }
Mike Stump11289f42009-09-09 15:08:12 +00002186
John McCalle66edc12009-11-24 19:00:30 +00002187 // These should be getting filtered out before they reach the AST.
2188 assert(false && "overloaded function decl survived to here");
2189 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190}
2191
2192template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002193void TreeTransform<Derived>::InventTemplateArgumentLoc(
2194 const TemplateArgument &Arg,
2195 TemplateArgumentLoc &Output) {
2196 SourceLocation Loc = getDerived().getBaseLocation();
2197 switch (Arg.getKind()) {
2198 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002199 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002200 break;
2201
2202 case TemplateArgument::Type:
2203 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002204 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002205
2206 break;
2207
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002208 case TemplateArgument::Template:
2209 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2210 break;
2211
John McCall0ad16662009-10-29 08:12:44 +00002212 case TemplateArgument::Expression:
2213 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2214 break;
2215
2216 case TemplateArgument::Declaration:
2217 case TemplateArgument::Integral:
2218 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002219 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002220 break;
2221 }
2222}
2223
2224template<typename Derived>
2225bool TreeTransform<Derived>::TransformTemplateArgument(
2226 const TemplateArgumentLoc &Input,
2227 TemplateArgumentLoc &Output) {
2228 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002229 switch (Arg.getKind()) {
2230 case TemplateArgument::Null:
2231 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002232 Output = Input;
2233 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregore922c772009-08-04 22:27:00 +00002235 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002236 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002237 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002238 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002239
2240 DI = getDerived().TransformType(DI);
2241 if (!DI) return true;
2242
2243 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2244 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregore922c772009-08-04 22:27:00 +00002247 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002248 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002249 DeclarationName Name;
2250 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2251 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002252 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002253 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002254 if (!D) return true;
2255
John McCall0d07eb32009-10-29 18:45:58 +00002256 Expr *SourceExpr = Input.getSourceDeclExpression();
2257 if (SourceExpr) {
2258 EnterExpressionEvaluationContext Unevaluated(getSema(),
2259 Action::Unevaluated);
2260 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2261 if (E.isInvalid())
2262 SourceExpr = NULL;
2263 else {
2264 SourceExpr = E.takeAs<Expr>();
2265 SourceExpr->Retain();
2266 }
2267 }
2268
2269 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002270 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002271 }
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002273 case TemplateArgument::Template: {
2274 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2275 TemplateName Template
2276 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2277 if (Template.isNull())
2278 return true;
2279
2280 Output = TemplateArgumentLoc(TemplateArgument(Template),
2281 Input.getTemplateQualifierRange(),
2282 Input.getTemplateNameLoc());
2283 return false;
2284 }
2285
Douglas Gregore922c772009-08-04 22:27:00 +00002286 case TemplateArgument::Expression: {
2287 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002288 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002289 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002290
John McCall0ad16662009-10-29 08:12:44 +00002291 Expr *InputExpr = Input.getSourceExpression();
2292 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2293
2294 Sema::OwningExprResult E
2295 = getDerived().TransformExpr(InputExpr);
2296 if (E.isInvalid()) return true;
2297
2298 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002299 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002300 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2301 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002302 }
Mike Stump11289f42009-09-09 15:08:12 +00002303
Douglas Gregore922c772009-08-04 22:27:00 +00002304 case TemplateArgument::Pack: {
2305 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2306 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002307 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002308 AEnd = Arg.pack_end();
2309 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002310
John McCall0ad16662009-10-29 08:12:44 +00002311 // FIXME: preserve source information here when we start
2312 // caring about parameter packs.
2313
John McCall0d07eb32009-10-29 18:45:58 +00002314 TemplateArgumentLoc InputArg;
2315 TemplateArgumentLoc OutputArg;
2316 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2317 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002318 return true;
2319
John McCall0d07eb32009-10-29 18:45:58 +00002320 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002321 }
2322 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002323 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002324 true);
John McCall0d07eb32009-10-29 18:45:58 +00002325 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002326 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002327 }
2328 }
Mike Stump11289f42009-09-09 15:08:12 +00002329
Douglas Gregore922c772009-08-04 22:27:00 +00002330 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002331 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002332}
2333
Douglas Gregord6ff3322009-08-04 16:50:30 +00002334//===----------------------------------------------------------------------===//
2335// Type transformation
2336//===----------------------------------------------------------------------===//
2337
2338template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002339QualType TreeTransform<Derived>::TransformType(QualType T,
2340 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341 if (getDerived().AlreadyTransformed(T))
2342 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002343
John McCall550e0c22009-10-21 00:40:46 +00002344 // Temporary workaround. All of these transformations should
2345 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002346 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002347 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002348
Douglas Gregorfe17d252010-02-16 19:09:40 +00002349 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002350
John McCall550e0c22009-10-21 00:40:46 +00002351 if (!NewDI)
2352 return QualType();
2353
2354 return NewDI->getType();
2355}
2356
2357template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002358TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2359 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002360 if (getDerived().AlreadyTransformed(DI->getType()))
2361 return DI;
2362
2363 TypeLocBuilder TLB;
2364
2365 TypeLoc TL = DI->getTypeLoc();
2366 TLB.reserve(TL.getFullDataSize());
2367
Douglas Gregorfe17d252010-02-16 19:09:40 +00002368 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002369 if (Result.isNull())
2370 return 0;
2371
John McCallbcd03502009-12-07 02:54:59 +00002372 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002373}
2374
2375template<typename Derived>
2376QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002377TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2378 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002379 switch (T.getTypeLocClass()) {
2380#define ABSTRACT_TYPELOC(CLASS, PARENT)
2381#define TYPELOC(CLASS, PARENT) \
2382 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002383 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2384 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002385#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386 }
Mike Stump11289f42009-09-09 15:08:12 +00002387
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002388 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002389 return QualType();
2390}
2391
2392/// FIXME: By default, this routine adds type qualifiers only to types
2393/// that can have qualifiers, and silently suppresses those qualifiers
2394/// that are not permitted (e.g., qualifiers on reference or function
2395/// types). This is the right thing for template instantiation, but
2396/// probably not for other clients.
2397template<typename Derived>
2398QualType
2399TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002400 QualifiedTypeLoc T,
2401 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002402 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002403
Douglas Gregorfe17d252010-02-16 19:09:40 +00002404 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2405 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002406 if (Result.isNull())
2407 return QualType();
2408
2409 // Silently suppress qualifiers if the result type can't be qualified.
2410 // FIXME: this is the right thing for template instantiation, but
2411 // probably not for other clients.
2412 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002413 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002414
John McCall550e0c22009-10-21 00:40:46 +00002415 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2416
2417 TLB.push<QualifiedTypeLoc>(Result);
2418
2419 // No location information to preserve.
2420
2421 return Result;
2422}
2423
2424template <class TyLoc> static inline
2425QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2426 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2427 NewT.setNameLoc(T.getNameLoc());
2428 return T.getType();
2429}
2430
John McCall550e0c22009-10-21 00:40:46 +00002431template<typename Derived>
2432QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002433 BuiltinTypeLoc T,
2434 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002435 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2436 NewT.setBuiltinLoc(T.getBuiltinLoc());
2437 if (T.needsExtraLocalData())
2438 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2439 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002440}
Mike Stump11289f42009-09-09 15:08:12 +00002441
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002443QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002444 ComplexTypeLoc T,
2445 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002446 // FIXME: recurse?
2447 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448}
Mike Stump11289f42009-09-09 15:08:12 +00002449
Douglas Gregord6ff3322009-08-04 16:50:30 +00002450template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002451QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002452 PointerTypeLoc TL,
2453 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002454 QualType PointeeType
2455 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2456 if (PointeeType.isNull())
2457 return QualType();
2458
2459 QualType Result = TL.getType();
2460 if (PointeeType->isObjCInterfaceType()) {
2461 // A dependent pointer type 'T *' has is being transformed such
2462 // that an Objective-C class type is being replaced for 'T'. The
2463 // resulting pointer type is an ObjCObjectPointerType, not a
2464 // PointerType.
2465 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2466 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2467 const_cast<ObjCProtocolDecl **>(
2468 IFace->qual_begin()),
2469 IFace->getNumProtocols());
2470
2471 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2472 NewT.setStarLoc(TL.getSigilLoc());
2473 NewT.setHasProtocolsAsWritten(false);
2474 NewT.setLAngleLoc(SourceLocation());
2475 NewT.setRAngleLoc(SourceLocation());
2476 NewT.setHasBaseTypeAsWritten(true);
2477 return Result;
2478 }
2479
2480 if (getDerived().AlwaysRebuild() ||
2481 PointeeType != TL.getPointeeLoc().getType()) {
2482 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2483 if (Result.isNull())
2484 return QualType();
2485 }
2486
2487 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2488 NewT.setSigilLoc(TL.getSigilLoc());
2489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002490}
Mike Stump11289f42009-09-09 15:08:12 +00002491
2492template<typename Derived>
2493QualType
John McCall550e0c22009-10-21 00:40:46 +00002494TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002495 BlockPointerTypeLoc TL,
2496 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002497 QualType PointeeType
2498 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2499 if (PointeeType.isNull())
2500 return QualType();
2501
2502 QualType Result = TL.getType();
2503 if (getDerived().AlwaysRebuild() ||
2504 PointeeType != TL.getPointeeLoc().getType()) {
2505 Result = getDerived().RebuildBlockPointerType(PointeeType,
2506 TL.getSigilLoc());
2507 if (Result.isNull())
2508 return QualType();
2509 }
2510
Douglas Gregor049211a2010-04-22 16:50:51 +00002511 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002512 NewT.setSigilLoc(TL.getSigilLoc());
2513 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002514}
2515
John McCall70dd5f62009-10-30 00:06:24 +00002516/// Transforms a reference type. Note that somewhat paradoxically we
2517/// don't care whether the type itself is an l-value type or an r-value
2518/// type; we only care if the type was *written* as an l-value type
2519/// or an r-value type.
2520template<typename Derived>
2521QualType
2522TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002523 ReferenceTypeLoc TL,
2524 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002525 const ReferenceType *T = TL.getTypePtr();
2526
2527 // Note that this works with the pointee-as-written.
2528 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2529 if (PointeeType.isNull())
2530 return QualType();
2531
2532 QualType Result = TL.getType();
2533 if (getDerived().AlwaysRebuild() ||
2534 PointeeType != T->getPointeeTypeAsWritten()) {
2535 Result = getDerived().RebuildReferenceType(PointeeType,
2536 T->isSpelledAsLValue(),
2537 TL.getSigilLoc());
2538 if (Result.isNull())
2539 return QualType();
2540 }
2541
2542 // r-value references can be rebuilt as l-value references.
2543 ReferenceTypeLoc NewTL;
2544 if (isa<LValueReferenceType>(Result))
2545 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2546 else
2547 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2548 NewTL.setSigilLoc(TL.getSigilLoc());
2549
2550 return Result;
2551}
2552
Mike Stump11289f42009-09-09 15:08:12 +00002553template<typename Derived>
2554QualType
John McCall550e0c22009-10-21 00:40:46 +00002555TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002556 LValueReferenceTypeLoc TL,
2557 QualType ObjectType) {
2558 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002559}
2560
Mike Stump11289f42009-09-09 15:08:12 +00002561template<typename Derived>
2562QualType
John McCall550e0c22009-10-21 00:40:46 +00002563TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002564 RValueReferenceTypeLoc TL,
2565 QualType ObjectType) {
2566 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567}
Mike Stump11289f42009-09-09 15:08:12 +00002568
Douglas Gregord6ff3322009-08-04 16:50:30 +00002569template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002570QualType
John McCall550e0c22009-10-21 00:40:46 +00002571TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002572 MemberPointerTypeLoc TL,
2573 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002574 MemberPointerType *T = TL.getTypePtr();
2575
2576 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577 if (PointeeType.isNull())
2578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002579
John McCall550e0c22009-10-21 00:40:46 +00002580 // TODO: preserve source information for this.
2581 QualType ClassType
2582 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583 if (ClassType.isNull())
2584 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002585
John McCall550e0c22009-10-21 00:40:46 +00002586 QualType Result = TL.getType();
2587 if (getDerived().AlwaysRebuild() ||
2588 PointeeType != T->getPointeeType() ||
2589 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002590 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2591 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002592 if (Result.isNull())
2593 return QualType();
2594 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595
John McCall550e0c22009-10-21 00:40:46 +00002596 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2597 NewTL.setSigilLoc(TL.getSigilLoc());
2598
2599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600}
2601
Mike Stump11289f42009-09-09 15:08:12 +00002602template<typename Derived>
2603QualType
John McCall550e0c22009-10-21 00:40:46 +00002604TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002605 ConstantArrayTypeLoc TL,
2606 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002607 ConstantArrayType *T = TL.getTypePtr();
2608 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002609 if (ElementType.isNull())
2610 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 ElementType != T->getElementType()) {
2615 Result = getDerived().RebuildConstantArrayType(ElementType,
2616 T->getSizeModifier(),
2617 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002618 T->getIndexTypeCVRQualifiers(),
2619 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002620 if (Result.isNull())
2621 return QualType();
2622 }
2623
2624 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2625 NewTL.setLBracketLoc(TL.getLBracketLoc());
2626 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002627
John McCall550e0c22009-10-21 00:40:46 +00002628 Expr *Size = TL.getSizeExpr();
2629 if (Size) {
2630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2631 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2632 }
2633 NewTL.setSizeExpr(Size);
2634
2635 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636}
Mike Stump11289f42009-09-09 15:08:12 +00002637
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002640 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002641 IncompleteArrayTypeLoc TL,
2642 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002643 IncompleteArrayType *T = TL.getTypePtr();
2644 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 if (ElementType.isNull())
2646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002647
John McCall550e0c22009-10-21 00:40:46 +00002648 QualType Result = TL.getType();
2649 if (getDerived().AlwaysRebuild() ||
2650 ElementType != T->getElementType()) {
2651 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002652 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002653 T->getIndexTypeCVRQualifiers(),
2654 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002655 if (Result.isNull())
2656 return QualType();
2657 }
2658
2659 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2660 NewTL.setLBracketLoc(TL.getLBracketLoc());
2661 NewTL.setRBracketLoc(TL.getRBracketLoc());
2662 NewTL.setSizeExpr(0);
2663
2664 return Result;
2665}
2666
2667template<typename Derived>
2668QualType
2669TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002670 VariableArrayTypeLoc TL,
2671 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002672 VariableArrayType *T = TL.getTypePtr();
2673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2674 if (ElementType.isNull())
2675 return QualType();
2676
2677 // Array bounds are not potentially evaluated contexts
2678 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2679
2680 Sema::OwningExprResult SizeResult
2681 = getDerived().TransformExpr(T->getSizeExpr());
2682 if (SizeResult.isInvalid())
2683 return QualType();
2684
2685 Expr *Size = static_cast<Expr*>(SizeResult.get());
2686
2687 QualType Result = TL.getType();
2688 if (getDerived().AlwaysRebuild() ||
2689 ElementType != T->getElementType() ||
2690 Size != T->getSizeExpr()) {
2691 Result = getDerived().RebuildVariableArrayType(ElementType,
2692 T->getSizeModifier(),
2693 move(SizeResult),
2694 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002695 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002696 if (Result.isNull())
2697 return QualType();
2698 }
2699 else SizeResult.take();
2700
2701 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2702 NewTL.setLBracketLoc(TL.getLBracketLoc());
2703 NewTL.setRBracketLoc(TL.getRBracketLoc());
2704 NewTL.setSizeExpr(Size);
2705
2706 return Result;
2707}
2708
2709template<typename Derived>
2710QualType
2711TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002712 DependentSizedArrayTypeLoc TL,
2713 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002714 DependentSizedArrayType *T = TL.getTypePtr();
2715 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2716 if (ElementType.isNull())
2717 return QualType();
2718
2719 // Array bounds are not potentially evaluated contexts
2720 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2721
2722 Sema::OwningExprResult SizeResult
2723 = getDerived().TransformExpr(T->getSizeExpr());
2724 if (SizeResult.isInvalid())
2725 return QualType();
2726
2727 Expr *Size = static_cast<Expr*>(SizeResult.get());
2728
2729 QualType Result = TL.getType();
2730 if (getDerived().AlwaysRebuild() ||
2731 ElementType != T->getElementType() ||
2732 Size != T->getSizeExpr()) {
2733 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2734 T->getSizeModifier(),
2735 move(SizeResult),
2736 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002737 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002738 if (Result.isNull())
2739 return QualType();
2740 }
2741 else SizeResult.take();
2742
2743 // We might have any sort of array type now, but fortunately they
2744 // all have the same location layout.
2745 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2746 NewTL.setLBracketLoc(TL.getLBracketLoc());
2747 NewTL.setRBracketLoc(TL.getRBracketLoc());
2748 NewTL.setSizeExpr(Size);
2749
2750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751}
Mike Stump11289f42009-09-09 15:08:12 +00002752
2753template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002754QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002755 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002756 DependentSizedExtVectorTypeLoc TL,
2757 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002758 DependentSizedExtVectorType *T = TL.getTypePtr();
2759
2760 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761 QualType ElementType = getDerived().TransformType(T->getElementType());
2762 if (ElementType.isNull())
2763 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002764
Douglas Gregore922c772009-08-04 22:27:00 +00002765 // Vector sizes are not potentially evaluated contexts
2766 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2767
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2769 if (Size.isInvalid())
2770 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002771
John McCall550e0c22009-10-21 00:40:46 +00002772 QualType Result = TL.getType();
2773 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002774 ElementType != T->getElementType() ||
2775 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002776 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002777 move(Size),
2778 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002779 if (Result.isNull())
2780 return QualType();
2781 }
2782 else Size.take();
2783
2784 // Result might be dependent or not.
2785 if (isa<DependentSizedExtVectorType>(Result)) {
2786 DependentSizedExtVectorTypeLoc NewTL
2787 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2788 NewTL.setNameLoc(TL.getNameLoc());
2789 } else {
2790 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2791 NewTL.setNameLoc(TL.getNameLoc());
2792 }
2793
2794 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002795}
Mike Stump11289f42009-09-09 15:08:12 +00002796
2797template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002798QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002799 VectorTypeLoc TL,
2800 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002801 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002802 QualType ElementType = getDerived().TransformType(T->getElementType());
2803 if (ElementType.isNull())
2804 return QualType();
2805
John McCall550e0c22009-10-21 00:40:46 +00002806 QualType Result = TL.getType();
2807 if (getDerived().AlwaysRebuild() ||
2808 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002809 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2810 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002811 if (Result.isNull())
2812 return QualType();
2813 }
2814
2815 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2816 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002817
John McCall550e0c22009-10-21 00:40:46 +00002818 return Result;
2819}
2820
2821template<typename Derived>
2822QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002823 ExtVectorTypeLoc TL,
2824 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002825 VectorType *T = TL.getTypePtr();
2826 QualType ElementType = getDerived().TransformType(T->getElementType());
2827 if (ElementType.isNull())
2828 return QualType();
2829
2830 QualType Result = TL.getType();
2831 if (getDerived().AlwaysRebuild() ||
2832 ElementType != T->getElementType()) {
2833 Result = getDerived().RebuildExtVectorType(ElementType,
2834 T->getNumElements(),
2835 /*FIXME*/ SourceLocation());
2836 if (Result.isNull())
2837 return QualType();
2838 }
2839
2840 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2841 NewTL.setNameLoc(TL.getNameLoc());
2842
2843 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002844}
Mike Stump11289f42009-09-09 15:08:12 +00002845
2846template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002847ParmVarDecl *
2848TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2849 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2850 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2851 if (!NewDI)
2852 return 0;
2853
2854 if (NewDI == OldDI)
2855 return OldParm;
2856 else
2857 return ParmVarDecl::Create(SemaRef.Context,
2858 OldParm->getDeclContext(),
2859 OldParm->getLocation(),
2860 OldParm->getIdentifier(),
2861 NewDI->getType(),
2862 NewDI,
2863 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002864 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002865 /* DefArg */ NULL);
2866}
2867
2868template<typename Derived>
2869bool TreeTransform<Derived>::
2870 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2871 llvm::SmallVectorImpl<QualType> &PTypes,
2872 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2873 FunctionProtoType *T = TL.getTypePtr();
2874
2875 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2876 ParmVarDecl *OldParm = TL.getArg(i);
2877
2878 QualType NewType;
2879 ParmVarDecl *NewParm;
2880
2881 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002882 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2883 if (!NewParm)
2884 return true;
2885 NewType = NewParm->getType();
2886
2887 // Deal with the possibility that we don't have a parameter
2888 // declaration for this parameter.
2889 } else {
2890 NewParm = 0;
2891
2892 QualType OldType = T->getArgType(i);
2893 NewType = getDerived().TransformType(OldType);
2894 if (NewType.isNull())
2895 return true;
2896 }
2897
2898 PTypes.push_back(NewType);
2899 PVars.push_back(NewParm);
2900 }
2901
2902 return false;
2903}
2904
2905template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002906QualType
John McCall550e0c22009-10-21 00:40:46 +00002907TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002908 FunctionProtoTypeLoc TL,
2909 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002910 FunctionProtoType *T = TL.getTypePtr();
2911 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002912 if (ResultType.isNull())
2913 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002914
John McCall550e0c22009-10-21 00:40:46 +00002915 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002917 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002918 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2919 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002920
John McCall550e0c22009-10-21 00:40:46 +00002921 QualType Result = TL.getType();
2922 if (getDerived().AlwaysRebuild() ||
2923 ResultType != T->getResultType() ||
2924 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2925 Result = getDerived().RebuildFunctionProtoType(ResultType,
2926 ParamTypes.data(),
2927 ParamTypes.size(),
2928 T->isVariadic(),
2929 T->getTypeQuals());
2930 if (Result.isNull())
2931 return QualType();
2932 }
Mike Stump11289f42009-09-09 15:08:12 +00002933
John McCall550e0c22009-10-21 00:40:46 +00002934 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2935 NewTL.setLParenLoc(TL.getLParenLoc());
2936 NewTL.setRParenLoc(TL.getRParenLoc());
2937 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2938 NewTL.setArg(i, ParamDecls[i]);
2939
2940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941}
Mike Stump11289f42009-09-09 15:08:12 +00002942
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943template<typename Derived>
2944QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002945 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002946 FunctionNoProtoTypeLoc TL,
2947 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002948 FunctionNoProtoType *T = TL.getTypePtr();
2949 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2950 if (ResultType.isNull())
2951 return QualType();
2952
2953 QualType Result = TL.getType();
2954 if (getDerived().AlwaysRebuild() ||
2955 ResultType != T->getResultType())
2956 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2957
2958 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2959 NewTL.setLParenLoc(TL.getLParenLoc());
2960 NewTL.setRParenLoc(TL.getRParenLoc());
2961
2962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002963}
Mike Stump11289f42009-09-09 15:08:12 +00002964
John McCallb96ec562009-12-04 22:46:56 +00002965template<typename Derived> QualType
2966TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002967 UnresolvedUsingTypeLoc TL,
2968 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002969 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002970 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002971 if (!D)
2972 return QualType();
2973
2974 QualType Result = TL.getType();
2975 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2976 Result = getDerived().RebuildUnresolvedUsingType(D);
2977 if (Result.isNull())
2978 return QualType();
2979 }
2980
2981 // We might get an arbitrary type spec type back. We should at
2982 // least always get a type spec type, though.
2983 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2984 NewTL.setNameLoc(TL.getNameLoc());
2985
2986 return Result;
2987}
2988
Douglas Gregord6ff3322009-08-04 16:50:30 +00002989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002990QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 TypedefTypeLoc TL,
2992 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002993 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002995 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2996 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002997 if (!Typedef)
2998 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002999
John McCall550e0c22009-10-21 00:40:46 +00003000 QualType Result = TL.getType();
3001 if (getDerived().AlwaysRebuild() ||
3002 Typedef != T->getDecl()) {
3003 Result = getDerived().RebuildTypedefType(Typedef);
3004 if (Result.isNull())
3005 return QualType();
3006 }
Mike Stump11289f42009-09-09 15:08:12 +00003007
John McCall550e0c22009-10-21 00:40:46 +00003008 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3009 NewTL.setNameLoc(TL.getNameLoc());
3010
3011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012}
Mike Stump11289f42009-09-09 15:08:12 +00003013
Douglas Gregord6ff3322009-08-04 16:50:30 +00003014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003015QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003016 TypeOfExprTypeLoc TL,
3017 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003018 // typeof expressions are not potentially evaluated contexts
3019 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003020
John McCalle8595032010-01-13 20:03:27 +00003021 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 if (E.isInvalid())
3023 return QualType();
3024
John McCall550e0c22009-10-21 00:40:46 +00003025 QualType Result = TL.getType();
3026 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003027 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003028 Result = getDerived().RebuildTypeOfExprType(move(E));
3029 if (Result.isNull())
3030 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003031 }
John McCall550e0c22009-10-21 00:40:46 +00003032 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003033
John McCall550e0c22009-10-21 00:40:46 +00003034 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003035 NewTL.setTypeofLoc(TL.getTypeofLoc());
3036 NewTL.setLParenLoc(TL.getLParenLoc());
3037 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003038
3039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003040}
Mike Stump11289f42009-09-09 15:08:12 +00003041
3042template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003043QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003044 TypeOfTypeLoc TL,
3045 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003046 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3047 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3048 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003050
John McCall550e0c22009-10-21 00:40:46 +00003051 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003052 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3053 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003054 if (Result.isNull())
3055 return QualType();
3056 }
Mike Stump11289f42009-09-09 15:08:12 +00003057
John McCall550e0c22009-10-21 00:40:46 +00003058 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003059 NewTL.setTypeofLoc(TL.getTypeofLoc());
3060 NewTL.setLParenLoc(TL.getLParenLoc());
3061 NewTL.setRParenLoc(TL.getRParenLoc());
3062 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003063
3064 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003065}
Mike Stump11289f42009-09-09 15:08:12 +00003066
3067template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003068QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003069 DecltypeTypeLoc TL,
3070 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003071 DecltypeType *T = TL.getTypePtr();
3072
Douglas Gregore922c772009-08-04 22:27:00 +00003073 // decltype expressions are not potentially evaluated contexts
3074 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003075
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3077 if (E.isInvalid())
3078 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003079
John McCall550e0c22009-10-21 00:40:46 +00003080 QualType Result = TL.getType();
3081 if (getDerived().AlwaysRebuild() ||
3082 E.get() != T->getUnderlyingExpr()) {
3083 Result = getDerived().RebuildDecltypeType(move(E));
3084 if (Result.isNull())
3085 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003086 }
John McCall550e0c22009-10-21 00:40:46 +00003087 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003088
John McCall550e0c22009-10-21 00:40:46 +00003089 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3090 NewTL.setNameLoc(TL.getNameLoc());
3091
3092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
3094
3095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003097 RecordTypeLoc TL,
3098 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003099 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003101 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3102 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103 if (!Record)
3104 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003105
John McCall550e0c22009-10-21 00:40:46 +00003106 QualType Result = TL.getType();
3107 if (getDerived().AlwaysRebuild() ||
3108 Record != T->getDecl()) {
3109 Result = getDerived().RebuildRecordType(Record);
3110 if (Result.isNull())
3111 return QualType();
3112 }
Mike Stump11289f42009-09-09 15:08:12 +00003113
John McCall550e0c22009-10-21 00:40:46 +00003114 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3115 NewTL.setNameLoc(TL.getNameLoc());
3116
3117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118}
Mike Stump11289f42009-09-09 15:08:12 +00003119
3120template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003121QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003122 EnumTypeLoc TL,
3123 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003124 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003126 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3127 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 if (!Enum)
3129 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003130
John McCall550e0c22009-10-21 00:40:46 +00003131 QualType Result = TL.getType();
3132 if (getDerived().AlwaysRebuild() ||
3133 Enum != T->getDecl()) {
3134 Result = getDerived().RebuildEnumType(Enum);
3135 if (Result.isNull())
3136 return QualType();
3137 }
Mike Stump11289f42009-09-09 15:08:12 +00003138
John McCall550e0c22009-10-21 00:40:46 +00003139 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3140 NewTL.setNameLoc(TL.getNameLoc());
3141
3142 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003143}
John McCallfcc33b02009-09-05 00:15:47 +00003144
3145template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003146QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003147 ElaboratedTypeLoc TL,
3148 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003149 ElaboratedType *T = TL.getTypePtr();
3150
3151 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003152 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3153 if (Underlying.isNull())
3154 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003155
John McCall550e0c22009-10-21 00:40:46 +00003156 QualType Result = TL.getType();
3157 if (getDerived().AlwaysRebuild() ||
3158 Underlying != T->getUnderlyingType()) {
3159 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3160 if (Result.isNull())
3161 return QualType();
3162 }
Mike Stump11289f42009-09-09 15:08:12 +00003163
John McCall550e0c22009-10-21 00:40:46 +00003164 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3165 NewTL.setNameLoc(TL.getNameLoc());
3166
3167 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003168}
Mike Stump11289f42009-09-09 15:08:12 +00003169
John McCalle78aac42010-03-10 03:28:59 +00003170template<typename Derived>
3171QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3172 TypeLocBuilder &TLB,
3173 InjectedClassNameTypeLoc TL,
3174 QualType ObjectType) {
3175 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3176 TL.getTypePtr()->getDecl());
3177 if (!D) return QualType();
3178
3179 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3180 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3181 return T;
3182}
3183
Mike Stump11289f42009-09-09 15:08:12 +00003184
Douglas Gregord6ff3322009-08-04 16:50:30 +00003185template<typename Derived>
3186QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003187 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003188 TemplateTypeParmTypeLoc TL,
3189 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003190 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003191}
3192
Mike Stump11289f42009-09-09 15:08:12 +00003193template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003194QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003195 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003196 SubstTemplateTypeParmTypeLoc TL,
3197 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003198 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003199}
3200
3201template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003202QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3203 const TemplateSpecializationType *TST,
3204 QualType ObjectType) {
3205 // FIXME: this entire method is a temporary workaround; callers
3206 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003207
John McCall0ad16662009-10-29 08:12:44 +00003208 // Fake up a TemplateSpecializationTypeLoc.
3209 TypeLocBuilder TLB;
3210 TemplateSpecializationTypeLoc TL
3211 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3212
John McCall0d07eb32009-10-29 18:45:58 +00003213 SourceLocation BaseLoc = getDerived().getBaseLocation();
3214
3215 TL.setTemplateNameLoc(BaseLoc);
3216 TL.setLAngleLoc(BaseLoc);
3217 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003218 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3219 const TemplateArgument &TA = TST->getArg(i);
3220 TemplateArgumentLoc TAL;
3221 getDerived().InventTemplateArgumentLoc(TA, TAL);
3222 TL.setArgLocInfo(i, TAL.getLocInfo());
3223 }
3224
3225 TypeLocBuilder IgnoredTLB;
3226 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003227}
3228
3229template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003230QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003231 TypeLocBuilder &TLB,
3232 TemplateSpecializationTypeLoc TL,
3233 QualType ObjectType) {
3234 const TemplateSpecializationType *T = TL.getTypePtr();
3235
Mike Stump11289f42009-09-09 15:08:12 +00003236 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003237 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003238 if (Template.isNull())
3239 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003240
John McCall6b51f282009-11-23 01:53:49 +00003241 TemplateArgumentListInfo NewTemplateArgs;
3242 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3243 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3244
3245 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3246 TemplateArgumentLoc Loc;
3247 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003249 NewTemplateArgs.addArgument(Loc);
3250 }
Mike Stump11289f42009-09-09 15:08:12 +00003251
John McCall0ad16662009-10-29 08:12:44 +00003252 // FIXME: maybe don't rebuild if all the template arguments are the same.
3253
3254 QualType Result =
3255 getDerived().RebuildTemplateSpecializationType(Template,
3256 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003257 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003258
3259 if (!Result.isNull()) {
3260 TemplateSpecializationTypeLoc NewTL
3261 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3262 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3263 NewTL.setLAngleLoc(TL.getLAngleLoc());
3264 NewTL.setRAngleLoc(TL.getRAngleLoc());
3265 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3266 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003267 }
Mike Stump11289f42009-09-09 15:08:12 +00003268
John McCall0ad16662009-10-29 08:12:44 +00003269 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003270}
Mike Stump11289f42009-09-09 15:08:12 +00003271
3272template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003273QualType
3274TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003275 QualifiedNameTypeLoc TL,
3276 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003277 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003278 NestedNameSpecifier *NNS
3279 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003280 SourceRange(),
3281 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282 if (!NNS)
3283 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003284
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285 QualType Named = getDerived().TransformType(T->getNamedType());
3286 if (Named.isNull())
3287 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003288
John McCall550e0c22009-10-21 00:40:46 +00003289 QualType Result = TL.getType();
3290 if (getDerived().AlwaysRebuild() ||
3291 NNS != T->getQualifier() ||
3292 Named != T->getNamedType()) {
3293 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3294 if (Result.isNull())
3295 return QualType();
3296 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003297
John McCall550e0c22009-10-21 00:40:46 +00003298 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3299 NewTL.setNameLoc(TL.getNameLoc());
3300
3301 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003302}
Mike Stump11289f42009-09-09 15:08:12 +00003303
3304template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003305QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3306 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003307 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003308 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003309
3310 /* FIXME: preserve source information better than this */
3311 SourceRange SR(TL.getNameLoc());
3312
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003314 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003315 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316 if (!NNS)
3317 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003318
John McCall550e0c22009-10-21 00:40:46 +00003319 QualType Result;
3320
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003322 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323 = getDerived().TransformType(QualType(TemplateId, 0));
3324 if (NewTemplateId.isNull())
3325 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003326
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327 if (!getDerived().AlwaysRebuild() &&
3328 NNS == T->getQualifier() &&
3329 NewTemplateId == QualType(TemplateId, 0))
3330 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003331
Douglas Gregor02085352010-03-31 20:19:30 +00003332 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3333 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003334 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003335 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3336 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003337 }
John McCall550e0c22009-10-21 00:40:46 +00003338 if (Result.isNull())
3339 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003341 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003342 NewTL.setNameLoc(TL.getNameLoc());
3343
3344 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003345}
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregord6ff3322009-08-04 16:50:30 +00003347template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003348QualType
3349TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003350 ObjCInterfaceTypeLoc TL,
3351 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003352 // ObjCInterfaceType is never dependent.
3353 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003354}
Mike Stump11289f42009-09-09 15:08:12 +00003355
3356template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003357QualType
3358TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003359 ObjCObjectPointerTypeLoc TL,
3360 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003361 // ObjCObjectPointerType is never dependent.
3362 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003363}
3364
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003366// Statement transformation
3367//===----------------------------------------------------------------------===//
3368template<typename Derived>
3369Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003370TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3371 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003372}
3373
3374template<typename Derived>
3375Sema::OwningStmtResult
3376TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3377 return getDerived().TransformCompoundStmt(S, false);
3378}
3379
3380template<typename Derived>
3381Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003382TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003383 bool IsStmtExpr) {
3384 bool SubStmtChanged = false;
3385 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3386 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3387 B != BEnd; ++B) {
3388 OwningStmtResult Result = getDerived().TransformStmt(*B);
3389 if (Result.isInvalid())
3390 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003391
Douglas Gregorebe10102009-08-20 07:17:43 +00003392 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3393 Statements.push_back(Result.takeAs<Stmt>());
3394 }
Mike Stump11289f42009-09-09 15:08:12 +00003395
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 if (!getDerived().AlwaysRebuild() &&
3397 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003398 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003399
3400 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3401 move_arg(Statements),
3402 S->getRBracLoc(),
3403 IsStmtExpr);
3404}
Mike Stump11289f42009-09-09 15:08:12 +00003405
Douglas Gregorebe10102009-08-20 07:17:43 +00003406template<typename Derived>
3407Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003408TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003409 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3410 {
3411 // The case value expressions are not potentially evaluated.
3412 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003413
Eli Friedman06577382009-11-19 03:14:00 +00003414 // Transform the left-hand case value.
3415 LHS = getDerived().TransformExpr(S->getLHS());
3416 if (LHS.isInvalid())
3417 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003418
Eli Friedman06577382009-11-19 03:14:00 +00003419 // Transform the right-hand case value (for the GNU case-range extension).
3420 RHS = getDerived().TransformExpr(S->getRHS());
3421 if (RHS.isInvalid())
3422 return SemaRef.StmtError();
3423 }
Mike Stump11289f42009-09-09 15:08:12 +00003424
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 // Build the case statement.
3426 // Case statements are always rebuilt so that they will attached to their
3427 // transformed switch statement.
3428 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3429 move(LHS),
3430 S->getEllipsisLoc(),
3431 move(RHS),
3432 S->getColonLoc());
3433 if (Case.isInvalid())
3434 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 // Transform the statement following the case
3437 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3438 if (SubStmt.isInvalid())
3439 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregorebe10102009-08-20 07:17:43 +00003441 // Attach the body to the case statement
3442 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3443}
3444
3445template<typename Derived>
3446Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003447TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003448 // Transform the statement following the default case
3449 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3450 if (SubStmt.isInvalid())
3451 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 // Default statements are always rebuilt
3454 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3455 move(SubStmt));
3456}
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458template<typename Derived>
3459Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003460TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3462 if (SubStmt.isInvalid())
3463 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003464
Douglas Gregorebe10102009-08-20 07:17:43 +00003465 // FIXME: Pass the real colon location in.
3466 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3467 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3468 move(SubStmt));
3469}
Mike Stump11289f42009-09-09 15:08:12 +00003470
Douglas Gregorebe10102009-08-20 07:17:43 +00003471template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003472Sema::OwningStmtResult
3473TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003474 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003475 OwningExprResult Cond(SemaRef);
3476 VarDecl *ConditionVar = 0;
3477 if (S->getConditionVariable()) {
3478 ConditionVar
3479 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003480 getDerived().TransformDefinition(
3481 S->getConditionVariable()->getLocation(),
3482 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003483 if (!ConditionVar)
3484 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003485 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003486 Cond = getDerived().TransformExpr(S->getCond());
3487
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003488 if (Cond.isInvalid())
3489 return SemaRef.StmtError();
3490 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003491
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003492 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003493
Douglas Gregorebe10102009-08-20 07:17:43 +00003494 // Transform the "then" branch.
3495 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3496 if (Then.isInvalid())
3497 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003498
Douglas Gregorebe10102009-08-20 07:17:43 +00003499 // Transform the "else" branch.
3500 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3501 if (Else.isInvalid())
3502 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003503
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 if (!getDerived().AlwaysRebuild() &&
3505 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003506 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 Then.get() == S->getThen() &&
3508 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003509 return SemaRef.Owned(S->Retain());
3510
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003511 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3512 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003513 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003514}
3515
3516template<typename Derived>
3517Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003520 OwningExprResult Cond(SemaRef);
3521 VarDecl *ConditionVar = 0;
3522 if (S->getConditionVariable()) {
3523 ConditionVar
3524 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003525 getDerived().TransformDefinition(
3526 S->getConditionVariable()->getLocation(),
3527 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003528 if (!ConditionVar)
3529 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003530 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003531 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003532
3533 if (Cond.isInvalid())
3534 return SemaRef.StmtError();
3535 }
Mike Stump11289f42009-09-09 15:08:12 +00003536
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003537 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003540 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3541 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003542 if (Switch.isInvalid())
3543 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the body of the switch statement.
3546 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3547 if (Body.isInvalid())
3548 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003549
Douglas Gregorebe10102009-08-20 07:17:43 +00003550 // Complete the switch statement.
3551 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3552 move(Body));
3553}
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555template<typename Derived>
3556Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003557TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003559 OwningExprResult Cond(SemaRef);
3560 VarDecl *ConditionVar = 0;
3561 if (S->getConditionVariable()) {
3562 ConditionVar
3563 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003564 getDerived().TransformDefinition(
3565 S->getConditionVariable()->getLocation(),
3566 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003567 if (!ConditionVar)
3568 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003569 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003570 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003571
3572 if (Cond.isInvalid())
3573 return SemaRef.StmtError();
3574 }
Mike Stump11289f42009-09-09 15:08:12 +00003575
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003576 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 // Transform the body
3579 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3580 if (Body.isInvalid())
3581 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 if (!getDerived().AlwaysRebuild() &&
3584 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003586 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003587 return SemaRef.Owned(S->Retain());
3588
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003589 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3590 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003591}
Mike Stump11289f42009-09-09 15:08:12 +00003592
Douglas Gregorebe10102009-08-20 07:17:43 +00003593template<typename Derived>
3594Sema::OwningStmtResult
3595TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3596 // Transform the condition
3597 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3598 if (Cond.isInvalid())
3599 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 // Transform the body
3602 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3603 if (Body.isInvalid())
3604 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 if (!getDerived().AlwaysRebuild() &&
3607 Cond.get() == S->getCond() &&
3608 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003609 return SemaRef.Owned(S->Retain());
3610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3612 /*FIXME:*/S->getWhileLoc(), move(Cond),
3613 S->getRParenLoc());
3614}
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616template<typename Derived>
3617Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003618TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003619 // Transform the initialization statement
3620 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3621 if (Init.isInvalid())
3622 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003623
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003625 OwningExprResult Cond(SemaRef);
3626 VarDecl *ConditionVar = 0;
3627 if (S->getConditionVariable()) {
3628 ConditionVar
3629 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003630 getDerived().TransformDefinition(
3631 S->getConditionVariable()->getLocation(),
3632 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003633 if (!ConditionVar)
3634 return SemaRef.StmtError();
3635 } else {
3636 Cond = getDerived().TransformExpr(S->getCond());
3637
3638 if (Cond.isInvalid())
3639 return SemaRef.StmtError();
3640 }
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 // Transform the increment
3643 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3644 if (Inc.isInvalid())
3645 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003646
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 // Transform the body
3648 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3649 if (Body.isInvalid())
3650 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregorebe10102009-08-20 07:17:43 +00003652 if (!getDerived().AlwaysRebuild() &&
3653 Init.get() == S->getInit() &&
3654 Cond.get() == S->getCond() &&
3655 Inc.get() == S->getInc() &&
3656 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003657 return SemaRef.Owned(S->Retain());
3658
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003660 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003661 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003662 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003663 S->getRParenLoc(), move(Body));
3664}
3665
3666template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003667Sema::OwningStmtResult
3668TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003669 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003670 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003671 S->getLabel());
3672}
3673
3674template<typename Derived>
3675Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003676TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3678 if (Target.isInvalid())
3679 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003680
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 if (!getDerived().AlwaysRebuild() &&
3682 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003683 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003684
3685 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3686 move(Target));
3687}
3688
3689template<typename Derived>
3690Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003691TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3692 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003693}
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregorebe10102009-08-20 07:17:43 +00003695template<typename Derived>
3696Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003697TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3698 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003699}
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701template<typename Derived>
3702Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003703TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3705 if (Result.isInvalid())
3706 return SemaRef.StmtError();
3707
Mike Stump11289f42009-09-09 15:08:12 +00003708 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 // to tell whether the return type of the function has changed.
3710 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3711}
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregorebe10102009-08-20 07:17:43 +00003713template<typename Derived>
3714Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003715TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003716 bool DeclChanged = false;
3717 llvm::SmallVector<Decl *, 4> Decls;
3718 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3719 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003720 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3721 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 if (!Transformed)
3723 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003724
Douglas Gregorebe10102009-08-20 07:17:43 +00003725 if (Transformed != *D)
3726 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregorebe10102009-08-20 07:17:43 +00003728 Decls.push_back(Transformed);
3729 }
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003732 return SemaRef.Owned(S->Retain());
3733
3734 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003735 S->getStartLoc(), S->getEndLoc());
3736}
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregorebe10102009-08-20 07:17:43 +00003738template<typename Derived>
3739Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003740TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003741 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003742 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003743}
3744
3745template<typename Derived>
3746Sema::OwningStmtResult
3747TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003748
3749 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3750 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003751 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003752
Anders Carlssonaaeef072010-01-24 05:50:09 +00003753 OwningExprResult AsmString(SemaRef);
3754 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3755
3756 bool ExprsChanged = false;
3757
3758 // Go through the outputs.
3759 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003760 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003761
Anders Carlssonaaeef072010-01-24 05:50:09 +00003762 // No need to transform the constraint literal.
3763 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3764
3765 // Transform the output expr.
3766 Expr *OutputExpr = S->getOutputExpr(I);
3767 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3768 if (Result.isInvalid())
3769 return SemaRef.StmtError();
3770
3771 ExprsChanged |= Result.get() != OutputExpr;
3772
3773 Exprs.push_back(Result.takeAs<Expr>());
3774 }
3775
3776 // Go through the inputs.
3777 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003778 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003779
Anders Carlssonaaeef072010-01-24 05:50:09 +00003780 // No need to transform the constraint literal.
3781 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3782
3783 // Transform the input expr.
3784 Expr *InputExpr = S->getInputExpr(I);
3785 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3786 if (Result.isInvalid())
3787 return SemaRef.StmtError();
3788
3789 ExprsChanged |= Result.get() != InputExpr;
3790
3791 Exprs.push_back(Result.takeAs<Expr>());
3792 }
3793
3794 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3795 return SemaRef.Owned(S->Retain());
3796
3797 // Go through the clobbers.
3798 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3799 Clobbers.push_back(S->getClobber(I)->Retain());
3800
3801 // No need to transform the asm string literal.
3802 AsmString = SemaRef.Owned(S->getAsmString());
3803
3804 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3805 S->isSimple(),
3806 S->isVolatile(),
3807 S->getNumOutputs(),
3808 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003809 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003810 move_arg(Constraints),
3811 move_arg(Exprs),
3812 move(AsmString),
3813 move_arg(Clobbers),
3814 S->getRParenLoc(),
3815 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003816}
3817
3818
3819template<typename Derived>
3820Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003821TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003822 // Transform the body of the @try.
3823 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3824 if (TryBody.isInvalid())
3825 return SemaRef.StmtError();
3826
Douglas Gregor96c79492010-04-23 22:50:49 +00003827 // Transform the @catch statements (if present).
3828 bool AnyCatchChanged = false;
3829 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3830 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3831 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003832 if (Catch.isInvalid())
3833 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003834 if (Catch.get() != S->getCatchStmt(I))
3835 AnyCatchChanged = true;
3836 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003837 }
3838
3839 // Transform the @finally statement (if present).
3840 OwningStmtResult Finally(SemaRef);
3841 if (S->getFinallyStmt()) {
3842 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3843 if (Finally.isInvalid())
3844 return SemaRef.StmtError();
3845 }
3846
3847 // If nothing changed, just retain this statement.
3848 if (!getDerived().AlwaysRebuild() &&
3849 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003850 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003851 Finally.get() == S->getFinallyStmt())
3852 return SemaRef.Owned(S->Retain());
3853
3854 // Build a new statement.
3855 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003856 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003857}
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregorebe10102009-08-20 07:17:43 +00003859template<typename Derived>
3860Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003861TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003862 // Transform the @catch parameter, if there is one.
3863 VarDecl *Var = 0;
3864 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3865 TypeSourceInfo *TSInfo = 0;
3866 if (FromVar->getTypeSourceInfo()) {
3867 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3868 if (!TSInfo)
3869 return SemaRef.StmtError();
3870 }
3871
3872 QualType T;
3873 if (TSInfo)
3874 T = TSInfo->getType();
3875 else {
3876 T = getDerived().TransformType(FromVar->getType());
3877 if (T.isNull())
3878 return SemaRef.StmtError();
3879 }
3880
3881 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3882 if (!Var)
3883 return SemaRef.StmtError();
3884 }
3885
3886 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3887 if (Body.isInvalid())
3888 return SemaRef.StmtError();
3889
3890 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
3891 S->getRParenLoc(),
3892 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003893}
Mike Stump11289f42009-09-09 15:08:12 +00003894
Douglas Gregorebe10102009-08-20 07:17:43 +00003895template<typename Derived>
3896Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003897TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003898 // Transform the body.
3899 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3900 if (Body.isInvalid())
3901 return SemaRef.StmtError();
3902
3903 // If nothing changed, just retain this statement.
3904 if (!getDerived().AlwaysRebuild() &&
3905 Body.get() == S->getFinallyBody())
3906 return SemaRef.Owned(S->Retain());
3907
3908 // Build a new statement.
3909 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3910 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregorebe10102009-08-20 07:17:43 +00003913template<typename Derived>
3914Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003915TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003916 OwningExprResult Operand(SemaRef);
3917 if (S->getThrowExpr()) {
3918 Operand = getDerived().TransformExpr(S->getThrowExpr());
3919 if (Operand.isInvalid())
3920 return getSema().StmtError();
3921 }
3922
3923 if (!getDerived().AlwaysRebuild() &&
3924 Operand.get() == S->getThrowExpr())
3925 return getSema().Owned(S->Retain());
3926
3927 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003928}
Mike Stump11289f42009-09-09 15:08:12 +00003929
Douglas Gregorebe10102009-08-20 07:17:43 +00003930template<typename Derived>
3931Sema::OwningStmtResult
3932TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003933 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003934 // Transform the object we are locking.
3935 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3936 if (Object.isInvalid())
3937 return SemaRef.StmtError();
3938
3939 // Transform the body.
3940 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3941 if (Body.isInvalid())
3942 return SemaRef.StmtError();
3943
3944 // If nothing change, just retain the current statement.
3945 if (!getDerived().AlwaysRebuild() &&
3946 Object.get() == S->getSynchExpr() &&
3947 Body.get() == S->getSynchBody())
3948 return SemaRef.Owned(S->Retain());
3949
3950 // Build a new statement.
3951 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3952 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003953}
3954
3955template<typename Derived>
3956Sema::OwningStmtResult
3957TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003958 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003959 // Transform the element statement.
3960 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3961 if (Element.isInvalid())
3962 return SemaRef.StmtError();
3963
3964 // Transform the collection expression.
3965 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3966 if (Collection.isInvalid())
3967 return SemaRef.StmtError();
3968
3969 // Transform the body.
3970 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3971 if (Body.isInvalid())
3972 return SemaRef.StmtError();
3973
3974 // If nothing changed, just retain this statement.
3975 if (!getDerived().AlwaysRebuild() &&
3976 Element.get() == S->getElement() &&
3977 Collection.get() == S->getCollection() &&
3978 Body.get() == S->getBody())
3979 return SemaRef.Owned(S->Retain());
3980
3981 // Build a new statement.
3982 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3983 /*FIXME:*/S->getForLoc(),
3984 move(Element),
3985 move(Collection),
3986 S->getRParenLoc(),
3987 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003988}
3989
3990
3991template<typename Derived>
3992Sema::OwningStmtResult
3993TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3994 // Transform the exception declaration, if any.
3995 VarDecl *Var = 0;
3996 if (S->getExceptionDecl()) {
3997 VarDecl *ExceptionDecl = S->getExceptionDecl();
3998 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3999 ExceptionDecl->getDeclName());
4000
4001 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4002 if (T.isNull())
4003 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregorebe10102009-08-20 07:17:43 +00004005 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4006 T,
John McCallbcd03502009-12-07 02:54:59 +00004007 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004008 ExceptionDecl->getIdentifier(),
4009 ExceptionDecl->getLocation(),
4010 /*FIXME: Inaccurate*/
4011 SourceRange(ExceptionDecl->getLocation()));
4012 if (!Var || Var->isInvalidDecl()) {
4013 if (Var)
4014 Var->Destroy(SemaRef.Context);
4015 return SemaRef.StmtError();
4016 }
4017 }
Mike Stump11289f42009-09-09 15:08:12 +00004018
Douglas Gregorebe10102009-08-20 07:17:43 +00004019 // Transform the actual exception handler.
4020 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4021 if (Handler.isInvalid()) {
4022 if (Var)
4023 Var->Destroy(SemaRef.Context);
4024 return SemaRef.StmtError();
4025 }
Mike Stump11289f42009-09-09 15:08:12 +00004026
Douglas Gregorebe10102009-08-20 07:17:43 +00004027 if (!getDerived().AlwaysRebuild() &&
4028 !Var &&
4029 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004030 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004031
4032 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4033 Var,
4034 move(Handler));
4035}
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037template<typename Derived>
4038Sema::OwningStmtResult
4039TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4040 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004041 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004042 = getDerived().TransformCompoundStmt(S->getTryBlock());
4043 if (TryBlock.isInvalid())
4044 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregorebe10102009-08-20 07:17:43 +00004046 // Transform the handlers.
4047 bool HandlerChanged = false;
4048 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4049 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004050 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004051 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4052 if (Handler.isInvalid())
4053 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregorebe10102009-08-20 07:17:43 +00004055 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4056 Handlers.push_back(Handler.takeAs<Stmt>());
4057 }
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregorebe10102009-08-20 07:17:43 +00004059 if (!getDerived().AlwaysRebuild() &&
4060 TryBlock.get() == S->getTryBlock() &&
4061 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004062 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004063
4064 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004065 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregorebe10102009-08-20 07:17:43 +00004068//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004069// Expression transformation
4070//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004071template<typename Derived>
4072Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004073TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004074 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004075}
Mike Stump11289f42009-09-09 15:08:12 +00004076
4077template<typename Derived>
4078Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004079TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004080 NestedNameSpecifier *Qualifier = 0;
4081 if (E->getQualifier()) {
4082 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004083 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004084 if (!Qualifier)
4085 return SemaRef.ExprError();
4086 }
John McCallce546572009-12-08 09:08:17 +00004087
4088 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004089 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4090 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 if (!ND)
4092 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004094 if (!getDerived().AlwaysRebuild() &&
4095 Qualifier == E->getQualifier() &&
4096 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004097 !E->hasExplicitTemplateArgumentList()) {
4098
4099 // Mark it referenced in the new context regardless.
4100 // FIXME: this is a bit instantiation-specific.
4101 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4102
Mike Stump11289f42009-09-09 15:08:12 +00004103 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004104 }
John McCallce546572009-12-08 09:08:17 +00004105
4106 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4107 if (E->hasExplicitTemplateArgumentList()) {
4108 TemplateArgs = &TransArgs;
4109 TransArgs.setLAngleLoc(E->getLAngleLoc());
4110 TransArgs.setRAngleLoc(E->getRAngleLoc());
4111 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4112 TemplateArgumentLoc Loc;
4113 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4114 return SemaRef.ExprError();
4115 TransArgs.addArgument(Loc);
4116 }
4117 }
4118
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004119 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004120 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004121}
Mike Stump11289f42009-09-09 15:08:12 +00004122
Douglas Gregora16548e2009-08-11 05:31:07 +00004123template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004125TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004126 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004127}
Mike Stump11289f42009-09-09 15:08:12 +00004128
Douglas Gregora16548e2009-08-11 05:31:07 +00004129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004130Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004131TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004132 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004133}
Mike Stump11289f42009-09-09 15:08:12 +00004134
Douglas Gregora16548e2009-08-11 05:31:07 +00004135template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004136Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004137TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004138 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004139}
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregora16548e2009-08-11 05:31:07 +00004141template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004142Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004143TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004144 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004145}
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004148Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004149TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004150 return SemaRef.Owned(E->Retain());
4151}
4152
4153template<typename Derived>
4154Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004155TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004156 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4157 if (SubExpr.isInvalid())
4158 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004161 return SemaRef.Owned(E->Retain());
4162
4163 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 E->getRParen());
4165}
4166
Mike Stump11289f42009-09-09 15:08:12 +00004167template<typename Derived>
4168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004169TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4170 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004171 if (SubExpr.isInvalid())
4172 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004175 return SemaRef.Owned(E->Retain());
4176
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4178 E->getOpcode(),
4179 move(SubExpr));
4180}
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregora16548e2009-08-11 05:31:07 +00004182template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004183Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004184TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4185 // Transform the type.
4186 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4187 if (!Type)
4188 return getSema().ExprError();
4189
4190 // Transform all of the components into components similar to what the
4191 // parser uses.
4192 // FIXME: It would be slightly more efficient in the non-dependent case to
4193 // just map FieldDecls, rather than requiring the rebuilder to look for
4194 // the fields again. However, __builtin_offsetof is rare enough in
4195 // template code that we don't care.
4196 bool ExprChanged = false;
4197 typedef Action::OffsetOfComponent Component;
4198 typedef OffsetOfExpr::OffsetOfNode Node;
4199 llvm::SmallVector<Component, 4> Components;
4200 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4201 const Node &ON = E->getComponent(I);
4202 Component Comp;
4203 Comp.LocStart = ON.getRange().getBegin();
4204 Comp.LocEnd = ON.getRange().getEnd();
4205 switch (ON.getKind()) {
4206 case Node::Array: {
4207 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4208 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4209 if (Index.isInvalid())
4210 return getSema().ExprError();
4211
4212 ExprChanged = ExprChanged || Index.get() != FromIndex;
4213 Comp.isBrackets = true;
4214 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4215 break;
4216 }
4217
4218 case Node::Field:
4219 case Node::Identifier:
4220 Comp.isBrackets = false;
4221 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004222 if (!Comp.U.IdentInfo)
4223 continue;
4224
Douglas Gregor882211c2010-04-28 22:16:22 +00004225 break;
4226 }
4227
4228 Components.push_back(Comp);
4229 }
4230
4231 // If nothing changed, retain the existing expression.
4232 if (!getDerived().AlwaysRebuild() &&
4233 Type == E->getTypeSourceInfo() &&
4234 !ExprChanged)
4235 return SemaRef.Owned(E->Retain());
4236
4237 // Build a new offsetof expression.
4238 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4239 Components.data(), Components.size(),
4240 E->getRParenLoc());
4241}
4242
4243template<typename Derived>
4244Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004245TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004246 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004247 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004248
John McCallbcd03502009-12-07 02:54:59 +00004249 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004250 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004251 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004252
John McCall4c98fd82009-11-04 07:28:41 +00004253 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004254 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004255
John McCall4c98fd82009-11-04 07:28:41 +00004256 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004257 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 E->getSourceRange());
4259 }
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004262 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004263 // C++0x [expr.sizeof]p1:
4264 // The operand is either an expression, which is an unevaluated operand
4265 // [...]
4266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4269 if (SubExpr.isInvalid())
4270 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4273 return SemaRef.Owned(E->Retain());
4274 }
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4277 E->isSizeOf(),
4278 E->getSourceRange());
4279}
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004282Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004283TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004284 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4285 if (LHS.isInvalid())
4286 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4289 if (RHS.isInvalid())
4290 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004291
4292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 if (!getDerived().AlwaysRebuild() &&
4294 LHS.get() == E->getLHS() &&
4295 RHS.get() == E->getRHS())
4296 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004297
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4299 /*FIXME:*/E->getLHS()->getLocStart(),
4300 move(RHS),
4301 E->getRBracketLoc());
4302}
Mike Stump11289f42009-09-09 15:08:12 +00004303
4304template<typename Derived>
4305Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004306TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 // Transform the callee.
4308 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4309 if (Callee.isInvalid())
4310 return SemaRef.ExprError();
4311
4312 // Transform arguments.
4313 bool ArgChanged = false;
4314 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4315 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4316 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4317 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4318 if (Arg.isInvalid())
4319 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004320
Douglas Gregora16548e2009-08-11 05:31:07 +00004321 // FIXME: Wrong source location information for the ','.
4322 FakeCommaLocs.push_back(
4323 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004324
4325 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 Args.push_back(Arg.takeAs<Expr>());
4327 }
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 if (!getDerived().AlwaysRebuild() &&
4330 Callee.get() == E->getCallee() &&
4331 !ArgChanged)
4332 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004335 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4337 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4338 move_arg(Args),
4339 FakeCommaLocs.data(),
4340 E->getRParenLoc());
4341}
Mike Stump11289f42009-09-09 15:08:12 +00004342
4343template<typename Derived>
4344Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004345TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004346 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4347 if (Base.isInvalid())
4348 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004350 NestedNameSpecifier *Qualifier = 0;
4351 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004352 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004353 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004354 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004355 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004356 return SemaRef.ExprError();
4357 }
Mike Stump11289f42009-09-09 15:08:12 +00004358
Eli Friedman2cfcef62009-12-04 06:40:45 +00004359 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004360 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4361 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 if (!Member)
4363 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004364
John McCall16df1e52010-03-30 21:47:33 +00004365 NamedDecl *FoundDecl = E->getFoundDecl();
4366 if (FoundDecl == E->getMemberDecl()) {
4367 FoundDecl = Member;
4368 } else {
4369 FoundDecl = cast_or_null<NamedDecl>(
4370 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4371 if (!FoundDecl)
4372 return SemaRef.ExprError();
4373 }
4374
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 if (!getDerived().AlwaysRebuild() &&
4376 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004377 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004378 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004379 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004380 !E->hasExplicitTemplateArgumentList()) {
4381
4382 // Mark it referenced in the new context regardless.
4383 // FIXME: this is a bit instantiation-specific.
4384 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004385 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004386 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004387
John McCall6b51f282009-11-23 01:53:49 +00004388 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004389 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004390 TransArgs.setLAngleLoc(E->getLAngleLoc());
4391 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004392 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004393 TemplateArgumentLoc Loc;
4394 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004395 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004396 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004397 }
4398 }
4399
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 // FIXME: Bogus source location for the operator
4401 SourceLocation FakeOperatorLoc
4402 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4403
John McCall38836f02010-01-15 08:34:02 +00004404 // FIXME: to do this check properly, we will need to preserve the
4405 // first-qualifier-in-scope here, just in case we had a dependent
4406 // base (and therefore couldn't do the check) and a
4407 // nested-name-qualifier (and therefore could do the lookup).
4408 NamedDecl *FirstQualifierInScope = 0;
4409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4411 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004412 Qualifier,
4413 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004415 Member,
John McCall16df1e52010-03-30 21:47:33 +00004416 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004417 (E->hasExplicitTemplateArgumentList()
4418 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004419 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004420}
Mike Stump11289f42009-09-09 15:08:12 +00004421
Douglas Gregora16548e2009-08-11 05:31:07 +00004422template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004423Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004424TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4426 if (LHS.isInvalid())
4427 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004428
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4430 if (RHS.isInvalid())
4431 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 if (!getDerived().AlwaysRebuild() &&
4434 LHS.get() == E->getLHS() &&
4435 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004436 return SemaRef.Owned(E->Retain());
4437
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4439 move(LHS), move(RHS));
4440}
4441
Mike Stump11289f42009-09-09 15:08:12 +00004442template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004443Sema::OwningExprResult
4444TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004445 CompoundAssignOperator *E) {
4446 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004447}
Mike Stump11289f42009-09-09 15:08:12 +00004448
Douglas Gregora16548e2009-08-11 05:31:07 +00004449template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004450Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004451TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4453 if (Cond.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4457 if (LHS.isInvalid())
4458 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004459
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4461 if (RHS.isInvalid())
4462 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 if (!getDerived().AlwaysRebuild() &&
4465 Cond.get() == E->getCond() &&
4466 LHS.get() == E->getLHS() &&
4467 RHS.get() == E->getRHS())
4468 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004469
4470 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004471 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004472 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004473 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 move(RHS));
4475}
Mike Stump11289f42009-09-09 15:08:12 +00004476
4477template<typename Derived>
4478Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004479TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004480 // Implicit casts are eliminated during transformation, since they
4481 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004482 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004483}
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregora16548e2009-08-11 05:31:07 +00004485template<typename Derived>
4486Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004487TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004488 TypeSourceInfo *OldT;
4489 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 {
4491 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004492 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4494 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004495
John McCall97513962010-01-15 18:39:57 +00004496 OldT = E->getTypeInfoAsWritten();
4497 NewT = getDerived().TransformType(OldT);
4498 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004499 return SemaRef.ExprError();
4500 }
Mike Stump11289f42009-09-09 15:08:12 +00004501
Douglas Gregor6131b442009-12-12 18:16:41 +00004502 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004503 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 if (SubExpr.isInvalid())
4505 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004508 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004510 return SemaRef.Owned(E->Retain());
4511
John McCall97513962010-01-15 18:39:57 +00004512 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4513 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 E->getRParenLoc(),
4515 move(SubExpr));
4516}
Mike Stump11289f42009-09-09 15:08:12 +00004517
Douglas Gregora16548e2009-08-11 05:31:07 +00004518template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004520TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004521 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4522 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4523 if (!NewT)
4524 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4527 if (Init.isInvalid())
4528 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004531 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004533 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004534
John McCall5d7aa7f2010-01-19 22:33:45 +00004535 // Note: the expression type doesn't necessarily match the
4536 // type-as-written, but that's okay, because it should always be
4537 // derivable from the initializer.
4538
John McCalle15bbff2010-01-18 19:35:47 +00004539 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 /*FIXME:*/E->getInitializer()->getLocEnd(),
4541 move(Init));
4542}
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregora16548e2009-08-11 05:31:07 +00004544template<typename Derived>
4545Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004546TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4548 if (Base.isInvalid())
4549 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 if (!getDerived().AlwaysRebuild() &&
4552 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004553 return SemaRef.Owned(E->Retain());
4554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004556 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4558 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4559 E->getAccessorLoc(),
4560 E->getAccessor());
4561}
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregora16548e2009-08-11 05:31:07 +00004563template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004564Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004565TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4569 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4570 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4571 if (Init.isInvalid())
4572 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 InitChanged = InitChanged || Init.get() != E->getInit(I);
4575 Inits.push_back(Init.takeAs<Expr>());
4576 }
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004579 return SemaRef.Owned(E->Retain());
4580
Douglas Gregora16548e2009-08-11 05:31:07 +00004581 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004582 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585template<typename Derived>
4586Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004587TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004588 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004589
Douglas Gregorebe10102009-08-20 07:17:43 +00004590 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4592 if (Init.isInvalid())
4593 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregorebe10102009-08-20 07:17:43 +00004595 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4597 bool ExprChanged = false;
4598 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4599 DEnd = E->designators_end();
4600 D != DEnd; ++D) {
4601 if (D->isFieldDesignator()) {
4602 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4603 D->getDotLoc(),
4604 D->getFieldLoc()));
4605 continue;
4606 }
Mike Stump11289f42009-09-09 15:08:12 +00004607
Douglas Gregora16548e2009-08-11 05:31:07 +00004608 if (D->isArrayDesignator()) {
4609 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4610 if (Index.isInvalid())
4611 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004612
4613 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4617 ArrayExprs.push_back(Index.release());
4618 continue;
4619 }
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004622 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4624 if (Start.isInvalid())
4625 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4628 if (End.isInvalid())
4629 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004630
4631 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004632 End.get(),
4633 D->getLBracketLoc(),
4634 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004635
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4637 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 ArrayExprs.push_back(Start.release());
4640 ArrayExprs.push_back(End.release());
4641 }
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 if (!getDerived().AlwaysRebuild() &&
4644 Init.get() == E->getInit() &&
4645 !ExprChanged)
4646 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4649 E->getEqualOrColonLoc(),
4650 E->usesGNUSyntax(), move(Init));
4651}
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004654Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004655TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004656 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004657 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4658
4659 // FIXME: Will we ever have proper type location here? Will we actually
4660 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004661 QualType T = getDerived().TransformType(E->getType());
4662 if (T.isNull())
4663 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 if (!getDerived().AlwaysRebuild() &&
4666 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004667 return SemaRef.Owned(E->Retain());
4668
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 return getDerived().RebuildImplicitValueInitExpr(T);
4670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregora16548e2009-08-11 05:31:07 +00004672template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004673Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004674TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 // FIXME: Do we want the type as written?
4676 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 {
4679 // FIXME: Source location isn't quite accurate.
4680 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4681 T = getDerived().TransformType(E->getType());
4682 if (T.isNull())
4683 return SemaRef.ExprError();
4684 }
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4687 if (SubExpr.isInvalid())
4688 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 if (!getDerived().AlwaysRebuild() &&
4691 T == E->getType() &&
4692 SubExpr.get() == E->getSubExpr())
4693 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4696 T, E->getRParenLoc());
4697}
4698
4699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004700Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004701TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 bool ArgumentChanged = false;
4703 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4704 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4705 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4706 if (Init.isInvalid())
4707 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4710 Inits.push_back(Init.takeAs<Expr>());
4711 }
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4714 move_arg(Inits),
4715 E->getRParenLoc());
4716}
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregora16548e2009-08-11 05:31:07 +00004718/// \brief Transform an address-of-label expression.
4719///
4720/// By default, the transformation of an address-of-label expression always
4721/// rebuilds the expression, so that the label identifier can be resolved to
4722/// the corresponding label statement by semantic analysis.
4723template<typename Derived>
4724Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004725TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4727 E->getLabel());
4728}
Mike Stump11289f42009-09-09 15:08:12 +00004729
4730template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004731Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004732TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004733 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004734 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4735 if (SubStmt.isInvalid())
4736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 if (!getDerived().AlwaysRebuild() &&
4739 SubStmt.get() == E->getSubStmt())
4740 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004741
4742 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 move(SubStmt),
4744 E->getRParenLoc());
4745}
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747template<typename Derived>
4748Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004749TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 QualType T1, T2;
4751 {
4752 // FIXME: Source location isn't quite accurate.
4753 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 T1 = getDerived().TransformType(E->getArgType1());
4756 if (T1.isNull())
4757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 T2 = getDerived().TransformType(E->getArgType2());
4760 if (T2.isNull())
4761 return SemaRef.ExprError();
4762 }
4763
4764 if (!getDerived().AlwaysRebuild() &&
4765 T1 == E->getArgType1() &&
4766 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004767 return SemaRef.Owned(E->Retain());
4768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4770 T1, T2, E->getRParenLoc());
4771}
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773template<typename Derived>
4774Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004775TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4777 if (Cond.isInvalid())
4778 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4781 if (LHS.isInvalid())
4782 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4785 if (RHS.isInvalid())
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 if (!getDerived().AlwaysRebuild() &&
4789 Cond.get() == E->getCond() &&
4790 LHS.get() == E->getLHS() &&
4791 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004792 return SemaRef.Owned(E->Retain());
4793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4795 move(Cond), move(LHS), move(RHS),
4796 E->getRParenLoc());
4797}
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004800Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004801TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004802 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004803}
4804
4805template<typename Derived>
4806Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004807TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004808 switch (E->getOperator()) {
4809 case OO_New:
4810 case OO_Delete:
4811 case OO_Array_New:
4812 case OO_Array_Delete:
4813 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4814 return SemaRef.ExprError();
4815
4816 case OO_Call: {
4817 // This is a call to an object's operator().
4818 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4819
4820 // Transform the object itself.
4821 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4822 if (Object.isInvalid())
4823 return SemaRef.ExprError();
4824
4825 // FIXME: Poor location information
4826 SourceLocation FakeLParenLoc
4827 = SemaRef.PP.getLocForEndOfToken(
4828 static_cast<Expr *>(Object.get())->getLocEnd());
4829
4830 // Transform the call arguments.
4831 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4832 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4833 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004834 if (getDerived().DropCallArgument(E->getArg(I)))
4835 break;
4836
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004837 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4838 if (Arg.isInvalid())
4839 return SemaRef.ExprError();
4840
4841 // FIXME: Poor source location information.
4842 SourceLocation FakeCommaLoc
4843 = SemaRef.PP.getLocForEndOfToken(
4844 static_cast<Expr *>(Arg.get())->getLocEnd());
4845 FakeCommaLocs.push_back(FakeCommaLoc);
4846 Args.push_back(Arg.release());
4847 }
4848
4849 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4850 move_arg(Args),
4851 FakeCommaLocs.data(),
4852 E->getLocEnd());
4853 }
4854
4855#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4856 case OO_##Name:
4857#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4858#include "clang/Basic/OperatorKinds.def"
4859 case OO_Subscript:
4860 // Handled below.
4861 break;
4862
4863 case OO_Conditional:
4864 llvm_unreachable("conditional operator is not actually overloadable");
4865 return SemaRef.ExprError();
4866
4867 case OO_None:
4868 case NUM_OVERLOADED_OPERATORS:
4869 llvm_unreachable("not an overloaded operator?");
4870 return SemaRef.ExprError();
4871 }
4872
Douglas Gregora16548e2009-08-11 05:31:07 +00004873 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4874 if (Callee.isInvalid())
4875 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004876
John McCall47f29ea2009-12-08 09:21:05 +00004877 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 if (First.isInvalid())
4879 return SemaRef.ExprError();
4880
4881 OwningExprResult Second(SemaRef);
4882 if (E->getNumArgs() == 2) {
4883 Second = getDerived().TransformExpr(E->getArg(1));
4884 if (Second.isInvalid())
4885 return SemaRef.ExprError();
4886 }
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 if (!getDerived().AlwaysRebuild() &&
4889 Callee.get() == E->getCallee() &&
4890 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004891 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4892 return SemaRef.Owned(E->Retain());
4893
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4895 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004896 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004897 move(First),
4898 move(Second));
4899}
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregora16548e2009-08-11 05:31:07 +00004901template<typename Derived>
4902Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004903TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4904 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004905}
Mike Stump11289f42009-09-09 15:08:12 +00004906
Douglas Gregora16548e2009-08-11 05:31:07 +00004907template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004908Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004909TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004910 TypeSourceInfo *OldT;
4911 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004912 {
4913 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004914 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004915 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4916 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004917
John McCall97513962010-01-15 18:39:57 +00004918 OldT = E->getTypeInfoAsWritten();
4919 NewT = getDerived().TransformType(OldT);
4920 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 return SemaRef.ExprError();
4922 }
Mike Stump11289f42009-09-09 15:08:12 +00004923
Douglas Gregor6131b442009-12-12 18:16:41 +00004924 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004925 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004926 if (SubExpr.isInvalid())
4927 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004928
Douglas Gregora16548e2009-08-11 05:31:07 +00004929 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004930 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004931 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004932 return SemaRef.Owned(E->Retain());
4933
Douglas Gregora16548e2009-08-11 05:31:07 +00004934 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004935 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4937 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4938 SourceLocation FakeRParenLoc
4939 = SemaRef.PP.getLocForEndOfToken(
4940 E->getSubExpr()->getSourceRange().getEnd());
4941 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004942 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004944 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 FakeRAngleLoc,
4946 FakeRAngleLoc,
4947 move(SubExpr),
4948 FakeRParenLoc);
4949}
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregora16548e2009-08-11 05:31:07 +00004951template<typename Derived>
4952Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004953TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4954 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004955}
Mike Stump11289f42009-09-09 15:08:12 +00004956
4957template<typename Derived>
4958Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004959TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4960 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004961}
4962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963template<typename Derived>
4964Sema::OwningExprResult
4965TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004966 CXXReinterpretCastExpr *E) {
4967 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004968}
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregora16548e2009-08-11 05:31:07 +00004970template<typename Derived>
4971Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004972TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4973 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004974}
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregora16548e2009-08-11 05:31:07 +00004976template<typename Derived>
4977Sema::OwningExprResult
4978TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004979 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004980 TypeSourceInfo *OldT;
4981 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 {
4983 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004984
John McCall97513962010-01-15 18:39:57 +00004985 OldT = E->getTypeInfoAsWritten();
4986 NewT = getDerived().TransformType(OldT);
4987 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004988 return SemaRef.ExprError();
4989 }
Mike Stump11289f42009-09-09 15:08:12 +00004990
Douglas Gregor6131b442009-12-12 18:16:41 +00004991 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004992 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 if (SubExpr.isInvalid())
4994 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004995
Douglas Gregora16548e2009-08-11 05:31:07 +00004996 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004997 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004999 return SemaRef.Owned(E->Retain());
5000
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 // FIXME: The end of the type's source range is wrong
5002 return getDerived().RebuildCXXFunctionalCastExpr(
5003 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005004 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 /*FIXME:*/E->getSubExpr()->getLocStart(),
5006 move(SubExpr),
5007 E->getRParenLoc());
5008}
Mike Stump11289f42009-09-09 15:08:12 +00005009
Douglas Gregora16548e2009-08-11 05:31:07 +00005010template<typename Derived>
5011Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005012TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005014 TypeSourceInfo *TInfo
5015 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5016 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005020 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregor9da64192010-04-26 22:37:10 +00005023 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5024 E->getLocStart(),
5025 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 E->getLocEnd());
5027 }
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregora16548e2009-08-11 05:31:07 +00005029 // We don't know whether the expression is potentially evaluated until
5030 // after we perform semantic analysis, so the expression is potentially
5031 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005032 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005034
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5036 if (SubExpr.isInvalid())
5037 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregora16548e2009-08-11 05:31:07 +00005039 if (!getDerived().AlwaysRebuild() &&
5040 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005041 return SemaRef.Owned(E->Retain());
5042
Douglas Gregor9da64192010-04-26 22:37:10 +00005043 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5044 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 move(SubExpr),
5046 E->getLocEnd());
5047}
5048
5049template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005050Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005051TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005052 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005053}
Mike Stump11289f42009-09-09 15:08:12 +00005054
Douglas Gregora16548e2009-08-11 05:31:07 +00005055template<typename Derived>
5056Sema::OwningExprResult
5057TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005058 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005059 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005060}
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062template<typename Derived>
5063Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005064TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005065 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 QualType T = getDerived().TransformType(E->getType());
5068 if (T.isNull())
5069 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 if (!getDerived().AlwaysRebuild() &&
5072 T == E->getType())
5073 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregorb15af892010-01-07 23:12:05 +00005075 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078template<typename Derived>
5079Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005080TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5082 if (SubExpr.isInvalid())
5083 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 if (!getDerived().AlwaysRebuild() &&
5086 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005087 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005088
5089 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5090}
Mike Stump11289f42009-09-09 15:08:12 +00005091
Douglas Gregora16548e2009-08-11 05:31:07 +00005092template<typename Derived>
5093Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005094TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005095 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005096 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5097 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 if (!Param)
5099 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005100
Chandler Carruth794da4c2010-02-08 06:42:49 +00005101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 Param == E->getParam())
5103 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregor033f6752009-12-23 23:03:06 +00005105 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005106}
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregora16548e2009-08-11 05:31:07 +00005108template<typename Derived>
5109Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005110TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5112
5113 QualType T = getDerived().TransformType(E->getType());
5114 if (T.isNull())
5115 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 if (!getDerived().AlwaysRebuild() &&
5118 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005119 return SemaRef.Owned(E->Retain());
5120
5121 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 /*FIXME:*/E->getTypeBeginLoc(),
5123 T,
5124 E->getRParenLoc());
5125}
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127template<typename Derived>
5128Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005129TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 // Transform the type that we're allocating
5131 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5132 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5133 if (AllocType.isNull())
5134 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 // Transform the size of the array we're allocating (if any).
5137 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5138 if (ArraySize.isInvalid())
5139 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 // Transform the placement arguments (if any).
5142 bool ArgumentChanged = false;
5143 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5144 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5145 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5146 if (Arg.isInvalid())
5147 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005148
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5150 PlacementArgs.push_back(Arg.take());
5151 }
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregorebe10102009-08-20 07:17:43 +00005153 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005154 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5155 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5156 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5157 if (Arg.isInvalid())
5158 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5161 ConstructorArgs.push_back(Arg.take());
5162 }
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregord2d9da02010-02-26 00:38:10 +00005164 // Transform constructor, new operator, and delete operator.
5165 CXXConstructorDecl *Constructor = 0;
5166 if (E->getConstructor()) {
5167 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005168 getDerived().TransformDecl(E->getLocStart(),
5169 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005170 if (!Constructor)
5171 return SemaRef.ExprError();
5172 }
5173
5174 FunctionDecl *OperatorNew = 0;
5175 if (E->getOperatorNew()) {
5176 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005177 getDerived().TransformDecl(E->getLocStart(),
5178 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005179 if (!OperatorNew)
5180 return SemaRef.ExprError();
5181 }
5182
5183 FunctionDecl *OperatorDelete = 0;
5184 if (E->getOperatorDelete()) {
5185 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005186 getDerived().TransformDecl(E->getLocStart(),
5187 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005188 if (!OperatorDelete)
5189 return SemaRef.ExprError();
5190 }
5191
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 if (!getDerived().AlwaysRebuild() &&
5193 AllocType == E->getAllocatedType() &&
5194 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005195 Constructor == E->getConstructor() &&
5196 OperatorNew == E->getOperatorNew() &&
5197 OperatorDelete == E->getOperatorDelete() &&
5198 !ArgumentChanged) {
5199 // Mark any declarations we need as referenced.
5200 // FIXME: instantiation-specific.
5201 if (Constructor)
5202 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5203 if (OperatorNew)
5204 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5205 if (OperatorDelete)
5206 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005207 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005208 }
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005210 if (!ArraySize.get()) {
5211 // If no array size was specified, but the new expression was
5212 // instantiated with an array type (e.g., "new T" where T is
5213 // instantiated with "int[4]"), extract the outer bound from the
5214 // array type as our array size. We do this with constant and
5215 // dependently-sized array types.
5216 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5217 if (!ArrayT) {
5218 // Do nothing
5219 } else if (const ConstantArrayType *ConsArrayT
5220 = dyn_cast<ConstantArrayType>(ArrayT)) {
5221 ArraySize
5222 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
5223 ConsArrayT->getSize(),
5224 SemaRef.Context.getSizeType(),
5225 /*FIXME:*/E->getLocStart()));
5226 AllocType = ConsArrayT->getElementType();
5227 } else if (const DependentSizedArrayType *DepArrayT
5228 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5229 if (DepArrayT->getSizeExpr()) {
5230 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5231 AllocType = DepArrayT->getElementType();
5232 }
5233 }
5234 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005235 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5236 E->isGlobalNew(),
5237 /*FIXME:*/E->getLocStart(),
5238 move_arg(PlacementArgs),
5239 /*FIXME:*/E->getLocStart(),
5240 E->isParenTypeId(),
5241 AllocType,
5242 /*FIXME:*/E->getLocStart(),
5243 /*FIXME:*/SourceRange(),
5244 move(ArraySize),
5245 /*FIXME:*/E->getLocStart(),
5246 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005247 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248}
Mike Stump11289f42009-09-09 15:08:12 +00005249
Douglas Gregora16548e2009-08-11 05:31:07 +00005250template<typename Derived>
5251Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5254 if (Operand.isInvalid())
5255 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregord2d9da02010-02-26 00:38:10 +00005257 // Transform the delete operator, if known.
5258 FunctionDecl *OperatorDelete = 0;
5259 if (E->getOperatorDelete()) {
5260 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005261 getDerived().TransformDecl(E->getLocStart(),
5262 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005263 if (!OperatorDelete)
5264 return SemaRef.ExprError();
5265 }
5266
Douglas Gregora16548e2009-08-11 05:31:07 +00005267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005268 Operand.get() == E->getArgument() &&
5269 OperatorDelete == E->getOperatorDelete()) {
5270 // Mark any declarations we need as referenced.
5271 // FIXME: instantiation-specific.
5272 if (OperatorDelete)
5273 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005274 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005275 }
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregora16548e2009-08-11 05:31:07 +00005277 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5278 E->isGlobalDelete(),
5279 E->isArrayForm(),
5280 move(Operand));
5281}
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregora16548e2009-08-11 05:31:07 +00005283template<typename Derived>
5284Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005285TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005286 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005287 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5288 if (Base.isInvalid())
5289 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005290
Douglas Gregor678f90d2010-02-25 01:56:36 +00005291 Sema::TypeTy *ObjectTypePtr = 0;
5292 bool MayBePseudoDestructor = false;
5293 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5294 E->getOperatorLoc(),
5295 E->isArrow()? tok::arrow : tok::period,
5296 ObjectTypePtr,
5297 MayBePseudoDestructor);
5298 if (Base.isInvalid())
5299 return SemaRef.ExprError();
5300
5301 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005302 NestedNameSpecifier *Qualifier
5303 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005304 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005305 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005306 if (E->getQualifier() && !Qualifier)
5307 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregor678f90d2010-02-25 01:56:36 +00005309 PseudoDestructorTypeStorage Destroyed;
5310 if (E->getDestroyedTypeInfo()) {
5311 TypeSourceInfo *DestroyedTypeInfo
5312 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5313 if (!DestroyedTypeInfo)
5314 return SemaRef.ExprError();
5315 Destroyed = DestroyedTypeInfo;
5316 } else if (ObjectType->isDependentType()) {
5317 // We aren't likely to be able to resolve the identifier down to a type
5318 // now anyway, so just retain the identifier.
5319 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5320 E->getDestroyedTypeLoc());
5321 } else {
5322 // Look for a destructor known with the given name.
5323 CXXScopeSpec SS;
5324 if (Qualifier) {
5325 SS.setScopeRep(Qualifier);
5326 SS.setRange(E->getQualifierRange());
5327 }
5328
5329 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5330 *E->getDestroyedTypeIdentifier(),
5331 E->getDestroyedTypeLoc(),
5332 /*Scope=*/0,
5333 SS, ObjectTypePtr,
5334 false);
5335 if (!T)
5336 return SemaRef.ExprError();
5337
5338 Destroyed
5339 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5340 E->getDestroyedTypeLoc());
5341 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005342
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005343 TypeSourceInfo *ScopeTypeInfo = 0;
5344 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005345 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5346 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005347 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005348 return SemaRef.ExprError();
5349 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005350
Douglas Gregorad8a3362009-09-04 17:36:40 +00005351 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5352 E->getOperatorLoc(),
5353 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005354 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005355 E->getQualifierRange(),
5356 ScopeTypeInfo,
5357 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005358 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005359 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005360}
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregorad8a3362009-09-04 17:36:40 +00005362template<typename Derived>
5363Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005364TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005365 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005366 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5367
5368 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5369 Sema::LookupOrdinaryName);
5370
5371 // Transform all the decls.
5372 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5373 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005374 NamedDecl *InstD = static_cast<NamedDecl*>(
5375 getDerived().TransformDecl(Old->getNameLoc(),
5376 *I));
John McCall84d87672009-12-10 09:41:52 +00005377 if (!InstD) {
5378 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5379 // This can happen because of dependent hiding.
5380 if (isa<UsingShadowDecl>(*I))
5381 continue;
5382 else
5383 return SemaRef.ExprError();
5384 }
John McCalle66edc12009-11-24 19:00:30 +00005385
5386 // Expand using declarations.
5387 if (isa<UsingDecl>(InstD)) {
5388 UsingDecl *UD = cast<UsingDecl>(InstD);
5389 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5390 E = UD->shadow_end(); I != E; ++I)
5391 R.addDecl(*I);
5392 continue;
5393 }
5394
5395 R.addDecl(InstD);
5396 }
5397
5398 // Resolve a kind, but don't do any further analysis. If it's
5399 // ambiguous, the callee needs to deal with it.
5400 R.resolveKind();
5401
5402 // Rebuild the nested-name qualifier, if present.
5403 CXXScopeSpec SS;
5404 NestedNameSpecifier *Qualifier = 0;
5405 if (Old->getQualifier()) {
5406 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005407 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005408 if (!Qualifier)
5409 return SemaRef.ExprError();
5410
5411 SS.setScopeRep(Qualifier);
5412 SS.setRange(Old->getQualifierRange());
Douglas Gregor9262f472010-04-27 18:19:34 +00005413 }
5414
5415 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005416 CXXRecordDecl *NamingClass
5417 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5418 Old->getNameLoc(),
5419 Old->getNamingClass()));
5420 if (!NamingClass)
5421 return SemaRef.ExprError();
Douglas Gregor9262f472010-04-27 18:19:34 +00005422
Douglas Gregorda7be082010-04-27 16:10:10 +00005423 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005424 }
5425
5426 // If we have no template arguments, it's a normal declaration name.
5427 if (!Old->hasExplicitTemplateArgs())
5428 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5429
5430 // If we have template arguments, rebuild them, then rebuild the
5431 // templateid expression.
5432 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5433 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5434 TemplateArgumentLoc Loc;
5435 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5436 return SemaRef.ExprError();
5437 TransArgs.addArgument(Loc);
5438 }
5439
5440 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5441 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005442}
Mike Stump11289f42009-09-09 15:08:12 +00005443
Douglas Gregora16548e2009-08-11 05:31:07 +00005444template<typename Derived>
5445Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005446TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregora16548e2009-08-11 05:31:07 +00005449 QualType T = getDerived().TransformType(E->getQueriedType());
5450 if (T.isNull())
5451 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 if (!getDerived().AlwaysRebuild() &&
5454 T == E->getQueriedType())
5455 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 // FIXME: Bad location information
5458 SourceLocation FakeLParenLoc
5459 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005460
5461 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005462 E->getLocStart(),
5463 /*FIXME:*/FakeLParenLoc,
5464 T,
5465 E->getLocEnd());
5466}
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468template<typename Derived>
5469Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005470TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005471 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005472 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005473 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005474 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005475 if (!NNS)
5476 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005477
5478 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005479 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5480 if (!Name)
5481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005482
John McCalle66edc12009-11-24 19:00:30 +00005483 if (!E->hasExplicitTemplateArgs()) {
5484 if (!getDerived().AlwaysRebuild() &&
5485 NNS == E->getQualifier() &&
5486 Name == E->getDeclName())
5487 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005488
John McCalle66edc12009-11-24 19:00:30 +00005489 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5490 E->getQualifierRange(),
5491 Name, E->getLocation(),
5492 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005493 }
John McCall6b51f282009-11-23 01:53:49 +00005494
5495 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005496 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005497 TemplateArgumentLoc Loc;
5498 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005500 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005501 }
5502
John McCalle66edc12009-11-24 19:00:30 +00005503 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5504 E->getQualifierRange(),
5505 Name, E->getLocation(),
5506 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005507}
5508
5509template<typename Derived>
5510Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005511TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005512 // CXXConstructExprs are always implicit, so when we have a
5513 // 1-argument construction we just transform that argument.
5514 if (E->getNumArgs() == 1 ||
5515 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5516 return getDerived().TransformExpr(E->getArg(0));
5517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5519
5520 QualType T = getDerived().TransformType(E->getType());
5521 if (T.isNull())
5522 return SemaRef.ExprError();
5523
5524 CXXConstructorDecl *Constructor
5525 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005526 getDerived().TransformDecl(E->getLocStart(),
5527 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005528 if (!Constructor)
5529 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 bool ArgumentChanged = false;
5532 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005533 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005534 ArgEnd = E->arg_end();
5535 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005536 if (getDerived().DropCallArgument(*Arg)) {
5537 ArgumentChanged = true;
5538 break;
5539 }
5540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5542 if (TransArg.isInvalid())
5543 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005544
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5546 Args.push_back(TransArg.takeAs<Expr>());
5547 }
5548
5549 if (!getDerived().AlwaysRebuild() &&
5550 T == E->getType() &&
5551 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005552 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005553 // Mark the constructor as referenced.
5554 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005555 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005557 }
Mike Stump11289f42009-09-09 15:08:12 +00005558
Douglas Gregordb121ba2009-12-14 16:27:04 +00005559 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5560 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 move_arg(Args));
5562}
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregora16548e2009-08-11 05:31:07 +00005564/// \brief Transform a C++ temporary-binding expression.
5565///
Douglas Gregor363b1512009-12-24 18:51:59 +00005566/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5567/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005568template<typename Derived>
5569Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005570TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005571 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005572}
Mike Stump11289f42009-09-09 15:08:12 +00005573
Anders Carlssonba6c4372010-01-29 02:39:32 +00005574/// \brief Transform a C++ reference-binding expression.
5575///
5576/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5577/// transform the subexpression and return that.
5578template<typename Derived>
5579Sema::OwningExprResult
5580TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5581 return getDerived().TransformExpr(E->getSubExpr());
5582}
5583
Mike Stump11289f42009-09-09 15:08:12 +00005584/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005585/// be destroyed after the expression is evaluated.
5586///
Douglas Gregor363b1512009-12-24 18:51:59 +00005587/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5588/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005589template<typename Derived>
5590Sema::OwningExprResult
5591TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005592 CXXExprWithTemporaries *E) {
5593 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005594}
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregora16548e2009-08-11 05:31:07 +00005596template<typename Derived>
5597Sema::OwningExprResult
5598TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005599 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5601 QualType T = getDerived().TransformType(E->getType());
5602 if (T.isNull())
5603 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005604
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 CXXConstructorDecl *Constructor
5606 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005607 getDerived().TransformDecl(E->getLocStart(),
5608 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 if (!Constructor)
5610 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 bool ArgumentChanged = false;
5613 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5614 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005615 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005616 ArgEnd = E->arg_end();
5617 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005618 if (getDerived().DropCallArgument(*Arg)) {
5619 ArgumentChanged = true;
5620 break;
5621 }
5622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5624 if (TransArg.isInvalid())
5625 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5628 Args.push_back((Expr *)TransArg.release());
5629 }
Mike Stump11289f42009-09-09 15:08:12 +00005630
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 if (!getDerived().AlwaysRebuild() &&
5632 T == E->getType() &&
5633 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005634 !ArgumentChanged) {
5635 // FIXME: Instantiation-specific
5636 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005637 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005638 }
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 // FIXME: Bogus location information
5641 SourceLocation CommaLoc;
5642 if (Args.size() > 1) {
5643 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005644 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005645 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5646 }
5647 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5648 T,
5649 /*FIXME:*/E->getTypeBeginLoc(),
5650 move_arg(Args),
5651 &CommaLoc,
5652 E->getLocEnd());
5653}
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregora16548e2009-08-11 05:31:07 +00005655template<typename Derived>
5656Sema::OwningExprResult
5657TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005658 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5660 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5661 if (T.isNull())
5662 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 bool ArgumentChanged = false;
5665 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5666 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5667 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5668 ArgEnd = E->arg_end();
5669 Arg != ArgEnd; ++Arg) {
5670 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5671 if (TransArg.isInvalid())
5672 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5675 FakeCommaLocs.push_back(
5676 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5677 Args.push_back(TransArg.takeAs<Expr>());
5678 }
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 if (!getDerived().AlwaysRebuild() &&
5681 T == E->getTypeAsWritten() &&
5682 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005683 return SemaRef.Owned(E->Retain());
5684
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 // FIXME: we're faking the locations of the commas
5686 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5687 T,
5688 E->getLParenLoc(),
5689 move_arg(Args),
5690 FakeCommaLocs.data(),
5691 E->getRParenLoc());
5692}
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregora16548e2009-08-11 05:31:07 +00005694template<typename Derived>
5695Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005696TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005697 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005699 OwningExprResult Base(SemaRef, (Expr*) 0);
5700 Expr *OldBase;
5701 QualType BaseType;
5702 QualType ObjectType;
5703 if (!E->isImplicitAccess()) {
5704 OldBase = E->getBase();
5705 Base = getDerived().TransformExpr(OldBase);
5706 if (Base.isInvalid())
5707 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005708
John McCall2d74de92009-12-01 22:10:20 +00005709 // Start the member reference and compute the object's type.
5710 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005711 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005712 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5713 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005714 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005715 ObjectTy,
5716 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005717 if (Base.isInvalid())
5718 return SemaRef.ExprError();
5719
5720 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5721 BaseType = ((Expr*) Base.get())->getType();
5722 } else {
5723 OldBase = 0;
5724 BaseType = getDerived().TransformType(E->getBaseType());
5725 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5726 }
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005728 // Transform the first part of the nested-name-specifier that qualifies
5729 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005730 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005731 = getDerived().TransformFirstQualifierInScope(
5732 E->getFirstQualifierFoundInScope(),
5733 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005734
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005735 NestedNameSpecifier *Qualifier = 0;
5736 if (E->getQualifier()) {
5737 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5738 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005739 ObjectType,
5740 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005741 if (!Qualifier)
5742 return SemaRef.ExprError();
5743 }
Mike Stump11289f42009-09-09 15:08:12 +00005744
5745 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005746 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005747 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005748 if (!Name)
5749 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005750
John McCall2d74de92009-12-01 22:10:20 +00005751 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005752 // This is a reference to a member without an explicitly-specified
5753 // template argument list. Optimize for this common case.
5754 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005755 Base.get() == OldBase &&
5756 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005757 Qualifier == E->getQualifier() &&
5758 Name == E->getMember() &&
5759 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005760 return SemaRef.Owned(E->Retain());
5761
John McCall8cd78132009-11-19 22:55:06 +00005762 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005763 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005764 E->isArrow(),
5765 E->getOperatorLoc(),
5766 Qualifier,
5767 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005768 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005769 Name,
5770 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005771 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005772 }
5773
John McCall6b51f282009-11-23 01:53:49 +00005774 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005775 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005776 TemplateArgumentLoc Loc;
5777 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005778 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005779 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005780 }
Mike Stump11289f42009-09-09 15:08:12 +00005781
John McCall8cd78132009-11-19 22:55:06 +00005782 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005783 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005784 E->isArrow(),
5785 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005786 Qualifier,
5787 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005788 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005789 Name,
5790 E->getMemberLoc(),
5791 &TransArgs);
5792}
5793
5794template<typename Derived>
5795Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005796TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005797 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005798 OwningExprResult Base(SemaRef, (Expr*) 0);
5799 QualType BaseType;
5800 if (!Old->isImplicitAccess()) {
5801 Base = getDerived().TransformExpr(Old->getBase());
5802 if (Base.isInvalid())
5803 return SemaRef.ExprError();
5804 BaseType = ((Expr*) Base.get())->getType();
5805 } else {
5806 BaseType = getDerived().TransformType(Old->getBaseType());
5807 }
John McCall10eae182009-11-30 22:42:35 +00005808
5809 NestedNameSpecifier *Qualifier = 0;
5810 if (Old->getQualifier()) {
5811 Qualifier
5812 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005813 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005814 if (Qualifier == 0)
5815 return SemaRef.ExprError();
5816 }
5817
5818 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5819 Sema::LookupOrdinaryName);
5820
5821 // Transform all the decls.
5822 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5823 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005824 NamedDecl *InstD = static_cast<NamedDecl*>(
5825 getDerived().TransformDecl(Old->getMemberLoc(),
5826 *I));
John McCall84d87672009-12-10 09:41:52 +00005827 if (!InstD) {
5828 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5829 // This can happen because of dependent hiding.
5830 if (isa<UsingShadowDecl>(*I))
5831 continue;
5832 else
5833 return SemaRef.ExprError();
5834 }
John McCall10eae182009-11-30 22:42:35 +00005835
5836 // Expand using declarations.
5837 if (isa<UsingDecl>(InstD)) {
5838 UsingDecl *UD = cast<UsingDecl>(InstD);
5839 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5840 E = UD->shadow_end(); I != E; ++I)
5841 R.addDecl(*I);
5842 continue;
5843 }
5844
5845 R.addDecl(InstD);
5846 }
5847
5848 R.resolveKind();
5849
Douglas Gregor9262f472010-04-27 18:19:34 +00005850 // Determine the naming class.
5851 if (!Old->getNamingClass()) {
5852 CXXRecordDecl *NamingClass
5853 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005854 Old->getMemberLoc(),
5855 Old->getNamingClass()));
5856 if (!NamingClass)
5857 return SemaRef.ExprError();
Douglas Gregor9262f472010-04-27 18:19:34 +00005858
Douglas Gregorda7be082010-04-27 16:10:10 +00005859 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005860 }
Douglas Gregorda7be082010-04-27 16:10:10 +00005861
John McCall10eae182009-11-30 22:42:35 +00005862 TemplateArgumentListInfo TransArgs;
5863 if (Old->hasExplicitTemplateArgs()) {
5864 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5865 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5866 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5867 TemplateArgumentLoc Loc;
5868 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5869 Loc))
5870 return SemaRef.ExprError();
5871 TransArgs.addArgument(Loc);
5872 }
5873 }
John McCall38836f02010-01-15 08:34:02 +00005874
5875 // FIXME: to do this check properly, we will need to preserve the
5876 // first-qualifier-in-scope here, just in case we had a dependent
5877 // base (and therefore couldn't do the check) and a
5878 // nested-name-qualifier (and therefore could do the lookup).
5879 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005880
5881 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005882 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005883 Old->getOperatorLoc(),
5884 Old->isArrow(),
5885 Qualifier,
5886 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005887 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005888 R,
5889 (Old->hasExplicitTemplateArgs()
5890 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005891}
5892
5893template<typename Derived>
5894Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005895TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005896 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005897}
5898
Mike Stump11289f42009-09-09 15:08:12 +00005899template<typename Derived>
5900Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005901TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005902 TypeSourceInfo *EncodedTypeInfo
5903 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5904 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005908 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005909 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005910
5911 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005912 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 E->getRParenLoc());
5914}
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregora16548e2009-08-11 05:31:07 +00005916template<typename Derived>
5917Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005918TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005919 // Transform arguments.
5920 bool ArgChanged = false;
5921 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5922 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5923 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5924 if (Arg.isInvalid())
5925 return SemaRef.ExprError();
5926
5927 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5928 Args.push_back(Arg.takeAs<Expr>());
5929 }
5930
5931 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5932 // Class message: transform the receiver type.
5933 TypeSourceInfo *ReceiverTypeInfo
5934 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5935 if (!ReceiverTypeInfo)
5936 return SemaRef.ExprError();
5937
5938 // If nothing changed, just retain the existing message send.
5939 if (!getDerived().AlwaysRebuild() &&
5940 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5941 return SemaRef.Owned(E->Retain());
5942
5943 // Build a new class message send.
5944 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5945 E->getSelector(),
5946 E->getMethodDecl(),
5947 E->getLeftLoc(),
5948 move_arg(Args),
5949 E->getRightLoc());
5950 }
5951
5952 // Instance message: transform the receiver
5953 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5954 "Only class and instance messages may be instantiated");
5955 OwningExprResult Receiver
5956 = getDerived().TransformExpr(E->getInstanceReceiver());
5957 if (Receiver.isInvalid())
5958 return SemaRef.ExprError();
5959
5960 // If nothing changed, just retain the existing message send.
5961 if (!getDerived().AlwaysRebuild() &&
5962 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5963 return SemaRef.Owned(E->Retain());
5964
5965 // Build a new instance message send.
5966 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5967 E->getSelector(),
5968 E->getMethodDecl(),
5969 E->getLeftLoc(),
5970 move_arg(Args),
5971 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005972}
5973
Mike Stump11289f42009-09-09 15:08:12 +00005974template<typename Derived>
5975Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005976TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005977 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005978}
5979
Mike Stump11289f42009-09-09 15:08:12 +00005980template<typename Derived>
5981Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005982TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005983 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005984}
5985
Mike Stump11289f42009-09-09 15:08:12 +00005986template<typename Derived>
5987Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005988TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005989 // Transform the base expression.
5990 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5991 if (Base.isInvalid())
5992 return SemaRef.ExprError();
5993
5994 // We don't need to transform the ivar; it will never change.
5995
5996 // If nothing changed, just retain the existing expression.
5997 if (!getDerived().AlwaysRebuild() &&
5998 Base.get() == E->getBase())
5999 return SemaRef.Owned(E->Retain());
6000
6001 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6002 E->getLocation(),
6003 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006004}
6005
Mike Stump11289f42009-09-09 15:08:12 +00006006template<typename Derived>
6007Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006008TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006009 // Transform the base expression.
6010 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6011 if (Base.isInvalid())
6012 return SemaRef.ExprError();
6013
6014 // We don't need to transform the property; it will never change.
6015
6016 // If nothing changed, just retain the existing expression.
6017 if (!getDerived().AlwaysRebuild() &&
6018 Base.get() == E->getBase())
6019 return SemaRef.Owned(E->Retain());
6020
6021 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6022 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006023}
6024
Mike Stump11289f42009-09-09 15:08:12 +00006025template<typename Derived>
6026Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006027TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006028 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006029 // If this implicit setter/getter refers to class methods, it cannot have any
6030 // dependent parts. Just retain the existing declaration.
6031 if (E->getInterfaceDecl())
6032 return SemaRef.Owned(E->Retain());
6033
6034 // Transform the base expression.
6035 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6036 if (Base.isInvalid())
6037 return SemaRef.ExprError();
6038
6039 // We don't need to transform the getters/setters; they will never change.
6040
6041 // If nothing changed, just retain the existing expression.
6042 if (!getDerived().AlwaysRebuild() &&
6043 Base.get() == E->getBase())
6044 return SemaRef.Owned(E->Retain());
6045
6046 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6047 E->getGetterMethod(),
6048 E->getType(),
6049 E->getSetterMethod(),
6050 E->getLocation(),
6051 move(Base));
6052
Douglas Gregora16548e2009-08-11 05:31:07 +00006053}
6054
Mike Stump11289f42009-09-09 15:08:12 +00006055template<typename Derived>
6056Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006057TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006058 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006059 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006060}
6061
Mike Stump11289f42009-09-09 15:08:12 +00006062template<typename Derived>
6063Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006065 // Transform the base expression.
6066 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6067 if (Base.isInvalid())
6068 return SemaRef.ExprError();
6069
6070 // If nothing changed, just retain the existing expression.
6071 if (!getDerived().AlwaysRebuild() &&
6072 Base.get() == E->getBase())
6073 return SemaRef.Owned(E->Retain());
6074
6075 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6076 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006077}
6078
Mike Stump11289f42009-09-09 15:08:12 +00006079template<typename Derived>
6080Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006081TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006082 bool ArgumentChanged = false;
6083 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6084 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6085 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6086 if (SubExpr.isInvalid())
6087 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006088
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6090 SubExprs.push_back(SubExpr.takeAs<Expr>());
6091 }
Mike Stump11289f42009-09-09 15:08:12 +00006092
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 if (!getDerived().AlwaysRebuild() &&
6094 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006095 return SemaRef.Owned(E->Retain());
6096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6098 move_arg(SubExprs),
6099 E->getRParenLoc());
6100}
6101
Mike Stump11289f42009-09-09 15:08:12 +00006102template<typename Derived>
6103Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006104TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 // FIXME: Implement this!
6106 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006107 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006108}
6109
Mike Stump11289f42009-09-09 15:08:12 +00006110template<typename Derived>
6111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006112TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006113 // FIXME: Implement this!
6114 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006115 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006116}
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006119// Type reconstruction
6120//===----------------------------------------------------------------------===//
6121
Mike Stump11289f42009-09-09 15:08:12 +00006122template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006123QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6124 SourceLocation Star) {
6125 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006126 getDerived().getBaseEntity());
6127}
6128
Mike Stump11289f42009-09-09 15:08:12 +00006129template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006130QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6131 SourceLocation Star) {
6132 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006133 getDerived().getBaseEntity());
6134}
6135
Mike Stump11289f42009-09-09 15:08:12 +00006136template<typename Derived>
6137QualType
John McCall70dd5f62009-10-30 00:06:24 +00006138TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6139 bool WrittenAsLValue,
6140 SourceLocation Sigil) {
6141 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6142 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006143}
6144
6145template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006146QualType
John McCall70dd5f62009-10-30 00:06:24 +00006147TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6148 QualType ClassType,
6149 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006150 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006151 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006152}
6153
6154template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006155QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006156TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6157 ArrayType::ArraySizeModifier SizeMod,
6158 const llvm::APInt *Size,
6159 Expr *SizeExpr,
6160 unsigned IndexTypeQuals,
6161 SourceRange BracketsRange) {
6162 if (SizeExpr || !Size)
6163 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6164 IndexTypeQuals, BracketsRange,
6165 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006166
6167 QualType Types[] = {
6168 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6169 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6170 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006171 };
6172 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6173 QualType SizeType;
6174 for (unsigned I = 0; I != NumTypes; ++I)
6175 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6176 SizeType = Types[I];
6177 break;
6178 }
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregord6ff3322009-08-04 16:50:30 +00006180 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006181 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006182 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006183 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006184}
Mike Stump11289f42009-09-09 15:08:12 +00006185
Douglas Gregord6ff3322009-08-04 16:50:30 +00006186template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006187QualType
6188TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006189 ArrayType::ArraySizeModifier SizeMod,
6190 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006191 unsigned IndexTypeQuals,
6192 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006193 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006194 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006195}
6196
6197template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006198QualType
Mike Stump11289f42009-09-09 15:08:12 +00006199TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006200 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006201 unsigned IndexTypeQuals,
6202 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006203 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006204 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006205}
Mike Stump11289f42009-09-09 15:08:12 +00006206
Douglas Gregord6ff3322009-08-04 16:50:30 +00006207template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006208QualType
6209TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006210 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006212 unsigned IndexTypeQuals,
6213 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006214 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006215 SizeExpr.takeAs<Expr>(),
6216 IndexTypeQuals, BracketsRange);
6217}
6218
6219template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006220QualType
6221TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006222 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006224 unsigned IndexTypeQuals,
6225 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006226 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006227 SizeExpr.takeAs<Expr>(),
6228 IndexTypeQuals, BracketsRange);
6229}
6230
6231template<typename Derived>
6232QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006233 unsigned NumElements,
6234 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006235 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006236 return SemaRef.Context.getVectorType(ElementType, NumElements,
6237 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006238}
Mike Stump11289f42009-09-09 15:08:12 +00006239
Douglas Gregord6ff3322009-08-04 16:50:30 +00006240template<typename Derived>
6241QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6242 unsigned NumElements,
6243 SourceLocation AttributeLoc) {
6244 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6245 NumElements, true);
6246 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006247 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006248 AttributeLoc);
6249 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6250 AttributeLoc);
6251}
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregord6ff3322009-08-04 16:50:30 +00006253template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006254QualType
6255TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006257 SourceLocation AttributeLoc) {
6258 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6259}
Mike Stump11289f42009-09-09 15:08:12 +00006260
Douglas Gregord6ff3322009-08-04 16:50:30 +00006261template<typename Derived>
6262QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006263 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006264 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006265 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006266 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006267 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006268 Quals,
6269 getDerived().getBaseLocation(),
6270 getDerived().getBaseEntity());
6271}
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregord6ff3322009-08-04 16:50:30 +00006273template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006274QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6275 return SemaRef.Context.getFunctionNoProtoType(T);
6276}
6277
6278template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006279QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6280 assert(D && "no decl found");
6281 if (D->isInvalidDecl()) return QualType();
6282
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006283 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006284 TypeDecl *Ty;
6285 if (isa<UsingDecl>(D)) {
6286 UsingDecl *Using = cast<UsingDecl>(D);
6287 assert(Using->isTypeName() &&
6288 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6289
6290 // A valid resolved using typename decl points to exactly one type decl.
6291 assert(++Using->shadow_begin() == Using->shadow_end());
6292 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6293
6294 } else {
6295 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6296 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6297 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6298 }
6299
6300 return SemaRef.Context.getTypeDeclType(Ty);
6301}
6302
6303template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006304QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006305 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6306}
6307
6308template<typename Derived>
6309QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6310 return SemaRef.Context.getTypeOfType(Underlying);
6311}
6312
6313template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006314QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006315 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6316}
6317
6318template<typename Derived>
6319QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006320 TemplateName Template,
6321 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006322 const TemplateArgumentListInfo &TemplateArgs) {
6323 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006324}
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregor1135c352009-08-06 05:28:30 +00006326template<typename Derived>
6327NestedNameSpecifier *
6328TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6329 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006330 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006331 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006332 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006333 CXXScopeSpec SS;
6334 // FIXME: The source location information is all wrong.
6335 SS.setRange(Range);
6336 SS.setScopeRep(Prefix);
6337 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006338 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006339 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006340 ObjectType,
6341 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006342 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006343}
6344
6345template<typename Derived>
6346NestedNameSpecifier *
6347TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6348 SourceRange Range,
6349 NamespaceDecl *NS) {
6350 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6351}
6352
6353template<typename Derived>
6354NestedNameSpecifier *
6355TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6356 SourceRange Range,
6357 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006358 QualType T) {
6359 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006360 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006361 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006362 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6363 T.getTypePtr());
6364 }
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregor1135c352009-08-06 05:28:30 +00006366 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6367 return 0;
6368}
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregor71dc5092009-08-06 06:41:21 +00006370template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006371TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006372TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6373 bool TemplateKW,
6374 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006375 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006376 Template);
6377}
6378
6379template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006380TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006381TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006382 const IdentifierInfo &II,
6383 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006384 CXXScopeSpec SS;
6385 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006386 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006387 UnqualifiedId Name;
6388 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006389 return getSema().ActOnDependentTemplateName(
6390 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006391 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006392 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006393 ObjectType.getAsOpaquePtr(),
6394 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006395 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006396}
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregora16548e2009-08-11 05:31:07 +00006398template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006399TemplateName
6400TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6401 OverloadedOperatorKind Operator,
6402 QualType ObjectType) {
6403 CXXScopeSpec SS;
6404 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6405 SS.setScopeRep(Qualifier);
6406 UnqualifiedId Name;
6407 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6408 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6409 Operator, SymbolLocations);
6410 return getSema().ActOnDependentTemplateName(
6411 /*FIXME:*/getDerived().getBaseLocation(),
6412 SS,
6413 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006414 ObjectType.getAsOpaquePtr(),
6415 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006416 .template getAsVal<TemplateName>();
6417}
6418
6419template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006420Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006421TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6422 SourceLocation OpLoc,
6423 ExprArg Callee,
6424 ExprArg First,
6425 ExprArg Second) {
6426 Expr *FirstExpr = (Expr *)First.get();
6427 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006428 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006429 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregora16548e2009-08-11 05:31:07 +00006431 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006432 if (Op == OO_Subscript) {
6433 if (!FirstExpr->getType()->isOverloadableType() &&
6434 !SecondExpr->getType()->isOverloadableType())
6435 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006436 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006437 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006438 } else if (Op == OO_Arrow) {
6439 // -> is never a builtin operation.
6440 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006441 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 if (!FirstExpr->getType()->isOverloadableType()) {
6443 // The argument is not of overloadable type, so try to create a
6444 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006445 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6449 }
6450 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006451 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 !SecondExpr->getType()->isOverloadableType()) {
6453 // Neither of the arguments is an overloadable type, so try to
6454 // create a built-in binary operation.
6455 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006456 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006457 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6458 if (Result.isInvalid())
6459 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 First.release();
6462 Second.release();
6463 return move(Result);
6464 }
6465 }
Mike Stump11289f42009-09-09 15:08:12 +00006466
6467 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006468 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006469 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006470
John McCalld14a8642009-11-21 08:51:07 +00006471 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6472 assert(ULE->requiresADL());
6473
6474 // FIXME: Do we have to check
6475 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006476 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006477 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006478 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006479 }
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregora16548e2009-08-11 05:31:07 +00006481 // Add any functions found via argument-dependent lookup.
6482 Expr *Args[2] = { FirstExpr, SecondExpr };
6483 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 // Create the overloaded operator invocation for unary operators.
6486 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006487 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6489 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6490 }
Mike Stump11289f42009-09-09 15:08:12 +00006491
Sebastian Redladba46e2009-10-29 20:17:01 +00006492 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006493 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6494 OpLoc,
6495 move(First),
6496 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006497
Douglas Gregora16548e2009-08-11 05:31:07 +00006498 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006499 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006500 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006501 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6503 if (Result.isInvalid())
6504 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006505
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 First.release();
6507 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006508 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006509}
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006511template<typename Derived>
6512Sema::OwningExprResult
6513TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6514 SourceLocation OperatorLoc,
6515 bool isArrow,
6516 NestedNameSpecifier *Qualifier,
6517 SourceRange QualifierRange,
6518 TypeSourceInfo *ScopeType,
6519 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006520 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006521 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006522 CXXScopeSpec SS;
6523 if (Qualifier) {
6524 SS.setRange(QualifierRange);
6525 SS.setScopeRep(Qualifier);
6526 }
6527
6528 Expr *BaseE = (Expr *)Base.get();
6529 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006530 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006531 (!isArrow && !BaseType->getAs<RecordType>()) ||
6532 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006533 !BaseType->getAs<PointerType>()->getPointeeType()
6534 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006535 // This pseudo-destructor expression is still a pseudo-destructor.
6536 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6537 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006538 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006539 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006540 /*FIXME?*/true);
6541 }
6542
Douglas Gregor678f90d2010-02-25 01:56:36 +00006543 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006544 DeclarationName Name
6545 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6546 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6547
6548 // FIXME: the ScopeType should be tacked onto SS.
6549
6550 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6551 OperatorLoc, isArrow,
6552 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006553 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006554 /*TemplateArgs*/ 0);
6555}
6556
Douglas Gregord6ff3322009-08-04 16:50:30 +00006557} // end namespace clang
6558
6559#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H