blob: cded16cd60dccfd8a8ded0183adc9cda6dd8e974 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregore677daf2010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000577 // Fall through.
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 case ETK_Typename:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000579 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
Douglas Gregore677daf2010-03-31 22:19:08 +0000580
581 case ETK_Class: Kind = TagDecl::TK_class; break;
582 case ETK_Struct: Kind = TagDecl::TK_struct; break;
583 case ETK_Union: Kind = TagDecl::TK_union; break;
584 case ETK_Enum: Kind = TagDecl::TK_enum; break;
585 }
586
587 // We had a dependent elaborated-type-specifier that as been transformed
588 // into a non-dependent elaborated-type-specifier. Find the tag we're
589 // referring to.
590 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
591 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
592 if (!DC)
593 return QualType();
594
595 TagDecl *Tag = 0;
596 SemaRef.LookupQualifiedName(Result, DC);
597 switch (Result.getResultKind()) {
598 case LookupResult::NotFound:
599 case LookupResult::NotFoundInCurrentInstantiation:
600 break;
601
602 case LookupResult::Found:
603 Tag = Result.getAsSingle<TagDecl>();
604 break;
605
606 case LookupResult::FoundOverloaded:
607 case LookupResult::FoundUnresolvedValue:
608 llvm_unreachable("Tag lookup cannot find non-tags");
609 return QualType();
610
611 case LookupResult::Ambiguous:
612 // Let the LookupResult structure handle ambiguities.
613 return QualType();
614 }
615
616 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000617 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000619 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 return QualType();
621 }
622
623 // FIXME: Terrible location information
624 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
625 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
626 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
627 return QualType();
628 }
629
630 // Build the elaborated-type-specifier type.
631 QualType T = SemaRef.Context.getTypeDeclType(Tag);
632 T = SemaRef.Context.getQualifiedNameType(NNS, T);
633 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000634 }
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregor1135c352009-08-06 05:28:30 +0000636 /// \brief Build a new nested-name-specifier given the prefix and an
637 /// identifier that names the next step in the nested-name-specifier.
638 ///
639 /// By default, performs semantic analysis when building the new
640 /// nested-name-specifier. Subclasses may override this routine to provide
641 /// different behavior.
642 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
643 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000644 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000645 QualType ObjectType,
646 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000647
648 /// \brief Build a new nested-name-specifier given the prefix and the
649 /// namespace named in the next step in the nested-name-specifier.
650 ///
651 /// By default, performs semantic analysis when building the new
652 /// nested-name-specifier. Subclasses may override this routine to provide
653 /// different behavior.
654 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
655 SourceRange Range,
656 NamespaceDecl *NS);
657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// type named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000667 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000668
669 /// \brief Build a new template name given a nested name specifier, a flag
670 /// indicating whether the "template" keyword was provided, and the template
671 /// that the template name refers to.
672 ///
673 /// By default, builds the new template name directly. Subclasses may override
674 /// this routine to provide different behavior.
675 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
676 bool TemplateKW,
677 TemplateDecl *Template);
678
Douglas Gregor71dc5092009-08-06 06:41:21 +0000679 /// \brief Build a new template name given a nested name specifier and the
680 /// name that is referred to as a template.
681 ///
682 /// By default, performs semantic analysis to determine whether the name can
683 /// be resolved to a specific template, then builds the appropriate kind of
684 /// template name. Subclasses may override this routine to provide different
685 /// behavior.
686 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000687 const IdentifierInfo &II,
688 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregor71395fa2009-11-04 00:56:37 +0000690 /// \brief Build a new template name given a nested name specifier and the
691 /// overloaded operator name that is referred to as a template.
692 ///
693 /// By default, performs semantic analysis to determine whether the name can
694 /// be resolved to a specific template, then builds the appropriate kind of
695 /// template name. Subclasses may override this routine to provide different
696 /// behavior.
697 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
698 OverloadedOperatorKind Operator,
699 QualType ObjectType);
700
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 /// \brief Build a new compound statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
706 MultiStmtArg Statements,
707 SourceLocation RBraceLoc,
708 bool IsStmtExpr) {
709 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
710 IsStmtExpr);
711 }
712
713 /// \brief Build a new case statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
718 ExprArg LHS,
719 SourceLocation EllipsisLoc,
720 ExprArg RHS,
721 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000722 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 ColonLoc);
724 }
Mike Stump11289f42009-09-09 15:08:12 +0000725
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 /// \brief Attach the body to a new case statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
730 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
731 getSema().ActOnCaseStmtBody(S.get(), move(Body));
732 return move(S);
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new default statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000742 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /*CurScope=*/0);
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Build a new label statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 IdentifierInfo *Id,
752 SourceLocation ColonLoc,
753 StmtArg SubStmt) {
754 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
755 }
Mike Stump11289f42009-09-09 15:08:12 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new "if" statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000761 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000762 VarDecl *CondVar, StmtArg Then,
763 SourceLocation ElseLoc, StmtArg Else) {
764 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
765 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 }
Mike Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 /// \brief Start building a new switch statement.
769 ///
770 /// By default, performs semantic analysis to build the new statement.
771 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000772 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
773 VarDecl *CondVar) {
774 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 }
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 /// \brief Attach the body to the switch statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000781 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 StmtArg Switch, StmtArg Body) {
783 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
784 move(Body));
785 }
786
787 /// \brief Build a new while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
792 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000793 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000795 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
796 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
Mike Stump11289f42009-09-09 15:08:12 +0000798
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 /// \brief Build a new do-while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
803 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
804 SourceLocation WhileLoc,
805 SourceLocation LParenLoc,
806 ExprArg Cond,
807 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000808 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000809 move(Cond), RParenLoc);
810 }
811
812 /// \brief Build a new for statement.
813 ///
814 /// By default, performs semantic analysis to build the new statement.
815 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000816 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000818 StmtArg Init, Sema::FullExprArg Cond,
819 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000821 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
822 DeclPtrTy::make(CondVar),
823 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 }
Mike Stump11289f42009-09-09 15:08:12 +0000825
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 /// \brief Build a new goto statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
831 SourceLocation LabelLoc,
832 LabelStmt *Label) {
833 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
834 }
835
836 /// \brief Build a new indirect goto statement.
837 ///
838 /// By default, performs semantic analysis to build the new statement.
839 /// Subclasses may override this routine to provide different behavior.
840 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
841 SourceLocation StarLoc,
842 ExprArg Target) {
843 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
844 }
Mike Stump11289f42009-09-09 15:08:12 +0000845
Douglas Gregorebe10102009-08-20 07:17:43 +0000846 /// \brief Build a new return statement.
847 ///
848 /// By default, performs semantic analysis to build the new statement.
849 /// Subclasses may override this routine to provide different behavior.
850 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
851 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000852
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregorebe10102009-08-20 07:17:43 +0000856 /// \brief Build a new declaration statement.
857 ///
858 /// By default, performs semantic analysis to build the new statement.
859 /// Subclasses may override this routine to provide different behavior.
860 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000861 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 SourceLocation EndLoc) {
863 return getSema().Owned(
864 new (getSema().Context) DeclStmt(
865 DeclGroupRef::Create(getSema().Context,
866 Decls, NumDecls),
867 StartLoc, EndLoc));
868 }
Mike Stump11289f42009-09-09 15:08:12 +0000869
Anders Carlssonaaeef072010-01-24 05:50:09 +0000870 /// \brief Build a new inline asm statement.
871 ///
872 /// By default, performs semantic analysis to build the new statement.
873 /// Subclasses may override this routine to provide different behavior.
874 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
875 bool IsSimple,
876 bool IsVolatile,
877 unsigned NumOutputs,
878 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000879 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000880 MultiExprArg Constraints,
881 MultiExprArg Exprs,
882 ExprArg AsmString,
883 MultiExprArg Clobbers,
884 SourceLocation RParenLoc,
885 bool MSAsm) {
886 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
887 NumInputs, Names, move(Constraints),
888 move(Exprs), move(AsmString), move(Clobbers),
889 RParenLoc, MSAsm);
890 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000891
892 /// \brief Build a new Objective-C @try statement.
893 ///
894 /// By default, performs semantic analysis to build the new statement.
895 /// Subclasses may override this routine to provide different behavior.
896 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
897 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000898 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000899 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000900 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000901 move(Finally));
902 }
903
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000904 /// \brief Rebuild an Objective-C exception declaration.
905 ///
906 /// By default, performs semantic analysis to build the new declaration.
907 /// Subclasses may override this routine to provide different behavior.
908 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
909 TypeSourceInfo *TInfo, QualType T) {
910 return getSema().BuildObjCExceptionDecl(TInfo, T,
911 ExceptionDecl->getIdentifier(),
912 ExceptionDecl->getLocation());
913 }
914
915 /// \brief Build a new Objective-C @catch statement.
916 ///
917 /// By default, performs semantic analysis to build the new statement.
918 /// Subclasses may override this routine to provide different behavior.
919 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
920 SourceLocation RParenLoc,
921 VarDecl *Var,
922 StmtArg Body) {
923 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
924 Sema::DeclPtrTy::make(Var),
925 move(Body));
926 }
927
Douglas Gregor306de2f2010-04-22 23:59:56 +0000928 /// \brief Build a new Objective-C @finally statement.
929 ///
930 /// By default, performs semantic analysis to build the new statement.
931 /// Subclasses may override this routine to provide different behavior.
932 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
933 StmtArg Body) {
934 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
935 }
Anders Carlssonaaeef072010-01-24 05:50:09 +0000936
Douglas Gregor6148de72010-04-22 22:01:21 +0000937 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
942 ExprArg Operand) {
943 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
944 }
945
Douglas Gregor6148de72010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @synchronized statement.
947 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
951 ExprArg Object,
952 StmtArg Body) {
953 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
954 move(Body));
955 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000956
957 /// \brief Build a new Objective-C fast enumeration statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
961 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
962 SourceLocation LParenLoc,
963 StmtArg Element,
964 ExprArg Collection,
965 SourceLocation RParenLoc,
966 StmtArg Body) {
967 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
968 move(Element),
969 move(Collection),
970 RParenLoc,
971 move(Body));
972 }
Douglas Gregor6148de72010-04-22 22:01:21 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new C++ exception declaration.
975 ///
976 /// By default, performs semantic analysis to build the new decaration.
977 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000978 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000979 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 IdentifierInfo *Name,
981 SourceLocation Loc,
982 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000983 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 TypeRange);
985 }
986
987 /// \brief Build a new C++ catch statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
992 VarDecl *ExceptionDecl,
993 StmtArg Handler) {
994 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000995 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 Handler.takeAs<Stmt>()));
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /// \brief Build a new C++ try statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
1003 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1004 StmtArg TryBlock,
1005 MultiStmtArg Handlers) {
1006 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 /// \brief Build a new expression that references a declaration.
1010 ///
1011 /// By default, performs semantic analysis to build the new expression.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001013 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1014 LookupResult &R,
1015 bool RequiresADL) {
1016 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1017 }
1018
1019
1020 /// \brief Build a new expression that references a declaration.
1021 ///
1022 /// By default, performs semantic analysis to build the new expression.
1023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001024 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1025 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001026 ValueDecl *VD, SourceLocation Loc,
1027 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001028 CXXScopeSpec SS;
1029 SS.setScopeRep(Qualifier);
1030 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001031
1032 // FIXME: loses template args.
1033
1034 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1042 SourceLocation RParen) {
1043 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1044 }
1045
Douglas Gregorad8a3362009-09-04 17:36:40 +00001046 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001047 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// By default, performs semantic analysis to build the new expression.
1049 /// Subclasses may override this routine to provide different behavior.
1050 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1051 SourceLocation OperatorLoc,
1052 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001053 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001054 SourceRange QualifierRange,
1055 TypeSourceInfo *ScopeType,
1056 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001057 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001058 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001061 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1065 UnaryOperator::Opcode Opc,
1066 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001067 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001071 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// By default, performs semantic analysis to build the new expression.
1073 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001074 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001075 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001077 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 }
1079
Mike Stump11289f42009-09-09 15:08:12 +00001080 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001081 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001082 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 /// By default, performs semantic analysis to build the new expression.
1084 /// Subclasses may override this routine to provide different behavior.
1085 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1086 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001087 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1089 OpLoc, isSizeOf, R);
1090 if (Result.isInvalid())
1091 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 SubExpr.release();
1094 return move(Result);
1095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, performs semantic analysis to build the new expression.
1100 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001101 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 SourceLocation LBracketLoc,
1103 ExprArg RHS,
1104 SourceLocation RBracketLoc) {
1105 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001106 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 RBracketLoc);
1108 }
1109
1110 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
1114 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1115 MultiExprArg Args,
1116 SourceLocation *CommaLocs,
1117 SourceLocation RParenLoc) {
1118 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1119 move(Args), CommaLocs, RParenLoc);
1120 }
1121
1122 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001123 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// By default, performs semantic analysis to build the new expression.
1125 /// Subclasses may override this routine to provide different behavior.
1126 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001127 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001128 NestedNameSpecifier *Qualifier,
1129 SourceRange QualifierRange,
1130 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001131 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001132 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001133 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001134 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001135 if (!Member->getDeclName()) {
1136 // We have a reference to an unnamed field.
1137 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001139 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001140 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1141 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001142 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001143
Mike Stump11289f42009-09-09 15:08:12 +00001144 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001145 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001146 Member, MemberLoc,
1147 cast<FieldDecl>(Member)->getType());
1148 return getSema().Owned(ME);
1149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001151 CXXScopeSpec SS;
1152 if (Qualifier) {
1153 SS.setRange(QualifierRange);
1154 SS.setScopeRep(Qualifier);
1155 }
1156
John McCall2d74de92009-12-01 22:10:20 +00001157 QualType BaseType = ((Expr*) Base.get())->getType();
1158
John McCall16df1e52010-03-30 21:47:33 +00001159 // FIXME: this involves duplicating earlier analysis in a lot of
1160 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001161 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1162 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001163 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001164 R.resolveKind();
1165
John McCall2d74de92009-12-01 22:10:20 +00001166 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1167 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001168 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001169 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregora16548e2009-08-11 05:31:07 +00001172 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001173 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001174 /// By default, performs semantic analysis to build the new expression.
1175 /// Subclasses may override this routine to provide different behavior.
1176 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1177 BinaryOperator::Opcode Opc,
1178 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001179 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1180 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
1182
1183 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
1187 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1188 SourceLocation QuestionLoc,
1189 ExprArg LHS,
1190 SourceLocation ColonLoc,
1191 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001192 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 move(LHS), move(RHS));
1194 }
1195
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001200 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1201 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 SourceLocation RParenLoc,
1203 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001204 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1205 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 }
Mike Stump11289f42009-09-09 15:08:12 +00001207
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001209 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// By default, performs semantic analysis to build the new expression.
1211 /// Subclasses may override this routine to provide different behavior.
1212 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001213 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 SourceLocation RParenLoc,
1215 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001216 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1217 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001224 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 SourceLocation OpLoc,
1226 SourceLocation AccessorLoc,
1227 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001228
John McCall10eae182009-11-30 22:42:35 +00001229 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001230 QualType BaseType = ((Expr*) Base.get())->getType();
1231 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001232 OpLoc, /*IsArrow*/ false,
1233 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001234 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001235 AccessorLoc,
1236 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 }
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001240 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
1243 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1244 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001245 SourceLocation RBraceLoc,
1246 QualType ResultTy) {
1247 OwningExprResult Result
1248 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1249 if (Result.isInvalid() || ResultTy->isDependentType())
1250 return move(Result);
1251
1252 // Patch in the result type we were given, which may have been computed
1253 // when the initial InitListExpr was built.
1254 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1255 ILE->setType(ResultTy);
1256 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1264 MultiExprArg ArrayExprs,
1265 SourceLocation EqualOrColonLoc,
1266 bool GNUSyntax,
1267 ExprArg Init) {
1268 OwningExprResult Result
1269 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1270 move(Init));
1271 if (Result.isInvalid())
1272 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001273
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 ArrayExprs.release();
1275 return move(Result);
1276 }
Mike Stump11289f42009-09-09 15:08:12 +00001277
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001279 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// By default, builds the implicit value initialization without performing
1281 /// any semantic analysis. Subclasses may override this routine to provide
1282 /// different behavior.
1283 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1284 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
1291 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1292 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001293 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 RParenLoc);
1295 }
1296
1297 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001298 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
1301 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1302 MultiExprArg SubExprs,
1303 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001304 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1305 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
Mike Stump11289f42009-09-09 15:08:12 +00001307
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
1310 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// rather than attempting to map the label statement itself.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1314 SourceLocation LabelLoc,
1315 LabelStmt *Label) {
1316 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1324 StmtArg SubStmt,
1325 SourceLocation RParenLoc) {
1326 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1327 }
Mike Stump11289f42009-09-09 15:08:12 +00001328
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// \brief Build a new __builtin_types_compatible_p expression.
1330 ///
1331 /// By default, performs semantic analysis to build the new expression.
1332 /// Subclasses may override this routine to provide different behavior.
1333 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1334 QualType T1, QualType T2,
1335 SourceLocation RParenLoc) {
1336 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1337 T1.getAsOpaquePtr(),
1338 T2.getAsOpaquePtr(),
1339 RParenLoc);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_choose_expr expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1347 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1348 SourceLocation RParenLoc) {
1349 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1350 move(Cond), move(LHS), move(RHS),
1351 RParenLoc);
1352 }
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new overloaded operator call expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// The semantic analysis provides the behavior of template instantiation,
1358 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001359 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 /// argument-dependent lookup, etc. Subclasses may override this routine to
1361 /// provide different behavior.
1362 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1363 SourceLocation OpLoc,
1364 ExprArg Callee,
1365 ExprArg First,
1366 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001367
1368 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// reinterpret_cast.
1370 ///
1371 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// Subclasses may override this routine to provide different behavior.
1374 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1375 Stmt::StmtClass Class,
1376 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001377 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 SourceLocation RAngleLoc,
1379 SourceLocation LParenLoc,
1380 ExprArg SubExpr,
1381 SourceLocation RParenLoc) {
1382 switch (Class) {
1383 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001384 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001385 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 move(SubExpr), RParenLoc);
1387
1388 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001389 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001390 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001392
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001394 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001395 RAngleLoc, LParenLoc,
1396 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 default:
1405 assert(false && "Invalid C++ named cast");
1406 break;
1407 }
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 return getSema().ExprError();
1410 }
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// \brief Build a new C++ static_cast expression.
1413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
1416 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1417 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001418 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 SourceLocation RAngleLoc,
1420 SourceLocation LParenLoc,
1421 ExprArg SubExpr,
1422 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001423 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1424 TInfo, move(SubExpr),
1425 SourceRange(LAngleLoc, RAngleLoc),
1426 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 }
1428
1429 /// \brief Build a new C++ dynamic_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1434 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
1438 ExprArg SubExpr,
1439 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1441 TInfo, move(SubExpr),
1442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ reinterpret_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1451 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
1455 ExprArg SubExpr,
1456 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1458 TInfo, move(SubExpr),
1459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ const_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1468 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
1472 ExprArg SubExpr,
1473 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1475 TInfo, move(SubExpr),
1476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
Mike Stump11289f42009-09-09 15:08:12 +00001479
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// \brief Build a new C++ functional-style cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
1484 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001485 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation LParenLoc,
1487 ExprArg SubExpr,
1488 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001489 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001491 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001493 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001494 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 RParenLoc);
1496 }
Mike Stump11289f42009-09-09 15:08:12 +00001497
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// \brief Build a new C++ typeid(type) expression.
1499 ///
1500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
1502 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1503 SourceLocation LParenLoc,
1504 QualType T,
1505 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001506 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 T.getAsOpaquePtr(), RParenLoc);
1508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(expr) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
1514 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1515 SourceLocation LParenLoc,
1516 ExprArg Operand,
1517 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001518 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1520 RParenLoc);
1521 if (Result.isInvalid())
1522 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1525 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001526 }
1527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new C++ "this" expression.
1529 ///
1530 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001531 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001533 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001534 QualType ThisType,
1535 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001537 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1538 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 }
1540
1541 /// \brief Build a new C++ throw expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
1545 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1546 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1547 }
1548
1549 /// \brief Build a new C++ default-argument expression.
1550 ///
1551 /// By default, builds a new default-argument expression, which does not
1552 /// require any semantic analysis. Subclasses may override this routine to
1553 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001554 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1555 ParmVarDecl *Param) {
1556 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1557 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
1559
1560 /// \brief Build a new C++ zero-initialization expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001564 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 SourceLocation LParenLoc,
1566 QualType T,
1567 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001568 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1569 T.getAsOpaquePtr(), LParenLoc,
1570 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 0, RParenLoc);
1572 }
Mike Stump11289f42009-09-09 15:08:12 +00001573
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// \brief Build a new C++ "new" expression.
1575 ///
1576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001578 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 bool UseGlobal,
1580 SourceLocation PlacementLParen,
1581 MultiExprArg PlacementArgs,
1582 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001583 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 QualType AllocType,
1585 SourceLocation TypeLoc,
1586 SourceRange TypeRange,
1587 ExprArg ArraySize,
1588 SourceLocation ConstructorLParen,
1589 MultiExprArg ConstructorArgs,
1590 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001591 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 PlacementLParen,
1593 move(PlacementArgs),
1594 PlacementRParen,
1595 ParenTypeId,
1596 AllocType,
1597 TypeLoc,
1598 TypeRange,
1599 move(ArraySize),
1600 ConstructorLParen,
1601 move(ConstructorArgs),
1602 ConstructorRParen);
1603 }
Mike Stump11289f42009-09-09 15:08:12 +00001604
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// \brief Build a new C++ "delete" expression.
1606 ///
1607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
1609 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1610 bool IsGlobalDelete,
1611 bool IsArrayForm,
1612 ExprArg Operand) {
1613 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1614 move(Operand));
1615 }
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 /// \brief Build a new unary type trait expression.
1618 ///
1619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
1621 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1622 SourceLocation StartLoc,
1623 SourceLocation LParenLoc,
1624 QualType T,
1625 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001626 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 T.getAsOpaquePtr(), RParenLoc);
1628 }
1629
Mike Stump11289f42009-09-09 15:08:12 +00001630 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 /// expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001635 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 SourceRange QualifierRange,
1637 DeclarationName Name,
1638 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001639 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 CXXScopeSpec SS;
1641 SS.setRange(QualifierRange);
1642 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001643
1644 if (TemplateArgs)
1645 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1646 *TemplateArgs);
1647
1648 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
1650
1651 /// \brief Build a new template-id expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001655 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1656 LookupResult &R,
1657 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001658 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001659 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 }
1661
1662 /// \brief Build a new object-construction expression.
1663 ///
1664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
1666 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001667 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 CXXConstructorDecl *Constructor,
1669 bool IsElidable,
1670 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001671 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1672 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1673 ConvertedArgs))
1674 return getSema().ExprError();
1675
1676 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1677 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new object-construction expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1685 QualType T,
1686 SourceLocation LParenLoc,
1687 MultiExprArg Args,
1688 SourceLocation *Commas,
1689 SourceLocation RParenLoc) {
1690 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1691 T.getAsOpaquePtr(),
1692 LParenLoc,
1693 move(Args),
1694 Commas,
1695 RParenLoc);
1696 }
1697
1698 /// \brief Build a new object-construction expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
1702 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1703 QualType T,
1704 SourceLocation LParenLoc,
1705 MultiExprArg Args,
1706 SourceLocation *Commas,
1707 SourceLocation RParenLoc) {
1708 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1709 /*FIXME*/LParenLoc),
1710 T.getAsOpaquePtr(),
1711 LParenLoc,
1712 move(Args),
1713 Commas,
1714 RParenLoc);
1715 }
Mike Stump11289f42009-09-09 15:08:12 +00001716
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// \brief Build a new member reference expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001721 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001722 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 bool IsArrow,
1724 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001725 NestedNameSpecifier *Qualifier,
1726 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001727 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001729 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001730 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 SS.setRange(QualifierRange);
1733 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001734
John McCall2d74de92009-12-01 22:10:20 +00001735 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1736 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001737 SS, FirstQualifierInScope,
1738 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
1740
John McCall10eae182009-11-30 22:42:35 +00001741 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001745 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001746 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001747 SourceLocation OperatorLoc,
1748 bool IsArrow,
1749 NestedNameSpecifier *Qualifier,
1750 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001751 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001752 LookupResult &R,
1753 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001754 CXXScopeSpec SS;
1755 SS.setRange(QualifierRange);
1756 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001757
John McCall2d74de92009-12-01 22:10:20 +00001758 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1759 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001760 SS, FirstQualifierInScope,
1761 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001762 }
Mike Stump11289f42009-09-09 15:08:12 +00001763
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// \brief Build a new Objective-C @encode expression.
1765 ///
1766 /// By default, performs semantic analysis to build the new expression.
1767 /// Subclasses may override this routine to provide different behavior.
1768 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001769 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001771 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001773 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001774
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001775 /// \brief Build a new Objective-C class message.
1776 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1777 Selector Sel,
1778 ObjCMethodDecl *Method,
1779 SourceLocation LBracLoc,
1780 MultiExprArg Args,
1781 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001782 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1783 ReceiverTypeInfo->getType(),
1784 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001785 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001786 move(Args));
1787 }
1788
1789 /// \brief Build a new Objective-C instance message.
1790 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1791 Selector Sel,
1792 ObjCMethodDecl *Method,
1793 SourceLocation LBracLoc,
1794 MultiExprArg Args,
1795 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001796 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1797 return SemaRef.BuildInstanceMessage(move(Receiver),
1798 ReceiverType,
1799 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001800 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001801 move(Args));
1802 }
1803
Douglas Gregord51d90d2010-04-26 20:11:03 +00001804 /// \brief Build a new Objective-C ivar reference expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
1808 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1809 SourceLocation IvarLoc,
1810 bool IsArrow, bool IsFreeIvar) {
1811 // FIXME: We lose track of the IsFreeIvar bit.
1812 CXXScopeSpec SS;
1813 Expr *Base = BaseArg.takeAs<Expr>();
1814 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1815 Sema::LookupMemberName);
1816 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1817 /*FIME:*/IvarLoc,
1818 SS, DeclPtrTy());
1819 if (Result.isInvalid())
1820 return getSema().ExprError();
1821
1822 if (Result.get())
1823 return move(Result);
1824
1825 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1826 Base->getType(),
1827 /*FIXME:*/IvarLoc, IsArrow, SS,
1828 /*FirstQualifierInScope=*/0,
1829 R,
1830 /*TemplateArgs=*/0);
1831 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001832
1833 /// \brief Build a new Objective-C property reference expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
1837 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
1838 ObjCPropertyDecl *Property,
1839 SourceLocation PropertyLoc) {
1840 CXXScopeSpec SS;
1841 Expr *Base = BaseArg.takeAs<Expr>();
1842 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1843 Sema::LookupMemberName);
1844 bool IsArrow = false;
1845 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1846 /*FIME:*/PropertyLoc,
1847 SS, DeclPtrTy());
1848 if (Result.isInvalid())
1849 return getSema().ExprError();
1850
1851 if (Result.get())
1852 return move(Result);
1853
1854 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1855 Base->getType(),
1856 /*FIXME:*/PropertyLoc, IsArrow,
1857 SS,
1858 /*FirstQualifierInScope=*/0,
1859 R,
1860 /*TemplateArgs=*/0);
1861 }
1862
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001863 /// \brief Build a new Objective-C implicit setter/getter reference
1864 /// expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
1868 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1869 ObjCMethodDecl *Getter,
1870 QualType T,
1871 ObjCMethodDecl *Setter,
1872 SourceLocation NameLoc,
1873 ExprArg Base) {
1874 // Since these expressions can only be value-dependent, we do not need to
1875 // perform semantic analysis again.
1876 return getSema().Owned(
1877 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1878 Setter,
1879 NameLoc,
1880 Base.takeAs<Expr>()));
1881 }
1882
Douglas Gregord51d90d2010-04-26 20:11:03 +00001883 /// \brief Build a new Objective-C "isa" expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
1887 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1888 bool IsArrow) {
1889 CXXScopeSpec SS;
1890 Expr *Base = BaseArg.takeAs<Expr>();
1891 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1892 Sema::LookupMemberName);
1893 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1894 /*FIME:*/IsaLoc,
1895 SS, DeclPtrTy());
1896 if (Result.isInvalid())
1897 return getSema().ExprError();
1898
1899 if (Result.get())
1900 return move(Result);
1901
1902 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1903 Base->getType(),
1904 /*FIXME:*/IsaLoc, IsArrow, SS,
1905 /*FirstQualifierInScope=*/0,
1906 R,
1907 /*TemplateArgs=*/0);
1908 }
1909
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 /// \brief Build a new shuffle vector expression.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
1914 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1915 MultiExprArg SubExprs,
1916 SourceLocation RParenLoc) {
1917 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001918 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1920 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1921 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1922 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001923
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 // Build a reference to the __builtin_shufflevector builtin
1925 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001926 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001928 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001930
1931 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 unsigned NumSubExprs = SubExprs.size();
1933 Expr **Subs = (Expr **)SubExprs.release();
1934 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1935 Subs, NumSubExprs,
1936 Builtin->getResultType(),
1937 RParenLoc);
1938 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 // Type-check the __builtin_shufflevector expression.
1941 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1942 if (Result.isInvalid())
1943 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001946 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001948};
Douglas Gregora16548e2009-08-11 05:31:07 +00001949
Douglas Gregorebe10102009-08-20 07:17:43 +00001950template<typename Derived>
1951Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1952 if (!S)
1953 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001954
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 switch (S->getStmtClass()) {
1956 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregorebe10102009-08-20 07:17:43 +00001958 // Transform individual statement nodes
1959#define STMT(Node, Parent) \
1960 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1961#define EXPR(Node, Parent)
1962#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001963
Douglas Gregorebe10102009-08-20 07:17:43 +00001964 // Transform expressions by calling TransformExpr.
1965#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001966#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001967#define EXPR(Node, Parent) case Stmt::Node##Class:
1968#include "clang/AST/StmtNodes.def"
1969 {
1970 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1971 if (E.isInvalid())
1972 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001973
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001974 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001975 }
Mike Stump11289f42009-09-09 15:08:12 +00001976 }
1977
Douglas Gregorebe10102009-08-20 07:17:43 +00001978 return SemaRef.Owned(S->Retain());
1979}
Mike Stump11289f42009-09-09 15:08:12 +00001980
1981
Douglas Gregore922c772009-08-04 22:27:00 +00001982template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001983Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 if (!E)
1985 return SemaRef.Owned(E);
1986
1987 switch (E->getStmtClass()) {
1988 case Stmt::NoStmtClass: break;
1989#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001990#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001991#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001992 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001993#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001994 }
1995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001997}
1998
1999template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002000NestedNameSpecifier *
2001TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002002 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002003 QualType ObjectType,
2004 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002005 if (!NNS)
2006 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002009 NestedNameSpecifier *Prefix = NNS->getPrefix();
2010 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002011 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002012 ObjectType,
2013 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002014 if (!Prefix)
2015 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002016
2017 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002018 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002019 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002020 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002021 }
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregor1135c352009-08-06 05:28:30 +00002023 switch (NNS->getKind()) {
2024 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002025 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002026 "Identifier nested-name-specifier with no prefix or object type");
2027 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2028 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002029 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002030
2031 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002032 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002033 ObjectType,
2034 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002035
Douglas Gregor1135c352009-08-06 05:28:30 +00002036 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002037 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002038 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002039 getDerived().TransformDecl(Range.getBegin(),
2040 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002041 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 Prefix == NNS->getPrefix() &&
2043 NS == NNS->getAsNamespace())
2044 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002045
Douglas Gregor1135c352009-08-06 05:28:30 +00002046 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2047 }
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 case NestedNameSpecifier::Global:
2050 // There is no meaningful transformation that one could perform on the
2051 // global scope.
2052 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregor1135c352009-08-06 05:28:30 +00002054 case NestedNameSpecifier::TypeSpecWithTemplate:
2055 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002056 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002057 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2058 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002059 if (T.isNull())
2060 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002061
Douglas Gregor1135c352009-08-06 05:28:30 +00002062 if (!getDerived().AlwaysRebuild() &&
2063 Prefix == NNS->getPrefix() &&
2064 T == QualType(NNS->getAsType(), 0))
2065 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002066
2067 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2068 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002069 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002070 }
2071 }
Mike Stump11289f42009-09-09 15:08:12 +00002072
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002074 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002075}
2076
2077template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002078DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002079TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002080 SourceLocation Loc,
2081 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002082 if (!Name)
2083 return Name;
2084
2085 switch (Name.getNameKind()) {
2086 case DeclarationName::Identifier:
2087 case DeclarationName::ObjCZeroArgSelector:
2088 case DeclarationName::ObjCOneArgSelector:
2089 case DeclarationName::ObjCMultiArgSelector:
2090 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002091 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002092 case DeclarationName::CXXUsingDirective:
2093 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002094
Douglas Gregorf816bd72009-09-03 22:13:48 +00002095 case DeclarationName::CXXConstructorName:
2096 case DeclarationName::CXXDestructorName:
2097 case DeclarationName::CXXConversionFunctionName: {
2098 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00002099 QualType T = getDerived().TransformType(Name.getCXXNameType(),
2100 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 if (T.isNull())
2102 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002103
Douglas Gregorf816bd72009-09-03 22:13:48 +00002104 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002105 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002106 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002107 }
Mike Stump11289f42009-09-09 15:08:12 +00002108 }
2109
Douglas Gregorf816bd72009-09-03 22:13:48 +00002110 return DeclarationName();
2111}
2112
2113template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002114TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002115TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2116 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002117 SourceLocation Loc = getDerived().getBaseLocation();
2118
Douglas Gregor71dc5092009-08-06 06:41:21 +00002119 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002120 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002121 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002122 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2123 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002124 if (!NNS)
2125 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002126
Douglas Gregor71dc5092009-08-06 06:41:21 +00002127 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002128 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002129 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002130 if (!TransTemplate)
2131 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002132
Douglas Gregor71dc5092009-08-06 06:41:21 +00002133 if (!getDerived().AlwaysRebuild() &&
2134 NNS == QTN->getQualifier() &&
2135 TransTemplate == Template)
2136 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002137
Douglas Gregor71dc5092009-08-06 06:41:21 +00002138 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2139 TransTemplate);
2140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141
John McCalle66edc12009-11-24 19:00:30 +00002142 // These should be getting filtered out before they make it into the AST.
2143 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002144 }
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregor71dc5092009-08-06 06:41:21 +00002146 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002147 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002148 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002149 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2150 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002151 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002155 NNS == DTN->getQualifier() &&
2156 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002157 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002158
Douglas Gregor71395fa2009-11-04 00:56:37 +00002159 if (DTN->isIdentifier())
2160 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2161 ObjectType);
2162
2163 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2164 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002168 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002169 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002170 if (!TransTemplate)
2171 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregor71dc5092009-08-06 06:41:21 +00002173 if (!getDerived().AlwaysRebuild() &&
2174 TransTemplate == Template)
2175 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 return TemplateName(TransTemplate);
2178 }
Mike Stump11289f42009-09-09 15:08:12 +00002179
John McCalle66edc12009-11-24 19:00:30 +00002180 // These should be getting filtered out before they reach the AST.
2181 assert(false && "overloaded function decl survived to here");
2182 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002183}
2184
2185template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002186void TreeTransform<Derived>::InventTemplateArgumentLoc(
2187 const TemplateArgument &Arg,
2188 TemplateArgumentLoc &Output) {
2189 SourceLocation Loc = getDerived().getBaseLocation();
2190 switch (Arg.getKind()) {
2191 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002192 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002193 break;
2194
2195 case TemplateArgument::Type:
2196 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002197 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002198
2199 break;
2200
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002201 case TemplateArgument::Template:
2202 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2203 break;
2204
John McCall0ad16662009-10-29 08:12:44 +00002205 case TemplateArgument::Expression:
2206 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2207 break;
2208
2209 case TemplateArgument::Declaration:
2210 case TemplateArgument::Integral:
2211 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002212 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002213 break;
2214 }
2215}
2216
2217template<typename Derived>
2218bool TreeTransform<Derived>::TransformTemplateArgument(
2219 const TemplateArgumentLoc &Input,
2220 TemplateArgumentLoc &Output) {
2221 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002222 switch (Arg.getKind()) {
2223 case TemplateArgument::Null:
2224 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002225 Output = Input;
2226 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002227
Douglas Gregore922c772009-08-04 22:27:00 +00002228 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002229 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002230 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002231 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002232
2233 DI = getDerived().TransformType(DI);
2234 if (!DI) return true;
2235
2236 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2237 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002238 }
Mike Stump11289f42009-09-09 15:08:12 +00002239
Douglas Gregore922c772009-08-04 22:27:00 +00002240 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002241 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002242 DeclarationName Name;
2243 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2244 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002245 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002246 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002247 if (!D) return true;
2248
John McCall0d07eb32009-10-29 18:45:58 +00002249 Expr *SourceExpr = Input.getSourceDeclExpression();
2250 if (SourceExpr) {
2251 EnterExpressionEvaluationContext Unevaluated(getSema(),
2252 Action::Unevaluated);
2253 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2254 if (E.isInvalid())
2255 SourceExpr = NULL;
2256 else {
2257 SourceExpr = E.takeAs<Expr>();
2258 SourceExpr->Retain();
2259 }
2260 }
2261
2262 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002263 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002264 }
Mike Stump11289f42009-09-09 15:08:12 +00002265
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002266 case TemplateArgument::Template: {
2267 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2268 TemplateName Template
2269 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2270 if (Template.isNull())
2271 return true;
2272
2273 Output = TemplateArgumentLoc(TemplateArgument(Template),
2274 Input.getTemplateQualifierRange(),
2275 Input.getTemplateNameLoc());
2276 return false;
2277 }
2278
Douglas Gregore922c772009-08-04 22:27:00 +00002279 case TemplateArgument::Expression: {
2280 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002281 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002282 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002283
John McCall0ad16662009-10-29 08:12:44 +00002284 Expr *InputExpr = Input.getSourceExpression();
2285 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2286
2287 Sema::OwningExprResult E
2288 = getDerived().TransformExpr(InputExpr);
2289 if (E.isInvalid()) return true;
2290
2291 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002292 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002293 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2294 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002295 }
Mike Stump11289f42009-09-09 15:08:12 +00002296
Douglas Gregore922c772009-08-04 22:27:00 +00002297 case TemplateArgument::Pack: {
2298 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2299 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002300 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002301 AEnd = Arg.pack_end();
2302 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002303
John McCall0ad16662009-10-29 08:12:44 +00002304 // FIXME: preserve source information here when we start
2305 // caring about parameter packs.
2306
John McCall0d07eb32009-10-29 18:45:58 +00002307 TemplateArgumentLoc InputArg;
2308 TemplateArgumentLoc OutputArg;
2309 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2310 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002311 return true;
2312
John McCall0d07eb32009-10-29 18:45:58 +00002313 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002314 }
2315 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002316 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002317 true);
John McCall0d07eb32009-10-29 18:45:58 +00002318 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002319 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002320 }
2321 }
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregore922c772009-08-04 22:27:00 +00002323 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002324 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002325}
2326
Douglas Gregord6ff3322009-08-04 16:50:30 +00002327//===----------------------------------------------------------------------===//
2328// Type transformation
2329//===----------------------------------------------------------------------===//
2330
2331template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002332QualType TreeTransform<Derived>::TransformType(QualType T,
2333 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002334 if (getDerived().AlreadyTransformed(T))
2335 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002336
John McCall550e0c22009-10-21 00:40:46 +00002337 // Temporary workaround. All of these transformations should
2338 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002339 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002340 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002341
Douglas Gregorfe17d252010-02-16 19:09:40 +00002342 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002343
John McCall550e0c22009-10-21 00:40:46 +00002344 if (!NewDI)
2345 return QualType();
2346
2347 return NewDI->getType();
2348}
2349
2350template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002351TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2352 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002353 if (getDerived().AlreadyTransformed(DI->getType()))
2354 return DI;
2355
2356 TypeLocBuilder TLB;
2357
2358 TypeLoc TL = DI->getTypeLoc();
2359 TLB.reserve(TL.getFullDataSize());
2360
Douglas Gregorfe17d252010-02-16 19:09:40 +00002361 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002362 if (Result.isNull())
2363 return 0;
2364
John McCallbcd03502009-12-07 02:54:59 +00002365 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002366}
2367
2368template<typename Derived>
2369QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002370TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2371 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002372 switch (T.getTypeLocClass()) {
2373#define ABSTRACT_TYPELOC(CLASS, PARENT)
2374#define TYPELOC(CLASS, PARENT) \
2375 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002376 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2377 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002378#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002379 }
Mike Stump11289f42009-09-09 15:08:12 +00002380
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002381 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002382 return QualType();
2383}
2384
2385/// FIXME: By default, this routine adds type qualifiers only to types
2386/// that can have qualifiers, and silently suppresses those qualifiers
2387/// that are not permitted (e.g., qualifiers on reference or function
2388/// types). This is the right thing for template instantiation, but
2389/// probably not for other clients.
2390template<typename Derived>
2391QualType
2392TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002393 QualifiedTypeLoc T,
2394 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002395 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002396
Douglas Gregorfe17d252010-02-16 19:09:40 +00002397 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2398 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002399 if (Result.isNull())
2400 return QualType();
2401
2402 // Silently suppress qualifiers if the result type can't be qualified.
2403 // FIXME: this is the right thing for template instantiation, but
2404 // probably not for other clients.
2405 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002406 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002407
John McCall550e0c22009-10-21 00:40:46 +00002408 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2409
2410 TLB.push<QualifiedTypeLoc>(Result);
2411
2412 // No location information to preserve.
2413
2414 return Result;
2415}
2416
2417template <class TyLoc> static inline
2418QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2419 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2420 NewT.setNameLoc(T.getNameLoc());
2421 return T.getType();
2422}
2423
John McCall550e0c22009-10-21 00:40:46 +00002424template<typename Derived>
2425QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002426 BuiltinTypeLoc T,
2427 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002428 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2429 NewT.setBuiltinLoc(T.getBuiltinLoc());
2430 if (T.needsExtraLocalData())
2431 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2432 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002433}
Mike Stump11289f42009-09-09 15:08:12 +00002434
Douglas Gregord6ff3322009-08-04 16:50:30 +00002435template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002436QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002437 ComplexTypeLoc T,
2438 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002439 // FIXME: recurse?
2440 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002441}
Mike Stump11289f42009-09-09 15:08:12 +00002442
Douglas Gregord6ff3322009-08-04 16:50:30 +00002443template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002444QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002445 PointerTypeLoc TL,
2446 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002447 QualType PointeeType
2448 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2449 if (PointeeType.isNull())
2450 return QualType();
2451
2452 QualType Result = TL.getType();
2453 if (PointeeType->isObjCInterfaceType()) {
2454 // A dependent pointer type 'T *' has is being transformed such
2455 // that an Objective-C class type is being replaced for 'T'. The
2456 // resulting pointer type is an ObjCObjectPointerType, not a
2457 // PointerType.
2458 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2459 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2460 const_cast<ObjCProtocolDecl **>(
2461 IFace->qual_begin()),
2462 IFace->getNumProtocols());
2463
2464 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2465 NewT.setStarLoc(TL.getSigilLoc());
2466 NewT.setHasProtocolsAsWritten(false);
2467 NewT.setLAngleLoc(SourceLocation());
2468 NewT.setRAngleLoc(SourceLocation());
2469 NewT.setHasBaseTypeAsWritten(true);
2470 return Result;
2471 }
2472
2473 if (getDerived().AlwaysRebuild() ||
2474 PointeeType != TL.getPointeeLoc().getType()) {
2475 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2476 if (Result.isNull())
2477 return QualType();
2478 }
2479
2480 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2481 NewT.setSigilLoc(TL.getSigilLoc());
2482 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002483}
Mike Stump11289f42009-09-09 15:08:12 +00002484
2485template<typename Derived>
2486QualType
John McCall550e0c22009-10-21 00:40:46 +00002487TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002488 BlockPointerTypeLoc TL,
2489 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002490 QualType PointeeType
2491 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2492 if (PointeeType.isNull())
2493 return QualType();
2494
2495 QualType Result = TL.getType();
2496 if (getDerived().AlwaysRebuild() ||
2497 PointeeType != TL.getPointeeLoc().getType()) {
2498 Result = getDerived().RebuildBlockPointerType(PointeeType,
2499 TL.getSigilLoc());
2500 if (Result.isNull())
2501 return QualType();
2502 }
2503
Douglas Gregor049211a2010-04-22 16:50:51 +00002504 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002505 NewT.setSigilLoc(TL.getSigilLoc());
2506 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002507}
2508
John McCall70dd5f62009-10-30 00:06:24 +00002509/// Transforms a reference type. Note that somewhat paradoxically we
2510/// don't care whether the type itself is an l-value type or an r-value
2511/// type; we only care if the type was *written* as an l-value type
2512/// or an r-value type.
2513template<typename Derived>
2514QualType
2515TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002516 ReferenceTypeLoc TL,
2517 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002518 const ReferenceType *T = TL.getTypePtr();
2519
2520 // Note that this works with the pointee-as-written.
2521 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2522 if (PointeeType.isNull())
2523 return QualType();
2524
2525 QualType Result = TL.getType();
2526 if (getDerived().AlwaysRebuild() ||
2527 PointeeType != T->getPointeeTypeAsWritten()) {
2528 Result = getDerived().RebuildReferenceType(PointeeType,
2529 T->isSpelledAsLValue(),
2530 TL.getSigilLoc());
2531 if (Result.isNull())
2532 return QualType();
2533 }
2534
2535 // r-value references can be rebuilt as l-value references.
2536 ReferenceTypeLoc NewTL;
2537 if (isa<LValueReferenceType>(Result))
2538 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2539 else
2540 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2541 NewTL.setSigilLoc(TL.getSigilLoc());
2542
2543 return Result;
2544}
2545
Mike Stump11289f42009-09-09 15:08:12 +00002546template<typename Derived>
2547QualType
John McCall550e0c22009-10-21 00:40:46 +00002548TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002549 LValueReferenceTypeLoc TL,
2550 QualType ObjectType) {
2551 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002552}
2553
Mike Stump11289f42009-09-09 15:08:12 +00002554template<typename Derived>
2555QualType
John McCall550e0c22009-10-21 00:40:46 +00002556TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002557 RValueReferenceTypeLoc TL,
2558 QualType ObjectType) {
2559 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002560}
Mike Stump11289f42009-09-09 15:08:12 +00002561
Douglas Gregord6ff3322009-08-04 16:50:30 +00002562template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002563QualType
John McCall550e0c22009-10-21 00:40:46 +00002564TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002565 MemberPointerTypeLoc TL,
2566 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002567 MemberPointerType *T = TL.getTypePtr();
2568
2569 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002570 if (PointeeType.isNull())
2571 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002572
John McCall550e0c22009-10-21 00:40:46 +00002573 // TODO: preserve source information for this.
2574 QualType ClassType
2575 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576 if (ClassType.isNull())
2577 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002578
John McCall550e0c22009-10-21 00:40:46 +00002579 QualType Result = TL.getType();
2580 if (getDerived().AlwaysRebuild() ||
2581 PointeeType != T->getPointeeType() ||
2582 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002583 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2584 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002585 if (Result.isNull())
2586 return QualType();
2587 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002588
John McCall550e0c22009-10-21 00:40:46 +00002589 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2590 NewTL.setSigilLoc(TL.getSigilLoc());
2591
2592 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002593}
2594
Mike Stump11289f42009-09-09 15:08:12 +00002595template<typename Derived>
2596QualType
John McCall550e0c22009-10-21 00:40:46 +00002597TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002598 ConstantArrayTypeLoc TL,
2599 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002600 ConstantArrayType *T = TL.getTypePtr();
2601 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002602 if (ElementType.isNull())
2603 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002604
John McCall550e0c22009-10-21 00:40:46 +00002605 QualType Result = TL.getType();
2606 if (getDerived().AlwaysRebuild() ||
2607 ElementType != T->getElementType()) {
2608 Result = getDerived().RebuildConstantArrayType(ElementType,
2609 T->getSizeModifier(),
2610 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002611 T->getIndexTypeCVRQualifiers(),
2612 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002613 if (Result.isNull())
2614 return QualType();
2615 }
2616
2617 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2618 NewTL.setLBracketLoc(TL.getLBracketLoc());
2619 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002620
John McCall550e0c22009-10-21 00:40:46 +00002621 Expr *Size = TL.getSizeExpr();
2622 if (Size) {
2623 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2624 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2625 }
2626 NewTL.setSizeExpr(Size);
2627
2628 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002629}
Mike Stump11289f42009-09-09 15:08:12 +00002630
Douglas Gregord6ff3322009-08-04 16:50:30 +00002631template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002633 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002634 IncompleteArrayTypeLoc TL,
2635 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002636 IncompleteArrayType *T = TL.getTypePtr();
2637 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638 if (ElementType.isNull())
2639 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002640
John McCall550e0c22009-10-21 00:40:46 +00002641 QualType Result = TL.getType();
2642 if (getDerived().AlwaysRebuild() ||
2643 ElementType != T->getElementType()) {
2644 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002646 T->getIndexTypeCVRQualifiers(),
2647 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002648 if (Result.isNull())
2649 return QualType();
2650 }
2651
2652 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2653 NewTL.setLBracketLoc(TL.getLBracketLoc());
2654 NewTL.setRBracketLoc(TL.getRBracketLoc());
2655 NewTL.setSizeExpr(0);
2656
2657 return Result;
2658}
2659
2660template<typename Derived>
2661QualType
2662TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002663 VariableArrayTypeLoc TL,
2664 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002665 VariableArrayType *T = TL.getTypePtr();
2666 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2667 if (ElementType.isNull())
2668 return QualType();
2669
2670 // Array bounds are not potentially evaluated contexts
2671 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2672
2673 Sema::OwningExprResult SizeResult
2674 = getDerived().TransformExpr(T->getSizeExpr());
2675 if (SizeResult.isInvalid())
2676 return QualType();
2677
2678 Expr *Size = static_cast<Expr*>(SizeResult.get());
2679
2680 QualType Result = TL.getType();
2681 if (getDerived().AlwaysRebuild() ||
2682 ElementType != T->getElementType() ||
2683 Size != T->getSizeExpr()) {
2684 Result = getDerived().RebuildVariableArrayType(ElementType,
2685 T->getSizeModifier(),
2686 move(SizeResult),
2687 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002688 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002689 if (Result.isNull())
2690 return QualType();
2691 }
2692 else SizeResult.take();
2693
2694 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2695 NewTL.setLBracketLoc(TL.getLBracketLoc());
2696 NewTL.setRBracketLoc(TL.getRBracketLoc());
2697 NewTL.setSizeExpr(Size);
2698
2699 return Result;
2700}
2701
2702template<typename Derived>
2703QualType
2704TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002705 DependentSizedArrayTypeLoc TL,
2706 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002707 DependentSizedArrayType *T = TL.getTypePtr();
2708 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2709 if (ElementType.isNull())
2710 return QualType();
2711
2712 // Array bounds are not potentially evaluated contexts
2713 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2714
2715 Sema::OwningExprResult SizeResult
2716 = getDerived().TransformExpr(T->getSizeExpr());
2717 if (SizeResult.isInvalid())
2718 return QualType();
2719
2720 Expr *Size = static_cast<Expr*>(SizeResult.get());
2721
2722 QualType Result = TL.getType();
2723 if (getDerived().AlwaysRebuild() ||
2724 ElementType != T->getElementType() ||
2725 Size != T->getSizeExpr()) {
2726 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2727 T->getSizeModifier(),
2728 move(SizeResult),
2729 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002730 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002731 if (Result.isNull())
2732 return QualType();
2733 }
2734 else SizeResult.take();
2735
2736 // We might have any sort of array type now, but fortunately they
2737 // all have the same location layout.
2738 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2739 NewTL.setLBracketLoc(TL.getLBracketLoc());
2740 NewTL.setRBracketLoc(TL.getRBracketLoc());
2741 NewTL.setSizeExpr(Size);
2742
2743 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002744}
Mike Stump11289f42009-09-09 15:08:12 +00002745
2746template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002747QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002748 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002749 DependentSizedExtVectorTypeLoc TL,
2750 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002751 DependentSizedExtVectorType *T = TL.getTypePtr();
2752
2753 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002754 QualType ElementType = getDerived().TransformType(T->getElementType());
2755 if (ElementType.isNull())
2756 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002757
Douglas Gregore922c772009-08-04 22:27:00 +00002758 // Vector sizes are not potentially evaluated contexts
2759 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2760
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2762 if (Size.isInvalid())
2763 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002764
John McCall550e0c22009-10-21 00:40:46 +00002765 QualType Result = TL.getType();
2766 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002767 ElementType != T->getElementType() ||
2768 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002769 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002770 move(Size),
2771 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002772 if (Result.isNull())
2773 return QualType();
2774 }
2775 else Size.take();
2776
2777 // Result might be dependent or not.
2778 if (isa<DependentSizedExtVectorType>(Result)) {
2779 DependentSizedExtVectorTypeLoc NewTL
2780 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2781 NewTL.setNameLoc(TL.getNameLoc());
2782 } else {
2783 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785 }
2786
2787 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002788}
Mike Stump11289f42009-09-09 15:08:12 +00002789
2790template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002791QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002792 VectorTypeLoc TL,
2793 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002794 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002795 QualType ElementType = getDerived().TransformType(T->getElementType());
2796 if (ElementType.isNull())
2797 return QualType();
2798
John McCall550e0c22009-10-21 00:40:46 +00002799 QualType Result = TL.getType();
2800 if (getDerived().AlwaysRebuild() ||
2801 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002802 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2803 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002804 if (Result.isNull())
2805 return QualType();
2806 }
2807
2808 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2809 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002810
John McCall550e0c22009-10-21 00:40:46 +00002811 return Result;
2812}
2813
2814template<typename Derived>
2815QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002816 ExtVectorTypeLoc TL,
2817 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002818 VectorType *T = TL.getTypePtr();
2819 QualType ElementType = getDerived().TransformType(T->getElementType());
2820 if (ElementType.isNull())
2821 return QualType();
2822
2823 QualType Result = TL.getType();
2824 if (getDerived().AlwaysRebuild() ||
2825 ElementType != T->getElementType()) {
2826 Result = getDerived().RebuildExtVectorType(ElementType,
2827 T->getNumElements(),
2828 /*FIXME*/ SourceLocation());
2829 if (Result.isNull())
2830 return QualType();
2831 }
2832
2833 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2834 NewTL.setNameLoc(TL.getNameLoc());
2835
2836 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837}
Mike Stump11289f42009-09-09 15:08:12 +00002838
2839template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002840ParmVarDecl *
2841TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2842 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2843 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2844 if (!NewDI)
2845 return 0;
2846
2847 if (NewDI == OldDI)
2848 return OldParm;
2849 else
2850 return ParmVarDecl::Create(SemaRef.Context,
2851 OldParm->getDeclContext(),
2852 OldParm->getLocation(),
2853 OldParm->getIdentifier(),
2854 NewDI->getType(),
2855 NewDI,
2856 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002857 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002858 /* DefArg */ NULL);
2859}
2860
2861template<typename Derived>
2862bool TreeTransform<Derived>::
2863 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2864 llvm::SmallVectorImpl<QualType> &PTypes,
2865 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2866 FunctionProtoType *T = TL.getTypePtr();
2867
2868 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2869 ParmVarDecl *OldParm = TL.getArg(i);
2870
2871 QualType NewType;
2872 ParmVarDecl *NewParm;
2873
2874 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002875 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2876 if (!NewParm)
2877 return true;
2878 NewType = NewParm->getType();
2879
2880 // Deal with the possibility that we don't have a parameter
2881 // declaration for this parameter.
2882 } else {
2883 NewParm = 0;
2884
2885 QualType OldType = T->getArgType(i);
2886 NewType = getDerived().TransformType(OldType);
2887 if (NewType.isNull())
2888 return true;
2889 }
2890
2891 PTypes.push_back(NewType);
2892 PVars.push_back(NewParm);
2893 }
2894
2895 return false;
2896}
2897
2898template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002899QualType
John McCall550e0c22009-10-21 00:40:46 +00002900TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002901 FunctionProtoTypeLoc TL,
2902 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002903 FunctionProtoType *T = TL.getTypePtr();
2904 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002905 if (ResultType.isNull())
2906 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002907
John McCall550e0c22009-10-21 00:40:46 +00002908 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002910 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002911 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2912 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002913
John McCall550e0c22009-10-21 00:40:46 +00002914 QualType Result = TL.getType();
2915 if (getDerived().AlwaysRebuild() ||
2916 ResultType != T->getResultType() ||
2917 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2918 Result = getDerived().RebuildFunctionProtoType(ResultType,
2919 ParamTypes.data(),
2920 ParamTypes.size(),
2921 T->isVariadic(),
2922 T->getTypeQuals());
2923 if (Result.isNull())
2924 return QualType();
2925 }
Mike Stump11289f42009-09-09 15:08:12 +00002926
John McCall550e0c22009-10-21 00:40:46 +00002927 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2928 NewTL.setLParenLoc(TL.getLParenLoc());
2929 NewTL.setRParenLoc(TL.getRParenLoc());
2930 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2931 NewTL.setArg(i, ParamDecls[i]);
2932
2933 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934}
Mike Stump11289f42009-09-09 15:08:12 +00002935
Douglas Gregord6ff3322009-08-04 16:50:30 +00002936template<typename Derived>
2937QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002938 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002939 FunctionNoProtoTypeLoc TL,
2940 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002941 FunctionNoProtoType *T = TL.getTypePtr();
2942 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2943 if (ResultType.isNull())
2944 return QualType();
2945
2946 QualType Result = TL.getType();
2947 if (getDerived().AlwaysRebuild() ||
2948 ResultType != T->getResultType())
2949 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2950
2951 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2952 NewTL.setLParenLoc(TL.getLParenLoc());
2953 NewTL.setRParenLoc(TL.getRParenLoc());
2954
2955 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002956}
Mike Stump11289f42009-09-09 15:08:12 +00002957
John McCallb96ec562009-12-04 22:46:56 +00002958template<typename Derived> QualType
2959TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002960 UnresolvedUsingTypeLoc TL,
2961 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002962 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002963 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002964 if (!D)
2965 return QualType();
2966
2967 QualType Result = TL.getType();
2968 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2969 Result = getDerived().RebuildUnresolvedUsingType(D);
2970 if (Result.isNull())
2971 return QualType();
2972 }
2973
2974 // We might get an arbitrary type spec type back. We should at
2975 // least always get a type spec type, though.
2976 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2977 NewTL.setNameLoc(TL.getNameLoc());
2978
2979 return Result;
2980}
2981
Douglas Gregord6ff3322009-08-04 16:50:30 +00002982template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002983QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002984 TypedefTypeLoc TL,
2985 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002986 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002988 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2989 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002990 if (!Typedef)
2991 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002992
John McCall550e0c22009-10-21 00:40:46 +00002993 QualType Result = TL.getType();
2994 if (getDerived().AlwaysRebuild() ||
2995 Typedef != T->getDecl()) {
2996 Result = getDerived().RebuildTypedefType(Typedef);
2997 if (Result.isNull())
2998 return QualType();
2999 }
Mike Stump11289f42009-09-09 15:08:12 +00003000
John McCall550e0c22009-10-21 00:40:46 +00003001 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3002 NewTL.setNameLoc(TL.getNameLoc());
3003
3004 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003005}
Mike Stump11289f42009-09-09 15:08:12 +00003006
Douglas Gregord6ff3322009-08-04 16:50:30 +00003007template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003008QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003009 TypeOfExprTypeLoc TL,
3010 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003011 // typeof expressions are not potentially evaluated contexts
3012 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003013
John McCalle8595032010-01-13 20:03:27 +00003014 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015 if (E.isInvalid())
3016 return QualType();
3017
John McCall550e0c22009-10-21 00:40:46 +00003018 QualType Result = TL.getType();
3019 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003020 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003021 Result = getDerived().RebuildTypeOfExprType(move(E));
3022 if (Result.isNull())
3023 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024 }
John McCall550e0c22009-10-21 00:40:46 +00003025 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003026
John McCall550e0c22009-10-21 00:40:46 +00003027 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003028 NewTL.setTypeofLoc(TL.getTypeofLoc());
3029 NewTL.setLParenLoc(TL.getLParenLoc());
3030 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003031
3032 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033}
Mike Stump11289f42009-09-09 15:08:12 +00003034
3035template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003036QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003037 TypeOfTypeLoc TL,
3038 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003039 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3040 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3041 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003042 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003043
John McCall550e0c22009-10-21 00:40:46 +00003044 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003045 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3046 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003047 if (Result.isNull())
3048 return QualType();
3049 }
Mike Stump11289f42009-09-09 15:08:12 +00003050
John McCall550e0c22009-10-21 00:40:46 +00003051 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003052 NewTL.setTypeofLoc(TL.getTypeofLoc());
3053 NewTL.setLParenLoc(TL.getLParenLoc());
3054 NewTL.setRParenLoc(TL.getRParenLoc());
3055 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003056
3057 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003058}
Mike Stump11289f42009-09-09 15:08:12 +00003059
3060template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003061QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003062 DecltypeTypeLoc TL,
3063 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003064 DecltypeType *T = TL.getTypePtr();
3065
Douglas Gregore922c772009-08-04 22:27:00 +00003066 // decltype expressions are not potentially evaluated contexts
3067 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003068
Douglas Gregord6ff3322009-08-04 16:50:30 +00003069 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3070 if (E.isInvalid())
3071 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003072
John McCall550e0c22009-10-21 00:40:46 +00003073 QualType Result = TL.getType();
3074 if (getDerived().AlwaysRebuild() ||
3075 E.get() != T->getUnderlyingExpr()) {
3076 Result = getDerived().RebuildDecltypeType(move(E));
3077 if (Result.isNull())
3078 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003079 }
John McCall550e0c22009-10-21 00:40:46 +00003080 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003081
John McCall550e0c22009-10-21 00:40:46 +00003082 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3083 NewTL.setNameLoc(TL.getNameLoc());
3084
3085 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003086}
3087
3088template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003089QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003090 RecordTypeLoc TL,
3091 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003092 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003094 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3095 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003096 if (!Record)
3097 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003098
John McCall550e0c22009-10-21 00:40:46 +00003099 QualType Result = TL.getType();
3100 if (getDerived().AlwaysRebuild() ||
3101 Record != T->getDecl()) {
3102 Result = getDerived().RebuildRecordType(Record);
3103 if (Result.isNull())
3104 return QualType();
3105 }
Mike Stump11289f42009-09-09 15:08:12 +00003106
John McCall550e0c22009-10-21 00:40:46 +00003107 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3108 NewTL.setNameLoc(TL.getNameLoc());
3109
3110 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003111}
Mike Stump11289f42009-09-09 15:08:12 +00003112
3113template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003114QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003115 EnumTypeLoc TL,
3116 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003117 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003119 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3120 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121 if (!Enum)
3122 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003123
John McCall550e0c22009-10-21 00:40:46 +00003124 QualType Result = TL.getType();
3125 if (getDerived().AlwaysRebuild() ||
3126 Enum != T->getDecl()) {
3127 Result = getDerived().RebuildEnumType(Enum);
3128 if (Result.isNull())
3129 return QualType();
3130 }
Mike Stump11289f42009-09-09 15:08:12 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3133 NewTL.setNameLoc(TL.getNameLoc());
3134
3135 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003136}
John McCallfcc33b02009-09-05 00:15:47 +00003137
3138template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003139QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003140 ElaboratedTypeLoc TL,
3141 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003142 ElaboratedType *T = TL.getTypePtr();
3143
3144 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003145 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3146 if (Underlying.isNull())
3147 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003148
John McCall550e0c22009-10-21 00:40:46 +00003149 QualType Result = TL.getType();
3150 if (getDerived().AlwaysRebuild() ||
3151 Underlying != T->getUnderlyingType()) {
3152 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3153 if (Result.isNull())
3154 return QualType();
3155 }
Mike Stump11289f42009-09-09 15:08:12 +00003156
John McCall550e0c22009-10-21 00:40:46 +00003157 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3158 NewTL.setNameLoc(TL.getNameLoc());
3159
3160 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003161}
Mike Stump11289f42009-09-09 15:08:12 +00003162
John McCalle78aac42010-03-10 03:28:59 +00003163template<typename Derived>
3164QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3165 TypeLocBuilder &TLB,
3166 InjectedClassNameTypeLoc TL,
3167 QualType ObjectType) {
3168 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3169 TL.getTypePtr()->getDecl());
3170 if (!D) return QualType();
3171
3172 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3173 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3174 return T;
3175}
3176
Mike Stump11289f42009-09-09 15:08:12 +00003177
Douglas Gregord6ff3322009-08-04 16:50:30 +00003178template<typename Derived>
3179QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003180 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003181 TemplateTypeParmTypeLoc TL,
3182 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003183 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003184}
3185
Mike Stump11289f42009-09-09 15:08:12 +00003186template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003187QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003188 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003189 SubstTemplateTypeParmTypeLoc TL,
3190 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003191 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003192}
3193
3194template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003195QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3196 const TemplateSpecializationType *TST,
3197 QualType ObjectType) {
3198 // FIXME: this entire method is a temporary workaround; callers
3199 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003200
John McCall0ad16662009-10-29 08:12:44 +00003201 // Fake up a TemplateSpecializationTypeLoc.
3202 TypeLocBuilder TLB;
3203 TemplateSpecializationTypeLoc TL
3204 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3205
John McCall0d07eb32009-10-29 18:45:58 +00003206 SourceLocation BaseLoc = getDerived().getBaseLocation();
3207
3208 TL.setTemplateNameLoc(BaseLoc);
3209 TL.setLAngleLoc(BaseLoc);
3210 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003211 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3212 const TemplateArgument &TA = TST->getArg(i);
3213 TemplateArgumentLoc TAL;
3214 getDerived().InventTemplateArgumentLoc(TA, TAL);
3215 TL.setArgLocInfo(i, TAL.getLocInfo());
3216 }
3217
3218 TypeLocBuilder IgnoredTLB;
3219 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003220}
3221
3222template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003223QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003224 TypeLocBuilder &TLB,
3225 TemplateSpecializationTypeLoc TL,
3226 QualType ObjectType) {
3227 const TemplateSpecializationType *T = TL.getTypePtr();
3228
Mike Stump11289f42009-09-09 15:08:12 +00003229 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003230 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003231 if (Template.isNull())
3232 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003233
John McCall6b51f282009-11-23 01:53:49 +00003234 TemplateArgumentListInfo NewTemplateArgs;
3235 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3236 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3237
3238 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3239 TemplateArgumentLoc Loc;
3240 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003242 NewTemplateArgs.addArgument(Loc);
3243 }
Mike Stump11289f42009-09-09 15:08:12 +00003244
John McCall0ad16662009-10-29 08:12:44 +00003245 // FIXME: maybe don't rebuild if all the template arguments are the same.
3246
3247 QualType Result =
3248 getDerived().RebuildTemplateSpecializationType(Template,
3249 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003250 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003251
3252 if (!Result.isNull()) {
3253 TemplateSpecializationTypeLoc NewTL
3254 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3255 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3256 NewTL.setLAngleLoc(TL.getLAngleLoc());
3257 NewTL.setRAngleLoc(TL.getRAngleLoc());
3258 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3259 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003260 }
Mike Stump11289f42009-09-09 15:08:12 +00003261
John McCall0ad16662009-10-29 08:12:44 +00003262 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003263}
Mike Stump11289f42009-09-09 15:08:12 +00003264
3265template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003266QualType
3267TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003268 QualifiedNameTypeLoc TL,
3269 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003270 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003271 NestedNameSpecifier *NNS
3272 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003273 SourceRange(),
3274 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003275 if (!NNS)
3276 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003277
Douglas Gregord6ff3322009-08-04 16:50:30 +00003278 QualType Named = getDerived().TransformType(T->getNamedType());
3279 if (Named.isNull())
3280 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003281
John McCall550e0c22009-10-21 00:40:46 +00003282 QualType Result = TL.getType();
3283 if (getDerived().AlwaysRebuild() ||
3284 NNS != T->getQualifier() ||
3285 Named != T->getNamedType()) {
3286 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3287 if (Result.isNull())
3288 return QualType();
3289 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290
John McCall550e0c22009-10-21 00:40:46 +00003291 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3292 NewTL.setNameLoc(TL.getNameLoc());
3293
3294 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003295}
Mike Stump11289f42009-09-09 15:08:12 +00003296
3297template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003298QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3299 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003300 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003301 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003302
3303 /* FIXME: preserve source information better than this */
3304 SourceRange SR(TL.getNameLoc());
3305
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003307 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003308 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003309 if (!NNS)
3310 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 QualType Result;
3313
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003315 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316 = getDerived().TransformType(QualType(TemplateId, 0));
3317 if (NewTemplateId.isNull())
3318 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003319
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320 if (!getDerived().AlwaysRebuild() &&
3321 NNS == T->getQualifier() &&
3322 NewTemplateId == QualType(TemplateId, 0))
3323 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003324
Douglas Gregor02085352010-03-31 20:19:30 +00003325 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3326 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003327 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003328 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3329 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003330 }
John McCall550e0c22009-10-21 00:40:46 +00003331 if (Result.isNull())
3332 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003333
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003334 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003335 NewTL.setNameLoc(TL.getNameLoc());
3336
3337 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338}
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003341QualType
3342TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003343 ObjCInterfaceTypeLoc TL,
3344 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003345 // ObjCInterfaceType is never dependent.
3346 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003347}
Mike Stump11289f42009-09-09 15:08:12 +00003348
3349template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003350QualType
3351TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003352 ObjCObjectPointerTypeLoc TL,
3353 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003354 // ObjCObjectPointerType is never dependent.
3355 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003356}
3357
Douglas Gregord6ff3322009-08-04 16:50:30 +00003358//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003359// Statement transformation
3360//===----------------------------------------------------------------------===//
3361template<typename Derived>
3362Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003363TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3364 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003365}
3366
3367template<typename Derived>
3368Sema::OwningStmtResult
3369TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3370 return getDerived().TransformCompoundStmt(S, false);
3371}
3372
3373template<typename Derived>
3374Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003375TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003376 bool IsStmtExpr) {
3377 bool SubStmtChanged = false;
3378 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3379 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3380 B != BEnd; ++B) {
3381 OwningStmtResult Result = getDerived().TransformStmt(*B);
3382 if (Result.isInvalid())
3383 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003384
Douglas Gregorebe10102009-08-20 07:17:43 +00003385 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3386 Statements.push_back(Result.takeAs<Stmt>());
3387 }
Mike Stump11289f42009-09-09 15:08:12 +00003388
Douglas Gregorebe10102009-08-20 07:17:43 +00003389 if (!getDerived().AlwaysRebuild() &&
3390 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003391 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003392
3393 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3394 move_arg(Statements),
3395 S->getRBracLoc(),
3396 IsStmtExpr);
3397}
Mike Stump11289f42009-09-09 15:08:12 +00003398
Douglas Gregorebe10102009-08-20 07:17:43 +00003399template<typename Derived>
3400Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003401TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003402 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3403 {
3404 // The case value expressions are not potentially evaluated.
3405 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003406
Eli Friedman06577382009-11-19 03:14:00 +00003407 // Transform the left-hand case value.
3408 LHS = getDerived().TransformExpr(S->getLHS());
3409 if (LHS.isInvalid())
3410 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003411
Eli Friedman06577382009-11-19 03:14:00 +00003412 // Transform the right-hand case value (for the GNU case-range extension).
3413 RHS = getDerived().TransformExpr(S->getRHS());
3414 if (RHS.isInvalid())
3415 return SemaRef.StmtError();
3416 }
Mike Stump11289f42009-09-09 15:08:12 +00003417
Douglas Gregorebe10102009-08-20 07:17:43 +00003418 // Build the case statement.
3419 // Case statements are always rebuilt so that they will attached to their
3420 // transformed switch statement.
3421 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3422 move(LHS),
3423 S->getEllipsisLoc(),
3424 move(RHS),
3425 S->getColonLoc());
3426 if (Case.isInvalid())
3427 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003428
Douglas Gregorebe10102009-08-20 07:17:43 +00003429 // Transform the statement following the case
3430 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3431 if (SubStmt.isInvalid())
3432 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003433
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 // Attach the body to the case statement
3435 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3436}
3437
3438template<typename Derived>
3439Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003440TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003441 // Transform the statement following the default case
3442 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3443 if (SubStmt.isInvalid())
3444 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003445
Douglas Gregorebe10102009-08-20 07:17:43 +00003446 // Default statements are always rebuilt
3447 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3448 move(SubStmt));
3449}
Mike Stump11289f42009-09-09 15:08:12 +00003450
Douglas Gregorebe10102009-08-20 07:17:43 +00003451template<typename Derived>
3452Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003453TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003454 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3455 if (SubStmt.isInvalid())
3456 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458 // FIXME: Pass the real colon location in.
3459 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3460 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3461 move(SubStmt));
3462}
Mike Stump11289f42009-09-09 15:08:12 +00003463
Douglas Gregorebe10102009-08-20 07:17:43 +00003464template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003465Sema::OwningStmtResult
3466TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003468 OwningExprResult Cond(SemaRef);
3469 VarDecl *ConditionVar = 0;
3470 if (S->getConditionVariable()) {
3471 ConditionVar
3472 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003473 getDerived().TransformDefinition(
3474 S->getConditionVariable()->getLocation(),
3475 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003476 if (!ConditionVar)
3477 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003478 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003479 Cond = getDerived().TransformExpr(S->getCond());
3480
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003481 if (Cond.isInvalid())
3482 return SemaRef.StmtError();
3483 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003484
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003485 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003486
Douglas Gregorebe10102009-08-20 07:17:43 +00003487 // Transform the "then" branch.
3488 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3489 if (Then.isInvalid())
3490 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003491
Douglas Gregorebe10102009-08-20 07:17:43 +00003492 // Transform the "else" branch.
3493 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3494 if (Else.isInvalid())
3495 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003496
Douglas Gregorebe10102009-08-20 07:17:43 +00003497 if (!getDerived().AlwaysRebuild() &&
3498 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003499 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003500 Then.get() == S->getThen() &&
3501 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003502 return SemaRef.Owned(S->Retain());
3503
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003504 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3505 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003506 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003507}
3508
3509template<typename Derived>
3510Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003511TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003513 OwningExprResult Cond(SemaRef);
3514 VarDecl *ConditionVar = 0;
3515 if (S->getConditionVariable()) {
3516 ConditionVar
3517 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003518 getDerived().TransformDefinition(
3519 S->getConditionVariable()->getLocation(),
3520 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003521 if (!ConditionVar)
3522 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003523 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003524 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003525
3526 if (Cond.isInvalid())
3527 return SemaRef.StmtError();
3528 }
Mike Stump11289f42009-09-09 15:08:12 +00003529
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003530 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003531
Douglas Gregorebe10102009-08-20 07:17:43 +00003532 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003533 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3534 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003535 if (Switch.isInvalid())
3536 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 // Transform the body of the switch statement.
3539 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3540 if (Body.isInvalid())
3541 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003542
Douglas Gregorebe10102009-08-20 07:17:43 +00003543 // Complete the switch statement.
3544 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3545 move(Body));
3546}
Mike Stump11289f42009-09-09 15:08:12 +00003547
Douglas Gregorebe10102009-08-20 07:17:43 +00003548template<typename Derived>
3549Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003550TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003551 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003552 OwningExprResult Cond(SemaRef);
3553 VarDecl *ConditionVar = 0;
3554 if (S->getConditionVariable()) {
3555 ConditionVar
3556 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003557 getDerived().TransformDefinition(
3558 S->getConditionVariable()->getLocation(),
3559 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003560 if (!ConditionVar)
3561 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003562 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003563 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003564
3565 if (Cond.isInvalid())
3566 return SemaRef.StmtError();
3567 }
Mike Stump11289f42009-09-09 15:08:12 +00003568
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003569 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003570
Douglas Gregorebe10102009-08-20 07:17:43 +00003571 // Transform the body
3572 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3573 if (Body.isInvalid())
3574 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregorebe10102009-08-20 07:17:43 +00003576 if (!getDerived().AlwaysRebuild() &&
3577 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003578 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003580 return SemaRef.Owned(S->Retain());
3581
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003582 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3583 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregorebe10102009-08-20 07:17:43 +00003586template<typename Derived>
3587Sema::OwningStmtResult
3588TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3589 // Transform the condition
3590 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3591 if (Cond.isInvalid())
3592 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregorebe10102009-08-20 07:17:43 +00003594 // Transform the body
3595 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3596 if (Body.isInvalid())
3597 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003598
Douglas Gregorebe10102009-08-20 07:17:43 +00003599 if (!getDerived().AlwaysRebuild() &&
3600 Cond.get() == S->getCond() &&
3601 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003602 return SemaRef.Owned(S->Retain());
3603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3605 /*FIXME:*/S->getWhileLoc(), move(Cond),
3606 S->getRParenLoc());
3607}
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregorebe10102009-08-20 07:17:43 +00003609template<typename Derived>
3610Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003611TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003612 // Transform the initialization statement
3613 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3614 if (Init.isInvalid())
3615 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregorebe10102009-08-20 07:17:43 +00003617 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003618 OwningExprResult Cond(SemaRef);
3619 VarDecl *ConditionVar = 0;
3620 if (S->getConditionVariable()) {
3621 ConditionVar
3622 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003623 getDerived().TransformDefinition(
3624 S->getConditionVariable()->getLocation(),
3625 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003626 if (!ConditionVar)
3627 return SemaRef.StmtError();
3628 } else {
3629 Cond = getDerived().TransformExpr(S->getCond());
3630
3631 if (Cond.isInvalid())
3632 return SemaRef.StmtError();
3633 }
Mike Stump11289f42009-09-09 15:08:12 +00003634
Douglas Gregorebe10102009-08-20 07:17:43 +00003635 // Transform the increment
3636 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3637 if (Inc.isInvalid())
3638 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003639
Douglas Gregorebe10102009-08-20 07:17:43 +00003640 // Transform the body
3641 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3642 if (Body.isInvalid())
3643 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 if (!getDerived().AlwaysRebuild() &&
3646 Init.get() == S->getInit() &&
3647 Cond.get() == S->getCond() &&
3648 Inc.get() == S->getInc() &&
3649 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003650 return SemaRef.Owned(S->Retain());
3651
Douglas Gregorebe10102009-08-20 07:17:43 +00003652 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003653 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003654 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003655 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003656 S->getRParenLoc(), move(Body));
3657}
3658
3659template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003660Sema::OwningStmtResult
3661TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003662 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003663 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003664 S->getLabel());
3665}
3666
3667template<typename Derived>
3668Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003669TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3671 if (Target.isInvalid())
3672 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregorebe10102009-08-20 07:17:43 +00003674 if (!getDerived().AlwaysRebuild() &&
3675 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003676 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003677
3678 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3679 move(Target));
3680}
3681
3682template<typename Derived>
3683Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003684TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3685 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003686}
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregorebe10102009-08-20 07:17:43 +00003688template<typename Derived>
3689Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003690TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3691 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003692}
Mike Stump11289f42009-09-09 15:08:12 +00003693
Douglas Gregorebe10102009-08-20 07:17:43 +00003694template<typename Derived>
3695Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003696TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003697 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3698 if (Result.isInvalid())
3699 return SemaRef.StmtError();
3700
Mike Stump11289f42009-09-09 15:08:12 +00003701 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003702 // to tell whether the return type of the function has changed.
3703 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3704}
Mike Stump11289f42009-09-09 15:08:12 +00003705
Douglas Gregorebe10102009-08-20 07:17:43 +00003706template<typename Derived>
3707Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003708TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 bool DeclChanged = false;
3710 llvm::SmallVector<Decl *, 4> Decls;
3711 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3712 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003713 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3714 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003715 if (!Transformed)
3716 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003717
Douglas Gregorebe10102009-08-20 07:17:43 +00003718 if (Transformed != *D)
3719 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003720
Douglas Gregorebe10102009-08-20 07:17:43 +00003721 Decls.push_back(Transformed);
3722 }
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregorebe10102009-08-20 07:17:43 +00003724 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003725 return SemaRef.Owned(S->Retain());
3726
3727 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003728 S->getStartLoc(), S->getEndLoc());
3729}
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregorebe10102009-08-20 07:17:43 +00003731template<typename Derived>
3732Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003733TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003735 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003736}
3737
3738template<typename Derived>
3739Sema::OwningStmtResult
3740TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003741
3742 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3743 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003744 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003745
Anders Carlssonaaeef072010-01-24 05:50:09 +00003746 OwningExprResult AsmString(SemaRef);
3747 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3748
3749 bool ExprsChanged = false;
3750
3751 // Go through the outputs.
3752 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003753 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003754
Anders Carlssonaaeef072010-01-24 05:50:09 +00003755 // No need to transform the constraint literal.
3756 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3757
3758 // Transform the output expr.
3759 Expr *OutputExpr = S->getOutputExpr(I);
3760 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3761 if (Result.isInvalid())
3762 return SemaRef.StmtError();
3763
3764 ExprsChanged |= Result.get() != OutputExpr;
3765
3766 Exprs.push_back(Result.takeAs<Expr>());
3767 }
3768
3769 // Go through the inputs.
3770 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003771 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003772
Anders Carlssonaaeef072010-01-24 05:50:09 +00003773 // No need to transform the constraint literal.
3774 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3775
3776 // Transform the input expr.
3777 Expr *InputExpr = S->getInputExpr(I);
3778 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3779 if (Result.isInvalid())
3780 return SemaRef.StmtError();
3781
3782 ExprsChanged |= Result.get() != InputExpr;
3783
3784 Exprs.push_back(Result.takeAs<Expr>());
3785 }
3786
3787 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3788 return SemaRef.Owned(S->Retain());
3789
3790 // Go through the clobbers.
3791 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3792 Clobbers.push_back(S->getClobber(I)->Retain());
3793
3794 // No need to transform the asm string literal.
3795 AsmString = SemaRef.Owned(S->getAsmString());
3796
3797 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3798 S->isSimple(),
3799 S->isVolatile(),
3800 S->getNumOutputs(),
3801 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003802 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003803 move_arg(Constraints),
3804 move_arg(Exprs),
3805 move(AsmString),
3806 move_arg(Clobbers),
3807 S->getRParenLoc(),
3808 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003809}
3810
3811
3812template<typename Derived>
3813Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003814TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003815 // Transform the body of the @try.
3816 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3817 if (TryBody.isInvalid())
3818 return SemaRef.StmtError();
3819
Douglas Gregor96c79492010-04-23 22:50:49 +00003820 // Transform the @catch statements (if present).
3821 bool AnyCatchChanged = false;
3822 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3823 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3824 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003825 if (Catch.isInvalid())
3826 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003827 if (Catch.get() != S->getCatchStmt(I))
3828 AnyCatchChanged = true;
3829 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003830 }
3831
3832 // Transform the @finally statement (if present).
3833 OwningStmtResult Finally(SemaRef);
3834 if (S->getFinallyStmt()) {
3835 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3836 if (Finally.isInvalid())
3837 return SemaRef.StmtError();
3838 }
3839
3840 // If nothing changed, just retain this statement.
3841 if (!getDerived().AlwaysRebuild() &&
3842 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003843 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003844 Finally.get() == S->getFinallyStmt())
3845 return SemaRef.Owned(S->Retain());
3846
3847 // Build a new statement.
3848 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003849 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003850}
Mike Stump11289f42009-09-09 15:08:12 +00003851
Douglas Gregorebe10102009-08-20 07:17:43 +00003852template<typename Derived>
3853Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003854TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003855 // Transform the @catch parameter, if there is one.
3856 VarDecl *Var = 0;
3857 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3858 TypeSourceInfo *TSInfo = 0;
3859 if (FromVar->getTypeSourceInfo()) {
3860 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3861 if (!TSInfo)
3862 return SemaRef.StmtError();
3863 }
3864
3865 QualType T;
3866 if (TSInfo)
3867 T = TSInfo->getType();
3868 else {
3869 T = getDerived().TransformType(FromVar->getType());
3870 if (T.isNull())
3871 return SemaRef.StmtError();
3872 }
3873
3874 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3875 if (!Var)
3876 return SemaRef.StmtError();
3877 }
3878
3879 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3880 if (Body.isInvalid())
3881 return SemaRef.StmtError();
3882
3883 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
3884 S->getRParenLoc(),
3885 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003886}
Mike Stump11289f42009-09-09 15:08:12 +00003887
Douglas Gregorebe10102009-08-20 07:17:43 +00003888template<typename Derived>
3889Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003890TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003891 // Transform the body.
3892 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3893 if (Body.isInvalid())
3894 return SemaRef.StmtError();
3895
3896 // If nothing changed, just retain this statement.
3897 if (!getDerived().AlwaysRebuild() &&
3898 Body.get() == S->getFinallyBody())
3899 return SemaRef.Owned(S->Retain());
3900
3901 // Build a new statement.
3902 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3903 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003904}
Mike Stump11289f42009-09-09 15:08:12 +00003905
Douglas Gregorebe10102009-08-20 07:17:43 +00003906template<typename Derived>
3907Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003908TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003909 OwningExprResult Operand(SemaRef);
3910 if (S->getThrowExpr()) {
3911 Operand = getDerived().TransformExpr(S->getThrowExpr());
3912 if (Operand.isInvalid())
3913 return getSema().StmtError();
3914 }
3915
3916 if (!getDerived().AlwaysRebuild() &&
3917 Operand.get() == S->getThrowExpr())
3918 return getSema().Owned(S->Retain());
3919
3920 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003921}
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregorebe10102009-08-20 07:17:43 +00003923template<typename Derived>
3924Sema::OwningStmtResult
3925TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003926 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003927 // Transform the object we are locking.
3928 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3929 if (Object.isInvalid())
3930 return SemaRef.StmtError();
3931
3932 // Transform the body.
3933 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3934 if (Body.isInvalid())
3935 return SemaRef.StmtError();
3936
3937 // If nothing change, just retain the current statement.
3938 if (!getDerived().AlwaysRebuild() &&
3939 Object.get() == S->getSynchExpr() &&
3940 Body.get() == S->getSynchBody())
3941 return SemaRef.Owned(S->Retain());
3942
3943 // Build a new statement.
3944 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3945 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003946}
3947
3948template<typename Derived>
3949Sema::OwningStmtResult
3950TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003951 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003952 // Transform the element statement.
3953 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3954 if (Element.isInvalid())
3955 return SemaRef.StmtError();
3956
3957 // Transform the collection expression.
3958 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3959 if (Collection.isInvalid())
3960 return SemaRef.StmtError();
3961
3962 // Transform the body.
3963 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3964 if (Body.isInvalid())
3965 return SemaRef.StmtError();
3966
3967 // If nothing changed, just retain this statement.
3968 if (!getDerived().AlwaysRebuild() &&
3969 Element.get() == S->getElement() &&
3970 Collection.get() == S->getCollection() &&
3971 Body.get() == S->getBody())
3972 return SemaRef.Owned(S->Retain());
3973
3974 // Build a new statement.
3975 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3976 /*FIXME:*/S->getForLoc(),
3977 move(Element),
3978 move(Collection),
3979 S->getRParenLoc(),
3980 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003981}
3982
3983
3984template<typename Derived>
3985Sema::OwningStmtResult
3986TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3987 // Transform the exception declaration, if any.
3988 VarDecl *Var = 0;
3989 if (S->getExceptionDecl()) {
3990 VarDecl *ExceptionDecl = S->getExceptionDecl();
3991 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3992 ExceptionDecl->getDeclName());
3993
3994 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3995 if (T.isNull())
3996 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003997
Douglas Gregorebe10102009-08-20 07:17:43 +00003998 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3999 T,
John McCallbcd03502009-12-07 02:54:59 +00004000 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004001 ExceptionDecl->getIdentifier(),
4002 ExceptionDecl->getLocation(),
4003 /*FIXME: Inaccurate*/
4004 SourceRange(ExceptionDecl->getLocation()));
4005 if (!Var || Var->isInvalidDecl()) {
4006 if (Var)
4007 Var->Destroy(SemaRef.Context);
4008 return SemaRef.StmtError();
4009 }
4010 }
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregorebe10102009-08-20 07:17:43 +00004012 // Transform the actual exception handler.
4013 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4014 if (Handler.isInvalid()) {
4015 if (Var)
4016 Var->Destroy(SemaRef.Context);
4017 return SemaRef.StmtError();
4018 }
Mike Stump11289f42009-09-09 15:08:12 +00004019
Douglas Gregorebe10102009-08-20 07:17:43 +00004020 if (!getDerived().AlwaysRebuild() &&
4021 !Var &&
4022 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004023 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004024
4025 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4026 Var,
4027 move(Handler));
4028}
Mike Stump11289f42009-09-09 15:08:12 +00004029
Douglas Gregorebe10102009-08-20 07:17:43 +00004030template<typename Derived>
4031Sema::OwningStmtResult
4032TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4033 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004034 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004035 = getDerived().TransformCompoundStmt(S->getTryBlock());
4036 if (TryBlock.isInvalid())
4037 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004038
Douglas Gregorebe10102009-08-20 07:17:43 +00004039 // Transform the handlers.
4040 bool HandlerChanged = false;
4041 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4042 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004043 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004044 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4045 if (Handler.isInvalid())
4046 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004047
Douglas Gregorebe10102009-08-20 07:17:43 +00004048 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4049 Handlers.push_back(Handler.takeAs<Stmt>());
4050 }
Mike Stump11289f42009-09-09 15:08:12 +00004051
Douglas Gregorebe10102009-08-20 07:17:43 +00004052 if (!getDerived().AlwaysRebuild() &&
4053 TryBlock.get() == S->getTryBlock() &&
4054 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004055 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004056
4057 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004058 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004059}
Mike Stump11289f42009-09-09 15:08:12 +00004060
Douglas Gregorebe10102009-08-20 07:17:43 +00004061//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004062// Expression transformation
4063//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004064template<typename Derived>
4065Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004066TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004067 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004068}
Mike Stump11289f42009-09-09 15:08:12 +00004069
4070template<typename Derived>
4071Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004072TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004073 NestedNameSpecifier *Qualifier = 0;
4074 if (E->getQualifier()) {
4075 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004076 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004077 if (!Qualifier)
4078 return SemaRef.ExprError();
4079 }
John McCallce546572009-12-08 09:08:17 +00004080
4081 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004082 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4083 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004084 if (!ND)
4085 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004086
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004087 if (!getDerived().AlwaysRebuild() &&
4088 Qualifier == E->getQualifier() &&
4089 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004090 !E->hasExplicitTemplateArgumentList()) {
4091
4092 // Mark it referenced in the new context regardless.
4093 // FIXME: this is a bit instantiation-specific.
4094 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4095
Mike Stump11289f42009-09-09 15:08:12 +00004096 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004097 }
John McCallce546572009-12-08 09:08:17 +00004098
4099 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4100 if (E->hasExplicitTemplateArgumentList()) {
4101 TemplateArgs = &TransArgs;
4102 TransArgs.setLAngleLoc(E->getLAngleLoc());
4103 TransArgs.setRAngleLoc(E->getRAngleLoc());
4104 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4105 TemplateArgumentLoc Loc;
4106 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4107 return SemaRef.ExprError();
4108 TransArgs.addArgument(Loc);
4109 }
4110 }
4111
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004112 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004113 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004114}
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004117Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004118TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004119 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004120}
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004123Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004124TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004125 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004126}
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004129Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004130TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004131 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregora16548e2009-08-11 05:31:07 +00004134template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004135Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004136TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004137 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004138}
Mike Stump11289f42009-09-09 15:08:12 +00004139
Douglas Gregora16548e2009-08-11 05:31:07 +00004140template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004141Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004142TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004143 return SemaRef.Owned(E->Retain());
4144}
4145
4146template<typename Derived>
4147Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004148TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004149 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4150 if (SubExpr.isInvalid())
4151 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregora16548e2009-08-11 05:31:07 +00004153 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004154 return SemaRef.Owned(E->Retain());
4155
4156 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004157 E->getRParen());
4158}
4159
Mike Stump11289f42009-09-09 15:08:12 +00004160template<typename Derived>
4161Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004162TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4163 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 if (SubExpr.isInvalid())
4165 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004166
Douglas Gregora16548e2009-08-11 05:31:07 +00004167 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004168 return SemaRef.Owned(E->Retain());
4169
Douglas Gregora16548e2009-08-11 05:31:07 +00004170 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4171 E->getOpcode(),
4172 move(SubExpr));
4173}
Mike Stump11289f42009-09-09 15:08:12 +00004174
Douglas Gregora16548e2009-08-11 05:31:07 +00004175template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004176Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004177TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004178 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004179 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004180
John McCallbcd03502009-12-07 02:54:59 +00004181 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004182 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004183 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall4c98fd82009-11-04 07:28:41 +00004185 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004187
John McCall4c98fd82009-11-04 07:28:41 +00004188 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004189 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004190 E->getSourceRange());
4191 }
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004194 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004195 // C++0x [expr.sizeof]p1:
4196 // The operand is either an expression, which is an unevaluated operand
4197 // [...]
4198 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregora16548e2009-08-11 05:31:07 +00004200 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4201 if (SubExpr.isInvalid())
4202 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004203
Douglas Gregora16548e2009-08-11 05:31:07 +00004204 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4205 return SemaRef.Owned(E->Retain());
4206 }
Mike Stump11289f42009-09-09 15:08:12 +00004207
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4209 E->isSizeOf(),
4210 E->getSourceRange());
4211}
Mike Stump11289f42009-09-09 15:08:12 +00004212
Douglas Gregora16548e2009-08-11 05:31:07 +00004213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004214Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004215TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4217 if (LHS.isInvalid())
4218 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004219
Douglas Gregora16548e2009-08-11 05:31:07 +00004220 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4221 if (RHS.isInvalid())
4222 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004223
4224
Douglas Gregora16548e2009-08-11 05:31:07 +00004225 if (!getDerived().AlwaysRebuild() &&
4226 LHS.get() == E->getLHS() &&
4227 RHS.get() == E->getRHS())
4228 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregora16548e2009-08-11 05:31:07 +00004230 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4231 /*FIXME:*/E->getLHS()->getLocStart(),
4232 move(RHS),
4233 E->getRBracketLoc());
4234}
Mike Stump11289f42009-09-09 15:08:12 +00004235
4236template<typename Derived>
4237Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004238TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004239 // Transform the callee.
4240 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4241 if (Callee.isInvalid())
4242 return SemaRef.ExprError();
4243
4244 // Transform arguments.
4245 bool ArgChanged = false;
4246 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4247 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4248 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4249 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4250 if (Arg.isInvalid())
4251 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004252
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 // FIXME: Wrong source location information for the ','.
4254 FakeCommaLocs.push_back(
4255 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004256
4257 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 Args.push_back(Arg.takeAs<Expr>());
4259 }
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 if (!getDerived().AlwaysRebuild() &&
4262 Callee.get() == E->getCallee() &&
4263 !ArgChanged)
4264 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004265
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004267 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4269 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4270 move_arg(Args),
4271 FakeCommaLocs.data(),
4272 E->getRParenLoc());
4273}
Mike Stump11289f42009-09-09 15:08:12 +00004274
4275template<typename Derived>
4276Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004277TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4279 if (Base.isInvalid())
4280 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004281
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004282 NestedNameSpecifier *Qualifier = 0;
4283 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004284 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004285 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004286 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004287 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004288 return SemaRef.ExprError();
4289 }
Mike Stump11289f42009-09-09 15:08:12 +00004290
Eli Friedman2cfcef62009-12-04 06:40:45 +00004291 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004292 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4293 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004294 if (!Member)
4295 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004296
John McCall16df1e52010-03-30 21:47:33 +00004297 NamedDecl *FoundDecl = E->getFoundDecl();
4298 if (FoundDecl == E->getMemberDecl()) {
4299 FoundDecl = Member;
4300 } else {
4301 FoundDecl = cast_or_null<NamedDecl>(
4302 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4303 if (!FoundDecl)
4304 return SemaRef.ExprError();
4305 }
4306
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 if (!getDerived().AlwaysRebuild() &&
4308 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004309 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004310 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004311 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004312 !E->hasExplicitTemplateArgumentList()) {
4313
4314 // Mark it referenced in the new context regardless.
4315 // FIXME: this is a bit instantiation-specific.
4316 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004317 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004318 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004319
John McCall6b51f282009-11-23 01:53:49 +00004320 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004321 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004322 TransArgs.setLAngleLoc(E->getLAngleLoc());
4323 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004324 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004325 TemplateArgumentLoc Loc;
4326 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004327 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004328 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004329 }
4330 }
4331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332 // FIXME: Bogus source location for the operator
4333 SourceLocation FakeOperatorLoc
4334 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4335
John McCall38836f02010-01-15 08:34:02 +00004336 // FIXME: to do this check properly, we will need to preserve the
4337 // first-qualifier-in-scope here, just in case we had a dependent
4338 // base (and therefore couldn't do the check) and a
4339 // nested-name-qualifier (and therefore could do the lookup).
4340 NamedDecl *FirstQualifierInScope = 0;
4341
Douglas Gregora16548e2009-08-11 05:31:07 +00004342 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4343 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004344 Qualifier,
4345 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004346 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004347 Member,
John McCall16df1e52010-03-30 21:47:33 +00004348 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004349 (E->hasExplicitTemplateArgumentList()
4350 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004351 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004352}
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004355Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4358 if (LHS.isInvalid())
4359 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4362 if (RHS.isInvalid())
4363 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 if (!getDerived().AlwaysRebuild() &&
4366 LHS.get() == E->getLHS() &&
4367 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004368 return SemaRef.Owned(E->Retain());
4369
Douglas Gregora16548e2009-08-11 05:31:07 +00004370 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4371 move(LHS), move(RHS));
4372}
4373
Mike Stump11289f42009-09-09 15:08:12 +00004374template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004375Sema::OwningExprResult
4376TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004377 CompoundAssignOperator *E) {
4378 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004379}
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004382Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004383TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4385 if (Cond.isInvalid())
4386 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4389 if (LHS.isInvalid())
4390 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4393 if (RHS.isInvalid())
4394 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004395
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 if (!getDerived().AlwaysRebuild() &&
4397 Cond.get() == E->getCond() &&
4398 LHS.get() == E->getLHS() &&
4399 RHS.get() == E->getRHS())
4400 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004401
4402 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004403 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004404 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004405 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 move(RHS));
4407}
Mike Stump11289f42009-09-09 15:08:12 +00004408
4409template<typename Derived>
4410Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004411TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004412 // Implicit casts are eliminated during transformation, since they
4413 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004414 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
4418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004420 TypeSourceInfo *OldT;
4421 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004422 {
4423 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004424 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4426 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004427
John McCall97513962010-01-15 18:39:57 +00004428 OldT = E->getTypeInfoAsWritten();
4429 NewT = getDerived().TransformType(OldT);
4430 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 return SemaRef.ExprError();
4432 }
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregor6131b442009-12-12 18:16:41 +00004434 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004435 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 if (SubExpr.isInvalid())
4437 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004440 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004442 return SemaRef.Owned(E->Retain());
4443
John McCall97513962010-01-15 18:39:57 +00004444 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4445 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 E->getRParenLoc(),
4447 move(SubExpr));
4448}
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004451Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004452TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004453 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4454 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4455 if (!NewT)
4456 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4459 if (Init.isInvalid())
4460 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004463 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004465 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004466
John McCall5d7aa7f2010-01-19 22:33:45 +00004467 // Note: the expression type doesn't necessarily match the
4468 // type-as-written, but that's okay, because it should always be
4469 // derivable from the initializer.
4470
John McCalle15bbff2010-01-18 19:35:47 +00004471 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 /*FIXME:*/E->getInitializer()->getLocEnd(),
4473 move(Init));
4474}
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregora16548e2009-08-11 05:31:07 +00004476template<typename Derived>
4477Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004478TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4480 if (Base.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004485 return SemaRef.Owned(E->Retain());
4486
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004488 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004489 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4490 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4491 E->getAccessorLoc(),
4492 E->getAccessor());
4493}
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004496Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004497TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4501 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4502 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4503 if (Init.isInvalid())
4504 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 InitChanged = InitChanged || Init.get() != E->getInit(I);
4507 Inits.push_back(Init.takeAs<Expr>());
4508 }
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregora16548e2009-08-11 05:31:07 +00004510 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004511 return SemaRef.Owned(E->Retain());
4512
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004514 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004515}
Mike Stump11289f42009-09-09 15:08:12 +00004516
Douglas Gregora16548e2009-08-11 05:31:07 +00004517template<typename Derived>
4518Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004519TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004521
Douglas Gregorebe10102009-08-20 07:17:43 +00004522 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004523 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4524 if (Init.isInvalid())
4525 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004526
Douglas Gregorebe10102009-08-20 07:17:43 +00004527 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004528 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4529 bool ExprChanged = false;
4530 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4531 DEnd = E->designators_end();
4532 D != DEnd; ++D) {
4533 if (D->isFieldDesignator()) {
4534 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4535 D->getDotLoc(),
4536 D->getFieldLoc()));
4537 continue;
4538 }
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 if (D->isArrayDesignator()) {
4541 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4542 if (Index.isInvalid())
4543 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004544
4545 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4549 ArrayExprs.push_back(Index.release());
4550 continue;
4551 }
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004554 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4556 if (Start.isInvalid())
4557 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4560 if (End.isInvalid())
4561 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
4563 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 End.get(),
4565 D->getLBracketLoc(),
4566 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4569 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 ArrayExprs.push_back(Start.release());
4572 ArrayExprs.push_back(End.release());
4573 }
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575 if (!getDerived().AlwaysRebuild() &&
4576 Init.get() == E->getInit() &&
4577 !ExprChanged)
4578 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4581 E->getEqualOrColonLoc(),
4582 E->usesGNUSyntax(), move(Init));
4583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004586Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004587TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004588 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004589 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4590
4591 // FIXME: Will we ever have proper type location here? Will we actually
4592 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004593 QualType T = getDerived().TransformType(E->getType());
4594 if (T.isNull())
4595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 if (!getDerived().AlwaysRebuild() &&
4598 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004599 return SemaRef.Owned(E->Retain());
4600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 return getDerived().RebuildImplicitValueInitExpr(T);
4602}
Mike Stump11289f42009-09-09 15:08:12 +00004603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004605Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004606TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 // FIXME: Do we want the type as written?
4608 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004609
Douglas Gregora16548e2009-08-11 05:31:07 +00004610 {
4611 // FIXME: Source location isn't quite accurate.
4612 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4613 T = getDerived().TransformType(E->getType());
4614 if (T.isNull())
4615 return SemaRef.ExprError();
4616 }
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4619 if (SubExpr.isInvalid())
4620 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 if (!getDerived().AlwaysRebuild() &&
4623 T == E->getType() &&
4624 SubExpr.get() == E->getSubExpr())
4625 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4628 T, E->getRParenLoc());
4629}
4630
4631template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004632Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004633TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 bool ArgumentChanged = false;
4635 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4636 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4637 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4638 if (Init.isInvalid())
4639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4642 Inits.push_back(Init.takeAs<Expr>());
4643 }
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregora16548e2009-08-11 05:31:07 +00004645 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4646 move_arg(Inits),
4647 E->getRParenLoc());
4648}
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregora16548e2009-08-11 05:31:07 +00004650/// \brief Transform an address-of-label expression.
4651///
4652/// By default, the transformation of an address-of-label expression always
4653/// rebuilds the expression, so that the label identifier can be resolved to
4654/// the corresponding label statement by semantic analysis.
4655template<typename Derived>
4656Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004657TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4659 E->getLabel());
4660}
Mike Stump11289f42009-09-09 15:08:12 +00004661
4662template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004663Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004664TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004665 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4667 if (SubStmt.isInvalid())
4668 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregora16548e2009-08-11 05:31:07 +00004670 if (!getDerived().AlwaysRebuild() &&
4671 SubStmt.get() == E->getSubStmt())
4672 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004673
4674 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 move(SubStmt),
4676 E->getRParenLoc());
4677}
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregora16548e2009-08-11 05:31:07 +00004679template<typename Derived>
4680Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004681TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 QualType T1, T2;
4683 {
4684 // FIXME: Source location isn't quite accurate.
4685 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687 T1 = getDerived().TransformType(E->getArgType1());
4688 if (T1.isNull())
4689 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004690
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 T2 = getDerived().TransformType(E->getArgType2());
4692 if (T2.isNull())
4693 return SemaRef.ExprError();
4694 }
4695
4696 if (!getDerived().AlwaysRebuild() &&
4697 T1 == E->getArgType1() &&
4698 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004699 return SemaRef.Owned(E->Retain());
4700
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4702 T1, T2, E->getRParenLoc());
4703}
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregora16548e2009-08-11 05:31:07 +00004705template<typename Derived>
4706Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004707TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4709 if (Cond.isInvalid())
4710 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004711
Douglas Gregora16548e2009-08-11 05:31:07 +00004712 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4713 if (LHS.isInvalid())
4714 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4717 if (RHS.isInvalid())
4718 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 if (!getDerived().AlwaysRebuild() &&
4721 Cond.get() == E->getCond() &&
4722 LHS.get() == E->getLHS() &&
4723 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004724 return SemaRef.Owned(E->Retain());
4725
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4727 move(Cond), move(LHS), move(RHS),
4728 E->getRParenLoc());
4729}
Mike Stump11289f42009-09-09 15:08:12 +00004730
Douglas Gregora16548e2009-08-11 05:31:07 +00004731template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004732Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004733TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004734 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004735}
4736
4737template<typename Derived>
4738Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004739TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004740 switch (E->getOperator()) {
4741 case OO_New:
4742 case OO_Delete:
4743 case OO_Array_New:
4744 case OO_Array_Delete:
4745 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4746 return SemaRef.ExprError();
4747
4748 case OO_Call: {
4749 // This is a call to an object's operator().
4750 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4751
4752 // Transform the object itself.
4753 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4754 if (Object.isInvalid())
4755 return SemaRef.ExprError();
4756
4757 // FIXME: Poor location information
4758 SourceLocation FakeLParenLoc
4759 = SemaRef.PP.getLocForEndOfToken(
4760 static_cast<Expr *>(Object.get())->getLocEnd());
4761
4762 // Transform the call arguments.
4763 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4764 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4765 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004766 if (getDerived().DropCallArgument(E->getArg(I)))
4767 break;
4768
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004769 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4770 if (Arg.isInvalid())
4771 return SemaRef.ExprError();
4772
4773 // FIXME: Poor source location information.
4774 SourceLocation FakeCommaLoc
4775 = SemaRef.PP.getLocForEndOfToken(
4776 static_cast<Expr *>(Arg.get())->getLocEnd());
4777 FakeCommaLocs.push_back(FakeCommaLoc);
4778 Args.push_back(Arg.release());
4779 }
4780
4781 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4782 move_arg(Args),
4783 FakeCommaLocs.data(),
4784 E->getLocEnd());
4785 }
4786
4787#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4788 case OO_##Name:
4789#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4790#include "clang/Basic/OperatorKinds.def"
4791 case OO_Subscript:
4792 // Handled below.
4793 break;
4794
4795 case OO_Conditional:
4796 llvm_unreachable("conditional operator is not actually overloadable");
4797 return SemaRef.ExprError();
4798
4799 case OO_None:
4800 case NUM_OVERLOADED_OPERATORS:
4801 llvm_unreachable("not an overloaded operator?");
4802 return SemaRef.ExprError();
4803 }
4804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4806 if (Callee.isInvalid())
4807 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004808
John McCall47f29ea2009-12-08 09:21:05 +00004809 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 if (First.isInvalid())
4811 return SemaRef.ExprError();
4812
4813 OwningExprResult Second(SemaRef);
4814 if (E->getNumArgs() == 2) {
4815 Second = getDerived().TransformExpr(E->getArg(1));
4816 if (Second.isInvalid())
4817 return SemaRef.ExprError();
4818 }
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 if (!getDerived().AlwaysRebuild() &&
4821 Callee.get() == E->getCallee() &&
4822 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004823 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4824 return SemaRef.Owned(E->Retain());
4825
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4827 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004828 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 move(First),
4830 move(Second));
4831}
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833template<typename Derived>
4834Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004835TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4836 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004837}
Mike Stump11289f42009-09-09 15:08:12 +00004838
Douglas Gregora16548e2009-08-11 05:31:07 +00004839template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004840Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004841TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004842 TypeSourceInfo *OldT;
4843 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 {
4845 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004846 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4848 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004849
John McCall97513962010-01-15 18:39:57 +00004850 OldT = E->getTypeInfoAsWritten();
4851 NewT = getDerived().TransformType(OldT);
4852 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004853 return SemaRef.ExprError();
4854 }
Mike Stump11289f42009-09-09 15:08:12 +00004855
Douglas Gregor6131b442009-12-12 18:16:41 +00004856 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004857 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004858 if (SubExpr.isInvalid())
4859 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004862 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004864 return SemaRef.Owned(E->Retain());
4865
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004867 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4869 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4870 SourceLocation FakeRParenLoc
4871 = SemaRef.PP.getLocForEndOfToken(
4872 E->getSubExpr()->getSourceRange().getEnd());
4873 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004874 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004876 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 FakeRAngleLoc,
4878 FakeRAngleLoc,
4879 move(SubExpr),
4880 FakeRParenLoc);
4881}
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregora16548e2009-08-11 05:31:07 +00004883template<typename Derived>
4884Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004885TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4886 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004887}
Mike Stump11289f42009-09-09 15:08:12 +00004888
4889template<typename Derived>
4890Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004891TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4892 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004893}
4894
Douglas Gregora16548e2009-08-11 05:31:07 +00004895template<typename Derived>
4896Sema::OwningExprResult
4897TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004898 CXXReinterpretCastExpr *E) {
4899 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004900}
Mike Stump11289f42009-09-09 15:08:12 +00004901
Douglas Gregora16548e2009-08-11 05:31:07 +00004902template<typename Derived>
4903Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004904TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4905 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908template<typename Derived>
4909Sema::OwningExprResult
4910TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004911 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004912 TypeSourceInfo *OldT;
4913 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004914 {
4915 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004916
John McCall97513962010-01-15 18:39:57 +00004917 OldT = E->getTypeInfoAsWritten();
4918 NewT = getDerived().TransformType(OldT);
4919 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004920 return SemaRef.ExprError();
4921 }
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregor6131b442009-12-12 18:16:41 +00004923 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004924 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 if (SubExpr.isInvalid())
4926 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004929 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004930 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004931 return SemaRef.Owned(E->Retain());
4932
Douglas Gregora16548e2009-08-11 05:31:07 +00004933 // FIXME: The end of the type's source range is wrong
4934 return getDerived().RebuildCXXFunctionalCastExpr(
4935 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004936 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004937 /*FIXME:*/E->getSubExpr()->getLocStart(),
4938 move(SubExpr),
4939 E->getRParenLoc());
4940}
Mike Stump11289f42009-09-09 15:08:12 +00004941
Douglas Gregora16548e2009-08-11 05:31:07 +00004942template<typename Derived>
4943Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004944TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 if (E->isTypeOperand()) {
4946 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004947
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 QualType T = getDerived().TransformType(E->getTypeOperand());
4949 if (T.isNull())
4950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 if (!getDerived().AlwaysRebuild() &&
4953 T == E->getTypeOperand())
4954 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004955
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4957 /*FIXME:*/E->getLocStart(),
4958 T,
4959 E->getLocEnd());
4960 }
Mike Stump11289f42009-09-09 15:08:12 +00004961
Douglas Gregora16548e2009-08-11 05:31:07 +00004962 // We don't know whether the expression is potentially evaluated until
4963 // after we perform semantic analysis, so the expression is potentially
4964 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004965 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004966 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregora16548e2009-08-11 05:31:07 +00004968 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4969 if (SubExpr.isInvalid())
4970 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004971
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 if (!getDerived().AlwaysRebuild() &&
4973 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004974 return SemaRef.Owned(E->Retain());
4975
Douglas Gregora16548e2009-08-11 05:31:07 +00004976 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4977 /*FIXME:*/E->getLocStart(),
4978 move(SubExpr),
4979 E->getLocEnd());
4980}
4981
4982template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004983Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004984TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004985 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004986}
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregora16548e2009-08-11 05:31:07 +00004988template<typename Derived>
4989Sema::OwningExprResult
4990TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004991 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004992 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004993}
Mike Stump11289f42009-09-09 15:08:12 +00004994
Douglas Gregora16548e2009-08-11 05:31:07 +00004995template<typename Derived>
4996Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004997TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 QualType T = getDerived().TransformType(E->getType());
5001 if (T.isNull())
5002 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 if (!getDerived().AlwaysRebuild() &&
5005 T == E->getType())
5006 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregorb15af892010-01-07 23:12:05 +00005008 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005009}
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011template<typename Derived>
5012Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005013TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5015 if (SubExpr.isInvalid())
5016 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 if (!getDerived().AlwaysRebuild() &&
5019 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005020 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005021
5022 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5023}
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregora16548e2009-08-11 05:31:07 +00005025template<typename Derived>
5026Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005027TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005028 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005029 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5030 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 if (!Param)
5032 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005033
Chandler Carruth794da4c2010-02-08 06:42:49 +00005034 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 Param == E->getParam())
5036 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregor033f6752009-12-23 23:03:06 +00005038 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005039}
Mike Stump11289f42009-09-09 15:08:12 +00005040
Douglas Gregora16548e2009-08-11 05:31:07 +00005041template<typename Derived>
5042Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005043TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5045
5046 QualType T = getDerived().TransformType(E->getType());
5047 if (T.isNull())
5048 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 if (!getDerived().AlwaysRebuild() &&
5051 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005052 return SemaRef.Owned(E->Retain());
5053
5054 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 /*FIXME:*/E->getTypeBeginLoc(),
5056 T,
5057 E->getRParenLoc());
5058}
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregora16548e2009-08-11 05:31:07 +00005060template<typename Derived>
5061Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005062TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 // Transform the type that we're allocating
5064 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5065 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5066 if (AllocType.isNull())
5067 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069 // Transform the size of the array we're allocating (if any).
5070 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5071 if (ArraySize.isInvalid())
5072 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 // Transform the placement arguments (if any).
5075 bool ArgumentChanged = false;
5076 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5077 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5078 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5079 if (Arg.isInvalid())
5080 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5083 PlacementArgs.push_back(Arg.take());
5084 }
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005087 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5088 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5089 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5090 if (Arg.isInvalid())
5091 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregora16548e2009-08-11 05:31:07 +00005093 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5094 ConstructorArgs.push_back(Arg.take());
5095 }
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregord2d9da02010-02-26 00:38:10 +00005097 // Transform constructor, new operator, and delete operator.
5098 CXXConstructorDecl *Constructor = 0;
5099 if (E->getConstructor()) {
5100 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005101 getDerived().TransformDecl(E->getLocStart(),
5102 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005103 if (!Constructor)
5104 return SemaRef.ExprError();
5105 }
5106
5107 FunctionDecl *OperatorNew = 0;
5108 if (E->getOperatorNew()) {
5109 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005110 getDerived().TransformDecl(E->getLocStart(),
5111 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005112 if (!OperatorNew)
5113 return SemaRef.ExprError();
5114 }
5115
5116 FunctionDecl *OperatorDelete = 0;
5117 if (E->getOperatorDelete()) {
5118 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005119 getDerived().TransformDecl(E->getLocStart(),
5120 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005121 if (!OperatorDelete)
5122 return SemaRef.ExprError();
5123 }
5124
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 if (!getDerived().AlwaysRebuild() &&
5126 AllocType == E->getAllocatedType() &&
5127 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005128 Constructor == E->getConstructor() &&
5129 OperatorNew == E->getOperatorNew() &&
5130 OperatorDelete == E->getOperatorDelete() &&
5131 !ArgumentChanged) {
5132 // Mark any declarations we need as referenced.
5133 // FIXME: instantiation-specific.
5134 if (Constructor)
5135 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5136 if (OperatorNew)
5137 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5138 if (OperatorDelete)
5139 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005140 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005141 }
Mike Stump11289f42009-09-09 15:08:12 +00005142
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005143 if (!ArraySize.get()) {
5144 // If no array size was specified, but the new expression was
5145 // instantiated with an array type (e.g., "new T" where T is
5146 // instantiated with "int[4]"), extract the outer bound from the
5147 // array type as our array size. We do this with constant and
5148 // dependently-sized array types.
5149 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5150 if (!ArrayT) {
5151 // Do nothing
5152 } else if (const ConstantArrayType *ConsArrayT
5153 = dyn_cast<ConstantArrayType>(ArrayT)) {
5154 ArraySize
5155 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
5156 ConsArrayT->getSize(),
5157 SemaRef.Context.getSizeType(),
5158 /*FIXME:*/E->getLocStart()));
5159 AllocType = ConsArrayT->getElementType();
5160 } else if (const DependentSizedArrayType *DepArrayT
5161 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5162 if (DepArrayT->getSizeExpr()) {
5163 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5164 AllocType = DepArrayT->getElementType();
5165 }
5166 }
5167 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5169 E->isGlobalNew(),
5170 /*FIXME:*/E->getLocStart(),
5171 move_arg(PlacementArgs),
5172 /*FIXME:*/E->getLocStart(),
5173 E->isParenTypeId(),
5174 AllocType,
5175 /*FIXME:*/E->getLocStart(),
5176 /*FIXME:*/SourceRange(),
5177 move(ArraySize),
5178 /*FIXME:*/E->getLocStart(),
5179 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005180 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005181}
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183template<typename Derived>
5184Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005185TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005186 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5187 if (Operand.isInvalid())
5188 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregord2d9da02010-02-26 00:38:10 +00005190 // Transform the delete operator, if known.
5191 FunctionDecl *OperatorDelete = 0;
5192 if (E->getOperatorDelete()) {
5193 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005194 getDerived().TransformDecl(E->getLocStart(),
5195 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005196 if (!OperatorDelete)
5197 return SemaRef.ExprError();
5198 }
5199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005201 Operand.get() == E->getArgument() &&
5202 OperatorDelete == E->getOperatorDelete()) {
5203 // Mark any declarations we need as referenced.
5204 // FIXME: instantiation-specific.
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 Gregora16548e2009-08-11 05:31:07 +00005210 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5211 E->isGlobalDelete(),
5212 E->isArrayForm(),
5213 move(Operand));
5214}
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregora16548e2009-08-11 05:31:07 +00005216template<typename Derived>
5217Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005218TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005219 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005220 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5221 if (Base.isInvalid())
5222 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregor678f90d2010-02-25 01:56:36 +00005224 Sema::TypeTy *ObjectTypePtr = 0;
5225 bool MayBePseudoDestructor = false;
5226 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5227 E->getOperatorLoc(),
5228 E->isArrow()? tok::arrow : tok::period,
5229 ObjectTypePtr,
5230 MayBePseudoDestructor);
5231 if (Base.isInvalid())
5232 return SemaRef.ExprError();
5233
5234 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005235 NestedNameSpecifier *Qualifier
5236 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005237 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005238 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005239 if (E->getQualifier() && !Qualifier)
5240 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregor678f90d2010-02-25 01:56:36 +00005242 PseudoDestructorTypeStorage Destroyed;
5243 if (E->getDestroyedTypeInfo()) {
5244 TypeSourceInfo *DestroyedTypeInfo
5245 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5246 if (!DestroyedTypeInfo)
5247 return SemaRef.ExprError();
5248 Destroyed = DestroyedTypeInfo;
5249 } else if (ObjectType->isDependentType()) {
5250 // We aren't likely to be able to resolve the identifier down to a type
5251 // now anyway, so just retain the identifier.
5252 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5253 E->getDestroyedTypeLoc());
5254 } else {
5255 // Look for a destructor known with the given name.
5256 CXXScopeSpec SS;
5257 if (Qualifier) {
5258 SS.setScopeRep(Qualifier);
5259 SS.setRange(E->getQualifierRange());
5260 }
5261
5262 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5263 *E->getDestroyedTypeIdentifier(),
5264 E->getDestroyedTypeLoc(),
5265 /*Scope=*/0,
5266 SS, ObjectTypePtr,
5267 false);
5268 if (!T)
5269 return SemaRef.ExprError();
5270
5271 Destroyed
5272 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5273 E->getDestroyedTypeLoc());
5274 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005275
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005276 TypeSourceInfo *ScopeTypeInfo = 0;
5277 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005278 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5279 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005280 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005281 return SemaRef.ExprError();
5282 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005283
Douglas Gregorad8a3362009-09-04 17:36:40 +00005284 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5285 E->getOperatorLoc(),
5286 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005287 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005288 E->getQualifierRange(),
5289 ScopeTypeInfo,
5290 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005291 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005292 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005293}
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregorad8a3362009-09-04 17:36:40 +00005295template<typename Derived>
5296Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005297TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005298 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005299 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5300
5301 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5302 Sema::LookupOrdinaryName);
5303
5304 // Transform all the decls.
5305 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5306 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005307 NamedDecl *InstD = static_cast<NamedDecl*>(
5308 getDerived().TransformDecl(Old->getNameLoc(),
5309 *I));
John McCall84d87672009-12-10 09:41:52 +00005310 if (!InstD) {
5311 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5312 // This can happen because of dependent hiding.
5313 if (isa<UsingShadowDecl>(*I))
5314 continue;
5315 else
5316 return SemaRef.ExprError();
5317 }
John McCalle66edc12009-11-24 19:00:30 +00005318
5319 // Expand using declarations.
5320 if (isa<UsingDecl>(InstD)) {
5321 UsingDecl *UD = cast<UsingDecl>(InstD);
5322 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5323 E = UD->shadow_end(); I != E; ++I)
5324 R.addDecl(*I);
5325 continue;
5326 }
5327
5328 R.addDecl(InstD);
5329 }
5330
5331 // Resolve a kind, but don't do any further analysis. If it's
5332 // ambiguous, the callee needs to deal with it.
5333 R.resolveKind();
5334
5335 // Rebuild the nested-name qualifier, if present.
5336 CXXScopeSpec SS;
5337 NestedNameSpecifier *Qualifier = 0;
5338 if (Old->getQualifier()) {
5339 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005340 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005341 if (!Qualifier)
5342 return SemaRef.ExprError();
5343
5344 SS.setScopeRep(Qualifier);
5345 SS.setRange(Old->getQualifierRange());
5346 }
5347
5348 // If we have no template arguments, it's a normal declaration name.
5349 if (!Old->hasExplicitTemplateArgs())
5350 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5351
5352 // If we have template arguments, rebuild them, then rebuild the
5353 // templateid expression.
5354 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5355 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5356 TemplateArgumentLoc Loc;
5357 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5358 return SemaRef.ExprError();
5359 TransArgs.addArgument(Loc);
5360 }
5361
5362 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5363 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregora16548e2009-08-11 05:31:07 +00005366template<typename Derived>
5367Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005368TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 QualType T = getDerived().TransformType(E->getQueriedType());
5372 if (T.isNull())
5373 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregora16548e2009-08-11 05:31:07 +00005375 if (!getDerived().AlwaysRebuild() &&
5376 T == E->getQueriedType())
5377 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005378
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 // FIXME: Bad location information
5380 SourceLocation FakeLParenLoc
5381 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005382
5383 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005384 E->getLocStart(),
5385 /*FIXME:*/FakeLParenLoc,
5386 T,
5387 E->getLocEnd());
5388}
Mike Stump11289f42009-09-09 15:08:12 +00005389
Douglas Gregora16548e2009-08-11 05:31:07 +00005390template<typename Derived>
5391Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005392TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005393 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005395 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005396 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 if (!NNS)
5398 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005399
5400 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005401 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5402 if (!Name)
5403 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005404
John McCalle66edc12009-11-24 19:00:30 +00005405 if (!E->hasExplicitTemplateArgs()) {
5406 if (!getDerived().AlwaysRebuild() &&
5407 NNS == E->getQualifier() &&
5408 Name == E->getDeclName())
5409 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005410
John McCalle66edc12009-11-24 19:00:30 +00005411 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5412 E->getQualifierRange(),
5413 Name, E->getLocation(),
5414 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005415 }
John McCall6b51f282009-11-23 01:53:49 +00005416
5417 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005418 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005419 TemplateArgumentLoc Loc;
5420 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005421 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005422 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 }
5424
John McCalle66edc12009-11-24 19:00:30 +00005425 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5426 E->getQualifierRange(),
5427 Name, E->getLocation(),
5428 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005429}
5430
5431template<typename Derived>
5432Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005433TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005434 // CXXConstructExprs are always implicit, so when we have a
5435 // 1-argument construction we just transform that argument.
5436 if (E->getNumArgs() == 1 ||
5437 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5438 return getDerived().TransformExpr(E->getArg(0));
5439
Douglas Gregora16548e2009-08-11 05:31:07 +00005440 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5441
5442 QualType T = getDerived().TransformType(E->getType());
5443 if (T.isNull())
5444 return SemaRef.ExprError();
5445
5446 CXXConstructorDecl *Constructor
5447 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005448 getDerived().TransformDecl(E->getLocStart(),
5449 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 if (!Constructor)
5451 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 bool ArgumentChanged = false;
5454 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005455 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005456 ArgEnd = E->arg_end();
5457 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005458 if (getDerived().DropCallArgument(*Arg)) {
5459 ArgumentChanged = true;
5460 break;
5461 }
5462
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5464 if (TransArg.isInvalid())
5465 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005466
Douglas Gregora16548e2009-08-11 05:31:07 +00005467 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5468 Args.push_back(TransArg.takeAs<Expr>());
5469 }
5470
5471 if (!getDerived().AlwaysRebuild() &&
5472 T == E->getType() &&
5473 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005474 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005475 // Mark the constructor as referenced.
5476 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005477 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005478 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005479 }
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregordb121ba2009-12-14 16:27:04 +00005481 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5482 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005483 move_arg(Args));
5484}
Mike Stump11289f42009-09-09 15:08:12 +00005485
Douglas Gregora16548e2009-08-11 05:31:07 +00005486/// \brief Transform a C++ temporary-binding expression.
5487///
Douglas Gregor363b1512009-12-24 18:51:59 +00005488/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5489/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005490template<typename Derived>
5491Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005492TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005493 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005494}
Mike Stump11289f42009-09-09 15:08:12 +00005495
Anders Carlssonba6c4372010-01-29 02:39:32 +00005496/// \brief Transform a C++ reference-binding expression.
5497///
5498/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5499/// transform the subexpression and return that.
5500template<typename Derived>
5501Sema::OwningExprResult
5502TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5503 return getDerived().TransformExpr(E->getSubExpr());
5504}
5505
Mike Stump11289f42009-09-09 15:08:12 +00005506/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005507/// be destroyed after the expression is evaluated.
5508///
Douglas Gregor363b1512009-12-24 18:51:59 +00005509/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5510/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005511template<typename Derived>
5512Sema::OwningExprResult
5513TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005514 CXXExprWithTemporaries *E) {
5515 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005516}
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518template<typename Derived>
5519Sema::OwningExprResult
5520TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005521 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5523 QualType T = getDerived().TransformType(E->getType());
5524 if (T.isNull())
5525 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 CXXConstructorDecl *Constructor
5528 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005529 getDerived().TransformDecl(E->getLocStart(),
5530 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 if (!Constructor)
5532 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005533
Douglas Gregora16548e2009-08-11 05:31:07 +00005534 bool ArgumentChanged = false;
5535 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5536 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005537 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 ArgEnd = E->arg_end();
5539 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005540 if (getDerived().DropCallArgument(*Arg)) {
5541 ArgumentChanged = true;
5542 break;
5543 }
5544
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5546 if (TransArg.isInvalid())
5547 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5550 Args.push_back((Expr *)TransArg.release());
5551 }
Mike Stump11289f42009-09-09 15:08:12 +00005552
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 if (!getDerived().AlwaysRebuild() &&
5554 T == E->getType() &&
5555 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005556 !ArgumentChanged) {
5557 // FIXME: Instantiation-specific
5558 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005559 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005560 }
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 // FIXME: Bogus location information
5563 SourceLocation CommaLoc;
5564 if (Args.size() > 1) {
5565 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005566 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005567 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5568 }
5569 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5570 T,
5571 /*FIXME:*/E->getTypeBeginLoc(),
5572 move_arg(Args),
5573 &CommaLoc,
5574 E->getLocEnd());
5575}
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregora16548e2009-08-11 05:31:07 +00005577template<typename Derived>
5578Sema::OwningExprResult
5579TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005580 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5582 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5583 if (T.isNull())
5584 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregora16548e2009-08-11 05:31:07 +00005586 bool ArgumentChanged = false;
5587 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5588 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5589 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5590 ArgEnd = E->arg_end();
5591 Arg != ArgEnd; ++Arg) {
5592 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5593 if (TransArg.isInvalid())
5594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregora16548e2009-08-11 05:31:07 +00005596 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5597 FakeCommaLocs.push_back(
5598 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5599 Args.push_back(TransArg.takeAs<Expr>());
5600 }
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 if (!getDerived().AlwaysRebuild() &&
5603 T == E->getTypeAsWritten() &&
5604 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005605 return SemaRef.Owned(E->Retain());
5606
Douglas Gregora16548e2009-08-11 05:31:07 +00005607 // FIXME: we're faking the locations of the commas
5608 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5609 T,
5610 E->getLParenLoc(),
5611 move_arg(Args),
5612 FakeCommaLocs.data(),
5613 E->getRParenLoc());
5614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
5617Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005618TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005619 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005621 OwningExprResult Base(SemaRef, (Expr*) 0);
5622 Expr *OldBase;
5623 QualType BaseType;
5624 QualType ObjectType;
5625 if (!E->isImplicitAccess()) {
5626 OldBase = E->getBase();
5627 Base = getDerived().TransformExpr(OldBase);
5628 if (Base.isInvalid())
5629 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005630
John McCall2d74de92009-12-01 22:10:20 +00005631 // Start the member reference and compute the object's type.
5632 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005633 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005634 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5635 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005636 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005637 ObjectTy,
5638 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005639 if (Base.isInvalid())
5640 return SemaRef.ExprError();
5641
5642 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5643 BaseType = ((Expr*) Base.get())->getType();
5644 } else {
5645 OldBase = 0;
5646 BaseType = getDerived().TransformType(E->getBaseType());
5647 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5648 }
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005650 // Transform the first part of the nested-name-specifier that qualifies
5651 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005652 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005653 = getDerived().TransformFirstQualifierInScope(
5654 E->getFirstQualifierFoundInScope(),
5655 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005657 NestedNameSpecifier *Qualifier = 0;
5658 if (E->getQualifier()) {
5659 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5660 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005661 ObjectType,
5662 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005663 if (!Qualifier)
5664 return SemaRef.ExprError();
5665 }
Mike Stump11289f42009-09-09 15:08:12 +00005666
5667 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005668 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005669 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005670 if (!Name)
5671 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005672
John McCall2d74de92009-12-01 22:10:20 +00005673 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005674 // This is a reference to a member without an explicitly-specified
5675 // template argument list. Optimize for this common case.
5676 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005677 Base.get() == OldBase &&
5678 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005679 Qualifier == E->getQualifier() &&
5680 Name == E->getMember() &&
5681 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005682 return SemaRef.Owned(E->Retain());
5683
John McCall8cd78132009-11-19 22:55:06 +00005684 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005685 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005686 E->isArrow(),
5687 E->getOperatorLoc(),
5688 Qualifier,
5689 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005690 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005691 Name,
5692 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005693 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005694 }
5695
John McCall6b51f282009-11-23 01:53:49 +00005696 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005697 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005698 TemplateArgumentLoc Loc;
5699 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005700 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005701 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005702 }
Mike Stump11289f42009-09-09 15:08:12 +00005703
John McCall8cd78132009-11-19 22:55:06 +00005704 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005705 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 E->isArrow(),
5707 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005708 Qualifier,
5709 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005710 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005711 Name,
5712 E->getMemberLoc(),
5713 &TransArgs);
5714}
5715
5716template<typename Derived>
5717Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005719 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005720 OwningExprResult Base(SemaRef, (Expr*) 0);
5721 QualType BaseType;
5722 if (!Old->isImplicitAccess()) {
5723 Base = getDerived().TransformExpr(Old->getBase());
5724 if (Base.isInvalid())
5725 return SemaRef.ExprError();
5726 BaseType = ((Expr*) Base.get())->getType();
5727 } else {
5728 BaseType = getDerived().TransformType(Old->getBaseType());
5729 }
John McCall10eae182009-11-30 22:42:35 +00005730
5731 NestedNameSpecifier *Qualifier = 0;
5732 if (Old->getQualifier()) {
5733 Qualifier
5734 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005735 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005736 if (Qualifier == 0)
5737 return SemaRef.ExprError();
5738 }
5739
5740 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5741 Sema::LookupOrdinaryName);
5742
5743 // Transform all the decls.
5744 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5745 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005746 NamedDecl *InstD = static_cast<NamedDecl*>(
5747 getDerived().TransformDecl(Old->getMemberLoc(),
5748 *I));
John McCall84d87672009-12-10 09:41:52 +00005749 if (!InstD) {
5750 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5751 // This can happen because of dependent hiding.
5752 if (isa<UsingShadowDecl>(*I))
5753 continue;
5754 else
5755 return SemaRef.ExprError();
5756 }
John McCall10eae182009-11-30 22:42:35 +00005757
5758 // Expand using declarations.
5759 if (isa<UsingDecl>(InstD)) {
5760 UsingDecl *UD = cast<UsingDecl>(InstD);
5761 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5762 E = UD->shadow_end(); I != E; ++I)
5763 R.addDecl(*I);
5764 continue;
5765 }
5766
5767 R.addDecl(InstD);
5768 }
5769
5770 R.resolveKind();
5771
5772 TemplateArgumentListInfo TransArgs;
5773 if (Old->hasExplicitTemplateArgs()) {
5774 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5775 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5776 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5777 TemplateArgumentLoc Loc;
5778 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5779 Loc))
5780 return SemaRef.ExprError();
5781 TransArgs.addArgument(Loc);
5782 }
5783 }
John McCall38836f02010-01-15 08:34:02 +00005784
5785 // FIXME: to do this check properly, we will need to preserve the
5786 // first-qualifier-in-scope here, just in case we had a dependent
5787 // base (and therefore couldn't do the check) and a
5788 // nested-name-qualifier (and therefore could do the lookup).
5789 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005790
5791 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005792 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005793 Old->getOperatorLoc(),
5794 Old->isArrow(),
5795 Qualifier,
5796 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005797 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005798 R,
5799 (Old->hasExplicitTemplateArgs()
5800 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005801}
5802
5803template<typename Derived>
5804Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005806 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005807}
5808
Mike Stump11289f42009-09-09 15:08:12 +00005809template<typename Derived>
5810Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005811TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005812 TypeSourceInfo *EncodedTypeInfo
5813 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5814 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005818 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005819 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005820
5821 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005822 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 E->getRParenLoc());
5824}
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826template<typename Derived>
5827Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005828TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005829 // Transform arguments.
5830 bool ArgChanged = false;
5831 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5832 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5833 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5834 if (Arg.isInvalid())
5835 return SemaRef.ExprError();
5836
5837 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5838 Args.push_back(Arg.takeAs<Expr>());
5839 }
5840
5841 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5842 // Class message: transform the receiver type.
5843 TypeSourceInfo *ReceiverTypeInfo
5844 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5845 if (!ReceiverTypeInfo)
5846 return SemaRef.ExprError();
5847
5848 // If nothing changed, just retain the existing message send.
5849 if (!getDerived().AlwaysRebuild() &&
5850 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5851 return SemaRef.Owned(E->Retain());
5852
5853 // Build a new class message send.
5854 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5855 E->getSelector(),
5856 E->getMethodDecl(),
5857 E->getLeftLoc(),
5858 move_arg(Args),
5859 E->getRightLoc());
5860 }
5861
5862 // Instance message: transform the receiver
5863 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5864 "Only class and instance messages may be instantiated");
5865 OwningExprResult Receiver
5866 = getDerived().TransformExpr(E->getInstanceReceiver());
5867 if (Receiver.isInvalid())
5868 return SemaRef.ExprError();
5869
5870 // If nothing changed, just retain the existing message send.
5871 if (!getDerived().AlwaysRebuild() &&
5872 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5873 return SemaRef.Owned(E->Retain());
5874
5875 // Build a new instance message send.
5876 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5877 E->getSelector(),
5878 E->getMethodDecl(),
5879 E->getLeftLoc(),
5880 move_arg(Args),
5881 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005882}
5883
Mike Stump11289f42009-09-09 15:08:12 +00005884template<typename Derived>
5885Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005886TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005887 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005888}
5889
Mike Stump11289f42009-09-09 15:08:12 +00005890template<typename Derived>
5891Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005892TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005893 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005894}
5895
Mike Stump11289f42009-09-09 15:08:12 +00005896template<typename Derived>
5897Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005898TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005899 // Transform the base expression.
5900 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5901 if (Base.isInvalid())
5902 return SemaRef.ExprError();
5903
5904 // We don't need to transform the ivar; it will never change.
5905
5906 // If nothing changed, just retain the existing expression.
5907 if (!getDerived().AlwaysRebuild() &&
5908 Base.get() == E->getBase())
5909 return SemaRef.Owned(E->Retain());
5910
5911 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
5912 E->getLocation(),
5913 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00005914}
5915
Mike Stump11289f42009-09-09 15:08:12 +00005916template<typename Derived>
5917Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005918TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00005919 // Transform the base expression.
5920 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5921 if (Base.isInvalid())
5922 return SemaRef.ExprError();
5923
5924 // We don't need to transform the property; it will never change.
5925
5926 // If nothing changed, just retain the existing expression.
5927 if (!getDerived().AlwaysRebuild() &&
5928 Base.get() == E->getBase())
5929 return SemaRef.Owned(E->Retain());
5930
5931 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
5932 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00005933}
5934
Mike Stump11289f42009-09-09 15:08:12 +00005935template<typename Derived>
5936Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005937TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005938 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00005939 // If this implicit setter/getter refers to class methods, it cannot have any
5940 // dependent parts. Just retain the existing declaration.
5941 if (E->getInterfaceDecl())
5942 return SemaRef.Owned(E->Retain());
5943
5944 // Transform the base expression.
5945 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5946 if (Base.isInvalid())
5947 return SemaRef.ExprError();
5948
5949 // We don't need to transform the getters/setters; they will never change.
5950
5951 // If nothing changed, just retain the existing expression.
5952 if (!getDerived().AlwaysRebuild() &&
5953 Base.get() == E->getBase())
5954 return SemaRef.Owned(E->Retain());
5955
5956 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
5957 E->getGetterMethod(),
5958 E->getType(),
5959 E->getSetterMethod(),
5960 E->getLocation(),
5961 move(Base));
5962
Douglas Gregora16548e2009-08-11 05:31:07 +00005963}
5964
Mike Stump11289f42009-09-09 15:08:12 +00005965template<typename Derived>
5966Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005967TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005968 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005969 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005970}
5971
Mike Stump11289f42009-09-09 15:08:12 +00005972template<typename Derived>
5973Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005974TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005975 // Transform the base expression.
5976 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5977 if (Base.isInvalid())
5978 return SemaRef.ExprError();
5979
5980 // If nothing changed, just retain the existing expression.
5981 if (!getDerived().AlwaysRebuild() &&
5982 Base.get() == E->getBase())
5983 return SemaRef.Owned(E->Retain());
5984
5985 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
5986 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00005987}
5988
Mike Stump11289f42009-09-09 15:08:12 +00005989template<typename Derived>
5990Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005991TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005992 bool ArgumentChanged = false;
5993 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5994 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5995 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5996 if (SubExpr.isInvalid())
5997 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005998
Douglas Gregora16548e2009-08-11 05:31:07 +00005999 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6000 SubExprs.push_back(SubExpr.takeAs<Expr>());
6001 }
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregora16548e2009-08-11 05:31:07 +00006003 if (!getDerived().AlwaysRebuild() &&
6004 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006005 return SemaRef.Owned(E->Retain());
6006
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6008 move_arg(SubExprs),
6009 E->getRParenLoc());
6010}
6011
Mike Stump11289f42009-09-09 15:08:12 +00006012template<typename Derived>
6013Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006015 // FIXME: Implement this!
6016 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006017 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006018}
6019
Mike Stump11289f42009-09-09 15:08:12 +00006020template<typename Derived>
6021Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006022TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 // FIXME: Implement this!
6024 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006025 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006026}
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006029// Type reconstruction
6030//===----------------------------------------------------------------------===//
6031
Mike Stump11289f42009-09-09 15:08:12 +00006032template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006033QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6034 SourceLocation Star) {
6035 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006036 getDerived().getBaseEntity());
6037}
6038
Mike Stump11289f42009-09-09 15:08:12 +00006039template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006040QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6041 SourceLocation Star) {
6042 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006043 getDerived().getBaseEntity());
6044}
6045
Mike Stump11289f42009-09-09 15:08:12 +00006046template<typename Derived>
6047QualType
John McCall70dd5f62009-10-30 00:06:24 +00006048TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6049 bool WrittenAsLValue,
6050 SourceLocation Sigil) {
6051 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6052 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006053}
6054
6055template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006056QualType
John McCall70dd5f62009-10-30 00:06:24 +00006057TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6058 QualType ClassType,
6059 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006060 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006061 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006062}
6063
6064template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006065QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006066TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6067 ArrayType::ArraySizeModifier SizeMod,
6068 const llvm::APInt *Size,
6069 Expr *SizeExpr,
6070 unsigned IndexTypeQuals,
6071 SourceRange BracketsRange) {
6072 if (SizeExpr || !Size)
6073 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6074 IndexTypeQuals, BracketsRange,
6075 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006076
6077 QualType Types[] = {
6078 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6079 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6080 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006081 };
6082 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6083 QualType SizeType;
6084 for (unsigned I = 0; I != NumTypes; ++I)
6085 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6086 SizeType = Types[I];
6087 break;
6088 }
Mike Stump11289f42009-09-09 15:08:12 +00006089
Douglas Gregord6ff3322009-08-04 16:50:30 +00006090 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006091 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006092 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006093 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006094}
Mike Stump11289f42009-09-09 15:08:12 +00006095
Douglas Gregord6ff3322009-08-04 16:50:30 +00006096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006097QualType
6098TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006099 ArrayType::ArraySizeModifier SizeMod,
6100 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006101 unsigned IndexTypeQuals,
6102 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006103 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006104 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006105}
6106
6107template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006108QualType
Mike Stump11289f42009-09-09 15:08:12 +00006109TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006110 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006111 unsigned IndexTypeQuals,
6112 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006113 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006114 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006115}
Mike Stump11289f42009-09-09 15:08:12 +00006116
Douglas Gregord6ff3322009-08-04 16:50:30 +00006117template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006118QualType
6119TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006120 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006121 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006122 unsigned IndexTypeQuals,
6123 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006124 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006125 SizeExpr.takeAs<Expr>(),
6126 IndexTypeQuals, BracketsRange);
6127}
6128
6129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006130QualType
6131TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006132 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006133 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006134 unsigned IndexTypeQuals,
6135 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006136 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006137 SizeExpr.takeAs<Expr>(),
6138 IndexTypeQuals, BracketsRange);
6139}
6140
6141template<typename Derived>
6142QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006143 unsigned NumElements,
6144 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006145 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006146 return SemaRef.Context.getVectorType(ElementType, NumElements,
6147 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006148}
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregord6ff3322009-08-04 16:50:30 +00006150template<typename Derived>
6151QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6152 unsigned NumElements,
6153 SourceLocation AttributeLoc) {
6154 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6155 NumElements, true);
6156 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006157 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006158 AttributeLoc);
6159 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6160 AttributeLoc);
6161}
Mike Stump11289f42009-09-09 15:08:12 +00006162
Douglas Gregord6ff3322009-08-04 16:50:30 +00006163template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006164QualType
6165TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006167 SourceLocation AttributeLoc) {
6168 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6169}
Mike Stump11289f42009-09-09 15:08:12 +00006170
Douglas Gregord6ff3322009-08-04 16:50:30 +00006171template<typename Derived>
6172QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006173 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006174 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006175 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006176 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006177 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006178 Quals,
6179 getDerived().getBaseLocation(),
6180 getDerived().getBaseEntity());
6181}
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregord6ff3322009-08-04 16:50:30 +00006183template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006184QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6185 return SemaRef.Context.getFunctionNoProtoType(T);
6186}
6187
6188template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006189QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6190 assert(D && "no decl found");
6191 if (D->isInvalidDecl()) return QualType();
6192
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006193 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006194 TypeDecl *Ty;
6195 if (isa<UsingDecl>(D)) {
6196 UsingDecl *Using = cast<UsingDecl>(D);
6197 assert(Using->isTypeName() &&
6198 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6199
6200 // A valid resolved using typename decl points to exactly one type decl.
6201 assert(++Using->shadow_begin() == Using->shadow_end());
6202 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6203
6204 } else {
6205 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6206 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6207 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6208 }
6209
6210 return SemaRef.Context.getTypeDeclType(Ty);
6211}
6212
6213template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006214QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006215 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6216}
6217
6218template<typename Derived>
6219QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6220 return SemaRef.Context.getTypeOfType(Underlying);
6221}
6222
6223template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006224QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006225 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6226}
6227
6228template<typename Derived>
6229QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006230 TemplateName Template,
6231 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006232 const TemplateArgumentListInfo &TemplateArgs) {
6233 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006234}
Mike Stump11289f42009-09-09 15:08:12 +00006235
Douglas Gregor1135c352009-08-06 05:28:30 +00006236template<typename Derived>
6237NestedNameSpecifier *
6238TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6239 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006240 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006241 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006242 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006243 CXXScopeSpec SS;
6244 // FIXME: The source location information is all wrong.
6245 SS.setRange(Range);
6246 SS.setScopeRep(Prefix);
6247 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006248 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006249 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006250 ObjectType,
6251 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006252 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006253}
6254
6255template<typename Derived>
6256NestedNameSpecifier *
6257TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6258 SourceRange Range,
6259 NamespaceDecl *NS) {
6260 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6261}
6262
6263template<typename Derived>
6264NestedNameSpecifier *
6265TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6266 SourceRange Range,
6267 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006268 QualType T) {
6269 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006270 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006271 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006272 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6273 T.getTypePtr());
6274 }
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregor1135c352009-08-06 05:28:30 +00006276 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6277 return 0;
6278}
Mike Stump11289f42009-09-09 15:08:12 +00006279
Douglas Gregor71dc5092009-08-06 06:41:21 +00006280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006281TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006282TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6283 bool TemplateKW,
6284 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006285 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006286 Template);
6287}
6288
6289template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006290TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006291TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006292 const IdentifierInfo &II,
6293 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006294 CXXScopeSpec SS;
6295 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006296 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006297 UnqualifiedId Name;
6298 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006299 return getSema().ActOnDependentTemplateName(
6300 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006301 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006302 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006303 ObjectType.getAsOpaquePtr(),
6304 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006305 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006306}
Mike Stump11289f42009-09-09 15:08:12 +00006307
Douglas Gregora16548e2009-08-11 05:31:07 +00006308template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006309TemplateName
6310TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6311 OverloadedOperatorKind Operator,
6312 QualType ObjectType) {
6313 CXXScopeSpec SS;
6314 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6315 SS.setScopeRep(Qualifier);
6316 UnqualifiedId Name;
6317 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6318 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6319 Operator, SymbolLocations);
6320 return getSema().ActOnDependentTemplateName(
6321 /*FIXME:*/getDerived().getBaseLocation(),
6322 SS,
6323 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006324 ObjectType.getAsOpaquePtr(),
6325 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006326 .template getAsVal<TemplateName>();
6327}
6328
6329template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006330Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006331TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6332 SourceLocation OpLoc,
6333 ExprArg Callee,
6334 ExprArg First,
6335 ExprArg Second) {
6336 Expr *FirstExpr = (Expr *)First.get();
6337 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006338 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006342 if (Op == OO_Subscript) {
6343 if (!FirstExpr->getType()->isOverloadableType() &&
6344 !SecondExpr->getType()->isOverloadableType())
6345 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006346 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006347 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006348 } else if (Op == OO_Arrow) {
6349 // -> is never a builtin operation.
6350 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006351 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006352 if (!FirstExpr->getType()->isOverloadableType()) {
6353 // The argument is not of overloadable type, so try to create a
6354 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006355 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006356 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6359 }
6360 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006361 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006362 !SecondExpr->getType()->isOverloadableType()) {
6363 // Neither of the arguments is an overloadable type, so try to
6364 // create a built-in binary operation.
6365 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006366 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006367 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6368 if (Result.isInvalid())
6369 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006370
Douglas Gregora16548e2009-08-11 05:31:07 +00006371 First.release();
6372 Second.release();
6373 return move(Result);
6374 }
6375 }
Mike Stump11289f42009-09-09 15:08:12 +00006376
6377 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006378 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006379 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006380
John McCalld14a8642009-11-21 08:51:07 +00006381 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6382 assert(ULE->requiresADL());
6383
6384 // FIXME: Do we have to check
6385 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006386 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006387 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006388 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006389 }
Mike Stump11289f42009-09-09 15:08:12 +00006390
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 // Add any functions found via argument-dependent lookup.
6392 Expr *Args[2] = { FirstExpr, SecondExpr };
6393 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006394
Douglas Gregora16548e2009-08-11 05:31:07 +00006395 // Create the overloaded operator invocation for unary operators.
6396 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006397 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006398 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6399 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6400 }
Mike Stump11289f42009-09-09 15:08:12 +00006401
Sebastian Redladba46e2009-10-29 20:17:01 +00006402 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006403 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6404 OpLoc,
6405 move(First),
6406 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006407
Douglas Gregora16548e2009-08-11 05:31:07 +00006408 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006409 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006410 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006411 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006412 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6413 if (Result.isInvalid())
6414 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregora16548e2009-08-11 05:31:07 +00006416 First.release();
6417 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006418 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006419}
Mike Stump11289f42009-09-09 15:08:12 +00006420
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006421template<typename Derived>
6422Sema::OwningExprResult
6423TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6424 SourceLocation OperatorLoc,
6425 bool isArrow,
6426 NestedNameSpecifier *Qualifier,
6427 SourceRange QualifierRange,
6428 TypeSourceInfo *ScopeType,
6429 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006430 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006431 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006432 CXXScopeSpec SS;
6433 if (Qualifier) {
6434 SS.setRange(QualifierRange);
6435 SS.setScopeRep(Qualifier);
6436 }
6437
6438 Expr *BaseE = (Expr *)Base.get();
6439 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006440 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006441 (!isArrow && !BaseType->getAs<RecordType>()) ||
6442 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006443 !BaseType->getAs<PointerType>()->getPointeeType()
6444 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006445 // This pseudo-destructor expression is still a pseudo-destructor.
6446 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6447 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006448 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006449 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006450 /*FIXME?*/true);
6451 }
6452
Douglas Gregor678f90d2010-02-25 01:56:36 +00006453 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006454 DeclarationName Name
6455 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6456 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6457
6458 // FIXME: the ScopeType should be tacked onto SS.
6459
6460 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6461 OperatorLoc, isArrow,
6462 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006463 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006464 /*TemplateArgs*/ 0);
6465}
6466
Douglas Gregord6ff3322009-08-04 16:50:30 +00006467} // end namespace clang
6468
6469#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H