blob: 1ad76792a062cd31a35c3b0b02cbd72bbca188b0 [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
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000016#include "clang/Sema/Sema.h"
17#include "clang/Sema/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"
John McCall8b0666c2010-08-20 18:27:03 +000027#include "clang/Sema/Ownership.h"
28#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000029#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;
Alexis Hunta8136cc2010-05-05 15:23:54 +000099
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 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000184
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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000205 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 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000212 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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
247 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 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000253 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000254 /// 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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000262
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.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000279 DeclarationNameInfo
280 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
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
Alexis Hunta8136cc2010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Alexis Hunta8136cc2010-05-05 15:23:54 +0000336 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000337 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);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
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,
Chris Lattner37141f42010-06-23 06:00:24 +0000445 VectorType::AltiVecSpecific AltiVecSpec);
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,
Eli Friedmand8725a92010-08-05 02:54:05 +0000471 bool Variadic, unsigned Quals,
472 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000473
John McCall550e0c22009-10-21 00:40:46 +0000474 /// \brief Build a new unprototyped function type.
475 QualType RebuildFunctionNoProtoType(QualType ResultType);
476
John McCallb96ec562009-12-04 22:46:56 +0000477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType RebuildUnresolvedUsingType(Decl *D);
480
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481 /// \brief Build a new typedef type.
482 QualType RebuildTypedefType(TypedefDecl *Typedef) {
483 return SemaRef.Context.getTypeDeclType(Typedef);
484 }
485
486 /// \brief Build a new class/struct/union type.
487 QualType RebuildRecordType(RecordDecl *Record) {
488 return SemaRef.Context.getTypeDeclType(Record);
489 }
490
491 /// \brief Build a new Enum type.
492 QualType RebuildEnumType(EnumDecl *Enum) {
493 return SemaRef.Context.getTypeDeclType(Enum);
494 }
John McCallfcc33b02009-09-05 00:15:47 +0000495
Mike Stump11289f42009-09-09 15:08:12 +0000496 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 ///
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000500 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501
Mike Stump11289f42009-09-09 15:08:12 +0000502 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 ///
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType RebuildTypeOfType(QualType Underlying);
506
Mike Stump11289f42009-09-09 15:08:12 +0000507 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 ///
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000511 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new template specialization type.
514 ///
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000519 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000520 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Build a new qualified name type.
523 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000524 /// By default, builds a new ElaboratedType type from the keyword,
525 /// the nested-name-specifier and the named type.
526 /// Subclasses may override this routine to provide different behavior.
527 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
528 NestedNameSpecifier *NNS, QualType Named) {
529 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000530 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531
532 /// \brief Build a new typename type that refers to a template-id.
533 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000534 /// By default, builds a new DependentNameType type from the
535 /// nested-name-specifier and the given type. Subclasses may override
536 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000537 QualType RebuildDependentTemplateSpecializationType(
538 ElaboratedTypeKeyword Keyword,
539 NestedNameSpecifier *NNS,
540 const IdentifierInfo *Name,
541 SourceLocation NameLoc,
542 const TemplateArgumentListInfo &Args) {
543 // Rebuild the template name.
544 // TODO: avoid TemplateName abstraction
545 TemplateName InstName =
546 getDerived().RebuildTemplateName(NNS, *Name, QualType());
547
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCallc392f372010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
554 Keyword, NNS, Name, Args);
555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000561
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000564 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara6150c882010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarad7548482010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCallbf8c5192010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregore677daf2010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000610
Douglas Gregore677daf2010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000619
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000631
Abramo Bagnarad7548482010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 }
Mike Stump11289f42009-09-09 15:08:12 +0000642
Douglas Gregor1135c352009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregor71dc5092009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000694 const IdentifierInfo &II,
695 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000696
Douglas Gregor71395fa2009-11-04 00:56:37 +0000697 /// \brief Build a new template name given a nested name specifier and the
698 /// overloaded operator name that is referred to as a template.
699 ///
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
703 /// behavior.
704 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
705 OverloadedOperatorKind Operator,
706 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000707
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 /// \brief Build a new compound statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
713 MultiStmtArg Statements,
714 SourceLocation RBraceLoc,
715 bool IsStmtExpr) {
716 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
717 IsStmtExpr);
718 }
719
720 /// \brief Build a new case statement.
721 ///
722 /// By default, performs semantic analysis to build the new statement.
723 /// Subclasses may override this routine to provide different behavior.
724 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
725 ExprArg LHS,
726 SourceLocation EllipsisLoc,
727 ExprArg RHS,
728 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000729 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 ColonLoc);
731 }
Mike Stump11289f42009-09-09 15:08:12 +0000732
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 /// \brief Attach the body to a new case statement.
734 ///
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
737 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
738 getSema().ActOnCaseStmtBody(S.get(), move(Body));
739 return move(S);
740 }
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 /// \brief Build a new default statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000746 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 SourceLocation ColonLoc,
748 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000749 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000750 /*CurScope=*/0);
751 }
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 /// \brief Build a new label statement.
754 ///
755 /// By default, performs semantic analysis to build the new statement.
756 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000757 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 IdentifierInfo *Id,
759 SourceLocation ColonLoc,
760 StmtArg SubStmt) {
761 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
762 }
Mike Stump11289f42009-09-09 15:08:12 +0000763
Douglas Gregorebe10102009-08-20 07:17:43 +0000764 /// \brief Build a new "if" statement.
765 ///
766 /// By default, performs semantic analysis to build the new statement.
767 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000768 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000769 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000770 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000771 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000772 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 }
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000779 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
780 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000781 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000782 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
783 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 /// \brief Attach the body to the switch statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000790 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000791 StmtArg Switch, StmtArg Body) {
792 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
793 move(Body));
794 }
795
796 /// \brief Build a new while statement.
797 ///
798 /// By default, performs semantic analysis to build the new statement.
799 /// Subclasses may override this routine to provide different behavior.
800 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000801 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000802 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000804 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000805 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000806 }
Mike Stump11289f42009-09-09 15:08:12 +0000807
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 /// \brief Build a new do-while statement.
809 ///
810 /// By default, performs semantic analysis to build the new statement.
811 /// Subclasses may override this routine to provide different behavior.
812 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
813 SourceLocation WhileLoc,
814 SourceLocation LParenLoc,
815 ExprArg Cond,
816 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000817 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 move(Cond), RParenLoc);
819 }
820
821 /// \brief Build a new for statement.
822 ///
823 /// By default, performs semantic analysis to build the new statement.
824 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000825 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000827 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000828 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000830 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000831 DeclPtrTy::make(CondVar),
832 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 }
Mike Stump11289f42009-09-09 15:08:12 +0000834
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 /// \brief Build a new goto statement.
836 ///
837 /// By default, performs semantic analysis to build the new statement.
838 /// Subclasses may override this routine to provide different behavior.
839 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
840 SourceLocation LabelLoc,
841 LabelStmt *Label) {
842 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
843 }
844
845 /// \brief Build a new indirect goto statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
849 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
850 SourceLocation StarLoc,
851 ExprArg Target) {
852 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
853 }
Mike Stump11289f42009-09-09 15:08:12 +0000854
Douglas Gregorebe10102009-08-20 07:17:43 +0000855 /// \brief Build a new return statement.
856 ///
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
859 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
860 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000861
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
863 }
Mike Stump11289f42009-09-09 15:08:12 +0000864
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 /// \brief Build a new declaration statement.
866 ///
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
869 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000870 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000871 SourceLocation EndLoc) {
872 return getSema().Owned(
873 new (getSema().Context) DeclStmt(
874 DeclGroupRef::Create(getSema().Context,
875 Decls, NumDecls),
876 StartLoc, EndLoc));
877 }
Mike Stump11289f42009-09-09 15:08:12 +0000878
Anders Carlssonaaeef072010-01-24 05:50:09 +0000879 /// \brief Build a new inline asm statement.
880 ///
881 /// By default, performs semantic analysis to build the new statement.
882 /// Subclasses may override this routine to provide different behavior.
883 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
884 bool IsSimple,
885 bool IsVolatile,
886 unsigned NumOutputs,
887 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000888 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000889 MultiExprArg Constraints,
890 MultiExprArg Exprs,
891 ExprArg AsmString,
892 MultiExprArg Clobbers,
893 SourceLocation RParenLoc,
894 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000895 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000896 NumInputs, Names, move(Constraints),
897 move(Exprs), move(AsmString), move(Clobbers),
898 RParenLoc, MSAsm);
899 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000900
901 /// \brief Build a new Objective-C @try statement.
902 ///
903 /// By default, performs semantic analysis to build the new statement.
904 /// Subclasses may override this routine to provide different behavior.
905 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
906 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000907 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000908 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000909 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000910 move(Finally));
911 }
912
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000913 /// \brief Rebuild an Objective-C exception declaration.
914 ///
915 /// By default, performs semantic analysis to build the new declaration.
916 /// Subclasses may override this routine to provide different behavior.
917 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
918 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000919 return getSema().BuildObjCExceptionDecl(TInfo, T,
920 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000921 ExceptionDecl->getLocation());
922 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000923
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000924 /// \brief Build a new Objective-C @catch statement.
925 ///
926 /// By default, performs semantic analysis to build the new statement.
927 /// Subclasses may override this routine to provide different behavior.
928 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
929 SourceLocation RParenLoc,
930 VarDecl *Var,
931 StmtArg Body) {
932 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
933 Sema::DeclPtrTy::make(Var),
934 move(Body));
935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000936
Douglas Gregor306de2f2010-04-22 23:59:56 +0000937 /// \brief Build a new Objective-C @finally statement.
938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
942 StmtArg Body) {
943 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
944 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000945
Douglas Gregor6148de72010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000947 ///
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
951 ExprArg Operand) {
952 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000954
Douglas Gregor6148de72010-04-22 22:01:21 +0000955 /// \brief Build a new Objective-C @synchronized statement.
956 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
959 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
960 ExprArg Object,
961 StmtArg Body) {
962 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
963 move(Body));
964 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000965
966 /// \brief Build a new Objective-C fast enumeration statement.
967 ///
968 /// By default, performs semantic analysis to build the new statement.
969 /// Subclasses may override this routine to provide different behavior.
970 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
971 SourceLocation LParenLoc,
972 StmtArg Element,
973 ExprArg Collection,
974 SourceLocation RParenLoc,
975 StmtArg Body) {
976 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000977 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000978 move(Collection),
979 RParenLoc,
980 move(Body));
981 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000982
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /// \brief Build a new C++ exception declaration.
984 ///
985 /// By default, performs semantic analysis to build the new decaration.
986 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000987 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000988 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 IdentifierInfo *Name,
990 SourceLocation Loc,
991 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000992 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 TypeRange);
994 }
995
996 /// \brief Build a new C++ catch statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
1000 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1001 VarDecl *ExceptionDecl,
1002 StmtArg Handler) {
1003 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +00001004 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +00001005 Handler.takeAs<Stmt>()));
1006 }
Mike Stump11289f42009-09-09 15:08:12 +00001007
Douglas Gregorebe10102009-08-20 07:17:43 +00001008 /// \brief Build a new C++ try statement.
1009 ///
1010 /// By default, performs semantic analysis to build the new statement.
1011 /// Subclasses may override this routine to provide different behavior.
1012 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1013 StmtArg TryBlock,
1014 MultiStmtArg Handlers) {
1015 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1016 }
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 /// \brief Build a new expression that references a declaration.
1019 ///
1020 /// By default, performs semantic analysis to build the new expression.
1021 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001022 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1023 LookupResult &R,
1024 bool RequiresADL) {
1025 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1026 }
1027
1028
1029 /// \brief Build a new expression that references a declaration.
1030 ///
1031 /// By default, performs semantic analysis to build the new expression.
1032 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001033 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1034 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001035 ValueDecl *VD,
1036 const DeclarationNameInfo &NameInfo,
John McCallce546572009-12-08 09:08:17 +00001037 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001038 CXXScopeSpec SS;
1039 SS.setScopeRep(Qualifier);
1040 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001041
1042 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001043
1044 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001048 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// By default, performs semantic analysis to build the new expression.
1050 /// Subclasses may override this routine to provide different behavior.
1051 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1052 SourceLocation RParen) {
1053 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1054 }
1055
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001057 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001058 /// By default, performs semantic analysis to build the new expression.
1059 /// Subclasses may override this routine to provide different behavior.
1060 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1061 SourceLocation OperatorLoc,
1062 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001063 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001064 SourceRange QualifierRange,
1065 TypeSourceInfo *ScopeType,
1066 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001067 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001068 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// \brief Build a new unary operator expression.
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.
1074 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1075 UnaryOperator::Opcode Opc,
1076 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001077 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 }
Mike Stump11289f42009-09-09 15:08:12 +00001079
Douglas Gregor882211c2010-04-28 22:16:22 +00001080 /// \brief Build a new builtin offsetof expression.
1081 ///
1082 /// By default, performs semantic analysis to build the new expression.
1083 /// Subclasses may override this routine to provide different behavior.
1084 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1085 TypeSourceInfo *Type,
1086 Action::OffsetOfComponent *Components,
1087 unsigned NumComponents,
1088 SourceLocation RParenLoc) {
1089 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1090 NumComponents, RParenLoc);
1091 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001092
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001094 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 /// By default, performs semantic analysis to build the new expression.
1096 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001097 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001098 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001100 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 }
1102
Mike Stump11289f42009-09-09 15:08:12 +00001103 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001105 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 /// By default, performs semantic analysis to build the new expression.
1107 /// Subclasses may override this routine to provide different behavior.
1108 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1109 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001110 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1112 OpLoc, isSizeOf, R);
1113 if (Result.isInvalid())
1114 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 SubExpr.release();
1117 return move(Result);
1118 }
Mike Stump11289f42009-09-09 15:08:12 +00001119
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001121 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 /// By default, performs semantic analysis to build the new expression.
1123 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001124 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 SourceLocation LBracketLoc,
1126 ExprArg RHS,
1127 SourceLocation RBracketLoc) {
1128 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001129 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 RBracketLoc);
1131 }
1132
1133 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001134 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 /// By default, performs semantic analysis to build the new expression.
1136 /// Subclasses may override this routine to provide different behavior.
1137 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1138 MultiExprArg Args,
1139 SourceLocation *CommaLocs,
1140 SourceLocation RParenLoc) {
1141 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1142 move(Args), CommaLocs, RParenLoc);
1143 }
1144
1145 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001146 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001147 /// By default, performs semantic analysis to build the new expression.
1148 /// Subclasses may override this routine to provide different behavior.
1149 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001150 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001151 NestedNameSpecifier *Qualifier,
1152 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001153 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001154 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001155 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001156 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001157 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001158 if (!Member->getDeclName()) {
1159 // We have a reference to an unnamed field.
1160 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001161
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001162 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001163 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1164 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001165 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001166
Mike Stump11289f42009-09-09 15:08:12 +00001167 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001168 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001169 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001170 cast<FieldDecl>(Member)->getType());
1171 return getSema().Owned(ME);
1172 }
Mike Stump11289f42009-09-09 15:08:12 +00001173
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001174 CXXScopeSpec SS;
1175 if (Qualifier) {
1176 SS.setRange(QualifierRange);
1177 SS.setScopeRep(Qualifier);
1178 }
1179
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001180 Expr *BaseExpr = Base.takeAs<Expr>();
1181 getSema().DefaultFunctionArrayConversion(BaseExpr);
1182 QualType BaseType = BaseExpr->getType();
John McCall2d74de92009-12-01 22:10:20 +00001183
John McCall16df1e52010-03-30 21:47:33 +00001184 // FIXME: this involves duplicating earlier analysis in a lot of
1185 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001186 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001187 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001188 R.resolveKind();
1189
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001190 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1191 BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001192 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001193 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 }
Mike Stump11289f42009-09-09 15:08:12 +00001195
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
1200 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1201 BinaryOperator::Opcode Opc,
1202 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001203 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001204 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 }
1206
1207 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001208 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// By default, performs semantic analysis to build the new expression.
1210 /// Subclasses may override this routine to provide different behavior.
1211 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1212 SourceLocation QuestionLoc,
1213 ExprArg LHS,
1214 SourceLocation ColonLoc,
1215 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001216 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 move(LHS), move(RHS));
1218 }
1219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new C-style cast 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.
John McCall97513962010-01-15 18:39:57 +00001224 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1225 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation RParenLoc,
1227 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001228 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1229 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
1236 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001237 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 SourceLocation RParenLoc,
1239 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001240 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1241 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 }
Mike Stump11289f42009-09-09 15:08:12 +00001243
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001245 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 /// By default, performs semantic analysis to build the new expression.
1247 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001248 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 SourceLocation OpLoc,
1250 SourceLocation AccessorLoc,
1251 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001252
John McCall10eae182009-11-30 22:42:35 +00001253 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001254 QualType BaseType = ((Expr*) Base.get())->getType();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001255 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall2d74de92009-12-01 22:10:20 +00001256 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001257 OpLoc, /*IsArrow*/ false,
1258 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001259 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001260 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 }
Mike Stump11289f42009-09-09 15:08:12 +00001262
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001264 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
1267 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1268 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001269 SourceLocation RBraceLoc,
1270 QualType ResultTy) {
1271 OwningExprResult Result
1272 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1273 if (Result.isInvalid() || ResultTy->isDependentType())
1274 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001275
Douglas Gregord3d93062009-11-09 17:16:50 +00001276 // Patch in the result type we were given, which may have been computed
1277 // when the initial InitListExpr was built.
1278 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1279 ILE->setType(ResultTy);
1280 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 }
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001284 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
1287 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1288 MultiExprArg ArrayExprs,
1289 SourceLocation EqualOrColonLoc,
1290 bool GNUSyntax,
1291 ExprArg Init) {
1292 OwningExprResult Result
1293 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1294 move(Init));
1295 if (Result.isInvalid())
1296 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 ArrayExprs.release();
1299 return move(Result);
1300 }
Mike Stump11289f42009-09-09 15:08:12 +00001301
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001303 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// By default, builds the implicit value initialization without performing
1305 /// any semantic analysis. Subclasses may override this routine to provide
1306 /// different behavior.
1307 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1308 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1309 }
Mike Stump11289f42009-09-09 15:08:12 +00001310
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnara27db2392010-08-10 10:06:15 +00001315 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1316 ExprArg SubExpr, TypeSourceInfo *TInfo,
1317 SourceLocation RParenLoc) {
1318 return getSema().BuildVAArgExpr(BuiltinLoc,
1319 move(SubExpr), TInfo,
1320 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 }
1322
1323 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001324 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
1327 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1328 MultiExprArg SubExprs,
1329 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001330 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001331 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 }
Mike Stump11289f42009-09-09 15:08:12 +00001333
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001335 ///
1336 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// rather than attempting to map the label statement itself.
1338 /// Subclasses may override this routine to provide different behavior.
1339 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1340 SourceLocation LabelLoc,
1341 LabelStmt *Label) {
1342 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1343 }
Mike Stump11289f42009-09-09 15:08:12 +00001344
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001346 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
1349 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1350 StmtArg SubStmt,
1351 SourceLocation RParenLoc) {
1352 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new __builtin_types_compatible_p expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
1359 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001360 TypeSourceInfo *TInfo1,
1361 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001363 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1364 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 RParenLoc);
1366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 /// \brief Build a new __builtin_choose_expr expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1373 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1374 SourceLocation RParenLoc) {
1375 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1376 move(Cond), move(LHS), move(RHS),
1377 RParenLoc);
1378 }
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// \brief Build a new overloaded operator call expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// The semantic analysis provides the behavior of template instantiation,
1384 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001385 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// argument-dependent lookup, etc. Subclasses may override this routine to
1387 /// provide different behavior.
1388 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1389 SourceLocation OpLoc,
1390 ExprArg Callee,
1391 ExprArg First,
1392 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001393
1394 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// reinterpret_cast.
1396 ///
1397 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001398 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// Subclasses may override this routine to provide different behavior.
1400 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1401 Stmt::StmtClass Class,
1402 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001403 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 SourceLocation RAngleLoc,
1405 SourceLocation LParenLoc,
1406 ExprArg SubExpr,
1407 SourceLocation RParenLoc) {
1408 switch (Class) {
1409 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001410 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001411 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 move(SubExpr), RParenLoc);
1413
1414 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001415 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001416 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001418
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001420 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001421 RAngleLoc, LParenLoc,
1422 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001426 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001427 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 default:
1431 assert(false && "Invalid C++ named cast");
1432 break;
1433 }
Mike Stump11289f42009-09-09 15:08:12 +00001434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 return getSema().ExprError();
1436 }
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// \brief Build a new C++ static_cast expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
1442 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1443 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001444 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation RAngleLoc,
1446 SourceLocation LParenLoc,
1447 ExprArg SubExpr,
1448 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001449 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1450 TInfo, move(SubExpr),
1451 SourceRange(LAngleLoc, RAngleLoc),
1452 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 }
1454
1455 /// \brief Build a new C++ dynamic_cast expression.
1456 ///
1457 /// By default, performs semantic analysis to build the new expression.
1458 /// Subclasses may override this routine to provide different behavior.
1459 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1460 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001461 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation RAngleLoc,
1463 SourceLocation LParenLoc,
1464 ExprArg SubExpr,
1465 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001466 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1467 TInfo, move(SubExpr),
1468 SourceRange(LAngleLoc, RAngleLoc),
1469 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
1471
1472 /// \brief Build a new C++ reinterpret_cast expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
1476 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1477 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001478 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation RAngleLoc,
1480 SourceLocation LParenLoc,
1481 ExprArg SubExpr,
1482 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001483 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1484 TInfo, move(SubExpr),
1485 SourceRange(LAngleLoc, RAngleLoc),
1486 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
1488
1489 /// \brief Build a new C++ const_cast expression.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
1493 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1494 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001495 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 SourceLocation RAngleLoc,
1497 SourceLocation LParenLoc,
1498 ExprArg SubExpr,
1499 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001500 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1501 TInfo, move(SubExpr),
1502 SourceRange(LAngleLoc, RAngleLoc),
1503 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 }
Mike Stump11289f42009-09-09 15:08:12 +00001505
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 /// \brief Build a new C++ functional-style cast expression.
1507 ///
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001511 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 SourceLocation LParenLoc,
1513 ExprArg SubExpr,
1514 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001515 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001517 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001519 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001520 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 RParenLoc);
1522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new C++ typeid(type) expression.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001528 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1529 SourceLocation TypeidLoc,
1530 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001532 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001533 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new C++ typeid(expr) expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001540 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1541 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 ExprArg Operand,
1543 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001544 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1545 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001546 }
1547
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// \brief Build a new C++ "this" expression.
1549 ///
1550 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001551 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001553 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001554 QualType ThisType,
1555 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001557 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1558 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
1560
1561 /// \brief Build a new C++ throw expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1566 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1567 }
1568
1569 /// \brief Build a new C++ default-argument expression.
1570 ///
1571 /// By default, builds a new default-argument expression, which does not
1572 /// require any semantic analysis. Subclasses may override this routine to
1573 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001574 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001575 ParmVarDecl *Param) {
1576 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1577 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new C++ zero-initialization expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor747eb782010-07-08 06:14:04 +00001584 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 SourceLocation LParenLoc,
1586 QualType T,
1587 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001588 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1589 T.getAsOpaquePtr(), LParenLoc,
1590 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 0, RParenLoc);
1592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new C++ "new" expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001598 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 bool UseGlobal,
1600 SourceLocation PlacementLParen,
1601 MultiExprArg PlacementArgs,
1602 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001603 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 QualType AllocType,
1605 SourceLocation TypeLoc,
1606 SourceRange TypeRange,
1607 ExprArg ArraySize,
1608 SourceLocation ConstructorLParen,
1609 MultiExprArg ConstructorArgs,
1610 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001611 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 PlacementLParen,
1613 move(PlacementArgs),
1614 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001615 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 AllocType,
1617 TypeLoc,
1618 TypeRange,
1619 move(ArraySize),
1620 ConstructorLParen,
1621 move(ConstructorArgs),
1622 ConstructorRParen);
1623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 /// \brief Build a new C++ "delete" expression.
1626 ///
1627 /// By default, performs semantic analysis to build the new expression.
1628 /// Subclasses may override this routine to provide different behavior.
1629 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1630 bool IsGlobalDelete,
1631 bool IsArrayForm,
1632 ExprArg Operand) {
1633 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1634 move(Operand));
1635 }
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// \brief Build a new unary type trait expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 QualType T,
1645 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001646 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 T.getAsOpaquePtr(), RParenLoc);
1648 }
1649
Mike Stump11289f42009-09-09 15:08:12 +00001650 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 /// expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001655 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001657 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001658 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 CXXScopeSpec SS;
1660 SS.setRange(QualifierRange);
1661 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001662
1663 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001664 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001665 *TemplateArgs);
1666
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001667 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new template-id expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001674 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1675 LookupResult &R,
1676 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001677 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001678 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new object-construction expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001686 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 CXXConstructorDecl *Constructor,
1688 bool IsElidable,
1689 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001690 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001691 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001692 ConvertedArgs))
1693 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001694
Douglas Gregordb121ba2009-12-14 16:27:04 +00001695 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1696 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 }
1698
1699 /// \brief Build a new object-construction expression.
1700 ///
1701 /// By default, performs semantic analysis to build the new expression.
1702 /// Subclasses may override this routine to provide different behavior.
1703 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1704 QualType T,
1705 SourceLocation LParenLoc,
1706 MultiExprArg Args,
1707 SourceLocation *Commas,
1708 SourceLocation RParenLoc) {
1709 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1710 T.getAsOpaquePtr(),
1711 LParenLoc,
1712 move(Args),
1713 Commas,
1714 RParenLoc);
1715 }
1716
1717 /// \brief Build a new object-construction expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
1721 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1722 QualType T,
1723 SourceLocation LParenLoc,
1724 MultiExprArg Args,
1725 SourceLocation *Commas,
1726 SourceLocation RParenLoc) {
1727 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1728 /*FIXME*/LParenLoc),
1729 T.getAsOpaquePtr(),
1730 LParenLoc,
1731 move(Args),
1732 Commas,
1733 RParenLoc);
1734 }
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 /// \brief Build a new member reference expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001740 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001741 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 bool IsArrow,
1743 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001746 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001747 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001750 SS.setRange(QualifierRange);
1751 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001752
John McCall2d74de92009-12-01 22:10:20 +00001753 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1754 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001755 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001756 MemberNameInfo,
1757 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 }
1759
John McCall10eae182009-11-30 22:42:35 +00001760 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001764 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001765 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001766 SourceLocation OperatorLoc,
1767 bool IsArrow,
1768 NestedNameSpecifier *Qualifier,
1769 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001770 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001771 LookupResult &R,
1772 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001773 CXXScopeSpec SS;
1774 SS.setRange(QualifierRange);
1775 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001776
John McCall2d74de92009-12-01 22:10:20 +00001777 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1778 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001779 SS, FirstQualifierInScope,
1780 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001781 }
Mike Stump11289f42009-09-09 15:08:12 +00001782
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 /// \brief Build a new Objective-C @encode expression.
1784 ///
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
1787 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001788 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001790 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001792 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001793
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001794 /// \brief Build a new Objective-C class message.
1795 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1796 Selector Sel,
1797 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001798 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001799 MultiExprArg Args,
1800 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001801 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1802 ReceiverTypeInfo->getType(),
1803 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001804 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001805 move(Args));
1806 }
1807
1808 /// \brief Build a new Objective-C instance message.
1809 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1810 Selector Sel,
1811 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001812 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001813 MultiExprArg Args,
1814 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001815 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1816 return SemaRef.BuildInstanceMessage(move(Receiver),
1817 ReceiverType,
1818 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001819 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001820 move(Args));
1821 }
1822
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 /// \brief Build a new Objective-C ivar reference expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
1827 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1828 SourceLocation IvarLoc,
1829 bool IsArrow, bool IsFreeIvar) {
1830 // FIXME: We lose track of the IsFreeIvar bit.
1831 CXXScopeSpec SS;
1832 Expr *Base = BaseArg.takeAs<Expr>();
1833 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1834 Sema::LookupMemberName);
1835 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1836 /*FIME:*/IvarLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001837 SS, DeclPtrTy(),
1838 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001839 if (Result.isInvalid())
1840 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001841
Douglas Gregord51d90d2010-04-26 20:11:03 +00001842 if (Result.get())
1843 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001844
1845 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001846 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001847 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001848 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001849 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001850 /*TemplateArgs=*/0);
1851 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001852
1853 /// \brief Build a new Objective-C property reference expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001857 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001858 ObjCPropertyDecl *Property,
1859 SourceLocation PropertyLoc) {
1860 CXXScopeSpec SS;
1861 Expr *Base = BaseArg.takeAs<Expr>();
1862 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1863 Sema::LookupMemberName);
1864 bool IsArrow = false;
1865 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1866 /*FIME:*/PropertyLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001867 SS, DeclPtrTy(),
1868 false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001869 if (Result.isInvalid())
1870 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871
Douglas Gregor9faee212010-04-26 20:47:02 +00001872 if (Result.get())
1873 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001874
1875 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001876 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001877 /*FIXME:*/PropertyLoc, IsArrow,
1878 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001879 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001881 /*TemplateArgs=*/0);
1882 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001883
1884 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001885 /// expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001888 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001889 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1890 ObjCMethodDecl *Getter,
1891 QualType T,
1892 ObjCMethodDecl *Setter,
1893 SourceLocation NameLoc,
1894 ExprArg Base) {
1895 // Since these expressions can only be value-dependent, we do not need to
1896 // perform semantic analysis again.
1897 return getSema().Owned(
1898 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1899 Setter,
1900 NameLoc,
1901 Base.takeAs<Expr>()));
1902 }
1903
Douglas Gregord51d90d2010-04-26 20:11:03 +00001904 /// \brief Build a new Objective-C "isa" expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
1908 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1909 bool IsArrow) {
1910 CXXScopeSpec SS;
1911 Expr *Base = BaseArg.takeAs<Expr>();
1912 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1913 Sema::LookupMemberName);
1914 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1915 /*FIME:*/IsaLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001916 SS, DeclPtrTy(),
1917 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001918 if (Result.isInvalid())
1919 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001920
Douglas Gregord51d90d2010-04-26 20:11:03 +00001921 if (Result.get())
1922 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001923
1924 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001925 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001926 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001927 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001928 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001929 /*TemplateArgs=*/0);
1930 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 /// \brief Build a new shuffle vector expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1937 MultiExprArg SubExprs,
1938 SourceLocation RParenLoc) {
1939 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001940 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1942 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1943 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1944 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 // Build a reference to the __builtin_shufflevector builtin
1947 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001948 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001950 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001952
1953 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 unsigned NumSubExprs = SubExprs.size();
1955 Expr **Subs = (Expr **)SubExprs.release();
1956 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1957 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001958 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 RParenLoc);
1960 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 // Type-check the __builtin_shufflevector expression.
1963 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1964 if (Result.isInvalid())
1965 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001968 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001970};
Douglas Gregora16548e2009-08-11 05:31:07 +00001971
Douglas Gregorebe10102009-08-20 07:17:43 +00001972template<typename Derived>
1973Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1974 if (!S)
1975 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregorebe10102009-08-20 07:17:43 +00001977 switch (S->getStmtClass()) {
1978 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001979
Douglas Gregorebe10102009-08-20 07:17:43 +00001980 // Transform individual statement nodes
1981#define STMT(Node, Parent) \
1982 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1983#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001984#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001985
Douglas Gregorebe10102009-08-20 07:17:43 +00001986 // Transform expressions by calling TransformExpr.
1987#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001988#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001989#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001990#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001991 {
1992 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1993 if (E.isInvalid())
1994 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001995
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001996 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 }
Mike Stump11289f42009-09-09 15:08:12 +00001998 }
1999
Douglas Gregorebe10102009-08-20 07:17:43 +00002000 return SemaRef.Owned(S->Retain());
2001}
Mike Stump11289f42009-09-09 15:08:12 +00002002
2003
Douglas Gregore922c772009-08-04 22:27:00 +00002004template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00002005Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 if (!E)
2007 return SemaRef.Owned(E);
2008
2009 switch (E->getStmtClass()) {
2010 case Stmt::NoStmtClass: break;
2011#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002012#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002013#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002014 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002015#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002016 }
2017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002019}
2020
2021template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002022NestedNameSpecifier *
2023TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002024 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002025 QualType ObjectType,
2026 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002027 if (!NNS)
2028 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002029
Douglas Gregorebe10102009-08-20 07:17:43 +00002030 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002031 NestedNameSpecifier *Prefix = NNS->getPrefix();
2032 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002033 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002034 ObjectType,
2035 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002036 if (!Prefix)
2037 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002038
2039 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002040 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002041 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002042 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 }
Mike Stump11289f42009-09-09 15:08:12 +00002044
Douglas Gregor1135c352009-08-06 05:28:30 +00002045 switch (NNS->getKind()) {
2046 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002047 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002048 "Identifier nested-name-specifier with no prefix or object type");
2049 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2050 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002051 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002052
2053 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002054 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002055 ObjectType,
2056 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregor1135c352009-08-06 05:28:30 +00002058 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002059 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002060 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002061 getDerived().TransformDecl(Range.getBegin(),
2062 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002063 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002064 Prefix == NNS->getPrefix() &&
2065 NS == NNS->getAsNamespace())
2066 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregor1135c352009-08-06 05:28:30 +00002068 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2069 }
Mike Stump11289f42009-09-09 15:08:12 +00002070
Douglas Gregor1135c352009-08-06 05:28:30 +00002071 case NestedNameSpecifier::Global:
2072 // There is no meaningful transformation that one could perform on the
2073 // global scope.
2074 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregor1135c352009-08-06 05:28:30 +00002076 case NestedNameSpecifier::TypeSpecWithTemplate:
2077 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002078 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002079 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2080 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002081 if (T.isNull())
2082 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002083
Douglas Gregor1135c352009-08-06 05:28:30 +00002084 if (!getDerived().AlwaysRebuild() &&
2085 Prefix == NNS->getPrefix() &&
2086 T == QualType(NNS->getAsType(), 0))
2087 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002088
2089 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2090 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002091 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002092 }
2093 }
Mike Stump11289f42009-09-09 15:08:12 +00002094
Douglas Gregor1135c352009-08-06 05:28:30 +00002095 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002096 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002097}
2098
2099template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002100DeclarationNameInfo
2101TreeTransform<Derived>
2102::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2103 QualType ObjectType) {
2104 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002105 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002106 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002107
2108 switch (Name.getNameKind()) {
2109 case DeclarationName::Identifier:
2110 case DeclarationName::ObjCZeroArgSelector:
2111 case DeclarationName::ObjCOneArgSelector:
2112 case DeclarationName::ObjCMultiArgSelector:
2113 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002114 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002115 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002116 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregorf816bd72009-09-03 22:13:48 +00002118 case DeclarationName::CXXConstructorName:
2119 case DeclarationName::CXXDestructorName:
2120 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002121 TypeSourceInfo *NewTInfo;
2122 CanQualType NewCanTy;
2123 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2124 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2125 if (!NewTInfo)
2126 return DeclarationNameInfo();
2127 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2128 }
2129 else {
2130 NewTInfo = 0;
2131 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2132 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2133 ObjectType);
2134 if (NewT.isNull())
2135 return DeclarationNameInfo();
2136 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2137 }
Mike Stump11289f42009-09-09 15:08:12 +00002138
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002139 DeclarationName NewName
2140 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2141 NewCanTy);
2142 DeclarationNameInfo NewNameInfo(NameInfo);
2143 NewNameInfo.setName(NewName);
2144 NewNameInfo.setNamedTypeInfo(NewTInfo);
2145 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002146 }
Mike Stump11289f42009-09-09 15:08:12 +00002147 }
2148
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002149 assert(0 && "Unknown name kind.");
2150 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002151}
2152
2153template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002154TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002155TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2156 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002157 SourceLocation Loc = getDerived().getBaseLocation();
2158
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002160 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002161 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002162 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2163 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002164 if (!NNS)
2165 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
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 NNS == QTN->getQualifier() &&
2175 TransTemplate == Template)
2176 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2179 TransTemplate);
2180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
John McCalle66edc12009-11-24 19:00:30 +00002182 // These should be getting filtered out before they make it into the AST.
2183 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 }
Mike Stump11289f42009-09-09 15:08:12 +00002185
Douglas Gregor71dc5092009-08-06 06:41:21 +00002186 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002187 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002189 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2190 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002191 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002192 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002195 NNS == DTN->getQualifier() &&
2196 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002197 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002198
Douglas Gregor71395fa2009-11-04 00:56:37 +00002199 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002200 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002201 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002202
2203 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002204 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002205 }
Mike Stump11289f42009-09-09 15:08:12 +00002206
Douglas Gregor71dc5092009-08-06 06:41:21 +00002207 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002208 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002209 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002210 if (!TransTemplate)
2211 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002212
Douglas Gregor71dc5092009-08-06 06:41:21 +00002213 if (!getDerived().AlwaysRebuild() &&
2214 TransTemplate == Template)
2215 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002216
Douglas Gregor71dc5092009-08-06 06:41:21 +00002217 return TemplateName(TransTemplate);
2218 }
Mike Stump11289f42009-09-09 15:08:12 +00002219
John McCalle66edc12009-11-24 19:00:30 +00002220 // These should be getting filtered out before they reach the AST.
2221 assert(false && "overloaded function decl survived to here");
2222 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002223}
2224
2225template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002226void TreeTransform<Derived>::InventTemplateArgumentLoc(
2227 const TemplateArgument &Arg,
2228 TemplateArgumentLoc &Output) {
2229 SourceLocation Loc = getDerived().getBaseLocation();
2230 switch (Arg.getKind()) {
2231 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002232 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002233 break;
2234
2235 case TemplateArgument::Type:
2236 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002237 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002238
John McCall0ad16662009-10-29 08:12:44 +00002239 break;
2240
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002241 case TemplateArgument::Template:
2242 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2243 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002244
John McCall0ad16662009-10-29 08:12:44 +00002245 case TemplateArgument::Expression:
2246 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2247 break;
2248
2249 case TemplateArgument::Declaration:
2250 case TemplateArgument::Integral:
2251 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002252 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002253 break;
2254 }
2255}
2256
2257template<typename Derived>
2258bool TreeTransform<Derived>::TransformTemplateArgument(
2259 const TemplateArgumentLoc &Input,
2260 TemplateArgumentLoc &Output) {
2261 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002262 switch (Arg.getKind()) {
2263 case TemplateArgument::Null:
2264 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002265 Output = Input;
2266 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregore922c772009-08-04 22:27:00 +00002268 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002269 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002270 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002271 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002272
2273 DI = getDerived().TransformType(DI);
2274 if (!DI) return true;
2275
2276 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2277 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002278 }
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregore922c772009-08-04 22:27:00 +00002280 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002281 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002282 DeclarationName Name;
2283 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2284 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002285 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002286 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002287 if (!D) return true;
2288
John McCall0d07eb32009-10-29 18:45:58 +00002289 Expr *SourceExpr = Input.getSourceDeclExpression();
2290 if (SourceExpr) {
2291 EnterExpressionEvaluationContext Unevaluated(getSema(),
2292 Action::Unevaluated);
2293 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2294 if (E.isInvalid())
2295 SourceExpr = NULL;
2296 else {
2297 SourceExpr = E.takeAs<Expr>();
2298 SourceExpr->Retain();
2299 }
2300 }
2301
2302 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002303 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002304 }
Mike Stump11289f42009-09-09 15:08:12 +00002305
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002306 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002307 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002308 TemplateName Template
2309 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2310 if (Template.isNull())
2311 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002312
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002313 Output = TemplateArgumentLoc(TemplateArgument(Template),
2314 Input.getTemplateQualifierRange(),
2315 Input.getTemplateNameLoc());
2316 return false;
2317 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002318
Douglas Gregore922c772009-08-04 22:27:00 +00002319 case TemplateArgument::Expression: {
2320 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002321 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002322 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002323
John McCall0ad16662009-10-29 08:12:44 +00002324 Expr *InputExpr = Input.getSourceExpression();
2325 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2326
2327 Sema::OwningExprResult E
2328 = getDerived().TransformExpr(InputExpr);
2329 if (E.isInvalid()) return true;
2330
2331 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002332 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002333 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2334 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregore922c772009-08-04 22:27:00 +00002337 case TemplateArgument::Pack: {
2338 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2339 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002340 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002341 AEnd = Arg.pack_end();
2342 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002343
John McCall0ad16662009-10-29 08:12:44 +00002344 // FIXME: preserve source information here when we start
2345 // caring about parameter packs.
2346
John McCall0d07eb32009-10-29 18:45:58 +00002347 TemplateArgumentLoc InputArg;
2348 TemplateArgumentLoc OutputArg;
2349 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2350 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002351 return true;
2352
John McCall0d07eb32009-10-29 18:45:58 +00002353 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002354 }
2355 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002356 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002357 true);
John McCall0d07eb32009-10-29 18:45:58 +00002358 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002359 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002360 }
2361 }
Mike Stump11289f42009-09-09 15:08:12 +00002362
Douglas Gregore922c772009-08-04 22:27:00 +00002363 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002364 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002365}
2366
Douglas Gregord6ff3322009-08-04 16:50:30 +00002367//===----------------------------------------------------------------------===//
2368// Type transformation
2369//===----------------------------------------------------------------------===//
2370
2371template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002372QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002373 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002374 if (getDerived().AlreadyTransformed(T))
2375 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002376
John McCall550e0c22009-10-21 00:40:46 +00002377 // Temporary workaround. All of these transformations should
2378 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002379 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002380 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002381
Douglas Gregorfe17d252010-02-16 19:09:40 +00002382 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002383
John McCall550e0c22009-10-21 00:40:46 +00002384 if (!NewDI)
2385 return QualType();
2386
2387 return NewDI->getType();
2388}
2389
2390template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002391TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2392 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002393 if (getDerived().AlreadyTransformed(DI->getType()))
2394 return DI;
2395
2396 TypeLocBuilder TLB;
2397
2398 TypeLoc TL = DI->getTypeLoc();
2399 TLB.reserve(TL.getFullDataSize());
2400
Douglas Gregorfe17d252010-02-16 19:09:40 +00002401 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002402 if (Result.isNull())
2403 return 0;
2404
John McCallbcd03502009-12-07 02:54:59 +00002405 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002406}
2407
2408template<typename Derived>
2409QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002410TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2411 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002412 switch (T.getTypeLocClass()) {
2413#define ABSTRACT_TYPELOC(CLASS, PARENT)
2414#define TYPELOC(CLASS, PARENT) \
2415 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002416 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2417 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002418#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002419 }
Mike Stump11289f42009-09-09 15:08:12 +00002420
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002421 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002422 return QualType();
2423}
2424
2425/// FIXME: By default, this routine adds type qualifiers only to types
2426/// that can have qualifiers, and silently suppresses those qualifiers
2427/// that are not permitted (e.g., qualifiers on reference or function
2428/// types). This is the right thing for template instantiation, but
2429/// probably not for other clients.
2430template<typename Derived>
2431QualType
2432TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002433 QualifiedTypeLoc T,
2434 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002435 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002436
Douglas Gregorfe17d252010-02-16 19:09:40 +00002437 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2438 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002439 if (Result.isNull())
2440 return QualType();
2441
2442 // Silently suppress qualifiers if the result type can't be qualified.
2443 // FIXME: this is the right thing for template instantiation, but
2444 // probably not for other clients.
2445 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002446 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002447
John McCallcb0f89a2010-06-05 06:41:15 +00002448 if (!Quals.empty()) {
2449 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2450 TLB.push<QualifiedTypeLoc>(Result);
2451 // No location information to preserve.
2452 }
John McCall550e0c22009-10-21 00:40:46 +00002453
2454 return Result;
2455}
2456
2457template <class TyLoc> static inline
2458QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2459 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2460 NewT.setNameLoc(T.getNameLoc());
2461 return T.getType();
2462}
2463
John McCall550e0c22009-10-21 00:40:46 +00002464template<typename Derived>
2465QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002466 BuiltinTypeLoc T,
2467 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002468 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2469 NewT.setBuiltinLoc(T.getBuiltinLoc());
2470 if (T.needsExtraLocalData())
2471 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2472 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002473}
Mike Stump11289f42009-09-09 15:08:12 +00002474
Douglas Gregord6ff3322009-08-04 16:50:30 +00002475template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002476QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002477 ComplexTypeLoc T,
2478 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002479 // FIXME: recurse?
2480 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002481}
Mike Stump11289f42009-09-09 15:08:12 +00002482
Douglas Gregord6ff3322009-08-04 16:50:30 +00002483template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002484QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002486 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002487 QualType PointeeType
2488 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002489 if (PointeeType.isNull())
2490 return QualType();
2491
2492 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002493 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002494 // A dependent pointer type 'T *' has is being transformed such
2495 // that an Objective-C class type is being replaced for 'T'. The
2496 // resulting pointer type is an ObjCObjectPointerType, not a
2497 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002498 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002499
John McCall8b07ec22010-05-15 11:32:37 +00002500 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2501 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002502 return Result;
2503 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002504
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002505 if (getDerived().AlwaysRebuild() ||
2506 PointeeType != TL.getPointeeLoc().getType()) {
2507 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2508 if (Result.isNull())
2509 return QualType();
2510 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002511
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002512 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2513 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002514 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002515}
Mike Stump11289f42009-09-09 15:08:12 +00002516
2517template<typename Derived>
2518QualType
John McCall550e0c22009-10-21 00:40:46 +00002519TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002520 BlockPointerTypeLoc TL,
2521 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002522 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002523 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2524 if (PointeeType.isNull())
2525 return QualType();
2526
2527 QualType Result = TL.getType();
2528 if (getDerived().AlwaysRebuild() ||
2529 PointeeType != TL.getPointeeLoc().getType()) {
2530 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002531 TL.getSigilLoc());
2532 if (Result.isNull())
2533 return QualType();
2534 }
2535
Douglas Gregor049211a2010-04-22 16:50:51 +00002536 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002537 NewT.setSigilLoc(TL.getSigilLoc());
2538 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002539}
2540
John McCall70dd5f62009-10-30 00:06:24 +00002541/// Transforms a reference type. Note that somewhat paradoxically we
2542/// don't care whether the type itself is an l-value type or an r-value
2543/// type; we only care if the type was *written* as an l-value type
2544/// or an r-value type.
2545template<typename Derived>
2546QualType
2547TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002548 ReferenceTypeLoc TL,
2549 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002550 const ReferenceType *T = TL.getTypePtr();
2551
2552 // Note that this works with the pointee-as-written.
2553 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2554 if (PointeeType.isNull())
2555 return QualType();
2556
2557 QualType Result = TL.getType();
2558 if (getDerived().AlwaysRebuild() ||
2559 PointeeType != T->getPointeeTypeAsWritten()) {
2560 Result = getDerived().RebuildReferenceType(PointeeType,
2561 T->isSpelledAsLValue(),
2562 TL.getSigilLoc());
2563 if (Result.isNull())
2564 return QualType();
2565 }
2566
2567 // r-value references can be rebuilt as l-value references.
2568 ReferenceTypeLoc NewTL;
2569 if (isa<LValueReferenceType>(Result))
2570 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2571 else
2572 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2573 NewTL.setSigilLoc(TL.getSigilLoc());
2574
2575 return Result;
2576}
2577
Mike Stump11289f42009-09-09 15:08:12 +00002578template<typename Derived>
2579QualType
John McCall550e0c22009-10-21 00:40:46 +00002580TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002581 LValueReferenceTypeLoc TL,
2582 QualType ObjectType) {
2583 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002584}
2585
Mike Stump11289f42009-09-09 15:08:12 +00002586template<typename Derived>
2587QualType
John McCall550e0c22009-10-21 00:40:46 +00002588TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002589 RValueReferenceTypeLoc TL,
2590 QualType ObjectType) {
2591 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002592}
Mike Stump11289f42009-09-09 15:08:12 +00002593
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002595QualType
John McCall550e0c22009-10-21 00:40:46 +00002596TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002597 MemberPointerTypeLoc TL,
2598 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002599 MemberPointerType *T = TL.getTypePtr();
2600
2601 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002602 if (PointeeType.isNull())
2603 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002604
John McCall550e0c22009-10-21 00:40:46 +00002605 // TODO: preserve source information for this.
2606 QualType ClassType
2607 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608 if (ClassType.isNull())
2609 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002610
John McCall550e0c22009-10-21 00:40:46 +00002611 QualType Result = TL.getType();
2612 if (getDerived().AlwaysRebuild() ||
2613 PointeeType != T->getPointeeType() ||
2614 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002615 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2616 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002617 if (Result.isNull())
2618 return QualType();
2619 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002620
John McCall550e0c22009-10-21 00:40:46 +00002621 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2622 NewTL.setSigilLoc(TL.getSigilLoc());
2623
2624 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625}
2626
Mike Stump11289f42009-09-09 15:08:12 +00002627template<typename Derived>
2628QualType
John McCall550e0c22009-10-21 00:40:46 +00002629TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002630 ConstantArrayTypeLoc TL,
2631 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002632 ConstantArrayType *T = TL.getTypePtr();
2633 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634 if (ElementType.isNull())
2635 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002636
John McCall550e0c22009-10-21 00:40:46 +00002637 QualType Result = TL.getType();
2638 if (getDerived().AlwaysRebuild() ||
2639 ElementType != T->getElementType()) {
2640 Result = getDerived().RebuildConstantArrayType(ElementType,
2641 T->getSizeModifier(),
2642 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002643 T->getIndexTypeCVRQualifiers(),
2644 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002645 if (Result.isNull())
2646 return QualType();
2647 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002648
John McCall550e0c22009-10-21 00:40:46 +00002649 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2650 NewTL.setLBracketLoc(TL.getLBracketLoc());
2651 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002652
John McCall550e0c22009-10-21 00:40:46 +00002653 Expr *Size = TL.getSizeExpr();
2654 if (Size) {
2655 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2656 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2657 }
2658 NewTL.setSizeExpr(Size);
2659
2660 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002661}
Mike Stump11289f42009-09-09 15:08:12 +00002662
Douglas Gregord6ff3322009-08-04 16:50:30 +00002663template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002664QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002665 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002666 IncompleteArrayTypeLoc TL,
2667 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002668 IncompleteArrayType *T = TL.getTypePtr();
2669 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002670 if (ElementType.isNull())
2671 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002672
John McCall550e0c22009-10-21 00:40:46 +00002673 QualType Result = TL.getType();
2674 if (getDerived().AlwaysRebuild() ||
2675 ElementType != T->getElementType()) {
2676 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002677 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002678 T->getIndexTypeCVRQualifiers(),
2679 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002680 if (Result.isNull())
2681 return QualType();
2682 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002683
John McCall550e0c22009-10-21 00:40:46 +00002684 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2685 NewTL.setLBracketLoc(TL.getLBracketLoc());
2686 NewTL.setRBracketLoc(TL.getRBracketLoc());
2687 NewTL.setSizeExpr(0);
2688
2689 return Result;
2690}
2691
2692template<typename Derived>
2693QualType
2694TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002695 VariableArrayTypeLoc TL,
2696 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002697 VariableArrayType *T = TL.getTypePtr();
2698 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2699 if (ElementType.isNull())
2700 return QualType();
2701
2702 // Array bounds are not potentially evaluated contexts
2703 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2704
2705 Sema::OwningExprResult SizeResult
2706 = getDerived().TransformExpr(T->getSizeExpr());
2707 if (SizeResult.isInvalid())
2708 return QualType();
2709
2710 Expr *Size = static_cast<Expr*>(SizeResult.get());
2711
2712 QualType Result = TL.getType();
2713 if (getDerived().AlwaysRebuild() ||
2714 ElementType != T->getElementType() ||
2715 Size != T->getSizeExpr()) {
2716 Result = getDerived().RebuildVariableArrayType(ElementType,
2717 T->getSizeModifier(),
2718 move(SizeResult),
2719 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002720 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002721 if (Result.isNull())
2722 return QualType();
2723 }
2724 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002725
John McCall550e0c22009-10-21 00:40:46 +00002726 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2727 NewTL.setLBracketLoc(TL.getLBracketLoc());
2728 NewTL.setRBracketLoc(TL.getRBracketLoc());
2729 NewTL.setSizeExpr(Size);
2730
2731 return Result;
2732}
2733
2734template<typename Derived>
2735QualType
2736TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002737 DependentSizedArrayTypeLoc TL,
2738 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002739 DependentSizedArrayType *T = TL.getTypePtr();
2740 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2741 if (ElementType.isNull())
2742 return QualType();
2743
2744 // Array bounds are not potentially evaluated contexts
2745 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2746
2747 Sema::OwningExprResult SizeResult
2748 = getDerived().TransformExpr(T->getSizeExpr());
2749 if (SizeResult.isInvalid())
2750 return QualType();
2751
2752 Expr *Size = static_cast<Expr*>(SizeResult.get());
2753
2754 QualType Result = TL.getType();
2755 if (getDerived().AlwaysRebuild() ||
2756 ElementType != T->getElementType() ||
2757 Size != T->getSizeExpr()) {
2758 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2759 T->getSizeModifier(),
2760 move(SizeResult),
2761 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002762 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002763 if (Result.isNull())
2764 return QualType();
2765 }
2766 else SizeResult.take();
2767
2768 // We might have any sort of array type now, but fortunately they
2769 // all have the same location layout.
2770 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2771 NewTL.setLBracketLoc(TL.getLBracketLoc());
2772 NewTL.setRBracketLoc(TL.getRBracketLoc());
2773 NewTL.setSizeExpr(Size);
2774
2775 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776}
Mike Stump11289f42009-09-09 15:08:12 +00002777
2778template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002779QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002780 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002781 DependentSizedExtVectorTypeLoc TL,
2782 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002783 DependentSizedExtVectorType *T = TL.getTypePtr();
2784
2785 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002786 QualType ElementType = getDerived().TransformType(T->getElementType());
2787 if (ElementType.isNull())
2788 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002789
Douglas Gregore922c772009-08-04 22:27:00 +00002790 // Vector sizes are not potentially evaluated contexts
2791 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2792
Douglas Gregord6ff3322009-08-04 16:50:30 +00002793 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2794 if (Size.isInvalid())
2795 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002796
John McCall550e0c22009-10-21 00:40:46 +00002797 QualType Result = TL.getType();
2798 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002799 ElementType != T->getElementType() ||
2800 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002801 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002802 move(Size),
2803 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002804 if (Result.isNull())
2805 return QualType();
2806 }
2807 else Size.take();
2808
2809 // Result might be dependent or not.
2810 if (isa<DependentSizedExtVectorType>(Result)) {
2811 DependentSizedExtVectorTypeLoc NewTL
2812 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2813 NewTL.setNameLoc(TL.getNameLoc());
2814 } else {
2815 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2816 NewTL.setNameLoc(TL.getNameLoc());
2817 }
2818
2819 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002820}
Mike Stump11289f42009-09-09 15:08:12 +00002821
2822template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002823QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002824 VectorTypeLoc TL,
2825 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002826 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002827 QualType ElementType = getDerived().TransformType(T->getElementType());
2828 if (ElementType.isNull())
2829 return QualType();
2830
John McCall550e0c22009-10-21 00:40:46 +00002831 QualType Result = TL.getType();
2832 if (getDerived().AlwaysRebuild() ||
2833 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002834 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002835 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002836 if (Result.isNull())
2837 return QualType();
2838 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002839
John McCall550e0c22009-10-21 00:40:46 +00002840 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2841 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002842
John McCall550e0c22009-10-21 00:40:46 +00002843 return Result;
2844}
2845
2846template<typename Derived>
2847QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002848 ExtVectorTypeLoc TL,
2849 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002850 VectorType *T = TL.getTypePtr();
2851 QualType ElementType = getDerived().TransformType(T->getElementType());
2852 if (ElementType.isNull())
2853 return QualType();
2854
2855 QualType Result = TL.getType();
2856 if (getDerived().AlwaysRebuild() ||
2857 ElementType != T->getElementType()) {
2858 Result = getDerived().RebuildExtVectorType(ElementType,
2859 T->getNumElements(),
2860 /*FIXME*/ SourceLocation());
2861 if (Result.isNull())
2862 return QualType();
2863 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002864
John McCall550e0c22009-10-21 00:40:46 +00002865 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2866 NewTL.setNameLoc(TL.getNameLoc());
2867
2868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002869}
Mike Stump11289f42009-09-09 15:08:12 +00002870
2871template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002872ParmVarDecl *
2873TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2874 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2875 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2876 if (!NewDI)
2877 return 0;
2878
2879 if (NewDI == OldDI)
2880 return OldParm;
2881 else
2882 return ParmVarDecl::Create(SemaRef.Context,
2883 OldParm->getDeclContext(),
2884 OldParm->getLocation(),
2885 OldParm->getIdentifier(),
2886 NewDI->getType(),
2887 NewDI,
2888 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002889 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002890 /* DefArg */ NULL);
2891}
2892
2893template<typename Derived>
2894bool TreeTransform<Derived>::
2895 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2896 llvm::SmallVectorImpl<QualType> &PTypes,
2897 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2898 FunctionProtoType *T = TL.getTypePtr();
2899
2900 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2901 ParmVarDecl *OldParm = TL.getArg(i);
2902
2903 QualType NewType;
2904 ParmVarDecl *NewParm;
2905
2906 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002907 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2908 if (!NewParm)
2909 return true;
2910 NewType = NewParm->getType();
2911
2912 // Deal with the possibility that we don't have a parameter
2913 // declaration for this parameter.
2914 } else {
2915 NewParm = 0;
2916
2917 QualType OldType = T->getArgType(i);
2918 NewType = getDerived().TransformType(OldType);
2919 if (NewType.isNull())
2920 return true;
2921 }
2922
2923 PTypes.push_back(NewType);
2924 PVars.push_back(NewParm);
2925 }
2926
2927 return false;
2928}
2929
2930template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002931QualType
John McCall550e0c22009-10-21 00:40:46 +00002932TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002933 FunctionProtoTypeLoc TL,
2934 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002935 // Transform the parameters. We do this first for the benefit of template
2936 // instantiations, so that the ParmVarDecls get/ placed into the template
2937 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002938 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002939 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002940 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2941 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002942
Douglas Gregor14cf7522010-04-30 18:55:50 +00002943 FunctionProtoType *T = TL.getTypePtr();
2944 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2945 if (ResultType.isNull())
2946 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002947
John McCall550e0c22009-10-21 00:40:46 +00002948 QualType Result = TL.getType();
2949 if (getDerived().AlwaysRebuild() ||
2950 ResultType != T->getResultType() ||
2951 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2952 Result = getDerived().RebuildFunctionProtoType(ResultType,
2953 ParamTypes.data(),
2954 ParamTypes.size(),
2955 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002956 T->getTypeQuals(),
2957 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002958 if (Result.isNull())
2959 return QualType();
2960 }
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall550e0c22009-10-21 00:40:46 +00002962 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2963 NewTL.setLParenLoc(TL.getLParenLoc());
2964 NewTL.setRParenLoc(TL.getRParenLoc());
2965 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2966 NewTL.setArg(i, ParamDecls[i]);
2967
2968 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002969}
Mike Stump11289f42009-09-09 15:08:12 +00002970
Douglas Gregord6ff3322009-08-04 16:50:30 +00002971template<typename Derived>
2972QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002973 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002974 FunctionNoProtoTypeLoc TL,
2975 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002976 FunctionNoProtoType *T = TL.getTypePtr();
2977 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2978 if (ResultType.isNull())
2979 return QualType();
2980
2981 QualType Result = TL.getType();
2982 if (getDerived().AlwaysRebuild() ||
2983 ResultType != T->getResultType())
2984 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2985
2986 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2987 NewTL.setLParenLoc(TL.getLParenLoc());
2988 NewTL.setRParenLoc(TL.getRParenLoc());
2989
2990 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991}
Mike Stump11289f42009-09-09 15:08:12 +00002992
John McCallb96ec562009-12-04 22:46:56 +00002993template<typename Derived> QualType
2994TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002995 UnresolvedUsingTypeLoc TL,
2996 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002997 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002998 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002999 if (!D)
3000 return QualType();
3001
3002 QualType Result = TL.getType();
3003 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3004 Result = getDerived().RebuildUnresolvedUsingType(D);
3005 if (Result.isNull())
3006 return QualType();
3007 }
3008
3009 // We might get an arbitrary type spec type back. We should at
3010 // least always get a type spec type, though.
3011 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3012 NewTL.setNameLoc(TL.getNameLoc());
3013
3014 return Result;
3015}
3016
Douglas Gregord6ff3322009-08-04 16:50:30 +00003017template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003018QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003019 TypedefTypeLoc TL,
3020 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003021 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003023 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3024 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003025 if (!Typedef)
3026 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003027
John McCall550e0c22009-10-21 00:40:46 +00003028 QualType Result = TL.getType();
3029 if (getDerived().AlwaysRebuild() ||
3030 Typedef != T->getDecl()) {
3031 Result = getDerived().RebuildTypedefType(Typedef);
3032 if (Result.isNull())
3033 return QualType();
3034 }
Mike Stump11289f42009-09-09 15:08:12 +00003035
John McCall550e0c22009-10-21 00:40:46 +00003036 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3037 NewTL.setNameLoc(TL.getNameLoc());
3038
3039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003040}
Mike Stump11289f42009-09-09 15:08:12 +00003041
Douglas Gregord6ff3322009-08-04 16:50:30 +00003042template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003043QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003044 TypeOfExprTypeLoc TL,
3045 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003046 // typeof expressions are not potentially evaluated contexts
3047 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003048
John McCalle8595032010-01-13 20:03:27 +00003049 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003050 if (E.isInvalid())
3051 return QualType();
3052
John McCall550e0c22009-10-21 00:40:46 +00003053 QualType Result = TL.getType();
3054 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003055 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003056 Result = getDerived().RebuildTypeOfExprType(move(E));
3057 if (Result.isNull())
3058 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003059 }
John McCall550e0c22009-10-21 00:40:46 +00003060 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003061
John McCall550e0c22009-10-21 00:40:46 +00003062 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003063 NewTL.setTypeofLoc(TL.getTypeofLoc());
3064 NewTL.setLParenLoc(TL.getLParenLoc());
3065 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003066
3067 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003068}
Mike Stump11289f42009-09-09 15:08:12 +00003069
3070template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003071QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003072 TypeOfTypeLoc TL,
3073 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003074 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3075 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3076 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall550e0c22009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003080 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3081 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003082 if (Result.isNull())
3083 return QualType();
3084 }
Mike Stump11289f42009-09-09 15:08:12 +00003085
John McCall550e0c22009-10-21 00:40:46 +00003086 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003087 NewTL.setTypeofLoc(TL.getTypeofLoc());
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
3090 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003091
3092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
Mike Stump11289f42009-09-09 15:08:12 +00003094
3095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003097 DecltypeTypeLoc TL,
3098 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003099 DecltypeType *T = TL.getTypePtr();
3100
Douglas Gregore922c772009-08-04 22:27:00 +00003101 // decltype expressions are not potentially evaluated contexts
3102 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003103
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3105 if (E.isInvalid())
3106 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003107
John McCall550e0c22009-10-21 00:40:46 +00003108 QualType Result = TL.getType();
3109 if (getDerived().AlwaysRebuild() ||
3110 E.get() != T->getUnderlyingExpr()) {
3111 Result = getDerived().RebuildDecltypeType(move(E));
3112 if (Result.isNull())
3113 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003114 }
John McCall550e0c22009-10-21 00:40:46 +00003115 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003116
John McCall550e0c22009-10-21 00:40:46 +00003117 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3118 NewTL.setNameLoc(TL.getNameLoc());
3119
3120 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121}
3122
3123template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003124QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003125 RecordTypeLoc TL,
3126 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003127 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003129 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3130 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003131 if (!Record)
3132 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003133
John McCall550e0c22009-10-21 00:40:46 +00003134 QualType Result = TL.getType();
3135 if (getDerived().AlwaysRebuild() ||
3136 Record != T->getDecl()) {
3137 Result = getDerived().RebuildRecordType(Record);
3138 if (Result.isNull())
3139 return QualType();
3140 }
Mike Stump11289f42009-09-09 15:08:12 +00003141
John McCall550e0c22009-10-21 00:40:46 +00003142 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3143 NewTL.setNameLoc(TL.getNameLoc());
3144
3145 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146}
Mike Stump11289f42009-09-09 15:08:12 +00003147
3148template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003149QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003150 EnumTypeLoc TL,
3151 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003152 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003153 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003154 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3155 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003156 if (!Enum)
3157 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003158
John McCall550e0c22009-10-21 00:40:46 +00003159 QualType Result = TL.getType();
3160 if (getDerived().AlwaysRebuild() ||
3161 Enum != T->getDecl()) {
3162 Result = getDerived().RebuildEnumType(Enum);
3163 if (Result.isNull())
3164 return QualType();
3165 }
Mike Stump11289f42009-09-09 15:08:12 +00003166
John McCall550e0c22009-10-21 00:40:46 +00003167 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3168 NewTL.setNameLoc(TL.getNameLoc());
3169
3170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003171}
John McCallfcc33b02009-09-05 00:15:47 +00003172
John McCalle78aac42010-03-10 03:28:59 +00003173template<typename Derived>
3174QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3175 TypeLocBuilder &TLB,
3176 InjectedClassNameTypeLoc TL,
3177 QualType ObjectType) {
3178 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3179 TL.getTypePtr()->getDecl());
3180 if (!D) return QualType();
3181
3182 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3183 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3184 return T;
3185}
3186
Mike Stump11289f42009-09-09 15:08:12 +00003187
Douglas Gregord6ff3322009-08-04 16:50:30 +00003188template<typename Derived>
3189QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003190 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003191 TemplateTypeParmTypeLoc TL,
3192 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003193 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003194}
3195
Mike Stump11289f42009-09-09 15:08:12 +00003196template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003197QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003198 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003199 SubstTemplateTypeParmTypeLoc TL,
3200 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003201 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003202}
3203
3204template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003205QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3206 const TemplateSpecializationType *TST,
3207 QualType ObjectType) {
3208 // FIXME: this entire method is a temporary workaround; callers
3209 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003210
John McCall0ad16662009-10-29 08:12:44 +00003211 // Fake up a TemplateSpecializationTypeLoc.
3212 TypeLocBuilder TLB;
3213 TemplateSpecializationTypeLoc TL
3214 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3215
John McCall0d07eb32009-10-29 18:45:58 +00003216 SourceLocation BaseLoc = getDerived().getBaseLocation();
3217
3218 TL.setTemplateNameLoc(BaseLoc);
3219 TL.setLAngleLoc(BaseLoc);
3220 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003221 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3222 const TemplateArgument &TA = TST->getArg(i);
3223 TemplateArgumentLoc TAL;
3224 getDerived().InventTemplateArgumentLoc(TA, TAL);
3225 TL.setArgLocInfo(i, TAL.getLocInfo());
3226 }
3227
3228 TypeLocBuilder IgnoredTLB;
3229 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003230}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003231
Douglas Gregorc59e5612009-10-19 22:04:39 +00003232template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003233QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003234 TypeLocBuilder &TLB,
3235 TemplateSpecializationTypeLoc TL,
3236 QualType ObjectType) {
3237 const TemplateSpecializationType *T = TL.getTypePtr();
3238
Mike Stump11289f42009-09-09 15:08:12 +00003239 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003240 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 if (Template.isNull())
3242 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003243
John McCall6b51f282009-11-23 01:53:49 +00003244 TemplateArgumentListInfo NewTemplateArgs;
3245 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3246 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3247
3248 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3249 TemplateArgumentLoc Loc;
3250 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003252 NewTemplateArgs.addArgument(Loc);
3253 }
Mike Stump11289f42009-09-09 15:08:12 +00003254
John McCall0ad16662009-10-29 08:12:44 +00003255 // FIXME: maybe don't rebuild if all the template arguments are the same.
3256
3257 QualType Result =
3258 getDerived().RebuildTemplateSpecializationType(Template,
3259 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003260 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003261
3262 if (!Result.isNull()) {
3263 TemplateSpecializationTypeLoc NewTL
3264 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3265 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3266 NewTL.setLAngleLoc(TL.getLAngleLoc());
3267 NewTL.setRAngleLoc(TL.getRAngleLoc());
3268 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3269 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003270 }
Mike Stump11289f42009-09-09 15:08:12 +00003271
John McCall0ad16662009-10-29 08:12:44 +00003272 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003273}
Mike Stump11289f42009-09-09 15:08:12 +00003274
3275template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003276QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003277TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3278 ElaboratedTypeLoc TL,
3279 QualType ObjectType) {
3280 ElaboratedType *T = TL.getTypePtr();
3281
3282 NestedNameSpecifier *NNS = 0;
3283 // NOTE: the qualifier in an ElaboratedType is optional.
3284 if (T->getQualifier() != 0) {
3285 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003286 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003287 ObjectType);
3288 if (!NNS)
3289 return QualType();
3290 }
Mike Stump11289f42009-09-09 15:08:12 +00003291
Abramo Bagnarad7548482010-05-19 21:37:53 +00003292 QualType NamedT;
3293 // FIXME: this test is meant to workaround a problem (failing assertion)
3294 // occurring if directly executing the code in the else branch.
3295 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3296 TemplateSpecializationTypeLoc OldNamedTL
3297 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3298 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003299 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003300 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3301 if (NamedT.isNull())
3302 return QualType();
3303 TemplateSpecializationTypeLoc NewNamedTL
3304 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3305 NewNamedTL.copy(OldNamedTL);
3306 }
3307 else {
3308 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3309 if (NamedT.isNull())
3310 return QualType();
3311 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003312
John McCall550e0c22009-10-21 00:40:46 +00003313 QualType Result = TL.getType();
3314 if (getDerived().AlwaysRebuild() ||
3315 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003316 NamedT != T->getNamedType()) {
3317 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003318 if (Result.isNull())
3319 return QualType();
3320 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321
Abramo Bagnara6150c882010-05-11 21:36:43 +00003322 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003323 NewTL.setKeywordLoc(TL.getKeywordLoc());
3324 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003325
3326 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327}
Mike Stump11289f42009-09-09 15:08:12 +00003328
3329template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003330QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3331 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003332 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003333 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003334
Douglas Gregord6ff3322009-08-04 16:50:30 +00003335 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003336 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3337 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003338 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003339 if (!NNS)
3340 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003341
John McCallc392f372010-06-11 00:33:02 +00003342 QualType Result
3343 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3344 T->getIdentifier(),
3345 TL.getKeywordLoc(),
3346 TL.getQualifierRange(),
3347 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003348 if (Result.isNull())
3349 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003350
Abramo Bagnarad7548482010-05-19 21:37:53 +00003351 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3352 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003353 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3354
Abramo Bagnarad7548482010-05-19 21:37:53 +00003355 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3356 NewTL.setKeywordLoc(TL.getKeywordLoc());
3357 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003358 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003359 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3360 NewTL.setKeywordLoc(TL.getKeywordLoc());
3361 NewTL.setQualifierRange(TL.getQualifierRange());
3362 NewTL.setNameLoc(TL.getNameLoc());
3363 }
John McCall550e0c22009-10-21 00:40:46 +00003364 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365}
Mike Stump11289f42009-09-09 15:08:12 +00003366
Douglas Gregord6ff3322009-08-04 16:50:30 +00003367template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003368QualType TreeTransform<Derived>::
3369 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3370 DependentTemplateSpecializationTypeLoc TL,
3371 QualType ObjectType) {
3372 DependentTemplateSpecializationType *T = TL.getTypePtr();
3373
3374 NestedNameSpecifier *NNS
3375 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3376 TL.getQualifierRange(),
3377 ObjectType);
3378 if (!NNS)
3379 return QualType();
3380
3381 TemplateArgumentListInfo NewTemplateArgs;
3382 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3383 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3384
3385 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3386 TemplateArgumentLoc Loc;
3387 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3388 return QualType();
3389 NewTemplateArgs.addArgument(Loc);
3390 }
3391
3392 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3393 T->getKeyword(),
3394 NNS,
3395 T->getIdentifier(),
3396 TL.getNameLoc(),
3397 NewTemplateArgs);
3398 if (Result.isNull())
3399 return QualType();
3400
3401 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3402 QualType NamedT = ElabT->getNamedType();
3403
3404 // Copy information relevant to the template specialization.
3405 TemplateSpecializationTypeLoc NamedTL
3406 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3407 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3408 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3409 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3410 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3411
3412 // Copy information relevant to the elaborated type.
3413 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3414 NewTL.setKeywordLoc(TL.getKeywordLoc());
3415 NewTL.setQualifierRange(TL.getQualifierRange());
3416 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003417 TypeLoc NewTL(Result, TL.getOpaqueData());
3418 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003419 }
3420 return Result;
3421}
3422
3423template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003424QualType
3425TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003426 ObjCInterfaceTypeLoc TL,
3427 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003428 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003429 TLB.pushFullCopy(TL);
3430 return TL.getType();
3431}
3432
3433template<typename Derived>
3434QualType
3435TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3436 ObjCObjectTypeLoc TL,
3437 QualType ObjectType) {
3438 // ObjCObjectType is never dependent.
3439 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003440 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003441}
Mike Stump11289f42009-09-09 15:08:12 +00003442
3443template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003444QualType
3445TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003446 ObjCObjectPointerTypeLoc TL,
3447 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003448 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003449 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003450 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003451}
3452
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003454// Statement transformation
3455//===----------------------------------------------------------------------===//
3456template<typename Derived>
3457Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003458TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3459 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003460}
3461
3462template<typename Derived>
3463Sema::OwningStmtResult
3464TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3465 return getDerived().TransformCompoundStmt(S, false);
3466}
3467
3468template<typename Derived>
3469Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003470TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003471 bool IsStmtExpr) {
3472 bool SubStmtChanged = false;
3473 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3474 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3475 B != BEnd; ++B) {
3476 OwningStmtResult Result = getDerived().TransformStmt(*B);
3477 if (Result.isInvalid())
3478 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003479
Douglas Gregorebe10102009-08-20 07:17:43 +00003480 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3481 Statements.push_back(Result.takeAs<Stmt>());
3482 }
Mike Stump11289f42009-09-09 15:08:12 +00003483
Douglas Gregorebe10102009-08-20 07:17:43 +00003484 if (!getDerived().AlwaysRebuild() &&
3485 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003486 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003487
3488 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3489 move_arg(Statements),
3490 S->getRBracLoc(),
3491 IsStmtExpr);
3492}
Mike Stump11289f42009-09-09 15:08:12 +00003493
Douglas Gregorebe10102009-08-20 07:17:43 +00003494template<typename Derived>
3495Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003496TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003497 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3498 {
3499 // The case value expressions are not potentially evaluated.
3500 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003501
Eli Friedman06577382009-11-19 03:14:00 +00003502 // Transform the left-hand case value.
3503 LHS = getDerived().TransformExpr(S->getLHS());
3504 if (LHS.isInvalid())
3505 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003506
Eli Friedman06577382009-11-19 03:14:00 +00003507 // Transform the right-hand case value (for the GNU case-range extension).
3508 RHS = getDerived().TransformExpr(S->getRHS());
3509 if (RHS.isInvalid())
3510 return SemaRef.StmtError();
3511 }
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregorebe10102009-08-20 07:17:43 +00003513 // Build the case statement.
3514 // Case statements are always rebuilt so that they will attached to their
3515 // transformed switch statement.
3516 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3517 move(LHS),
3518 S->getEllipsisLoc(),
3519 move(RHS),
3520 S->getColonLoc());
3521 if (Case.isInvalid())
3522 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 // Transform the statement following the case
3525 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3526 if (SubStmt.isInvalid())
3527 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003528
Douglas Gregorebe10102009-08-20 07:17:43 +00003529 // Attach the body to the case statement
3530 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3531}
3532
3533template<typename Derived>
3534Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // Transform the statement following the default case
3537 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3538 if (SubStmt.isInvalid())
3539 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003540
Douglas Gregorebe10102009-08-20 07:17:43 +00003541 // Default statements are always rebuilt
3542 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3543 move(SubStmt));
3544}
Mike Stump11289f42009-09-09 15:08:12 +00003545
Douglas Gregorebe10102009-08-20 07:17:43 +00003546template<typename Derived>
3547Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003548TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003549 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3550 if (SubStmt.isInvalid())
3551 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003552
Douglas Gregorebe10102009-08-20 07:17:43 +00003553 // FIXME: Pass the real colon location in.
3554 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3555 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3556 move(SubStmt));
3557}
Mike Stump11289f42009-09-09 15:08:12 +00003558
Douglas Gregorebe10102009-08-20 07:17:43 +00003559template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003560Sema::OwningStmtResult
3561TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003562 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003563 OwningExprResult Cond(SemaRef);
3564 VarDecl *ConditionVar = 0;
3565 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003566 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003567 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003568 getDerived().TransformDefinition(
3569 S->getConditionVariable()->getLocation(),
3570 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003571 if (!ConditionVar)
3572 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003573 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003574 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003575
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003576 if (Cond.isInvalid())
3577 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003578
3579 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003580 if (S->getCond()) {
3581 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3582 S->getIfLoc(),
3583 move(Cond));
3584 if (CondE.isInvalid())
3585 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003586
Douglas Gregor6d319c62010-05-08 23:34:38 +00003587 Cond = move(CondE);
3588 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003589 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003590
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003591 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3592 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3593 return SemaRef.StmtError();
3594
Douglas Gregorebe10102009-08-20 07:17:43 +00003595 // Transform the "then" branch.
3596 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3597 if (Then.isInvalid())
3598 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003599
Douglas Gregorebe10102009-08-20 07:17:43 +00003600 // Transform the "else" branch.
3601 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3602 if (Else.isInvalid())
3603 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003604
Douglas Gregorebe10102009-08-20 07:17:43 +00003605 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003606 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003607 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003608 Then.get() == S->getThen() &&
3609 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003610 return SemaRef.Owned(S->Retain());
3611
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003612 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003613 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003614 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003615}
3616
3617template<typename Derived>
3618Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003619TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003621 OwningExprResult Cond(SemaRef);
3622 VarDecl *ConditionVar = 0;
3623 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003624 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003625 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003626 getDerived().TransformDefinition(
3627 S->getConditionVariable()->getLocation(),
3628 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003629 if (!ConditionVar)
3630 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003631 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003632 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003633
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003634 if (Cond.isInvalid())
3635 return SemaRef.StmtError();
3636 }
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregorebe10102009-08-20 07:17:43 +00003638 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003639 OwningStmtResult Switch
3640 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3641 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 if (Switch.isInvalid())
3643 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 // Transform the body of the switch statement.
3646 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3647 if (Body.isInvalid())
3648 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003649
Douglas Gregorebe10102009-08-20 07:17:43 +00003650 // Complete the switch statement.
3651 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3652 move(Body));
3653}
Mike Stump11289f42009-09-09 15:08:12 +00003654
Douglas Gregorebe10102009-08-20 07:17:43 +00003655template<typename Derived>
3656Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003657TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003658 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003659 OwningExprResult Cond(SemaRef);
3660 VarDecl *ConditionVar = 0;
3661 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003662 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003663 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003664 getDerived().TransformDefinition(
3665 S->getConditionVariable()->getLocation(),
3666 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003667 if (!ConditionVar)
3668 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003669 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003670 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003671
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003672 if (Cond.isInvalid())
3673 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003674
3675 if (S->getCond()) {
3676 // Convert the condition to a boolean value.
3677 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003678 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003679 move(Cond));
3680 if (CondE.isInvalid())
3681 return getSema().StmtError();
3682 Cond = move(CondE);
3683 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003684 }
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003686 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3687 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3688 return SemaRef.StmtError();
3689
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 // Transform the body
3691 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3692 if (Body.isInvalid())
3693 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregorebe10102009-08-20 07:17:43 +00003695 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003696 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003697 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003698 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003699 return SemaRef.Owned(S->Retain());
3700
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003701 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003702 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003703}
Mike Stump11289f42009-09-09 15:08:12 +00003704
Douglas Gregorebe10102009-08-20 07:17:43 +00003705template<typename Derived>
3706Sema::OwningStmtResult
3707TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 // Transform the body
3709 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3710 if (Body.isInvalid())
3711 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003713 // Transform the condition
3714 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3715 if (Cond.isInvalid())
3716 return SemaRef.StmtError();
3717
Douglas Gregorebe10102009-08-20 07:17:43 +00003718 if (!getDerived().AlwaysRebuild() &&
3719 Cond.get() == S->getCond() &&
3720 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003721 return SemaRef.Owned(S->Retain());
3722
Douglas Gregorebe10102009-08-20 07:17:43 +00003723 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3724 /*FIXME:*/S->getWhileLoc(), move(Cond),
3725 S->getRParenLoc());
3726}
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregorebe10102009-08-20 07:17:43 +00003728template<typename Derived>
3729Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003730TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 // Transform the initialization statement
3732 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3733 if (Init.isInvalid())
3734 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003735
Douglas Gregorebe10102009-08-20 07:17:43 +00003736 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003737 OwningExprResult Cond(SemaRef);
3738 VarDecl *ConditionVar = 0;
3739 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003740 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003741 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003742 getDerived().TransformDefinition(
3743 S->getConditionVariable()->getLocation(),
3744 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003745 if (!ConditionVar)
3746 return SemaRef.StmtError();
3747 } else {
3748 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003749
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003750 if (Cond.isInvalid())
3751 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003752
3753 if (S->getCond()) {
3754 // Convert the condition to a boolean value.
3755 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3756 S->getForLoc(),
3757 move(Cond));
3758 if (CondE.isInvalid())
3759 return getSema().StmtError();
3760
3761 Cond = move(CondE);
3762 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003763 }
Mike Stump11289f42009-09-09 15:08:12 +00003764
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003765 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3766 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3767 return SemaRef.StmtError();
3768
Douglas Gregorebe10102009-08-20 07:17:43 +00003769 // Transform the increment
3770 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3771 if (Inc.isInvalid())
3772 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003773
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003774 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3775 if (S->getInc() && !FullInc->get())
3776 return SemaRef.StmtError();
3777
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 // Transform the body
3779 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3780 if (Body.isInvalid())
3781 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003782
Douglas Gregorebe10102009-08-20 07:17:43 +00003783 if (!getDerived().AlwaysRebuild() &&
3784 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003785 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003786 Inc.get() == S->getInc() &&
3787 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003788 return SemaRef.Owned(S->Retain());
3789
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003791 move(Init), FullCond, ConditionVar,
3792 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003793}
3794
3795template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003796Sema::OwningStmtResult
3797TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003798 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003799 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003800 S->getLabel());
3801}
3802
3803template<typename Derived>
3804Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003805TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003806 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3807 if (Target.isInvalid())
3808 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003809
Douglas Gregorebe10102009-08-20 07:17:43 +00003810 if (!getDerived().AlwaysRebuild() &&
3811 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003812 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003813
3814 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3815 move(Target));
3816}
3817
3818template<typename Derived>
3819Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003820TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3821 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003822}
Mike Stump11289f42009-09-09 15:08:12 +00003823
Douglas Gregorebe10102009-08-20 07:17:43 +00003824template<typename Derived>
3825Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003826TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3827 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003828}
Mike Stump11289f42009-09-09 15:08:12 +00003829
Douglas Gregorebe10102009-08-20 07:17:43 +00003830template<typename Derived>
3831Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003832TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003833 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3834 if (Result.isInvalid())
3835 return SemaRef.StmtError();
3836
Mike Stump11289f42009-09-09 15:08:12 +00003837 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003838 // to tell whether the return type of the function has changed.
3839 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3840}
Mike Stump11289f42009-09-09 15:08:12 +00003841
Douglas Gregorebe10102009-08-20 07:17:43 +00003842template<typename Derived>
3843Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003844TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003845 bool DeclChanged = false;
3846 llvm::SmallVector<Decl *, 4> Decls;
3847 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3848 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003849 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3850 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003851 if (!Transformed)
3852 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003853
Douglas Gregorebe10102009-08-20 07:17:43 +00003854 if (Transformed != *D)
3855 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003856
Douglas Gregorebe10102009-08-20 07:17:43 +00003857 Decls.push_back(Transformed);
3858 }
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregorebe10102009-08-20 07:17:43 +00003860 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003861 return SemaRef.Owned(S->Retain());
3862
3863 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003864 S->getStartLoc(), S->getEndLoc());
3865}
Mike Stump11289f42009-09-09 15:08:12 +00003866
Douglas Gregorebe10102009-08-20 07:17:43 +00003867template<typename Derived>
3868Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003869TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003870 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003871 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003872}
3873
3874template<typename Derived>
3875Sema::OwningStmtResult
3876TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003877
Anders Carlssonaaeef072010-01-24 05:50:09 +00003878 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3879 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003880 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003881
Anders Carlssonaaeef072010-01-24 05:50:09 +00003882 OwningExprResult AsmString(SemaRef);
3883 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3884
3885 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003886
Anders Carlssonaaeef072010-01-24 05:50:09 +00003887 // Go through the outputs.
3888 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003889 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003890
Anders Carlssonaaeef072010-01-24 05:50:09 +00003891 // No need to transform the constraint literal.
3892 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003893
Anders Carlssonaaeef072010-01-24 05:50:09 +00003894 // Transform the output expr.
3895 Expr *OutputExpr = S->getOutputExpr(I);
3896 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3897 if (Result.isInvalid())
3898 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003899
Anders Carlssonaaeef072010-01-24 05:50:09 +00003900 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003901
Anders Carlssonaaeef072010-01-24 05:50:09 +00003902 Exprs.push_back(Result.takeAs<Expr>());
3903 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003904
Anders Carlssonaaeef072010-01-24 05:50:09 +00003905 // Go through the inputs.
3906 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003907 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003908
Anders Carlssonaaeef072010-01-24 05:50:09 +00003909 // No need to transform the constraint literal.
3910 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003911
Anders Carlssonaaeef072010-01-24 05:50:09 +00003912 // Transform the input expr.
3913 Expr *InputExpr = S->getInputExpr(I);
3914 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3915 if (Result.isInvalid())
3916 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003917
Anders Carlssonaaeef072010-01-24 05:50:09 +00003918 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003919
Anders Carlssonaaeef072010-01-24 05:50:09 +00003920 Exprs.push_back(Result.takeAs<Expr>());
3921 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003922
Anders Carlssonaaeef072010-01-24 05:50:09 +00003923 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3924 return SemaRef.Owned(S->Retain());
3925
3926 // Go through the clobbers.
3927 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3928 Clobbers.push_back(S->getClobber(I)->Retain());
3929
3930 // No need to transform the asm string literal.
3931 AsmString = SemaRef.Owned(S->getAsmString());
3932
3933 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3934 S->isSimple(),
3935 S->isVolatile(),
3936 S->getNumOutputs(),
3937 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003938 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003939 move_arg(Constraints),
3940 move_arg(Exprs),
3941 move(AsmString),
3942 move_arg(Clobbers),
3943 S->getRParenLoc(),
3944 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003945}
3946
3947
3948template<typename Derived>
3949Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003950TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003951 // Transform the body of the @try.
3952 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3953 if (TryBody.isInvalid())
3954 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003955
Douglas Gregor96c79492010-04-23 22:50:49 +00003956 // Transform the @catch statements (if present).
3957 bool AnyCatchChanged = false;
3958 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3959 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3960 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003961 if (Catch.isInvalid())
3962 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003963 if (Catch.get() != S->getCatchStmt(I))
3964 AnyCatchChanged = true;
3965 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003966 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003967
Douglas Gregor306de2f2010-04-22 23:59:56 +00003968 // Transform the @finally statement (if present).
3969 OwningStmtResult Finally(SemaRef);
3970 if (S->getFinallyStmt()) {
3971 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3972 if (Finally.isInvalid())
3973 return SemaRef.StmtError();
3974 }
3975
3976 // If nothing changed, just retain this statement.
3977 if (!getDerived().AlwaysRebuild() &&
3978 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003979 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003980 Finally.get() == S->getFinallyStmt())
3981 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003982
Douglas Gregor306de2f2010-04-22 23:59:56 +00003983 // Build a new statement.
3984 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003985 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003986}
Mike Stump11289f42009-09-09 15:08:12 +00003987
Douglas Gregorebe10102009-08-20 07:17:43 +00003988template<typename Derived>
3989Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003990TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003991 // Transform the @catch parameter, if there is one.
3992 VarDecl *Var = 0;
3993 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3994 TypeSourceInfo *TSInfo = 0;
3995 if (FromVar->getTypeSourceInfo()) {
3996 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3997 if (!TSInfo)
3998 return SemaRef.StmtError();
3999 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004000
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004001 QualType T;
4002 if (TSInfo)
4003 T = TSInfo->getType();
4004 else {
4005 T = getDerived().TransformType(FromVar->getType());
4006 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00004007 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004008 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004009
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004010 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4011 if (!Var)
4012 return SemaRef.StmtError();
4013 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004014
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004015 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4016 if (Body.isInvalid())
4017 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004018
4019 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004020 S->getRParenLoc(),
4021 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004022}
Mike Stump11289f42009-09-09 15:08:12 +00004023
Douglas Gregorebe10102009-08-20 07:17:43 +00004024template<typename Derived>
4025Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004026TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004027 // Transform the body.
4028 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4029 if (Body.isInvalid())
4030 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004031
Douglas Gregor306de2f2010-04-22 23:59:56 +00004032 // If nothing changed, just retain this statement.
4033 if (!getDerived().AlwaysRebuild() &&
4034 Body.get() == S->getFinallyBody())
4035 return SemaRef.Owned(S->Retain());
4036
4037 // Build a new statement.
4038 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4039 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004040}
Mike Stump11289f42009-09-09 15:08:12 +00004041
Douglas Gregorebe10102009-08-20 07:17:43 +00004042template<typename Derived>
4043Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004044TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00004045 OwningExprResult Operand(SemaRef);
4046 if (S->getThrowExpr()) {
4047 Operand = getDerived().TransformExpr(S->getThrowExpr());
4048 if (Operand.isInvalid())
4049 return getSema().StmtError();
4050 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004051
Douglas Gregor2900c162010-04-22 21:44:01 +00004052 if (!getDerived().AlwaysRebuild() &&
4053 Operand.get() == S->getThrowExpr())
4054 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004055
Douglas Gregor2900c162010-04-22 21:44:01 +00004056 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00004057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregorebe10102009-08-20 07:17:43 +00004059template<typename Derived>
4060Sema::OwningStmtResult
4061TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004062 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004063 // Transform the object we are locking.
4064 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4065 if (Object.isInvalid())
4066 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004067
Douglas Gregor6148de72010-04-22 22:01:21 +00004068 // Transform the body.
4069 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4070 if (Body.isInvalid())
4071 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004072
Douglas Gregor6148de72010-04-22 22:01:21 +00004073 // If nothing change, just retain the current statement.
4074 if (!getDerived().AlwaysRebuild() &&
4075 Object.get() == S->getSynchExpr() &&
4076 Body.get() == S->getSynchBody())
4077 return SemaRef.Owned(S->Retain());
4078
4079 // Build a new statement.
4080 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4081 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004082}
4083
4084template<typename Derived>
4085Sema::OwningStmtResult
4086TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004087 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004088 // Transform the element statement.
4089 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4090 if (Element.isInvalid())
4091 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004092
Douglas Gregorf68a5082010-04-22 23:10:45 +00004093 // Transform the collection expression.
4094 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4095 if (Collection.isInvalid())
4096 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004097
Douglas Gregorf68a5082010-04-22 23:10:45 +00004098 // Transform the body.
4099 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4100 if (Body.isInvalid())
4101 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004102
Douglas Gregorf68a5082010-04-22 23:10:45 +00004103 // If nothing changed, just retain this statement.
4104 if (!getDerived().AlwaysRebuild() &&
4105 Element.get() == S->getElement() &&
4106 Collection.get() == S->getCollection() &&
4107 Body.get() == S->getBody())
4108 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004109
Douglas Gregorf68a5082010-04-22 23:10:45 +00004110 // Build a new statement.
4111 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4112 /*FIXME:*/S->getForLoc(),
4113 move(Element),
4114 move(Collection),
4115 S->getRParenLoc(),
4116 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004117}
4118
4119
4120template<typename Derived>
4121Sema::OwningStmtResult
4122TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4123 // Transform the exception declaration, if any.
4124 VarDecl *Var = 0;
4125 if (S->getExceptionDecl()) {
4126 VarDecl *ExceptionDecl = S->getExceptionDecl();
4127 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4128 ExceptionDecl->getDeclName());
4129
4130 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4131 if (T.isNull())
4132 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregorebe10102009-08-20 07:17:43 +00004134 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4135 T,
John McCallbcd03502009-12-07 02:54:59 +00004136 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004137 ExceptionDecl->getIdentifier(),
4138 ExceptionDecl->getLocation(),
4139 /*FIXME: Inaccurate*/
4140 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004141 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004142 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004143 }
Mike Stump11289f42009-09-09 15:08:12 +00004144
Douglas Gregorebe10102009-08-20 07:17:43 +00004145 // Transform the actual exception handler.
4146 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004147 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004148 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregorebe10102009-08-20 07:17:43 +00004150 if (!getDerived().AlwaysRebuild() &&
4151 !Var &&
4152 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004153 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004154
4155 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4156 Var,
4157 move(Handler));
4158}
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregorebe10102009-08-20 07:17:43 +00004160template<typename Derived>
4161Sema::OwningStmtResult
4162TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4163 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004164 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004165 = getDerived().TransformCompoundStmt(S->getTryBlock());
4166 if (TryBlock.isInvalid())
4167 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregorebe10102009-08-20 07:17:43 +00004169 // Transform the handlers.
4170 bool HandlerChanged = false;
4171 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4172 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004173 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004174 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4175 if (Handler.isInvalid())
4176 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004177
Douglas Gregorebe10102009-08-20 07:17:43 +00004178 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4179 Handlers.push_back(Handler.takeAs<Stmt>());
4180 }
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregorebe10102009-08-20 07:17:43 +00004182 if (!getDerived().AlwaysRebuild() &&
4183 TryBlock.get() == S->getTryBlock() &&
4184 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004185 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004186
4187 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004188 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004189}
Mike Stump11289f42009-09-09 15:08:12 +00004190
Douglas Gregorebe10102009-08-20 07:17:43 +00004191//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004192// Expression transformation
4193//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004194template<typename Derived>
4195Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004196TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004197 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004198}
Mike Stump11289f42009-09-09 15:08:12 +00004199
4200template<typename Derived>
4201Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004202TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004203 NestedNameSpecifier *Qualifier = 0;
4204 if (E->getQualifier()) {
4205 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004206 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004207 if (!Qualifier)
4208 return SemaRef.ExprError();
4209 }
John McCallce546572009-12-08 09:08:17 +00004210
4211 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004212 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4213 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004214 if (!ND)
4215 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004216
John McCall815039a2010-08-17 21:27:17 +00004217 DeclarationNameInfo NameInfo = E->getNameInfo();
4218 if (NameInfo.getName()) {
4219 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4220 if (!NameInfo.getName())
4221 return SemaRef.ExprError();
4222 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004223
4224 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004225 Qualifier == E->getQualifier() &&
4226 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004227 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004228 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004229
4230 // Mark it referenced in the new context regardless.
4231 // FIXME: this is a bit instantiation-specific.
4232 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4233
Mike Stump11289f42009-09-09 15:08:12 +00004234 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004235 }
John McCallce546572009-12-08 09:08:17 +00004236
4237 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004238 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004239 TemplateArgs = &TransArgs;
4240 TransArgs.setLAngleLoc(E->getLAngleLoc());
4241 TransArgs.setRAngleLoc(E->getRAngleLoc());
4242 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4243 TemplateArgumentLoc Loc;
4244 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4245 return SemaRef.ExprError();
4246 TransArgs.addArgument(Loc);
4247 }
4248 }
4249
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004250 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004251 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004252}
Mike Stump11289f42009-09-09 15:08:12 +00004253
Douglas Gregora16548e2009-08-11 05:31:07 +00004254template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004255Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004256TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004257 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004258}
Mike Stump11289f42009-09-09 15:08:12 +00004259
Douglas Gregora16548e2009-08-11 05:31:07 +00004260template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004261Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004262TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004263 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004264}
Mike Stump11289f42009-09-09 15:08:12 +00004265
Douglas Gregora16548e2009-08-11 05:31:07 +00004266template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004267Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004268TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004269 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004270}
Mike Stump11289f42009-09-09 15:08:12 +00004271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004273Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004274TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004275 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004276}
Mike Stump11289f42009-09-09 15:08:12 +00004277
Douglas Gregora16548e2009-08-11 05:31:07 +00004278template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004279Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004280TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004281 return SemaRef.Owned(E->Retain());
4282}
4283
4284template<typename Derived>
4285Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004286TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004287 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4288 if (SubExpr.isInvalid())
4289 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004292 return SemaRef.Owned(E->Retain());
4293
4294 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 E->getRParen());
4296}
4297
Mike Stump11289f42009-09-09 15:08:12 +00004298template<typename Derived>
4299Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004300TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4301 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 if (SubExpr.isInvalid())
4303 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004306 return SemaRef.Owned(E->Retain());
4307
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4309 E->getOpcode(),
4310 move(SubExpr));
4311}
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004314Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004315TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4316 // Transform the type.
4317 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4318 if (!Type)
4319 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004320
Douglas Gregor882211c2010-04-28 22:16:22 +00004321 // Transform all of the components into components similar to what the
4322 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004323 // FIXME: It would be slightly more efficient in the non-dependent case to
4324 // just map FieldDecls, rather than requiring the rebuilder to look for
4325 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004326 // template code that we don't care.
4327 bool ExprChanged = false;
4328 typedef Action::OffsetOfComponent Component;
4329 typedef OffsetOfExpr::OffsetOfNode Node;
4330 llvm::SmallVector<Component, 4> Components;
4331 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4332 const Node &ON = E->getComponent(I);
4333 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004334 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004335 Comp.LocStart = ON.getRange().getBegin();
4336 Comp.LocEnd = ON.getRange().getEnd();
4337 switch (ON.getKind()) {
4338 case Node::Array: {
4339 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4340 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4341 if (Index.isInvalid())
4342 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004343
Douglas Gregor882211c2010-04-28 22:16:22 +00004344 ExprChanged = ExprChanged || Index.get() != FromIndex;
4345 Comp.isBrackets = true;
4346 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4347 break;
4348 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004349
Douglas Gregor882211c2010-04-28 22:16:22 +00004350 case Node::Field:
4351 case Node::Identifier:
4352 Comp.isBrackets = false;
4353 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004354 if (!Comp.U.IdentInfo)
4355 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004356
Douglas Gregor882211c2010-04-28 22:16:22 +00004357 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004358
Douglas Gregord1702062010-04-29 00:18:15 +00004359 case Node::Base:
4360 // Will be recomputed during the rebuild.
4361 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004362 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004363
Douglas Gregor882211c2010-04-28 22:16:22 +00004364 Components.push_back(Comp);
4365 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004366
Douglas Gregor882211c2010-04-28 22:16:22 +00004367 // If nothing changed, retain the existing expression.
4368 if (!getDerived().AlwaysRebuild() &&
4369 Type == E->getTypeSourceInfo() &&
4370 !ExprChanged)
4371 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004372
Douglas Gregor882211c2010-04-28 22:16:22 +00004373 // Build a new offsetof expression.
4374 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4375 Components.data(), Components.size(),
4376 E->getRParenLoc());
4377}
4378
4379template<typename Derived>
4380Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004381TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004383 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004384
John McCallbcd03502009-12-07 02:54:59 +00004385 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004386 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004388
John McCall4c98fd82009-11-04 07:28:41 +00004389 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004391
John McCall4c98fd82009-11-04 07:28:41 +00004392 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004393 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 E->getSourceRange());
4395 }
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004398 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004399 // C++0x [expr.sizeof]p1:
4400 // The operand is either an expression, which is an unevaluated operand
4401 // [...]
4402 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4405 if (SubExpr.isInvalid())
4406 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4409 return SemaRef.Owned(E->Retain());
4410 }
Mike Stump11289f42009-09-09 15:08:12 +00004411
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4413 E->isSizeOf(),
4414 E->getSourceRange());
4415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4421 if (LHS.isInvalid())
4422 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4425 if (RHS.isInvalid())
4426 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004427
4428
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 if (!getDerived().AlwaysRebuild() &&
4430 LHS.get() == E->getLHS() &&
4431 RHS.get() == E->getRHS())
4432 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4435 /*FIXME:*/E->getLHS()->getLocStart(),
4436 move(RHS),
4437 E->getRBracketLoc());
4438}
Mike Stump11289f42009-09-09 15:08:12 +00004439
4440template<typename Derived>
4441Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004442TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 // Transform the callee.
4444 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4445 if (Callee.isInvalid())
4446 return SemaRef.ExprError();
4447
4448 // Transform arguments.
4449 bool ArgChanged = false;
4450 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4451 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4452 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4453 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4454 if (Arg.isInvalid())
4455 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004456
Douglas Gregora16548e2009-08-11 05:31:07 +00004457 // FIXME: Wrong source location information for the ','.
4458 FakeCommaLocs.push_back(
4459 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004460
4461 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 Args.push_back(Arg.takeAs<Expr>());
4463 }
Mike Stump11289f42009-09-09 15:08:12 +00004464
Douglas Gregora16548e2009-08-11 05:31:07 +00004465 if (!getDerived().AlwaysRebuild() &&
4466 Callee.get() == E->getCallee() &&
4467 !ArgChanged)
4468 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004469
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004471 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4473 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4474 move_arg(Args),
4475 FakeCommaLocs.data(),
4476 E->getRParenLoc());
4477}
Mike Stump11289f42009-09-09 15:08:12 +00004478
4479template<typename Derived>
4480Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004481TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4483 if (Base.isInvalid())
4484 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004486 NestedNameSpecifier *Qualifier = 0;
4487 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004488 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004489 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004490 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004491 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004492 return SemaRef.ExprError();
4493 }
Mike Stump11289f42009-09-09 15:08:12 +00004494
Eli Friedman2cfcef62009-12-04 06:40:45 +00004495 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004496 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4497 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 if (!Member)
4499 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004500
John McCall16df1e52010-03-30 21:47:33 +00004501 NamedDecl *FoundDecl = E->getFoundDecl();
4502 if (FoundDecl == E->getMemberDecl()) {
4503 FoundDecl = Member;
4504 } else {
4505 FoundDecl = cast_or_null<NamedDecl>(
4506 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4507 if (!FoundDecl)
4508 return SemaRef.ExprError();
4509 }
4510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 if (!getDerived().AlwaysRebuild() &&
4512 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004513 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004514 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004515 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004516 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004517
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004518 // Mark it referenced in the new context regardless.
4519 // FIXME: this is a bit instantiation-specific.
4520 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004521 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004522 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004523
John McCall6b51f282009-11-23 01:53:49 +00004524 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004525 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004526 TransArgs.setLAngleLoc(E->getLAngleLoc());
4527 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004528 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004529 TemplateArgumentLoc Loc;
4530 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004531 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004532 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004533 }
4534 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004535
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 // FIXME: Bogus source location for the operator
4537 SourceLocation FakeOperatorLoc
4538 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4539
John McCall38836f02010-01-15 08:34:02 +00004540 // FIXME: to do this check properly, we will need to preserve the
4541 // first-qualifier-in-scope here, just in case we had a dependent
4542 // base (and therefore couldn't do the check) and a
4543 // nested-name-qualifier (and therefore could do the lookup).
4544 NamedDecl *FirstQualifierInScope = 0;
4545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4547 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004548 Qualifier,
4549 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004550 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004551 Member,
John McCall16df1e52010-03-30 21:47:33 +00004552 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004553 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004554 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004555 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004556}
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004559Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004560TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4562 if (LHS.isInvalid())
4563 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4566 if (RHS.isInvalid())
4567 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregora16548e2009-08-11 05:31:07 +00004569 if (!getDerived().AlwaysRebuild() &&
4570 LHS.get() == E->getLHS() &&
4571 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004572 return SemaRef.Owned(E->Retain());
4573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4575 move(LHS), move(RHS));
4576}
4577
Mike Stump11289f42009-09-09 15:08:12 +00004578template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004579Sema::OwningExprResult
4580TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004581 CompoundAssignOperator *E) {
4582 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004586Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004587TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004588 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4589 if (Cond.isInvalid())
4590 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4593 if (LHS.isInvalid())
4594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4597 if (RHS.isInvalid())
4598 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004599
Douglas Gregora16548e2009-08-11 05:31:07 +00004600 if (!getDerived().AlwaysRebuild() &&
4601 Cond.get() == E->getCond() &&
4602 LHS.get() == E->getLHS() &&
4603 RHS.get() == E->getRHS())
4604 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004605
4606 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004607 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004608 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004609 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004610 move(RHS));
4611}
Mike Stump11289f42009-09-09 15:08:12 +00004612
4613template<typename Derived>
4614Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004615TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004616 // Implicit casts are eliminated during transformation, since they
4617 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004618 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004619}
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregora16548e2009-08-11 05:31:07 +00004621template<typename Derived>
4622Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004623TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004624 TypeSourceInfo *OldT;
4625 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 {
4627 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004628 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4630 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004631
John McCall97513962010-01-15 18:39:57 +00004632 OldT = E->getTypeInfoAsWritten();
4633 NewT = getDerived().TransformType(OldT);
4634 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 return SemaRef.ExprError();
4636 }
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregor6131b442009-12-12 18:16:41 +00004638 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004639 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 if (SubExpr.isInvalid())
4641 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004644 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004645 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004646 return SemaRef.Owned(E->Retain());
4647
John McCall97513962010-01-15 18:39:57 +00004648 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4649 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 E->getRParenLoc(),
4651 move(SubExpr));
4652}
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregora16548e2009-08-11 05:31:07 +00004654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004655Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004656TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004657 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4658 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4659 if (!NewT)
4660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4663 if (Init.isInvalid())
4664 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004667 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004669 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004670
John McCall5d7aa7f2010-01-19 22:33:45 +00004671 // Note: the expression type doesn't necessarily match the
4672 // type-as-written, but that's okay, because it should always be
4673 // derivable from the initializer.
4674
John McCalle15bbff2010-01-18 19:35:47 +00004675 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 /*FIXME:*/E->getInitializer()->getLocEnd(),
4677 move(Init));
4678}
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680template<typename Derived>
4681Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004682TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004683 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4684 if (Base.isInvalid())
4685 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687 if (!getDerived().AlwaysRebuild() &&
4688 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004689 return SemaRef.Owned(E->Retain());
4690
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004692 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4694 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4695 E->getAccessorLoc(),
4696 E->getAccessor());
4697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregora16548e2009-08-11 05:31:07 +00004699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004700Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004701TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4705 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4706 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4707 if (Init.isInvalid())
4708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 InitChanged = InitChanged || Init.get() != E->getInit(I);
4711 Inits.push_back(Init.takeAs<Expr>());
4712 }
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004715 return SemaRef.Owned(E->Retain());
4716
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004718 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004719}
Mike Stump11289f42009-09-09 15:08:12 +00004720
Douglas Gregora16548e2009-08-11 05:31:07 +00004721template<typename Derived>
4722Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004723TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004725
Douglas Gregorebe10102009-08-20 07:17:43 +00004726 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4728 if (Init.isInvalid())
4729 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004730
Douglas Gregorebe10102009-08-20 07:17:43 +00004731 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4733 bool ExprChanged = false;
4734 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4735 DEnd = E->designators_end();
4736 D != DEnd; ++D) {
4737 if (D->isFieldDesignator()) {
4738 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4739 D->getDotLoc(),
4740 D->getFieldLoc()));
4741 continue;
4742 }
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 if (D->isArrayDesignator()) {
4745 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4746 if (Index.isInvalid())
4747 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004748
4749 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4753 ArrayExprs.push_back(Index.release());
4754 continue;
4755 }
Mike Stump11289f42009-09-09 15:08:12 +00004756
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004758 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4760 if (Start.isInvalid())
4761 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4764 if (End.isInvalid())
4765 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004766
4767 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 End.get(),
4769 D->getLBracketLoc(),
4770 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4773 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 ArrayExprs.push_back(Start.release());
4776 ArrayExprs.push_back(End.release());
4777 }
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 if (!getDerived().AlwaysRebuild() &&
4780 Init.get() == E->getInit() &&
4781 !ExprChanged)
4782 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4785 E->getEqualOrColonLoc(),
4786 E->usesGNUSyntax(), move(Init));
4787}
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004790Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004791TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004792 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004793 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004794
Douglas Gregor3da3c062009-10-28 00:29:27 +00004795 // FIXME: Will we ever have proper type location here? Will we actually
4796 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 QualType T = getDerived().TransformType(E->getType());
4798 if (T.isNull())
4799 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004800
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 if (!getDerived().AlwaysRebuild() &&
4802 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004803 return SemaRef.Owned(E->Retain());
4804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 return getDerived().RebuildImplicitValueInitExpr(T);
4806}
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregora16548e2009-08-11 05:31:07 +00004808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004809Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004810TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004811 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4812 if (!TInfo)
4813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4816 if (SubExpr.isInvalid())
4817 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004820 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004821 SubExpr.get() == E->getSubExpr())
4822 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004825 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004826}
4827
4828template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004829Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004830TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 bool ArgumentChanged = false;
4832 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4833 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4834 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4835 if (Init.isInvalid())
4836 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4839 Inits.push_back(Init.takeAs<Expr>());
4840 }
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4843 move_arg(Inits),
4844 E->getRParenLoc());
4845}
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregora16548e2009-08-11 05:31:07 +00004847/// \brief Transform an address-of-label expression.
4848///
4849/// By default, the transformation of an address-of-label expression always
4850/// rebuilds the expression, so that the label identifier can be resolved to
4851/// the corresponding label statement by semantic analysis.
4852template<typename Derived>
4853Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004854TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004855 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4856 E->getLabel());
4857}
Mike Stump11289f42009-09-09 15:08:12 +00004858
4859template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004860Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004861TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004862 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4864 if (SubStmt.isInvalid())
4865 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004866
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 if (!getDerived().AlwaysRebuild() &&
4868 SubStmt.get() == E->getSubStmt())
4869 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004870
4871 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 move(SubStmt),
4873 E->getRParenLoc());
4874}
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregora16548e2009-08-11 05:31:07 +00004876template<typename Derived>
4877Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004878TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004879 TypeSourceInfo *TInfo1;
4880 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004881
4882 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4883 if (!TInfo1)
4884 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregor7058c262010-08-10 14:27:00 +00004886 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4887 if (!TInfo2)
4888 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004889
4890 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004891 TInfo1 == E->getArgTInfo1() &&
4892 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004893 return SemaRef.Owned(E->Retain());
4894
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004896 TInfo1, TInfo2,
4897 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004898}
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregora16548e2009-08-11 05:31:07 +00004900template<typename Derived>
4901Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004902TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4904 if (Cond.isInvalid())
4905 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004906
Douglas Gregora16548e2009-08-11 05:31:07 +00004907 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4908 if (LHS.isInvalid())
4909 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4912 if (RHS.isInvalid())
4913 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregora16548e2009-08-11 05:31:07 +00004915 if (!getDerived().AlwaysRebuild() &&
4916 Cond.get() == E->getCond() &&
4917 LHS.get() == E->getLHS() &&
4918 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004919 return SemaRef.Owned(E->Retain());
4920
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4922 move(Cond), move(LHS), move(RHS),
4923 E->getRParenLoc());
4924}
Mike Stump11289f42009-09-09 15:08:12 +00004925
Douglas Gregora16548e2009-08-11 05:31:07 +00004926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004927Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004928TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004929 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004930}
4931
4932template<typename Derived>
4933Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004934TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004935 switch (E->getOperator()) {
4936 case OO_New:
4937 case OO_Delete:
4938 case OO_Array_New:
4939 case OO_Array_Delete:
4940 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4941 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004942
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004943 case OO_Call: {
4944 // This is a call to an object's operator().
4945 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4946
4947 // Transform the object itself.
4948 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4949 if (Object.isInvalid())
4950 return SemaRef.ExprError();
4951
4952 // FIXME: Poor location information
4953 SourceLocation FakeLParenLoc
4954 = SemaRef.PP.getLocForEndOfToken(
4955 static_cast<Expr *>(Object.get())->getLocEnd());
4956
4957 // Transform the call arguments.
4958 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4959 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4960 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004961 if (getDerived().DropCallArgument(E->getArg(I)))
4962 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004963
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004964 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4965 if (Arg.isInvalid())
4966 return SemaRef.ExprError();
4967
4968 // FIXME: Poor source location information.
4969 SourceLocation FakeCommaLoc
4970 = SemaRef.PP.getLocForEndOfToken(
4971 static_cast<Expr *>(Arg.get())->getLocEnd());
4972 FakeCommaLocs.push_back(FakeCommaLoc);
4973 Args.push_back(Arg.release());
4974 }
4975
4976 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4977 move_arg(Args),
4978 FakeCommaLocs.data(),
4979 E->getLocEnd());
4980 }
4981
4982#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4983 case OO_##Name:
4984#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4985#include "clang/Basic/OperatorKinds.def"
4986 case OO_Subscript:
4987 // Handled below.
4988 break;
4989
4990 case OO_Conditional:
4991 llvm_unreachable("conditional operator is not actually overloadable");
4992 return SemaRef.ExprError();
4993
4994 case OO_None:
4995 case NUM_OVERLOADED_OPERATORS:
4996 llvm_unreachable("not an overloaded operator?");
4997 return SemaRef.ExprError();
4998 }
4999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
5001 if (Callee.isInvalid())
5002 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
John McCall47f29ea2009-12-08 09:21:05 +00005004 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 if (First.isInvalid())
5006 return SemaRef.ExprError();
5007
5008 OwningExprResult Second(SemaRef);
5009 if (E->getNumArgs() == 2) {
5010 Second = getDerived().TransformExpr(E->getArg(1));
5011 if (Second.isInvalid())
5012 return SemaRef.ExprError();
5013 }
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 if (!getDerived().AlwaysRebuild() &&
5016 Callee.get() == E->getCallee() &&
5017 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005018 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5019 return SemaRef.Owned(E->Retain());
5020
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5022 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005023 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 move(First),
5025 move(Second));
5026}
Mike Stump11289f42009-09-09 15:08:12 +00005027
Douglas Gregora16548e2009-08-11 05:31:07 +00005028template<typename Derived>
5029Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005030TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5031 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005032}
Mike Stump11289f42009-09-09 15:08:12 +00005033
Douglas Gregora16548e2009-08-11 05:31:07 +00005034template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005035Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005036TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005037 TypeSourceInfo *OldT;
5038 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005039 {
5040 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005041 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5043 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005044
John McCall97513962010-01-15 18:39:57 +00005045 OldT = E->getTypeInfoAsWritten();
5046 NewT = getDerived().TransformType(OldT);
5047 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 return SemaRef.ExprError();
5049 }
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregor6131b442009-12-12 18:16:41 +00005051 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005052 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 if (SubExpr.isInvalid())
5054 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005057 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005059 return SemaRef.Owned(E->Retain());
5060
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005062 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5064 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5065 SourceLocation FakeRParenLoc
5066 = SemaRef.PP.getLocForEndOfToken(
5067 E->getSubExpr()->getSourceRange().getEnd());
5068 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005069 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005071 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005072 FakeRAngleLoc,
5073 FakeRAngleLoc,
5074 move(SubExpr),
5075 FakeRParenLoc);
5076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078template<typename Derived>
5079Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005080TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5081 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005082}
Mike Stump11289f42009-09-09 15:08:12 +00005083
5084template<typename Derived>
5085Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005086TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5087 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005088}
5089
Douglas Gregora16548e2009-08-11 05:31:07 +00005090template<typename Derived>
5091Sema::OwningExprResult
5092TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005093 CXXReinterpretCastExpr *E) {
5094 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005095}
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregora16548e2009-08-11 05:31:07 +00005097template<typename Derived>
5098Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005099TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5100 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005101}
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregora16548e2009-08-11 05:31:07 +00005103template<typename Derived>
5104Sema::OwningExprResult
5105TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005106 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005107 TypeSourceInfo *OldT;
5108 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 {
5110 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005111
John McCall97513962010-01-15 18:39:57 +00005112 OldT = E->getTypeInfoAsWritten();
5113 NewT = getDerived().TransformType(OldT);
5114 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 return SemaRef.ExprError();
5116 }
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregor6131b442009-12-12 18:16:41 +00005118 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005119 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 if (SubExpr.isInvalid())
5121 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005124 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005126 return SemaRef.Owned(E->Retain());
5127
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 // FIXME: The end of the type's source range is wrong
5129 return getDerived().RebuildCXXFunctionalCastExpr(
5130 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005131 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 /*FIXME:*/E->getSubExpr()->getLocStart(),
5133 move(SubExpr),
5134 E->getRParenLoc());
5135}
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregora16548e2009-08-11 05:31:07 +00005137template<typename Derived>
5138Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005139TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005141 TypeSourceInfo *TInfo
5142 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5143 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005147 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregor9da64192010-04-26 22:37:10 +00005150 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5151 E->getLocStart(),
5152 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 E->getLocEnd());
5154 }
Mike Stump11289f42009-09-09 15:08:12 +00005155
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 // We don't know whether the expression is potentially evaluated until
5157 // after we perform semantic analysis, so the expression is potentially
5158 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005159 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005160 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5163 if (SubExpr.isInvalid())
5164 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 if (!getDerived().AlwaysRebuild() &&
5167 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005168 return SemaRef.Owned(E->Retain());
5169
Douglas Gregor9da64192010-04-26 22:37:10 +00005170 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5171 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 move(SubExpr),
5173 E->getLocEnd());
5174}
5175
5176template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005177Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005178TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005179 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005180}
Mike Stump11289f42009-09-09 15:08:12 +00005181
Douglas Gregora16548e2009-08-11 05:31:07 +00005182template<typename Derived>
5183Sema::OwningExprResult
5184TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005185 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005186 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005187}
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregora16548e2009-08-11 05:31:07 +00005189template<typename Derived>
5190Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005191TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregora16548e2009-08-11 05:31:07 +00005194 QualType T = getDerived().TransformType(E->getType());
5195 if (T.isNull())
5196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 if (!getDerived().AlwaysRebuild() &&
5199 T == E->getType())
5200 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005201
Douglas Gregorb15af892010-01-07 23:12:05 +00005202 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregora16548e2009-08-11 05:31:07 +00005205template<typename Derived>
5206Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005208 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5209 if (SubExpr.isInvalid())
5210 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005211
Douglas Gregora16548e2009-08-11 05:31:07 +00005212 if (!getDerived().AlwaysRebuild() &&
5213 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005214 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005215
5216 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219template<typename Derived>
5220Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005221TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005222 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005223 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5224 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 if (!Param)
5226 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005227
Chandler Carruth794da4c2010-02-08 06:42:49 +00005228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 Param == E->getParam())
5230 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005231
Douglas Gregor033f6752009-12-23 23:03:06 +00005232 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005233}
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregora16548e2009-08-11 05:31:07 +00005235template<typename Derived>
5236Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005237TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005238 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5239
5240 QualType T = getDerived().TransformType(E->getType());
5241 if (T.isNull())
5242 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 if (!getDerived().AlwaysRebuild() &&
5245 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005246 return SemaRef.Owned(E->Retain());
5247
Douglas Gregor747eb782010-07-08 06:14:04 +00005248 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5249 /*FIXME:*/E->getTypeBeginLoc(),
5250 T,
5251 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254template<typename Derived>
5255Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005256TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 // Transform the type that we're allocating
5258 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5259 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5260 if (AllocType.isNull())
5261 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregora16548e2009-08-11 05:31:07 +00005263 // Transform the size of the array we're allocating (if any).
5264 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5265 if (ArraySize.isInvalid())
5266 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 // Transform the placement arguments (if any).
5269 bool ArgumentChanged = false;
5270 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5271 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5272 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5273 if (Arg.isInvalid())
5274 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5277 PlacementArgs.push_back(Arg.take());
5278 }
Mike Stump11289f42009-09-09 15:08:12 +00005279
Douglas Gregorebe10102009-08-20 07:17:43 +00005280 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005281 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5282 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005283 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5284 break;
5285
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5287 if (Arg.isInvalid())
5288 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5291 ConstructorArgs.push_back(Arg.take());
5292 }
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregord2d9da02010-02-26 00:38:10 +00005294 // Transform constructor, new operator, and delete operator.
5295 CXXConstructorDecl *Constructor = 0;
5296 if (E->getConstructor()) {
5297 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005298 getDerived().TransformDecl(E->getLocStart(),
5299 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005300 if (!Constructor)
5301 return SemaRef.ExprError();
5302 }
5303
5304 FunctionDecl *OperatorNew = 0;
5305 if (E->getOperatorNew()) {
5306 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005307 getDerived().TransformDecl(E->getLocStart(),
5308 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005309 if (!OperatorNew)
5310 return SemaRef.ExprError();
5311 }
5312
5313 FunctionDecl *OperatorDelete = 0;
5314 if (E->getOperatorDelete()) {
5315 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005316 getDerived().TransformDecl(E->getLocStart(),
5317 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005318 if (!OperatorDelete)
5319 return SemaRef.ExprError();
5320 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005321
Douglas Gregora16548e2009-08-11 05:31:07 +00005322 if (!getDerived().AlwaysRebuild() &&
5323 AllocType == E->getAllocatedType() &&
5324 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005325 Constructor == E->getConstructor() &&
5326 OperatorNew == E->getOperatorNew() &&
5327 OperatorDelete == E->getOperatorDelete() &&
5328 !ArgumentChanged) {
5329 // Mark any declarations we need as referenced.
5330 // FIXME: instantiation-specific.
5331 if (Constructor)
5332 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5333 if (OperatorNew)
5334 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5335 if (OperatorDelete)
5336 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005337 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005338 }
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005340 if (!ArraySize.get()) {
5341 // If no array size was specified, but the new expression was
5342 // instantiated with an array type (e.g., "new T" where T is
5343 // instantiated with "int[4]"), extract the outer bound from the
5344 // array type as our array size. We do this with constant and
5345 // dependently-sized array types.
5346 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5347 if (!ArrayT) {
5348 // Do nothing
5349 } else if (const ConstantArrayType *ConsArrayT
5350 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005352 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005353 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005354 SemaRef.Context.getSizeType(),
5355 /*FIXME:*/E->getLocStart()));
5356 AllocType = ConsArrayT->getElementType();
5357 } else if (const DependentSizedArrayType *DepArrayT
5358 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5359 if (DepArrayT->getSizeExpr()) {
5360 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5361 AllocType = DepArrayT->getElementType();
5362 }
5363 }
5364 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005365 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5366 E->isGlobalNew(),
5367 /*FIXME:*/E->getLocStart(),
5368 move_arg(PlacementArgs),
5369 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005370 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 AllocType,
5372 /*FIXME:*/E->getLocStart(),
5373 /*FIXME:*/SourceRange(),
5374 move(ArraySize),
5375 /*FIXME:*/E->getLocStart(),
5376 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005377 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005378}
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregora16548e2009-08-11 05:31:07 +00005380template<typename Derived>
5381Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005382TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005383 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5384 if (Operand.isInvalid())
5385 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005386
Douglas Gregord2d9da02010-02-26 00:38:10 +00005387 // Transform the delete operator, if known.
5388 FunctionDecl *OperatorDelete = 0;
5389 if (E->getOperatorDelete()) {
5390 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005391 getDerived().TransformDecl(E->getLocStart(),
5392 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005393 if (!OperatorDelete)
5394 return SemaRef.ExprError();
5395 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005396
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005398 Operand.get() == E->getArgument() &&
5399 OperatorDelete == E->getOperatorDelete()) {
5400 // Mark any declarations we need as referenced.
5401 // FIXME: instantiation-specific.
5402 if (OperatorDelete)
5403 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005404 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005405 }
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregora16548e2009-08-11 05:31:07 +00005407 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5408 E->isGlobalDelete(),
5409 E->isArrayForm(),
5410 move(Operand));
5411}
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregora16548e2009-08-11 05:31:07 +00005413template<typename Derived>
5414Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005415TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005416 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005417 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5418 if (Base.isInvalid())
5419 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregor678f90d2010-02-25 01:56:36 +00005421 Sema::TypeTy *ObjectTypePtr = 0;
5422 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005423 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005424 E->getOperatorLoc(),
5425 E->isArrow()? tok::arrow : tok::period,
5426 ObjectTypePtr,
5427 MayBePseudoDestructor);
5428 if (Base.isInvalid())
5429 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005430
Douglas Gregor678f90d2010-02-25 01:56:36 +00005431 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005432 NestedNameSpecifier *Qualifier
5433 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005434 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005435 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005436 if (E->getQualifier() && !Qualifier)
5437 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005438
Douglas Gregor678f90d2010-02-25 01:56:36 +00005439 PseudoDestructorTypeStorage Destroyed;
5440 if (E->getDestroyedTypeInfo()) {
5441 TypeSourceInfo *DestroyedTypeInfo
5442 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5443 if (!DestroyedTypeInfo)
5444 return SemaRef.ExprError();
5445 Destroyed = DestroyedTypeInfo;
5446 } else if (ObjectType->isDependentType()) {
5447 // We aren't likely to be able to resolve the identifier down to a type
5448 // now anyway, so just retain the identifier.
5449 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5450 E->getDestroyedTypeLoc());
5451 } else {
5452 // Look for a destructor known with the given name.
5453 CXXScopeSpec SS;
5454 if (Qualifier) {
5455 SS.setScopeRep(Qualifier);
5456 SS.setRange(E->getQualifierRange());
5457 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005458
Douglas Gregor678f90d2010-02-25 01:56:36 +00005459 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5460 *E->getDestroyedTypeIdentifier(),
5461 E->getDestroyedTypeLoc(),
5462 /*Scope=*/0,
5463 SS, ObjectTypePtr,
5464 false);
5465 if (!T)
5466 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
Douglas Gregor678f90d2010-02-25 01:56:36 +00005468 Destroyed
5469 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5470 E->getDestroyedTypeLoc());
5471 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005472
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005473 TypeSourceInfo *ScopeTypeInfo = 0;
5474 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005475 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005476 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005477 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005478 return SemaRef.ExprError();
5479 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005480
Douglas Gregorad8a3362009-09-04 17:36:40 +00005481 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5482 E->getOperatorLoc(),
5483 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005484 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005485 E->getQualifierRange(),
5486 ScopeTypeInfo,
5487 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005488 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005489 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005490}
Mike Stump11289f42009-09-09 15:08:12 +00005491
Douglas Gregorad8a3362009-09-04 17:36:40 +00005492template<typename Derived>
5493Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005494TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005495 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005496 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5497
5498 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5499 Sema::LookupOrdinaryName);
5500
5501 // Transform all the decls.
5502 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5503 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005504 NamedDecl *InstD = static_cast<NamedDecl*>(
5505 getDerived().TransformDecl(Old->getNameLoc(),
5506 *I));
John McCall84d87672009-12-10 09:41:52 +00005507 if (!InstD) {
5508 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5509 // This can happen because of dependent hiding.
5510 if (isa<UsingShadowDecl>(*I))
5511 continue;
5512 else
5513 return SemaRef.ExprError();
5514 }
John McCalle66edc12009-11-24 19:00:30 +00005515
5516 // Expand using declarations.
5517 if (isa<UsingDecl>(InstD)) {
5518 UsingDecl *UD = cast<UsingDecl>(InstD);
5519 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5520 E = UD->shadow_end(); I != E; ++I)
5521 R.addDecl(*I);
5522 continue;
5523 }
5524
5525 R.addDecl(InstD);
5526 }
5527
5528 // Resolve a kind, but don't do any further analysis. If it's
5529 // ambiguous, the callee needs to deal with it.
5530 R.resolveKind();
5531
5532 // Rebuild the nested-name qualifier, if present.
5533 CXXScopeSpec SS;
5534 NestedNameSpecifier *Qualifier = 0;
5535 if (Old->getQualifier()) {
5536 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005537 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005538 if (!Qualifier)
5539 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005540
John McCalle66edc12009-11-24 19:00:30 +00005541 SS.setScopeRep(Qualifier);
5542 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005543 }
5544
Douglas Gregor9262f472010-04-27 18:19:34 +00005545 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005546 CXXRecordDecl *NamingClass
5547 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5548 Old->getNameLoc(),
5549 Old->getNamingClass()));
5550 if (!NamingClass)
5551 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005552
Douglas Gregorda7be082010-04-27 16:10:10 +00005553 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005554 }
5555
5556 // If we have no template arguments, it's a normal declaration name.
5557 if (!Old->hasExplicitTemplateArgs())
5558 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5559
5560 // If we have template arguments, rebuild them, then rebuild the
5561 // templateid expression.
5562 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5563 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5564 TemplateArgumentLoc Loc;
5565 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5566 return SemaRef.ExprError();
5567 TransArgs.addArgument(Loc);
5568 }
5569
5570 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5571 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005572}
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregora16548e2009-08-11 05:31:07 +00005574template<typename Derived>
5575Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005576TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 QualType T = getDerived().TransformType(E->getQueriedType());
5580 if (T.isNull())
5581 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 if (!getDerived().AlwaysRebuild() &&
5584 T == E->getQueriedType())
5585 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 // FIXME: Bad location information
5588 SourceLocation FakeLParenLoc
5589 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005590
5591 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 E->getLocStart(),
5593 /*FIXME:*/FakeLParenLoc,
5594 T,
5595 E->getLocEnd());
5596}
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregora16548e2009-08-11 05:31:07 +00005598template<typename Derived>
5599Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005600TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005601 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005603 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005604 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 if (!NNS)
5606 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005608 DeclarationNameInfo NameInfo
5609 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5610 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005611 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005612
John McCalle66edc12009-11-24 19:00:30 +00005613 if (!E->hasExplicitTemplateArgs()) {
5614 if (!getDerived().AlwaysRebuild() &&
5615 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005616 // Note: it is sufficient to compare the Name component of NameInfo:
5617 // if name has not changed, DNLoc has not changed either.
5618 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005619 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005620
John McCalle66edc12009-11-24 19:00:30 +00005621 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5622 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005623 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005624 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005625 }
John McCall6b51f282009-11-23 01:53:49 +00005626
5627 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005629 TemplateArgumentLoc Loc;
5630 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005632 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 }
5634
John McCalle66edc12009-11-24 19:00:30 +00005635 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5636 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005637 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005638 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005639}
5640
5641template<typename Derived>
5642Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005643TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005644 // CXXConstructExprs are always implicit, so when we have a
5645 // 1-argument construction we just transform that argument.
5646 if (E->getNumArgs() == 1 ||
5647 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5648 return getDerived().TransformExpr(E->getArg(0));
5649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5651
5652 QualType T = getDerived().TransformType(E->getType());
5653 if (T.isNull())
5654 return SemaRef.ExprError();
5655
5656 CXXConstructorDecl *Constructor
5657 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005658 getDerived().TransformDecl(E->getLocStart(),
5659 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 if (!Constructor)
5661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 bool ArgumentChanged = false;
5664 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005665 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 ArgEnd = E->arg_end();
5667 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005668 if (getDerived().DropCallArgument(*Arg)) {
5669 ArgumentChanged = true;
5670 break;
5671 }
5672
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5674 if (TransArg.isInvalid())
5675 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5678 Args.push_back(TransArg.takeAs<Expr>());
5679 }
5680
5681 if (!getDerived().AlwaysRebuild() &&
5682 T == E->getType() &&
5683 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005684 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005685 // Mark the constructor as referenced.
5686 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005687 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005689 }
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregordb121ba2009-12-14 16:27:04 +00005691 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5692 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005693 move_arg(Args));
5694}
Mike Stump11289f42009-09-09 15:08:12 +00005695
Douglas Gregora16548e2009-08-11 05:31:07 +00005696/// \brief Transform a C++ temporary-binding expression.
5697///
Douglas Gregor363b1512009-12-24 18:51:59 +00005698/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5699/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005700template<typename Derived>
5701Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005702TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005703 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Anders Carlssonba6c4372010-01-29 02:39:32 +00005706/// \brief Transform a C++ reference-binding expression.
5707///
5708/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5709/// transform the subexpression and return that.
5710template<typename Derived>
5711Sema::OwningExprResult
5712TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5713 return getDerived().TransformExpr(E->getSubExpr());
5714}
5715
Mike Stump11289f42009-09-09 15:08:12 +00005716/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005717/// be destroyed after the expression is evaluated.
5718///
Douglas Gregor363b1512009-12-24 18:51:59 +00005719/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5720/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005721template<typename Derived>
5722Sema::OwningExprResult
5723TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005724 CXXExprWithTemporaries *E) {
5725 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005726}
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregora16548e2009-08-11 05:31:07 +00005728template<typename Derived>
5729Sema::OwningExprResult
5730TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005731 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5733 QualType T = getDerived().TransformType(E->getType());
5734 if (T.isNull())
5735 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 CXXConstructorDecl *Constructor
5738 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005739 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005740 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 if (!Constructor)
5742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005743
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 bool ArgumentChanged = false;
5745 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5746 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005747 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 ArgEnd = E->arg_end();
5749 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005750 if (getDerived().DropCallArgument(*Arg)) {
5751 ArgumentChanged = true;
5752 break;
5753 }
5754
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5756 if (TransArg.isInvalid())
5757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5760 Args.push_back((Expr *)TransArg.release());
5761 }
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregora16548e2009-08-11 05:31:07 +00005763 if (!getDerived().AlwaysRebuild() &&
5764 T == E->getType() &&
5765 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005766 !ArgumentChanged) {
5767 // FIXME: Instantiation-specific
5768 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005769 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005770 }
Mike Stump11289f42009-09-09 15:08:12 +00005771
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 // FIXME: Bogus location information
5773 SourceLocation CommaLoc;
5774 if (Args.size() > 1) {
5775 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005776 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5778 }
5779 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5780 T,
5781 /*FIXME:*/E->getTypeBeginLoc(),
5782 move_arg(Args),
5783 &CommaLoc,
5784 E->getLocEnd());
5785}
Mike Stump11289f42009-09-09 15:08:12 +00005786
Douglas Gregora16548e2009-08-11 05:31:07 +00005787template<typename Derived>
5788Sema::OwningExprResult
5789TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005790 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5792 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5793 if (T.isNull())
5794 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796 bool ArgumentChanged = false;
5797 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5798 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5799 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5800 ArgEnd = E->arg_end();
5801 Arg != ArgEnd; ++Arg) {
5802 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5803 if (TransArg.isInvalid())
5804 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5807 FakeCommaLocs.push_back(
5808 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5809 Args.push_back(TransArg.takeAs<Expr>());
5810 }
Mike Stump11289f42009-09-09 15:08:12 +00005811
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 if (!getDerived().AlwaysRebuild() &&
5813 T == E->getTypeAsWritten() &&
5814 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005815 return SemaRef.Owned(E->Retain());
5816
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 // FIXME: we're faking the locations of the commas
5818 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5819 T,
5820 E->getLParenLoc(),
5821 move_arg(Args),
5822 FakeCommaLocs.data(),
5823 E->getRParenLoc());
5824}
Mike Stump11289f42009-09-09 15:08:12 +00005825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826template<typename Derived>
5827Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005828TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005829 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005831 OwningExprResult Base(SemaRef, (Expr*) 0);
5832 Expr *OldBase;
5833 QualType BaseType;
5834 QualType ObjectType;
5835 if (!E->isImplicitAccess()) {
5836 OldBase = E->getBase();
5837 Base = getDerived().TransformExpr(OldBase);
5838 if (Base.isInvalid())
5839 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005840
John McCall2d74de92009-12-01 22:10:20 +00005841 // Start the member reference and compute the object's type.
5842 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005843 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005844 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5845 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005846 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005847 ObjectTy,
5848 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005849 if (Base.isInvalid())
5850 return SemaRef.ExprError();
5851
5852 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5853 BaseType = ((Expr*) Base.get())->getType();
5854 } else {
5855 OldBase = 0;
5856 BaseType = getDerived().TransformType(E->getBaseType());
5857 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5858 }
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005860 // Transform the first part of the nested-name-specifier that qualifies
5861 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005862 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005863 = getDerived().TransformFirstQualifierInScope(
5864 E->getFirstQualifierFoundInScope(),
5865 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005867 NestedNameSpecifier *Qualifier = 0;
5868 if (E->getQualifier()) {
5869 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5870 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005871 ObjectType,
5872 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005873 if (!Qualifier)
5874 return SemaRef.ExprError();
5875 }
Mike Stump11289f42009-09-09 15:08:12 +00005876
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005877 DeclarationNameInfo NameInfo
5878 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5879 ObjectType);
5880 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005881 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005882
John McCall2d74de92009-12-01 22:10:20 +00005883 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005884 // This is a reference to a member without an explicitly-specified
5885 // template argument list. Optimize for this common case.
5886 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005887 Base.get() == OldBase &&
5888 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005889 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005890 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005891 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005892 return SemaRef.Owned(E->Retain());
5893
John McCall8cd78132009-11-19 22:55:06 +00005894 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005895 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005896 E->isArrow(),
5897 E->getOperatorLoc(),
5898 Qualifier,
5899 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005900 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005901 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005902 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005903 }
5904
John McCall6b51f282009-11-23 01:53:49 +00005905 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005906 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005907 TemplateArgumentLoc Loc;
5908 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005909 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005910 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005911 }
Mike Stump11289f42009-09-09 15:08:12 +00005912
John McCall8cd78132009-11-19 22:55:06 +00005913 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005914 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005915 E->isArrow(),
5916 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005917 Qualifier,
5918 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005919 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005920 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005921 &TransArgs);
5922}
5923
5924template<typename Derived>
5925Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005926TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005927 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005928 OwningExprResult Base(SemaRef, (Expr*) 0);
5929 QualType BaseType;
5930 if (!Old->isImplicitAccess()) {
5931 Base = getDerived().TransformExpr(Old->getBase());
5932 if (Base.isInvalid())
5933 return SemaRef.ExprError();
5934 BaseType = ((Expr*) Base.get())->getType();
5935 } else {
5936 BaseType = getDerived().TransformType(Old->getBaseType());
5937 }
John McCall10eae182009-11-30 22:42:35 +00005938
5939 NestedNameSpecifier *Qualifier = 0;
5940 if (Old->getQualifier()) {
5941 Qualifier
5942 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005943 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005944 if (Qualifier == 0)
5945 return SemaRef.ExprError();
5946 }
5947
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005948 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005949 Sema::LookupOrdinaryName);
5950
5951 // Transform all the decls.
5952 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5953 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005954 NamedDecl *InstD = static_cast<NamedDecl*>(
5955 getDerived().TransformDecl(Old->getMemberLoc(),
5956 *I));
John McCall84d87672009-12-10 09:41:52 +00005957 if (!InstD) {
5958 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5959 // This can happen because of dependent hiding.
5960 if (isa<UsingShadowDecl>(*I))
5961 continue;
5962 else
5963 return SemaRef.ExprError();
5964 }
John McCall10eae182009-11-30 22:42:35 +00005965
5966 // Expand using declarations.
5967 if (isa<UsingDecl>(InstD)) {
5968 UsingDecl *UD = cast<UsingDecl>(InstD);
5969 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5970 E = UD->shadow_end(); I != E; ++I)
5971 R.addDecl(*I);
5972 continue;
5973 }
5974
5975 R.addDecl(InstD);
5976 }
5977
5978 R.resolveKind();
5979
Douglas Gregor9262f472010-04-27 18:19:34 +00005980 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005981 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005982 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005983 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005984 Old->getMemberLoc(),
5985 Old->getNamingClass()));
5986 if (!NamingClass)
5987 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005988
Douglas Gregorda7be082010-04-27 16:10:10 +00005989 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005990 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005991
John McCall10eae182009-11-30 22:42:35 +00005992 TemplateArgumentListInfo TransArgs;
5993 if (Old->hasExplicitTemplateArgs()) {
5994 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5995 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5996 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5997 TemplateArgumentLoc Loc;
5998 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5999 Loc))
6000 return SemaRef.ExprError();
6001 TransArgs.addArgument(Loc);
6002 }
6003 }
John McCall38836f02010-01-15 08:34:02 +00006004
6005 // FIXME: to do this check properly, we will need to preserve the
6006 // first-qualifier-in-scope here, just in case we had a dependent
6007 // base (and therefore couldn't do the check) and a
6008 // nested-name-qualifier (and therefore could do the lookup).
6009 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006010
John McCall10eae182009-11-30 22:42:35 +00006011 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00006012 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006013 Old->getOperatorLoc(),
6014 Old->isArrow(),
6015 Qualifier,
6016 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006017 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006018 R,
6019 (Old->hasExplicitTemplateArgs()
6020 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006021}
6022
6023template<typename Derived>
6024Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006025TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006026 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006027}
6028
Mike Stump11289f42009-09-09 15:08:12 +00006029template<typename Derived>
6030Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006031TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006032 TypeSourceInfo *EncodedTypeInfo
6033 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6034 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregora16548e2009-08-11 05:31:07 +00006037 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006038 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006039 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006040
6041 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006042 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 E->getRParenLoc());
6044}
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregora16548e2009-08-11 05:31:07 +00006046template<typename Derived>
6047Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006048TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006049 // Transform arguments.
6050 bool ArgChanged = false;
6051 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6052 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6053 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6054 if (Arg.isInvalid())
6055 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006056
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006057 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6058 Args.push_back(Arg.takeAs<Expr>());
6059 }
6060
6061 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6062 // Class message: transform the receiver type.
6063 TypeSourceInfo *ReceiverTypeInfo
6064 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6065 if (!ReceiverTypeInfo)
6066 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006067
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006068 // If nothing changed, just retain the existing message send.
6069 if (!getDerived().AlwaysRebuild() &&
6070 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6071 return SemaRef.Owned(E->Retain());
6072
6073 // Build a new class message send.
6074 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6075 E->getSelector(),
6076 E->getMethodDecl(),
6077 E->getLeftLoc(),
6078 move_arg(Args),
6079 E->getRightLoc());
6080 }
6081
6082 // Instance message: transform the receiver
6083 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6084 "Only class and instance messages may be instantiated");
6085 OwningExprResult Receiver
6086 = getDerived().TransformExpr(E->getInstanceReceiver());
6087 if (Receiver.isInvalid())
6088 return SemaRef.ExprError();
6089
6090 // If nothing changed, just retain the existing message send.
6091 if (!getDerived().AlwaysRebuild() &&
6092 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6093 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006094
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006095 // Build a new instance message send.
6096 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6097 E->getSelector(),
6098 E->getMethodDecl(),
6099 E->getLeftLoc(),
6100 move_arg(Args),
6101 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006102}
6103
Mike Stump11289f42009-09-09 15:08:12 +00006104template<typename Derived>
6105Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006106TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006107 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006108}
6109
Mike Stump11289f42009-09-09 15:08:12 +00006110template<typename Derived>
6111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006112TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006113 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006114}
6115
Mike Stump11289f42009-09-09 15:08:12 +00006116template<typename Derived>
6117Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006118TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006119 // Transform the base expression.
6120 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6121 if (Base.isInvalid())
6122 return SemaRef.ExprError();
6123
6124 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006125
Douglas Gregord51d90d2010-04-26 20:11:03 +00006126 // If nothing changed, just retain the existing expression.
6127 if (!getDerived().AlwaysRebuild() &&
6128 Base.get() == E->getBase())
6129 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006130
Douglas Gregord51d90d2010-04-26 20:11:03 +00006131 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6132 E->getLocation(),
6133 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006134}
6135
Mike Stump11289f42009-09-09 15:08:12 +00006136template<typename Derived>
6137Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006138TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006139 // Transform the base expression.
6140 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6141 if (Base.isInvalid())
6142 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006143
Douglas Gregor9faee212010-04-26 20:47:02 +00006144 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006145
Douglas Gregor9faee212010-04-26 20:47:02 +00006146 // If nothing changed, just retain the existing expression.
6147 if (!getDerived().AlwaysRebuild() &&
6148 Base.get() == E->getBase())
6149 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006150
Douglas Gregor9faee212010-04-26 20:47:02 +00006151 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6152 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006153}
6154
Mike Stump11289f42009-09-09 15:08:12 +00006155template<typename Derived>
6156Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006157TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006158 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006159 // If this implicit setter/getter refers to class methods, it cannot have any
6160 // dependent parts. Just retain the existing declaration.
6161 if (E->getInterfaceDecl())
6162 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006163
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006164 // Transform the base expression.
6165 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6166 if (Base.isInvalid())
6167 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006168
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006169 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006170
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006171 // If nothing changed, just retain the existing expression.
6172 if (!getDerived().AlwaysRebuild() &&
6173 Base.get() == E->getBase())
6174 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006175
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006176 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6177 E->getGetterMethod(),
6178 E->getType(),
6179 E->getSetterMethod(),
6180 E->getLocation(),
6181 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006182
Douglas Gregora16548e2009-08-11 05:31:07 +00006183}
6184
Mike Stump11289f42009-09-09 15:08:12 +00006185template<typename Derived>
6186Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006187TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006188 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006189 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006190}
6191
Mike Stump11289f42009-09-09 15:08:12 +00006192template<typename Derived>
6193Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006195 // Transform the base expression.
6196 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6197 if (Base.isInvalid())
6198 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006199
Douglas Gregord51d90d2010-04-26 20:11:03 +00006200 // If nothing changed, just retain the existing expression.
6201 if (!getDerived().AlwaysRebuild() &&
6202 Base.get() == E->getBase())
6203 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006204
Douglas Gregord51d90d2010-04-26 20:11:03 +00006205 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6206 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006207}
6208
Mike Stump11289f42009-09-09 15:08:12 +00006209template<typename Derived>
6210Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006211TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 bool ArgumentChanged = false;
6213 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6214 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6215 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6216 if (SubExpr.isInvalid())
6217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregora16548e2009-08-11 05:31:07 +00006219 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6220 SubExprs.push_back(SubExpr.takeAs<Expr>());
6221 }
Mike Stump11289f42009-09-09 15:08:12 +00006222
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 if (!getDerived().AlwaysRebuild() &&
6224 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006225 return SemaRef.Owned(E->Retain());
6226
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6228 move_arg(SubExprs),
6229 E->getRParenLoc());
6230}
6231
Mike Stump11289f42009-09-09 15:08:12 +00006232template<typename Derived>
6233Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006235 SourceLocation CaretLoc(E->getExprLoc());
6236
6237 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6238 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6239 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6240 llvm::SmallVector<ParmVarDecl*, 4> Params;
6241 llvm::SmallVector<QualType, 4> ParamTypes;
6242
6243 // Parameter substitution.
6244 const BlockDecl *BD = E->getBlockDecl();
6245 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6246 EN = BD->param_end(); P != EN; ++P) {
6247 ParmVarDecl *OldParm = (*P);
6248 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6249 QualType NewType = NewParm->getType();
6250 Params.push_back(NewParm);
6251 ParamTypes.push_back(NewParm->getType());
6252 }
6253
6254 const FunctionType *BExprFunctionType = E->getFunctionType();
6255 QualType BExprResultType = BExprFunctionType->getResultType();
6256 if (!BExprResultType.isNull()) {
6257 if (!BExprResultType->isDependentType())
6258 CurBlock->ReturnType = BExprResultType;
6259 else if (BExprResultType != SemaRef.Context.DependentTy)
6260 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6261 }
6262
6263 // Transform the body
6264 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6265 if (Body.isInvalid())
6266 return SemaRef.ExprError();
6267 // Set the parameters on the block decl.
6268 if (!Params.empty())
6269 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6270
6271 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6272 CurBlock->ReturnType,
6273 ParamTypes.data(),
6274 ParamTypes.size(),
6275 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006276 0,
6277 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006278
6279 CurBlock->FunctionType = FunctionType;
6280 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006281}
6282
Mike Stump11289f42009-09-09 15:08:12 +00006283template<typename Derived>
6284Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006285TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006286 NestedNameSpecifier *Qualifier = 0;
6287
6288 ValueDecl *ND
6289 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6290 E->getDecl()));
6291 if (!ND)
6292 return SemaRef.ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006293
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006294 if (!getDerived().AlwaysRebuild() &&
6295 ND == E->getDecl()) {
6296 // Mark it referenced in the new context regardless.
6297 // FIXME: this is a bit instantiation-specific.
6298 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6299
6300 return SemaRef.Owned(E->Retain());
6301 }
6302
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006303 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006304 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006305 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006306}
Mike Stump11289f42009-09-09 15:08:12 +00006307
Douglas Gregora16548e2009-08-11 05:31:07 +00006308//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006309// Type reconstruction
6310//===----------------------------------------------------------------------===//
6311
Mike Stump11289f42009-09-09 15:08:12 +00006312template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006313QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6314 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006315 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006316 getDerived().getBaseEntity());
6317}
6318
Mike Stump11289f42009-09-09 15:08:12 +00006319template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006320QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6321 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006322 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006323 getDerived().getBaseEntity());
6324}
6325
Mike Stump11289f42009-09-09 15:08:12 +00006326template<typename Derived>
6327QualType
John McCall70dd5f62009-10-30 00:06:24 +00006328TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6329 bool WrittenAsLValue,
6330 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006331 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006332 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006333}
6334
6335template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006336QualType
John McCall70dd5f62009-10-30 00:06:24 +00006337TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6338 QualType ClassType,
6339 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006340 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006341 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006342}
6343
6344template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006345QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006346TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6347 ArrayType::ArraySizeModifier SizeMod,
6348 const llvm::APInt *Size,
6349 Expr *SizeExpr,
6350 unsigned IndexTypeQuals,
6351 SourceRange BracketsRange) {
6352 if (SizeExpr || !Size)
6353 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6354 IndexTypeQuals, BracketsRange,
6355 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006356
6357 QualType Types[] = {
6358 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6359 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6360 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006361 };
6362 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6363 QualType SizeType;
6364 for (unsigned I = 0; I != NumTypes; ++I)
6365 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6366 SizeType = Types[I];
6367 break;
6368 }
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006371 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006372 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006373 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006374}
Mike Stump11289f42009-09-09 15:08:12 +00006375
Douglas Gregord6ff3322009-08-04 16:50:30 +00006376template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006377QualType
6378TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006379 ArrayType::ArraySizeModifier SizeMod,
6380 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006381 unsigned IndexTypeQuals,
6382 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006383 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006384 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006385}
6386
6387template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006388QualType
Mike Stump11289f42009-09-09 15:08:12 +00006389TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006390 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006391 unsigned IndexTypeQuals,
6392 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006393 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006394 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006395}
Mike Stump11289f42009-09-09 15:08:12 +00006396
Douglas Gregord6ff3322009-08-04 16:50:30 +00006397template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006398QualType
6399TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006400 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006402 unsigned IndexTypeQuals,
6403 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006404 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006405 SizeExpr.takeAs<Expr>(),
6406 IndexTypeQuals, BracketsRange);
6407}
6408
6409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006410QualType
6411TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006413 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414 unsigned IndexTypeQuals,
6415 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006416 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006417 SizeExpr.takeAs<Expr>(),
6418 IndexTypeQuals, BracketsRange);
6419}
6420
6421template<typename Derived>
6422QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006423 unsigned NumElements,
6424 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006425 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006426 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006427}
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429template<typename Derived>
6430QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6431 unsigned NumElements,
6432 SourceLocation AttributeLoc) {
6433 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6434 NumElements, true);
6435 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006436 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006437 AttributeLoc);
6438 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6439 AttributeLoc);
6440}
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregord6ff3322009-08-04 16:50:30 +00006442template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006443QualType
6444TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006446 SourceLocation AttributeLoc) {
6447 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6448}
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregord6ff3322009-08-04 16:50:30 +00006450template<typename Derived>
6451QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006452 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006453 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006454 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006455 unsigned Quals,
6456 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006457 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006458 Quals,
6459 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006460 getDerived().getBaseEntity(),
6461 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006462}
Mike Stump11289f42009-09-09 15:08:12 +00006463
Douglas Gregord6ff3322009-08-04 16:50:30 +00006464template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006465QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6466 return SemaRef.Context.getFunctionNoProtoType(T);
6467}
6468
6469template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006470QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6471 assert(D && "no decl found");
6472 if (D->isInvalidDecl()) return QualType();
6473
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006474 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006475 TypeDecl *Ty;
6476 if (isa<UsingDecl>(D)) {
6477 UsingDecl *Using = cast<UsingDecl>(D);
6478 assert(Using->isTypeName() &&
6479 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6480
6481 // A valid resolved using typename decl points to exactly one type decl.
6482 assert(++Using->shadow_begin() == Using->shadow_end());
6483 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006484
John McCallb96ec562009-12-04 22:46:56 +00006485 } else {
6486 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6487 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6488 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6489 }
6490
6491 return SemaRef.Context.getTypeDeclType(Ty);
6492}
6493
6494template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006495QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006496 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6497}
6498
6499template<typename Derived>
6500QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6501 return SemaRef.Context.getTypeOfType(Underlying);
6502}
6503
6504template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006505QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006506 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6507}
6508
6509template<typename Derived>
6510QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006511 TemplateName Template,
6512 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006513 const TemplateArgumentListInfo &TemplateArgs) {
6514 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregor1135c352009-08-06 05:28:30 +00006517template<typename Derived>
6518NestedNameSpecifier *
6519TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6520 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006521 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006522 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006523 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006524 CXXScopeSpec SS;
6525 // FIXME: The source location information is all wrong.
6526 SS.setRange(Range);
6527 SS.setScopeRep(Prefix);
6528 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006529 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006530 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006531 ObjectType,
6532 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006533 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006534}
6535
6536template<typename Derived>
6537NestedNameSpecifier *
6538TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6539 SourceRange Range,
6540 NamespaceDecl *NS) {
6541 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6542}
6543
6544template<typename Derived>
6545NestedNameSpecifier *
6546TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6547 SourceRange Range,
6548 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006549 QualType T) {
6550 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006551 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006552 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006553 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6554 T.getTypePtr());
6555 }
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregor1135c352009-08-06 05:28:30 +00006557 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6558 return 0;
6559}
Mike Stump11289f42009-09-09 15:08:12 +00006560
Douglas Gregor71dc5092009-08-06 06:41:21 +00006561template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006562TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006563TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6564 bool TemplateKW,
6565 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006566 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006567 Template);
6568}
6569
6570template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006571TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006572TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006573 const IdentifierInfo &II,
6574 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006575 CXXScopeSpec SS;
6576 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006577 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006578 UnqualifiedId Name;
6579 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006580 Sema::TemplateTy Template;
6581 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6582 /*FIXME:*/getDerived().getBaseLocation(),
6583 SS,
6584 Name,
6585 ObjectType.getAsOpaquePtr(),
6586 /*EnteringContext=*/false,
6587 Template);
6588 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006589}
Mike Stump11289f42009-09-09 15:08:12 +00006590
Douglas Gregora16548e2009-08-11 05:31:07 +00006591template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006592TemplateName
6593TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6594 OverloadedOperatorKind Operator,
6595 QualType ObjectType) {
6596 CXXScopeSpec SS;
6597 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6598 SS.setScopeRep(Qualifier);
6599 UnqualifiedId Name;
6600 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6601 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6602 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006603 Sema::TemplateTy Template;
6604 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006605 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006606 SS,
6607 Name,
6608 ObjectType.getAsOpaquePtr(),
6609 /*EnteringContext=*/false,
6610 Template);
6611 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006612}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006613
Douglas Gregor71395fa2009-11-04 00:56:37 +00006614template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006615Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006616TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6617 SourceLocation OpLoc,
6618 ExprArg Callee,
6619 ExprArg First,
6620 ExprArg Second) {
6621 Expr *FirstExpr = (Expr *)First.get();
6622 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006623 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006627 if (Op == OO_Subscript) {
6628 if (!FirstExpr->getType()->isOverloadableType() &&
6629 !SecondExpr->getType()->isOverloadableType())
6630 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006631 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006632 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006633 } else if (Op == OO_Arrow) {
6634 // -> is never a builtin operation.
6635 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006636 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 if (!FirstExpr->getType()->isOverloadableType()) {
6638 // The argument is not of overloadable type, so try to create a
6639 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006640 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006641 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6644 }
6645 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006646 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006647 !SecondExpr->getType()->isOverloadableType()) {
6648 // Neither of the arguments is an overloadable type, so try to
6649 // create a built-in binary operation.
6650 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006651 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006652 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6653 if (Result.isInvalid())
6654 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006655
Douglas Gregora16548e2009-08-11 05:31:07 +00006656 First.release();
6657 Second.release();
6658 return move(Result);
6659 }
6660 }
Mike Stump11289f42009-09-09 15:08:12 +00006661
6662 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006664 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006665
John McCalld14a8642009-11-21 08:51:07 +00006666 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6667 assert(ULE->requiresADL());
6668
6669 // FIXME: Do we have to check
6670 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006671 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006672 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006673 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006674 }
Mike Stump11289f42009-09-09 15:08:12 +00006675
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 // Add any functions found via argument-dependent lookup.
6677 Expr *Args[2] = { FirstExpr, SecondExpr };
6678 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 // Create the overloaded operator invocation for unary operators.
6681 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006682 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006683 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6684 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6685 }
Mike Stump11289f42009-09-09 15:08:12 +00006686
Sebastian Redladba46e2009-10-29 20:17:01 +00006687 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006688 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6689 OpLoc,
6690 move(First),
6691 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006692
Douglas Gregora16548e2009-08-11 05:31:07 +00006693 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006694 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006695 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006696 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6698 if (Result.isInvalid())
6699 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006700
Douglas Gregora16548e2009-08-11 05:31:07 +00006701 First.release();
6702 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006703 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006704}
Mike Stump11289f42009-09-09 15:08:12 +00006705
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006706template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006707Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006708TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6709 SourceLocation OperatorLoc,
6710 bool isArrow,
6711 NestedNameSpecifier *Qualifier,
6712 SourceRange QualifierRange,
6713 TypeSourceInfo *ScopeType,
6714 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006715 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006716 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006717 CXXScopeSpec SS;
6718 if (Qualifier) {
6719 SS.setRange(QualifierRange);
6720 SS.setScopeRep(Qualifier);
6721 }
6722
6723 Expr *BaseE = (Expr *)Base.get();
6724 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006725 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006726 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006727 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006728 !BaseType->getAs<PointerType>()->getPointeeType()
6729 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006730 // This pseudo-destructor expression is still a pseudo-destructor.
6731 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6732 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006733 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006734 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006735 /*FIXME?*/true);
6736 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006737
Douglas Gregor678f90d2010-02-25 01:56:36 +00006738 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006739 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6740 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6741 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6742 NameInfo.setNamedTypeInfo(DestroyedType);
6743
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006744 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006745
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006746 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6747 OperatorLoc, isArrow,
6748 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006749 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006750 /*TemplateArgs*/ 0);
6751}
6752
Douglas Gregord6ff3322009-08-04 16:50:30 +00006753} // end namespace clang
6754
6755#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H