blob: 4929bf7ba3b8cf36506f13d838004d4203bb3b26 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
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.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
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 Hunt656bb312010-05-05 15:24:00 +0000347#define ABSTRACT(Stmt)
348#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,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
Mike Stump11289f42009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000499 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500
Mike Stump11289f42009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000510 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000533 /// By default, builds a new DependentNameType type from the
Douglas Gregore677daf2010-03-31 22:19:08 +0000534 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000535 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000537 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
538 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000539 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000540 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000541 CXXScopeSpec SS;
542 SS.setScopeRep(NNS);
543 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000544 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000546 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000547
548 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000549 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550
551 /// \brief Build a new typename type that refers to an identifier.
552 ///
553 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000554 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555 /// different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000556 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000557 NestedNameSpecifier *NNS,
558 const IdentifierInfo *Id,
559 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000560 CXXScopeSpec SS;
561 SS.setScopeRep(NNS);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000562
Douglas Gregore677daf2010-03-31 22:19:08 +0000563 if (NNS->isDependent()) {
564 // If the name is still dependent, just build a new dependent name type.
565 if (!SemaRef.computeDeclContext(SS))
566 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
567 }
568
Abramo Bagnara6150c882010-05-11 21:36:43 +0000569 if (Keyword == ETK_None || Keyword == ETK_Typename)
570 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
571
572 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
573
Douglas Gregore677daf2010-03-31 22:19:08 +0000574 // We had a dependent elaborated-type-specifier that as been transformed
575 // into a non-dependent elaborated-type-specifier. Find the tag we're
576 // referring to.
577 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
578 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
579 if (!DC)
580 return QualType();
581
582 TagDecl *Tag = 0;
583 SemaRef.LookupQualifiedName(Result, DC);
584 switch (Result.getResultKind()) {
585 case LookupResult::NotFound:
586 case LookupResult::NotFoundInCurrentInstantiation:
587 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000588
Douglas Gregore677daf2010-03-31 22:19:08 +0000589 case LookupResult::Found:
590 Tag = Result.getAsSingle<TagDecl>();
591 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000592
Douglas Gregore677daf2010-03-31 22:19:08 +0000593 case LookupResult::FoundOverloaded:
594 case LookupResult::FoundUnresolvedValue:
595 llvm_unreachable("Tag lookup cannot find non-tags");
596 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000597
Douglas Gregore677daf2010-03-31 22:19:08 +0000598 case LookupResult::Ambiguous:
599 // Let the LookupResult structure handle ambiguities.
600 return QualType();
601 }
602
603 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000604 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000605 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000606 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000607 return QualType();
608 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000609
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 // FIXME: Terrible location information
611 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
612 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
613 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
614 return QualType();
615 }
616
617 // Build the elaborated-type-specifier type.
618 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000619 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000620 }
Mike Stump11289f42009-09-09 15:08:12 +0000621
Douglas Gregor1135c352009-08-06 05:28:30 +0000622 /// \brief Build a new nested-name-specifier given the prefix and an
623 /// identifier that names the next step in the nested-name-specifier.
624 ///
625 /// By default, performs semantic analysis when building the new
626 /// nested-name-specifier. Subclasses may override this routine to provide
627 /// different behavior.
628 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
629 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000630 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000631 QualType ObjectType,
632 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000633
634 /// \brief Build a new nested-name-specifier given the prefix and the
635 /// namespace named in the next step in the nested-name-specifier.
636 ///
637 /// By default, performs semantic analysis when building the new
638 /// nested-name-specifier. Subclasses may override this routine to provide
639 /// different behavior.
640 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
641 SourceRange Range,
642 NamespaceDecl *NS);
643
644 /// \brief Build a new nested-name-specifier given the prefix and the
645 /// type named in the next step in the nested-name-specifier.
646 ///
647 /// By default, performs semantic analysis when building the new
648 /// nested-name-specifier. Subclasses may override this routine to provide
649 /// different behavior.
650 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
651 SourceRange Range,
652 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000653 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000654
655 /// \brief Build a new template name given a nested name specifier, a flag
656 /// indicating whether the "template" keyword was provided, and the template
657 /// that the template name refers to.
658 ///
659 /// By default, builds the new template name directly. Subclasses may override
660 /// this routine to provide different behavior.
661 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
662 bool TemplateKW,
663 TemplateDecl *Template);
664
Douglas Gregor71dc5092009-08-06 06:41:21 +0000665 /// \brief Build a new template name given a nested name specifier and the
666 /// name that is referred to as a template.
667 ///
668 /// By default, performs semantic analysis to determine whether the name can
669 /// be resolved to a specific template, then builds the appropriate kind of
670 /// template name. Subclasses may override this routine to provide different
671 /// behavior.
672 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000673 const IdentifierInfo &II,
674 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregor71395fa2009-11-04 00:56:37 +0000676 /// \brief Build a new template name given a nested name specifier and the
677 /// overloaded operator name that is referred to as a template.
678 ///
679 /// By default, performs semantic analysis to determine whether the name can
680 /// be resolved to a specific template, then builds the appropriate kind of
681 /// template name. Subclasses may override this routine to provide different
682 /// behavior.
683 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
684 OverloadedOperatorKind Operator,
685 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000686
Douglas Gregorebe10102009-08-20 07:17:43 +0000687 /// \brief Build a new compound statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
691 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
692 MultiStmtArg Statements,
693 SourceLocation RBraceLoc,
694 bool IsStmtExpr) {
695 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
696 IsStmtExpr);
697 }
698
699 /// \brief Build a new case statement.
700 ///
701 /// By default, performs semantic analysis to build the new statement.
702 /// Subclasses may override this routine to provide different behavior.
703 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
704 ExprArg LHS,
705 SourceLocation EllipsisLoc,
706 ExprArg RHS,
707 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000708 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 ColonLoc);
710 }
Mike Stump11289f42009-09-09 15:08:12 +0000711
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 /// \brief Attach the body to a new case statement.
713 ///
714 /// By default, performs semantic analysis to build the new statement.
715 /// Subclasses may override this routine to provide different behavior.
716 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
717 getSema().ActOnCaseStmtBody(S.get(), move(Body));
718 return move(S);
719 }
Mike Stump11289f42009-09-09 15:08:12 +0000720
Douglas Gregorebe10102009-08-20 07:17:43 +0000721 /// \brief Build a new default statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000725 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation ColonLoc,
727 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000728 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 /*CurScope=*/0);
730 }
Mike Stump11289f42009-09-09 15:08:12 +0000731
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 /// \brief Build a new label statement.
733 ///
734 /// By default, performs semantic analysis to build the new statement.
735 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000736 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 IdentifierInfo *Id,
738 SourceLocation ColonLoc,
739 StmtArg SubStmt) {
740 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
741 }
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /// \brief Build a new "if" statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000747 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000748 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000749 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000750 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000751 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 }
Mike Stump11289f42009-09-09 15:08:12 +0000753
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 /// \brief Start building a new switch statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000758 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
759 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000760 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000761 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
762 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Attach the body to the switch statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000769 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 StmtArg Switch, StmtArg Body) {
771 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
772 move(Body));
773 }
774
775 /// \brief Build a new while statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
779 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000780 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000781 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000783 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000784 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 }
Mike Stump11289f42009-09-09 15:08:12 +0000786
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 /// \brief Build a new do-while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
792 SourceLocation WhileLoc,
793 SourceLocation LParenLoc,
794 ExprArg Cond,
795 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000796 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 move(Cond), RParenLoc);
798 }
799
800 /// \brief Build a new for statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000804 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000806 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000807 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000809 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000810 DeclPtrTy::make(CondVar),
811 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 /// \brief Build a new goto statement.
815 ///
816 /// By default, performs semantic analysis to build the new statement.
817 /// Subclasses may override this routine to provide different behavior.
818 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
819 SourceLocation LabelLoc,
820 LabelStmt *Label) {
821 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
822 }
823
824 /// \brief Build a new indirect goto statement.
825 ///
826 /// By default, performs semantic analysis to build the new statement.
827 /// Subclasses may override this routine to provide different behavior.
828 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
829 SourceLocation StarLoc,
830 ExprArg Target) {
831 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 /// \brief Build a new return statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
838 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
839 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000840
Douglas Gregorebe10102009-08-20 07:17:43 +0000841 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
842 }
Mike Stump11289f42009-09-09 15:08:12 +0000843
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 /// \brief Build a new declaration statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
848 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000849 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 SourceLocation EndLoc) {
851 return getSema().Owned(
852 new (getSema().Context) DeclStmt(
853 DeclGroupRef::Create(getSema().Context,
854 Decls, NumDecls),
855 StartLoc, EndLoc));
856 }
Mike Stump11289f42009-09-09 15:08:12 +0000857
Anders Carlssonaaeef072010-01-24 05:50:09 +0000858 /// \brief Build a new inline asm statement.
859 ///
860 /// By default, performs semantic analysis to build the new statement.
861 /// Subclasses may override this routine to provide different behavior.
862 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
863 bool IsSimple,
864 bool IsVolatile,
865 unsigned NumOutputs,
866 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000867 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000868 MultiExprArg Constraints,
869 MultiExprArg Exprs,
870 ExprArg AsmString,
871 MultiExprArg Clobbers,
872 SourceLocation RParenLoc,
873 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000874 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000875 NumInputs, Names, move(Constraints),
876 move(Exprs), move(AsmString), move(Clobbers),
877 RParenLoc, MSAsm);
878 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000879
880 /// \brief Build a new Objective-C @try statement.
881 ///
882 /// By default, performs semantic analysis to build the new statement.
883 /// Subclasses may override this routine to provide different behavior.
884 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
885 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000886 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000887 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000888 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000889 move(Finally));
890 }
891
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000892 /// \brief Rebuild an Objective-C exception declaration.
893 ///
894 /// By default, performs semantic analysis to build the new declaration.
895 /// Subclasses may override this routine to provide different behavior.
896 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
897 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000898 return getSema().BuildObjCExceptionDecl(TInfo, T,
899 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000900 ExceptionDecl->getLocation());
901 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000902
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000903 /// \brief Build a new Objective-C @catch statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
907 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
908 SourceLocation RParenLoc,
909 VarDecl *Var,
910 StmtArg Body) {
911 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
912 Sema::DeclPtrTy::make(Var),
913 move(Body));
914 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000915
Douglas Gregor306de2f2010-04-22 23:59:56 +0000916 /// \brief Build a new Objective-C @finally statement.
917 ///
918 /// By default, performs semantic analysis to build the new statement.
919 /// Subclasses may override this routine to provide different behavior.
920 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
921 StmtArg Body) {
922 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
923 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000924
Douglas Gregor6148de72010-04-22 22:01:21 +0000925 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000926 ///
927 /// By default, performs semantic analysis to build the new statement.
928 /// Subclasses may override this routine to provide different behavior.
929 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
930 ExprArg Operand) {
931 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
932 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000933
Douglas Gregor6148de72010-04-22 22:01:21 +0000934 /// \brief Build a new Objective-C @synchronized statement.
935 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
938 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
939 ExprArg Object,
940 StmtArg Body) {
941 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
942 move(Body));
943 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000944
945 /// \brief Build a new Objective-C fast enumeration statement.
946 ///
947 /// By default, performs semantic analysis to build the new statement.
948 /// Subclasses may override this routine to provide different behavior.
949 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
950 SourceLocation LParenLoc,
951 StmtArg Element,
952 ExprArg Collection,
953 SourceLocation RParenLoc,
954 StmtArg Body) {
955 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000956 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000957 move(Collection),
958 RParenLoc,
959 move(Body));
960 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000961
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 /// \brief Build a new C++ exception declaration.
963 ///
964 /// By default, performs semantic analysis to build the new decaration.
965 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000966 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000967 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000968 IdentifierInfo *Name,
969 SourceLocation Loc,
970 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000971 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 TypeRange);
973 }
974
975 /// \brief Build a new C++ catch statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
979 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
980 VarDecl *ExceptionDecl,
981 StmtArg Handler) {
982 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000983 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 Handler.takeAs<Stmt>()));
985 }
Mike Stump11289f42009-09-09 15:08:12 +0000986
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 /// \brief Build a new C++ try statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
992 StmtArg TryBlock,
993 MultiStmtArg Handlers) {
994 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
995 }
Mike Stump11289f42009-09-09 15:08:12 +0000996
Douglas Gregora16548e2009-08-11 05:31:07 +0000997 /// \brief Build a new expression that references a declaration.
998 ///
999 /// By default, performs semantic analysis to build the new expression.
1000 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001001 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1002 LookupResult &R,
1003 bool RequiresADL) {
1004 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1005 }
1006
1007
1008 /// \brief Build a new expression that references a declaration.
1009 ///
1010 /// By default, performs semantic analysis to build the new expression.
1011 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001012 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1013 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001014 ValueDecl *VD, SourceLocation Loc,
1015 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001016 CXXScopeSpec SS;
1017 SS.setScopeRep(Qualifier);
1018 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001019
1020 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001021
John McCallce546572009-12-08 09:08:17 +00001022 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1030 SourceLocation RParen) {
1031 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1032 }
1033
Douglas Gregorad8a3362009-09-04 17:36:40 +00001034 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001035 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001036 /// By default, performs semantic analysis to build the new expression.
1037 /// Subclasses may override this routine to provide different behavior.
1038 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1039 SourceLocation OperatorLoc,
1040 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001041 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001042 SourceRange QualifierRange,
1043 TypeSourceInfo *ScopeType,
1044 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001045 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001046 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001047
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
1052 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1053 UnaryOperator::Opcode Opc,
1054 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001055 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001056 }
Mike Stump11289f42009-09-09 15:08:12 +00001057
Douglas Gregor882211c2010-04-28 22:16:22 +00001058 /// \brief Build a new builtin offsetof expression.
1059 ///
1060 /// By default, performs semantic analysis to build the new expression.
1061 /// Subclasses may override this routine to provide different behavior.
1062 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1063 TypeSourceInfo *Type,
1064 Action::OffsetOfComponent *Components,
1065 unsigned NumComponents,
1066 SourceLocation RParenLoc) {
1067 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1068 NumComponents, RParenLoc);
1069 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001070
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001072 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 /// By default, performs semantic analysis to build the new expression.
1074 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001075 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001076 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001077 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001078 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001079 }
1080
Mike Stump11289f42009-09-09 15:08:12 +00001081 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001082 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001083 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 /// By default, performs semantic analysis to build the new expression.
1085 /// Subclasses may override this routine to provide different behavior.
1086 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1087 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001088 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1090 OpLoc, isSizeOf, R);
1091 if (Result.isInvalid())
1092 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001093
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 SubExpr.release();
1095 return move(Result);
1096 }
Mike Stump11289f42009-09-09 15:08:12 +00001097
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001102 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 SourceLocation LBracketLoc,
1104 ExprArg RHS,
1105 SourceLocation RBracketLoc) {
1106 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001107 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 RBracketLoc);
1109 }
1110
1111 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
1115 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1116 MultiExprArg Args,
1117 SourceLocation *CommaLocs,
1118 SourceLocation RParenLoc) {
1119 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1120 move(Args), CommaLocs, RParenLoc);
1121 }
1122
1123 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
1127 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001128 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001129 NestedNameSpecifier *Qualifier,
1130 SourceRange QualifierRange,
1131 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001132 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001133 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001134 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001135 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001136 if (!Member->getDeclName()) {
1137 // We have a reference to an unnamed field.
1138 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001139
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001140 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001141 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1142 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001143 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001144
Mike Stump11289f42009-09-09 15:08:12 +00001145 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001146 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001147 Member, MemberLoc,
1148 cast<FieldDecl>(Member)->getType());
1149 return getSema().Owned(ME);
1150 }
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001152 CXXScopeSpec SS;
1153 if (Qualifier) {
1154 SS.setRange(QualifierRange);
1155 SS.setScopeRep(Qualifier);
1156 }
1157
John McCall2d74de92009-12-01 22:10:20 +00001158 QualType BaseType = ((Expr*) Base.get())->getType();
1159
John McCall16df1e52010-03-30 21:47:33 +00001160 // FIXME: this involves duplicating earlier analysis in a lot of
1161 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001162 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1163 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001164 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001165 R.resolveKind();
1166
John McCall2d74de92009-12-01 22:10:20 +00001167 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1168 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001169 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001170 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001174 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
1177 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1178 BinaryOperator::Opcode Opc,
1179 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001181 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 }
1183
1184 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001185 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
1188 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1189 SourceLocation QuestionLoc,
1190 ExprArg LHS,
1191 SourceLocation ColonLoc,
1192 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001193 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 move(LHS), move(RHS));
1195 }
1196
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001198 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 /// By default, performs semantic analysis to build the new expression.
1200 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001201 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1202 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 SourceLocation RParenLoc,
1204 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001205 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1206 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001210 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
1213 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001214 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
1216 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001217 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1218 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001225 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation OpLoc,
1227 SourceLocation AccessorLoc,
1228 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001229
John McCall10eae182009-11-30 22:42:35 +00001230 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001231 QualType BaseType = ((Expr*) Base.get())->getType();
1232 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001233 OpLoc, /*IsArrow*/ false,
1234 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001235 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001236 AccessorLoc,
1237 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001241 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 /// By default, performs semantic analysis to build the new expression.
1243 /// Subclasses may override this routine to provide different behavior.
1244 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1245 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001246 SourceLocation RBraceLoc,
1247 QualType ResultTy) {
1248 OwningExprResult Result
1249 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1250 if (Result.isInvalid() || ResultTy->isDependentType())
1251 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001252
Douglas Gregord3d93062009-11-09 17:16:50 +00001253 // Patch in the result type we were given, which may have been computed
1254 // when the initial InitListExpr was built.
1255 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1256 ILE->setType(ResultTy);
1257 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001261 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
1264 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1265 MultiExprArg ArrayExprs,
1266 SourceLocation EqualOrColonLoc,
1267 bool GNUSyntax,
1268 ExprArg Init) {
1269 OwningExprResult Result
1270 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1271 move(Init));
1272 if (Result.isInvalid())
1273 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001274
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 ArrayExprs.release();
1276 return move(Result);
1277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// By default, builds the implicit value initialization without performing
1282 /// any semantic analysis. Subclasses may override this routine to provide
1283 /// different behavior.
1284 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1285 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1293 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001294 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 RParenLoc);
1296 }
1297
1298 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1303 MultiExprArg SubExprs,
1304 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001305 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001306 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
1311 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// rather than attempting to map the label statement itself.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1315 SourceLocation LabelLoc,
1316 LabelStmt *Label) {
1317 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001321 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// By default, performs semantic analysis to build the new expression.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1325 StmtArg SubStmt,
1326 SourceLocation RParenLoc) {
1327 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new __builtin_types_compatible_p expression.
1331 ///
1332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
1334 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1335 QualType T1, QualType T2,
1336 SourceLocation RParenLoc) {
1337 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1338 T1.getAsOpaquePtr(),
1339 T2.getAsOpaquePtr(),
1340 RParenLoc);
1341 }
Mike Stump11289f42009-09-09 15:08:12 +00001342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new __builtin_choose_expr expression.
1344 ///
1345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1348 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1349 SourceLocation RParenLoc) {
1350 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1351 move(Cond), move(LHS), move(RHS),
1352 RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new overloaded operator call expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// The semantic analysis provides the behavior of template instantiation,
1359 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001360 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// argument-dependent lookup, etc. Subclasses may override this routine to
1362 /// provide different behavior.
1363 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1364 SourceLocation OpLoc,
1365 ExprArg Callee,
1366 ExprArg First,
1367 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001368
1369 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// reinterpret_cast.
1371 ///
1372 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001373 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// Subclasses may override this routine to provide different behavior.
1375 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1376 Stmt::StmtClass Class,
1377 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001378 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 SourceLocation RAngleLoc,
1380 SourceLocation LParenLoc,
1381 ExprArg SubExpr,
1382 SourceLocation RParenLoc) {
1383 switch (Class) {
1384 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001385 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001386 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 move(SubExpr), RParenLoc);
1388
1389 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001390 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001391 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001393
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
1397 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001399
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001404
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 default:
1406 assert(false && "Invalid C++ named cast");
1407 break;
1408 }
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 return getSema().ExprError();
1411 }
Mike Stump11289f42009-09-09 15:08:12 +00001412
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// \brief Build a new C++ static_cast expression.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1418 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001419 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 SourceLocation RAngleLoc,
1421 SourceLocation LParenLoc,
1422 ExprArg SubExpr,
1423 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001424 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1425 TInfo, move(SubExpr),
1426 SourceRange(LAngleLoc, RAngleLoc),
1427 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 }
1429
1430 /// \brief Build a new C++ dynamic_cast expression.
1431 ///
1432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1435 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001436 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 SourceLocation RAngleLoc,
1438 SourceLocation LParenLoc,
1439 ExprArg SubExpr,
1440 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001441 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1442 TInfo, move(SubExpr),
1443 SourceRange(LAngleLoc, RAngleLoc),
1444 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 }
1446
1447 /// \brief Build a new C++ reinterpret_cast expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
1451 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1452 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001453 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 SourceLocation RAngleLoc,
1455 SourceLocation LParenLoc,
1456 ExprArg SubExpr,
1457 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001458 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1459 TInfo, move(SubExpr),
1460 SourceRange(LAngleLoc, RAngleLoc),
1461 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 }
1463
1464 /// \brief Build a new C++ const_cast expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
1468 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1469 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001470 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 SourceLocation RAngleLoc,
1472 SourceLocation LParenLoc,
1473 ExprArg SubExpr,
1474 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001475 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1476 TInfo, move(SubExpr),
1477 SourceRange(LAngleLoc, RAngleLoc),
1478 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 }
Mike Stump11289f42009-09-09 15:08:12 +00001480
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 /// \brief Build a new C++ functional-style cast expression.
1482 ///
1483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
1485 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 SourceLocation LParenLoc,
1488 ExprArg SubExpr,
1489 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001490 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001492 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001494 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001495 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 RParenLoc);
1497 }
Mike Stump11289f42009-09-09 15:08:12 +00001498
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 /// \brief Build a new C++ typeid(type) expression.
1500 ///
1501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001503 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1504 SourceLocation TypeidLoc,
1505 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001507 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001508 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new C++ typeid(expr) expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001515 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1516 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 ExprArg Operand,
1518 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1520 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001521 }
1522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new C++ "this" expression.
1524 ///
1525 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001526 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001528 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001529 QualType ThisType,
1530 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001532 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1533 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
1535
1536 /// \brief Build a new C++ throw expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
1540 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1541 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1542 }
1543
1544 /// \brief Build a new C++ default-argument expression.
1545 ///
1546 /// By default, builds a new default-argument expression, which does not
1547 /// require any semantic analysis. Subclasses may override this routine to
1548 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001549 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001550 ParmVarDecl *Param) {
1551 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1552 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 }
1554
1555 /// \brief Build a new C++ zero-initialization expression.
1556 ///
1557 /// By default, performs semantic analysis to build the new expression.
1558 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001559 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 SourceLocation LParenLoc,
1561 QualType T,
1562 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001563 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1564 T.getAsOpaquePtr(), LParenLoc,
1565 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 0, RParenLoc);
1567 }
Mike Stump11289f42009-09-09 15:08:12 +00001568
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// \brief Build a new C++ "new" expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001573 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 bool UseGlobal,
1575 SourceLocation PlacementLParen,
1576 MultiExprArg PlacementArgs,
1577 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001578 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 QualType AllocType,
1580 SourceLocation TypeLoc,
1581 SourceRange TypeRange,
1582 ExprArg ArraySize,
1583 SourceLocation ConstructorLParen,
1584 MultiExprArg ConstructorArgs,
1585 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001586 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 PlacementLParen,
1588 move(PlacementArgs),
1589 PlacementRParen,
1590 ParenTypeId,
1591 AllocType,
1592 TypeLoc,
1593 TypeRange,
1594 move(ArraySize),
1595 ConstructorLParen,
1596 move(ConstructorArgs),
1597 ConstructorRParen);
1598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new C++ "delete" expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
1604 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1605 bool IsGlobalDelete,
1606 bool IsArrayForm,
1607 ExprArg Operand) {
1608 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1609 move(Operand));
1610 }
Mike Stump11289f42009-09-09 15:08:12 +00001611
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// \brief Build a new unary type trait expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 QualType T,
1620 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001621 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 T.getAsOpaquePtr(), RParenLoc);
1623 }
1624
Mike Stump11289f42009-09-09 15:08:12 +00001625 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001630 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceRange QualifierRange,
1632 DeclarationName Name,
1633 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001634 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 CXXScopeSpec SS;
1636 SS.setRange(QualifierRange);
1637 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001638
1639 if (TemplateArgs)
1640 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1641 *TemplateArgs);
1642
1643 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 }
1645
1646 /// \brief Build a new template-id expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001650 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1651 LookupResult &R,
1652 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001653 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001654 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new object-construction expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
1661 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001662 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 CXXConstructorDecl *Constructor,
1664 bool IsElidable,
1665 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001666 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001667 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001668 ConvertedArgs))
1669 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001670
Douglas Gregordb121ba2009-12-14 16:27:04 +00001671 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1672 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 }
1674
1675 /// \brief Build a new object-construction expression.
1676 ///
1677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
1679 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1680 QualType T,
1681 SourceLocation LParenLoc,
1682 MultiExprArg Args,
1683 SourceLocation *Commas,
1684 SourceLocation RParenLoc) {
1685 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1686 T.getAsOpaquePtr(),
1687 LParenLoc,
1688 move(Args),
1689 Commas,
1690 RParenLoc);
1691 }
1692
1693 /// \brief Build a new object-construction expression.
1694 ///
1695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1698 QualType T,
1699 SourceLocation LParenLoc,
1700 MultiExprArg Args,
1701 SourceLocation *Commas,
1702 SourceLocation RParenLoc) {
1703 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1704 /*FIXME*/LParenLoc),
1705 T.getAsOpaquePtr(),
1706 LParenLoc,
1707 move(Args),
1708 Commas,
1709 RParenLoc);
1710 }
Mike Stump11289f42009-09-09 15:08:12 +00001711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// \brief Build a new member reference expression.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001716 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001717 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 bool IsArrow,
1719 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001720 NestedNameSpecifier *Qualifier,
1721 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001722 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001724 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001725 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001727 SS.setRange(QualifierRange);
1728 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001729
John McCall2d74de92009-12-01 22:10:20 +00001730 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1731 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001732 SS, FirstQualifierInScope,
1733 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 }
1735
John McCall10eae182009-11-30 22:42:35 +00001736 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001740 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001741 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001742 SourceLocation OperatorLoc,
1743 bool IsArrow,
1744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001746 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001747 LookupResult &R,
1748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001749 CXXScopeSpec SS;
1750 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 McCall38836f02010-01-15 08:34:02 +00001755 SS, FirstQualifierInScope,
1756 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001757 }
Mike Stump11289f42009-09-09 15:08:12 +00001758
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 /// \brief Build a new Objective-C @encode expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
1763 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001764 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001766 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001768 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001769
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001770 /// \brief Build a new Objective-C class message.
1771 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1772 Selector Sel,
1773 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001774 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001775 MultiExprArg Args,
1776 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001777 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1778 ReceiverTypeInfo->getType(),
1779 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001780 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001781 move(Args));
1782 }
1783
1784 /// \brief Build a new Objective-C instance message.
1785 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1786 Selector Sel,
1787 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001788 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 MultiExprArg Args,
1790 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001791 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1792 return SemaRef.BuildInstanceMessage(move(Receiver),
1793 ReceiverType,
1794 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001795 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001796 move(Args));
1797 }
1798
Douglas Gregord51d90d2010-04-26 20:11:03 +00001799 /// \brief Build a new Objective-C ivar reference expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
1803 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1804 SourceLocation IvarLoc,
1805 bool IsArrow, bool IsFreeIvar) {
1806 // FIXME: We lose track of the IsFreeIvar bit.
1807 CXXScopeSpec SS;
1808 Expr *Base = BaseArg.takeAs<Expr>();
1809 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1810 Sema::LookupMemberName);
1811 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1812 /*FIME:*/IvarLoc,
1813 SS, DeclPtrTy());
1814 if (Result.isInvalid())
1815 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001816
Douglas Gregord51d90d2010-04-26 20:11:03 +00001817 if (Result.get())
1818 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001819
1820 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001821 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001822 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001824 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001825 /*TemplateArgs=*/0);
1826 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001827
1828 /// \brief Build a new Objective-C property reference expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001833 ObjCPropertyDecl *Property,
1834 SourceLocation PropertyLoc) {
1835 CXXScopeSpec SS;
1836 Expr *Base = BaseArg.takeAs<Expr>();
1837 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1838 Sema::LookupMemberName);
1839 bool IsArrow = false;
1840 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1841 /*FIME:*/PropertyLoc,
1842 SS, DeclPtrTy());
1843 if (Result.isInvalid())
1844 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001845
Douglas Gregor9faee212010-04-26 20:47:02 +00001846 if (Result.get())
1847 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848
1849 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001850 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001851 /*FIXME:*/PropertyLoc, IsArrow,
1852 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001853 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001854 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001855 /*TemplateArgs=*/0);
1856 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001857
1858 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001859 /// expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001862 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001863 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1864 ObjCMethodDecl *Getter,
1865 QualType T,
1866 ObjCMethodDecl *Setter,
1867 SourceLocation NameLoc,
1868 ExprArg Base) {
1869 // Since these expressions can only be value-dependent, we do not need to
1870 // perform semantic analysis again.
1871 return getSema().Owned(
1872 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1873 Setter,
1874 NameLoc,
1875 Base.takeAs<Expr>()));
1876 }
1877
Douglas Gregord51d90d2010-04-26 20:11:03 +00001878 /// \brief Build a new Objective-C "isa" expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
1882 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1883 bool IsArrow) {
1884 CXXScopeSpec SS;
1885 Expr *Base = BaseArg.takeAs<Expr>();
1886 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1887 Sema::LookupMemberName);
1888 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1889 /*FIME:*/IsaLoc,
1890 SS, DeclPtrTy());
1891 if (Result.isInvalid())
1892 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001893
Douglas Gregord51d90d2010-04-26 20:11:03 +00001894 if (Result.get())
1895 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001896
1897 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001898 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001899 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001901 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001902 /*TemplateArgs=*/0);
1903 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001904
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 /// \brief Build a new shuffle vector expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1910 MultiExprArg SubExprs,
1911 SourceLocation RParenLoc) {
1912 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001913 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1915 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1916 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1917 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001918
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 // Build a reference to the __builtin_shufflevector builtin
1920 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001921 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001923 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001925
1926 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 unsigned NumSubExprs = SubExprs.size();
1928 Expr **Subs = (Expr **)SubExprs.release();
1929 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1930 Subs, NumSubExprs,
1931 Builtin->getResultType(),
1932 RParenLoc);
1933 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 // Type-check the __builtin_shufflevector expression.
1936 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1937 if (Result.isInvalid())
1938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001941 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001943};
Douglas Gregora16548e2009-08-11 05:31:07 +00001944
Douglas Gregorebe10102009-08-20 07:17:43 +00001945template<typename Derived>
1946Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1947 if (!S)
1948 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregorebe10102009-08-20 07:17:43 +00001950 switch (S->getStmtClass()) {
1951 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregorebe10102009-08-20 07:17:43 +00001953 // Transform individual statement nodes
1954#define STMT(Node, Parent) \
1955 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1956#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001957#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregorebe10102009-08-20 07:17:43 +00001959 // Transform expressions by calling TransformExpr.
1960#define STMT(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001961#define ABSTRACT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001962#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001963#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001964 {
1965 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1966 if (E.isInvalid())
1967 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001968
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001969 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971 }
1972
Douglas Gregorebe10102009-08-20 07:17:43 +00001973 return SemaRef.Owned(S->Retain());
1974}
Mike Stump11289f42009-09-09 15:08:12 +00001975
1976
Douglas Gregore922c772009-08-04 22:27:00 +00001977template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001978Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 if (!E)
1980 return SemaRef.Owned(E);
1981
1982 switch (E->getStmtClass()) {
1983 case Stmt::NoStmtClass: break;
1984#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Hunt656bb312010-05-05 15:24:00 +00001985#define ABSTRACT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001986#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001987 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001988#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001989 }
1990
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001992}
1993
1994template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001995NestedNameSpecifier *
1996TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001997 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001998 QualType ObjectType,
1999 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002000 if (!NNS)
2001 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregorebe10102009-08-20 07:17:43 +00002003 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002004 NestedNameSpecifier *Prefix = NNS->getPrefix();
2005 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002006 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002007 ObjectType,
2008 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002009 if (!Prefix)
2010 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002011
2012 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002013 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002014 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002015 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Douglas Gregor1135c352009-08-06 05:28:30 +00002018 switch (NNS->getKind()) {
2019 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002020 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002021 "Identifier nested-name-specifier with no prefix or object type");
2022 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2023 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002024 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002025
2026 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002027 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002028 ObjectType,
2029 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregor1135c352009-08-06 05:28:30 +00002031 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002032 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002033 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002034 getDerived().TransformDecl(Range.getBegin(),
2035 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002036 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002037 Prefix == NNS->getPrefix() &&
2038 NS == NNS->getAsNamespace())
2039 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2042 }
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregor1135c352009-08-06 05:28:30 +00002044 case NestedNameSpecifier::Global:
2045 // There is no meaningful transformation that one could perform on the
2046 // global scope.
2047 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 case NestedNameSpecifier::TypeSpecWithTemplate:
2050 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002051 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002052 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2053 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002054 if (T.isNull())
2055 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 if (!getDerived().AlwaysRebuild() &&
2058 Prefix == NNS->getPrefix() &&
2059 T == QualType(NNS->getAsType(), 0))
2060 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002061
2062 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2063 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002064 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 }
2066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregor1135c352009-08-06 05:28:30 +00002068 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002069 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002070}
2071
2072template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002073DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002074TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002075 SourceLocation Loc,
2076 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002077 if (!Name)
2078 return Name;
2079
2080 switch (Name.getNameKind()) {
2081 case DeclarationName::Identifier:
2082 case DeclarationName::ObjCZeroArgSelector:
2083 case DeclarationName::ObjCOneArgSelector:
2084 case DeclarationName::ObjCMultiArgSelector:
2085 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002086 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002087 case DeclarationName::CXXUsingDirective:
2088 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregorf816bd72009-09-03 22:13:48 +00002090 case DeclarationName::CXXConstructorName:
2091 case DeclarationName::CXXDestructorName:
2092 case DeclarationName::CXXConversionFunctionName: {
2093 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002094 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002095 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002096 if (T.isNull())
2097 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregorf816bd72009-09-03 22:13:48 +00002099 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002100 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002102 }
Mike Stump11289f42009-09-09 15:08:12 +00002103 }
2104
Douglas Gregorf816bd72009-09-03 22:13:48 +00002105 return DeclarationName();
2106}
2107
2108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002109TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002110TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2111 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002112 SourceLocation Loc = getDerived().getBaseLocation();
2113
Douglas Gregor71dc5092009-08-06 06:41:21 +00002114 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002115 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002116 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002117 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2118 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002119 if (!NNS)
2120 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002121
Douglas Gregor71dc5092009-08-06 06:41:21 +00002122 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002123 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002124 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002125 if (!TransTemplate)
2126 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregor71dc5092009-08-06 06:41:21 +00002128 if (!getDerived().AlwaysRebuild() &&
2129 NNS == QTN->getQualifier() &&
2130 TransTemplate == Template)
2131 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002132
Douglas Gregor71dc5092009-08-06 06:41:21 +00002133 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2134 TransTemplate);
2135 }
Mike Stump11289f42009-09-09 15:08:12 +00002136
John McCalle66edc12009-11-24 19:00:30 +00002137 // These should be getting filtered out before they make it into the AST.
2138 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002139 }
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregor71dc5092009-08-06 06:41:21 +00002141 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002142 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002143 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002144 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2145 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002146 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002147 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002148
Douglas Gregor71dc5092009-08-06 06:41:21 +00002149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002150 NNS == DTN->getQualifier() &&
2151 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregor71395fa2009-11-04 00:56:37 +00002154 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002156 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002157
2158 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002159 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 }
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregor71dc5092009-08-06 06:41:21 +00002162 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002163 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002164 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 if (!TransTemplate)
2166 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor71dc5092009-08-06 06:41:21 +00002168 if (!getDerived().AlwaysRebuild() &&
2169 TransTemplate == Template)
2170 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregor71dc5092009-08-06 06:41:21 +00002172 return TemplateName(TransTemplate);
2173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
John McCalle66edc12009-11-24 19:00:30 +00002175 // These should be getting filtered out before they reach the AST.
2176 assert(false && "overloaded function decl survived to here");
2177 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178}
2179
2180template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002181void TreeTransform<Derived>::InventTemplateArgumentLoc(
2182 const TemplateArgument &Arg,
2183 TemplateArgumentLoc &Output) {
2184 SourceLocation Loc = getDerived().getBaseLocation();
2185 switch (Arg.getKind()) {
2186 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002187 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002188 break;
2189
2190 case TemplateArgument::Type:
2191 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002192 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002193
John McCall0ad16662009-10-29 08:12:44 +00002194 break;
2195
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002196 case TemplateArgument::Template:
2197 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2198 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002199
John McCall0ad16662009-10-29 08:12:44 +00002200 case TemplateArgument::Expression:
2201 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2202 break;
2203
2204 case TemplateArgument::Declaration:
2205 case TemplateArgument::Integral:
2206 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002207 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002208 break;
2209 }
2210}
2211
2212template<typename Derived>
2213bool TreeTransform<Derived>::TransformTemplateArgument(
2214 const TemplateArgumentLoc &Input,
2215 TemplateArgumentLoc &Output) {
2216 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002217 switch (Arg.getKind()) {
2218 case TemplateArgument::Null:
2219 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002220 Output = Input;
2221 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregore922c772009-08-04 22:27:00 +00002223 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002224 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002225 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002226 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002227
2228 DI = getDerived().TransformType(DI);
2229 if (!DI) return true;
2230
2231 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2232 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregore922c772009-08-04 22:27:00 +00002235 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002236 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002237 DeclarationName Name;
2238 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2239 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002240 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002241 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002242 if (!D) return true;
2243
John McCall0d07eb32009-10-29 18:45:58 +00002244 Expr *SourceExpr = Input.getSourceDeclExpression();
2245 if (SourceExpr) {
2246 EnterExpressionEvaluationContext Unevaluated(getSema(),
2247 Action::Unevaluated);
2248 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2249 if (E.isInvalid())
2250 SourceExpr = NULL;
2251 else {
2252 SourceExpr = E.takeAs<Expr>();
2253 SourceExpr->Retain();
2254 }
2255 }
2256
2257 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002258 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002259 }
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002261 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002262 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002263 TemplateName Template
2264 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2265 if (Template.isNull())
2266 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002267
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002268 Output = TemplateArgumentLoc(TemplateArgument(Template),
2269 Input.getTemplateQualifierRange(),
2270 Input.getTemplateNameLoc());
2271 return false;
2272 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002273
Douglas Gregore922c772009-08-04 22:27:00 +00002274 case TemplateArgument::Expression: {
2275 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002276 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002277 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002278
John McCall0ad16662009-10-29 08:12:44 +00002279 Expr *InputExpr = Input.getSourceExpression();
2280 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2281
2282 Sema::OwningExprResult E
2283 = getDerived().TransformExpr(InputExpr);
2284 if (E.isInvalid()) return true;
2285
2286 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002287 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002288 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2289 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002290 }
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregore922c772009-08-04 22:27:00 +00002292 case TemplateArgument::Pack: {
2293 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2294 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002295 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002296 AEnd = Arg.pack_end();
2297 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002298
John McCall0ad16662009-10-29 08:12:44 +00002299 // FIXME: preserve source information here when we start
2300 // caring about parameter packs.
2301
John McCall0d07eb32009-10-29 18:45:58 +00002302 TemplateArgumentLoc InputArg;
2303 TemplateArgumentLoc OutputArg;
2304 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2305 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002306 return true;
2307
John McCall0d07eb32009-10-29 18:45:58 +00002308 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002309 }
2310 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002311 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002312 true);
John McCall0d07eb32009-10-29 18:45:58 +00002313 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002314 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002315 }
2316 }
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregore922c772009-08-04 22:27:00 +00002318 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002319 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002320}
2321
Douglas Gregord6ff3322009-08-04 16:50:30 +00002322//===----------------------------------------------------------------------===//
2323// Type transformation
2324//===----------------------------------------------------------------------===//
2325
2326template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002327QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002328 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329 if (getDerived().AlreadyTransformed(T))
2330 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002331
John McCall550e0c22009-10-21 00:40:46 +00002332 // Temporary workaround. All of these transformations should
2333 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002334 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002335 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002336
Douglas Gregorfe17d252010-02-16 19:09:40 +00002337 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002338
John McCall550e0c22009-10-21 00:40:46 +00002339 if (!NewDI)
2340 return QualType();
2341
2342 return NewDI->getType();
2343}
2344
2345template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002346TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2347 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002348 if (getDerived().AlreadyTransformed(DI->getType()))
2349 return DI;
2350
2351 TypeLocBuilder TLB;
2352
2353 TypeLoc TL = DI->getTypeLoc();
2354 TLB.reserve(TL.getFullDataSize());
2355
Douglas Gregorfe17d252010-02-16 19:09:40 +00002356 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002357 if (Result.isNull())
2358 return 0;
2359
John McCallbcd03502009-12-07 02:54:59 +00002360 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002361}
2362
2363template<typename Derived>
2364QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002365TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2366 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002367 switch (T.getTypeLocClass()) {
2368#define ABSTRACT_TYPELOC(CLASS, PARENT)
2369#define TYPELOC(CLASS, PARENT) \
2370 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002371 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2372 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002373#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002374 }
Mike Stump11289f42009-09-09 15:08:12 +00002375
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002376 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002377 return QualType();
2378}
2379
2380/// FIXME: By default, this routine adds type qualifiers only to types
2381/// that can have qualifiers, and silently suppresses those qualifiers
2382/// that are not permitted (e.g., qualifiers on reference or function
2383/// types). This is the right thing for template instantiation, but
2384/// probably not for other clients.
2385template<typename Derived>
2386QualType
2387TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002388 QualifiedTypeLoc T,
2389 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002390 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002391
Douglas Gregorfe17d252010-02-16 19:09:40 +00002392 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2393 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002394 if (Result.isNull())
2395 return QualType();
2396
2397 // Silently suppress qualifiers if the result type can't be qualified.
2398 // FIXME: this is the right thing for template instantiation, but
2399 // probably not for other clients.
2400 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002402
John McCall550e0c22009-10-21 00:40:46 +00002403 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2404
2405 TLB.push<QualifiedTypeLoc>(Result);
2406
2407 // No location information to preserve.
2408
2409 return Result;
2410}
2411
2412template <class TyLoc> static inline
2413QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2414 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2415 NewT.setNameLoc(T.getNameLoc());
2416 return T.getType();
2417}
2418
John McCall550e0c22009-10-21 00:40:46 +00002419template<typename Derived>
2420QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002421 BuiltinTypeLoc T,
2422 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002423 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2424 NewT.setBuiltinLoc(T.getBuiltinLoc());
2425 if (T.needsExtraLocalData())
2426 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2427 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002428}
Mike Stump11289f42009-09-09 15:08:12 +00002429
Douglas Gregord6ff3322009-08-04 16:50:30 +00002430template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002431QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002432 ComplexTypeLoc T,
2433 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002434 // FIXME: recurse?
2435 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002436}
Mike Stump11289f42009-09-09 15:08:12 +00002437
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002439QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002440 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002441 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002442 QualType PointeeType
2443 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002444 if (PointeeType.isNull())
2445 return QualType();
2446
2447 QualType Result = TL.getType();
John McCall01f21ad2010-05-13 08:39:13 +00002448 if (PointeeType->isObjCInterfaceType() ||
2449 PointeeType->isSpecificBuiltinType(BuiltinType::ObjCId)) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002450 // A dependent pointer type 'T *' has is being transformed such
2451 // that an Objective-C class type is being replaced for 'T'. The
2452 // resulting pointer type is an ObjCObjectPointerType, not a
2453 // PointerType.
John McCall01f21ad2010-05-13 08:39:13 +00002454 ObjCProtocolDecl **Protocols = 0;
2455 unsigned NumProtocols = 0;
2456
2457 if (const ObjCInterfaceType *IFace
2458 = PointeeType->getAs<ObjCInterfaceType>()) {
2459 Protocols = const_cast<ObjCProtocolDecl**>(IFace->qual_begin());
2460 NumProtocols = IFace->getNumProtocols();
2461 }
2462
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002463 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
John McCall01f21ad2010-05-13 08:39:13 +00002464 Protocols,
2465 NumProtocols);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002466
2467 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2468 NewT.setStarLoc(TL.getSigilLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002469 NewT.setHasProtocolsAsWritten(false);
2470 NewT.setLAngleLoc(SourceLocation());
2471 NewT.setRAngleLoc(SourceLocation());
2472 NewT.setHasBaseTypeAsWritten(true);
2473 return Result;
2474 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002475
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002476 if (getDerived().AlwaysRebuild() ||
2477 PointeeType != TL.getPointeeLoc().getType()) {
2478 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2479 if (Result.isNull())
2480 return QualType();
2481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002482
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002483 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2484 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486}
Mike Stump11289f42009-09-09 15:08:12 +00002487
2488template<typename Derived>
2489QualType
John McCall550e0c22009-10-21 00:40:46 +00002490TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002491 BlockPointerTypeLoc TL,
2492 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002493 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002494 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2495 if (PointeeType.isNull())
2496 return QualType();
2497
2498 QualType Result = TL.getType();
2499 if (getDerived().AlwaysRebuild() ||
2500 PointeeType != TL.getPointeeLoc().getType()) {
2501 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002502 TL.getSigilLoc());
2503 if (Result.isNull())
2504 return QualType();
2505 }
2506
Douglas Gregor049211a2010-04-22 16:50:51 +00002507 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002508 NewT.setSigilLoc(TL.getSigilLoc());
2509 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002510}
2511
John McCall70dd5f62009-10-30 00:06:24 +00002512/// Transforms a reference type. Note that somewhat paradoxically we
2513/// don't care whether the type itself is an l-value type or an r-value
2514/// type; we only care if the type was *written* as an l-value type
2515/// or an r-value type.
2516template<typename Derived>
2517QualType
2518TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002519 ReferenceTypeLoc TL,
2520 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002521 const ReferenceType *T = TL.getTypePtr();
2522
2523 // Note that this works with the pointee-as-written.
2524 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2525 if (PointeeType.isNull())
2526 return QualType();
2527
2528 QualType Result = TL.getType();
2529 if (getDerived().AlwaysRebuild() ||
2530 PointeeType != T->getPointeeTypeAsWritten()) {
2531 Result = getDerived().RebuildReferenceType(PointeeType,
2532 T->isSpelledAsLValue(),
2533 TL.getSigilLoc());
2534 if (Result.isNull())
2535 return QualType();
2536 }
2537
2538 // r-value references can be rebuilt as l-value references.
2539 ReferenceTypeLoc NewTL;
2540 if (isa<LValueReferenceType>(Result))
2541 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2542 else
2543 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2544 NewTL.setSigilLoc(TL.getSigilLoc());
2545
2546 return Result;
2547}
2548
Mike Stump11289f42009-09-09 15:08:12 +00002549template<typename Derived>
2550QualType
John McCall550e0c22009-10-21 00:40:46 +00002551TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002552 LValueReferenceTypeLoc TL,
2553 QualType ObjectType) {
2554 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002555}
2556
Mike Stump11289f42009-09-09 15:08:12 +00002557template<typename Derived>
2558QualType
John McCall550e0c22009-10-21 00:40:46 +00002559TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002560 RValueReferenceTypeLoc TL,
2561 QualType ObjectType) {
2562 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002563}
Mike Stump11289f42009-09-09 15:08:12 +00002564
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002566QualType
John McCall550e0c22009-10-21 00:40:46 +00002567TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002568 MemberPointerTypeLoc TL,
2569 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002570 MemberPointerType *T = TL.getTypePtr();
2571
2572 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002573 if (PointeeType.isNull())
2574 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002575
John McCall550e0c22009-10-21 00:40:46 +00002576 // TODO: preserve source information for this.
2577 QualType ClassType
2578 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002579 if (ClassType.isNull())
2580 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002581
John McCall550e0c22009-10-21 00:40:46 +00002582 QualType Result = TL.getType();
2583 if (getDerived().AlwaysRebuild() ||
2584 PointeeType != T->getPointeeType() ||
2585 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002586 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2587 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002588 if (Result.isNull())
2589 return QualType();
2590 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002591
John McCall550e0c22009-10-21 00:40:46 +00002592 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2593 NewTL.setSigilLoc(TL.getSigilLoc());
2594
2595 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002596}
2597
Mike Stump11289f42009-09-09 15:08:12 +00002598template<typename Derived>
2599QualType
John McCall550e0c22009-10-21 00:40:46 +00002600TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002601 ConstantArrayTypeLoc TL,
2602 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002603 ConstantArrayType *T = TL.getTypePtr();
2604 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002605 if (ElementType.isNull())
2606 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002607
John McCall550e0c22009-10-21 00:40:46 +00002608 QualType Result = TL.getType();
2609 if (getDerived().AlwaysRebuild() ||
2610 ElementType != T->getElementType()) {
2611 Result = getDerived().RebuildConstantArrayType(ElementType,
2612 T->getSizeModifier(),
2613 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002614 T->getIndexTypeCVRQualifiers(),
2615 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002616 if (Result.isNull())
2617 return QualType();
2618 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002619
John McCall550e0c22009-10-21 00:40:46 +00002620 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2621 NewTL.setLBracketLoc(TL.getLBracketLoc());
2622 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002623
John McCall550e0c22009-10-21 00:40:46 +00002624 Expr *Size = TL.getSizeExpr();
2625 if (Size) {
2626 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2627 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2628 }
2629 NewTL.setSizeExpr(Size);
2630
2631 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632}
Mike Stump11289f42009-09-09 15:08:12 +00002633
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002636 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002637 IncompleteArrayTypeLoc TL,
2638 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002639 IncompleteArrayType *T = TL.getTypePtr();
2640 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002641 if (ElementType.isNull())
2642 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002643
John McCall550e0c22009-10-21 00:40:46 +00002644 QualType Result = TL.getType();
2645 if (getDerived().AlwaysRebuild() ||
2646 ElementType != T->getElementType()) {
2647 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002648 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002649 T->getIndexTypeCVRQualifiers(),
2650 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002651 if (Result.isNull())
2652 return QualType();
2653 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002654
John McCall550e0c22009-10-21 00:40:46 +00002655 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2656 NewTL.setLBracketLoc(TL.getLBracketLoc());
2657 NewTL.setRBracketLoc(TL.getRBracketLoc());
2658 NewTL.setSizeExpr(0);
2659
2660 return Result;
2661}
2662
2663template<typename Derived>
2664QualType
2665TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002666 VariableArrayTypeLoc TL,
2667 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002668 VariableArrayType *T = TL.getTypePtr();
2669 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2670 if (ElementType.isNull())
2671 return QualType();
2672
2673 // Array bounds are not potentially evaluated contexts
2674 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2675
2676 Sema::OwningExprResult SizeResult
2677 = getDerived().TransformExpr(T->getSizeExpr());
2678 if (SizeResult.isInvalid())
2679 return QualType();
2680
2681 Expr *Size = static_cast<Expr*>(SizeResult.get());
2682
2683 QualType Result = TL.getType();
2684 if (getDerived().AlwaysRebuild() ||
2685 ElementType != T->getElementType() ||
2686 Size != T->getSizeExpr()) {
2687 Result = getDerived().RebuildVariableArrayType(ElementType,
2688 T->getSizeModifier(),
2689 move(SizeResult),
2690 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002691 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002692 if (Result.isNull())
2693 return QualType();
2694 }
2695 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002696
John McCall550e0c22009-10-21 00:40:46 +00002697 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2698 NewTL.setLBracketLoc(TL.getLBracketLoc());
2699 NewTL.setRBracketLoc(TL.getRBracketLoc());
2700 NewTL.setSizeExpr(Size);
2701
2702 return Result;
2703}
2704
2705template<typename Derived>
2706QualType
2707TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002708 DependentSizedArrayTypeLoc TL,
2709 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002710 DependentSizedArrayType *T = TL.getTypePtr();
2711 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2712 if (ElementType.isNull())
2713 return QualType();
2714
2715 // Array bounds are not potentially evaluated contexts
2716 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2717
2718 Sema::OwningExprResult SizeResult
2719 = getDerived().TransformExpr(T->getSizeExpr());
2720 if (SizeResult.isInvalid())
2721 return QualType();
2722
2723 Expr *Size = static_cast<Expr*>(SizeResult.get());
2724
2725 QualType Result = TL.getType();
2726 if (getDerived().AlwaysRebuild() ||
2727 ElementType != T->getElementType() ||
2728 Size != T->getSizeExpr()) {
2729 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2730 T->getSizeModifier(),
2731 move(SizeResult),
2732 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002733 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002734 if (Result.isNull())
2735 return QualType();
2736 }
2737 else SizeResult.take();
2738
2739 // We might have any sort of array type now, but fortunately they
2740 // all have the same location layout.
2741 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2742 NewTL.setLBracketLoc(TL.getLBracketLoc());
2743 NewTL.setRBracketLoc(TL.getRBracketLoc());
2744 NewTL.setSizeExpr(Size);
2745
2746 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002747}
Mike Stump11289f42009-09-09 15:08:12 +00002748
2749template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002751 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002752 DependentSizedExtVectorTypeLoc TL,
2753 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002754 DependentSizedExtVectorType *T = TL.getTypePtr();
2755
2756 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002757 QualType ElementType = getDerived().TransformType(T->getElementType());
2758 if (ElementType.isNull())
2759 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregore922c772009-08-04 22:27:00 +00002761 // Vector sizes are not potentially evaluated contexts
2762 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2763
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2765 if (Size.isInvalid())
2766 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002767
John McCall550e0c22009-10-21 00:40:46 +00002768 QualType Result = TL.getType();
2769 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002770 ElementType != T->getElementType() ||
2771 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002772 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002773 move(Size),
2774 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002775 if (Result.isNull())
2776 return QualType();
2777 }
2778 else Size.take();
2779
2780 // Result might be dependent or not.
2781 if (isa<DependentSizedExtVectorType>(Result)) {
2782 DependentSizedExtVectorTypeLoc NewTL
2783 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785 } else {
2786 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 }
2789
2790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791}
Mike Stump11289f42009-09-09 15:08:12 +00002792
2793template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002795 VectorTypeLoc TL,
2796 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002797 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002798 QualType ElementType = getDerived().TransformType(T->getElementType());
2799 if (ElementType.isNull())
2800 return QualType();
2801
John McCall550e0c22009-10-21 00:40:46 +00002802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
2804 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002805 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2806 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002810
John McCall550e0c22009-10-21 00:40:46 +00002811 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002813
John McCall550e0c22009-10-21 00:40:46 +00002814 return Result;
2815}
2816
2817template<typename Derived>
2818QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002819 ExtVectorTypeLoc TL,
2820 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002821 VectorType *T = TL.getTypePtr();
2822 QualType ElementType = getDerived().TransformType(T->getElementType());
2823 if (ElementType.isNull())
2824 return QualType();
2825
2826 QualType Result = TL.getType();
2827 if (getDerived().AlwaysRebuild() ||
2828 ElementType != T->getElementType()) {
2829 Result = getDerived().RebuildExtVectorType(ElementType,
2830 T->getNumElements(),
2831 /*FIXME*/ SourceLocation());
2832 if (Result.isNull())
2833 return QualType();
2834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002835
John McCall550e0c22009-10-21 00:40:46 +00002836 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
2838
2839 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002840}
Mike Stump11289f42009-09-09 15:08:12 +00002841
2842template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002843ParmVarDecl *
2844TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2845 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2846 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2847 if (!NewDI)
2848 return 0;
2849
2850 if (NewDI == OldDI)
2851 return OldParm;
2852 else
2853 return ParmVarDecl::Create(SemaRef.Context,
2854 OldParm->getDeclContext(),
2855 OldParm->getLocation(),
2856 OldParm->getIdentifier(),
2857 NewDI->getType(),
2858 NewDI,
2859 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002860 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002861 /* DefArg */ NULL);
2862}
2863
2864template<typename Derived>
2865bool TreeTransform<Derived>::
2866 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2867 llvm::SmallVectorImpl<QualType> &PTypes,
2868 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2869 FunctionProtoType *T = TL.getTypePtr();
2870
2871 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2872 ParmVarDecl *OldParm = TL.getArg(i);
2873
2874 QualType NewType;
2875 ParmVarDecl *NewParm;
2876
2877 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002878 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2879 if (!NewParm)
2880 return true;
2881 NewType = NewParm->getType();
2882
2883 // Deal with the possibility that we don't have a parameter
2884 // declaration for this parameter.
2885 } else {
2886 NewParm = 0;
2887
2888 QualType OldType = T->getArgType(i);
2889 NewType = getDerived().TransformType(OldType);
2890 if (NewType.isNull())
2891 return true;
2892 }
2893
2894 PTypes.push_back(NewType);
2895 PVars.push_back(NewParm);
2896 }
2897
2898 return false;
2899}
2900
2901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002902QualType
John McCall550e0c22009-10-21 00:40:46 +00002903TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002904 FunctionProtoTypeLoc TL,
2905 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002906 // Transform the parameters. We do this first for the benefit of template
2907 // instantiations, so that the ParmVarDecls get/ placed into the template
2908 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002910 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002911 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2912 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002913
Douglas Gregor14cf7522010-04-30 18:55:50 +00002914 FunctionProtoType *T = TL.getTypePtr();
2915 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2916 if (ResultType.isNull())
2917 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002918
John McCall550e0c22009-10-21 00:40:46 +00002919 QualType Result = TL.getType();
2920 if (getDerived().AlwaysRebuild() ||
2921 ResultType != T->getResultType() ||
2922 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2923 Result = getDerived().RebuildFunctionProtoType(ResultType,
2924 ParamTypes.data(),
2925 ParamTypes.size(),
2926 T->isVariadic(),
2927 T->getTypeQuals());
2928 if (Result.isNull())
2929 return QualType();
2930 }
Mike Stump11289f42009-09-09 15:08:12 +00002931
John McCall550e0c22009-10-21 00:40:46 +00002932 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2933 NewTL.setLParenLoc(TL.getLParenLoc());
2934 NewTL.setRParenLoc(TL.getRParenLoc());
2935 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2936 NewTL.setArg(i, ParamDecls[i]);
2937
2938 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002939}
Mike Stump11289f42009-09-09 15:08:12 +00002940
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941template<typename Derived>
2942QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002943 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002944 FunctionNoProtoTypeLoc TL,
2945 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002946 FunctionNoProtoType *T = TL.getTypePtr();
2947 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2948 if (ResultType.isNull())
2949 return QualType();
2950
2951 QualType Result = TL.getType();
2952 if (getDerived().AlwaysRebuild() ||
2953 ResultType != T->getResultType())
2954 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2955
2956 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2957 NewTL.setLParenLoc(TL.getLParenLoc());
2958 NewTL.setRParenLoc(TL.getRParenLoc());
2959
2960 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961}
Mike Stump11289f42009-09-09 15:08:12 +00002962
John McCallb96ec562009-12-04 22:46:56 +00002963template<typename Derived> QualType
2964TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002965 UnresolvedUsingTypeLoc TL,
2966 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002967 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002968 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002969 if (!D)
2970 return QualType();
2971
2972 QualType Result = TL.getType();
2973 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2974 Result = getDerived().RebuildUnresolvedUsingType(D);
2975 if (Result.isNull())
2976 return QualType();
2977 }
2978
2979 // We might get an arbitrary type spec type back. We should at
2980 // least always get a type spec type, though.
2981 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2982 NewTL.setNameLoc(TL.getNameLoc());
2983
2984 return Result;
2985}
2986
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002988QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002989 TypedefTypeLoc TL,
2990 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002991 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002992 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002993 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2994 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995 if (!Typedef)
2996 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002997
John McCall550e0c22009-10-21 00:40:46 +00002998 QualType Result = TL.getType();
2999 if (getDerived().AlwaysRebuild() ||
3000 Typedef != T->getDecl()) {
3001 Result = getDerived().RebuildTypedefType(Typedef);
3002 if (Result.isNull())
3003 return QualType();
3004 }
Mike Stump11289f42009-09-09 15:08:12 +00003005
John McCall550e0c22009-10-21 00:40:46 +00003006 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3007 NewTL.setNameLoc(TL.getNameLoc());
3008
3009 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003010}
Mike Stump11289f42009-09-09 15:08:12 +00003011
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003013QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003014 TypeOfExprTypeLoc TL,
3015 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003016 // typeof expressions are not potentially evaluated contexts
3017 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003018
John McCalle8595032010-01-13 20:03:27 +00003019 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020 if (E.isInvalid())
3021 return QualType();
3022
John McCall550e0c22009-10-21 00:40:46 +00003023 QualType Result = TL.getType();
3024 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003025 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003026 Result = getDerived().RebuildTypeOfExprType(move(E));
3027 if (Result.isNull())
3028 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029 }
John McCall550e0c22009-10-21 00:40:46 +00003030 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003031
John McCall550e0c22009-10-21 00:40:46 +00003032 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003033 NewTL.setTypeofLoc(TL.getTypeofLoc());
3034 NewTL.setLParenLoc(TL.getLParenLoc());
3035 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003036
3037 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038}
Mike Stump11289f42009-09-09 15:08:12 +00003039
3040template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003041QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003042 TypeOfTypeLoc TL,
3043 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003044 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3045 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3046 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003047 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003048
John McCall550e0c22009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003050 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3051 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003052 if (Result.isNull())
3053 return QualType();
3054 }
Mike Stump11289f42009-09-09 15:08:12 +00003055
John McCall550e0c22009-10-21 00:40:46 +00003056 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003057 NewTL.setTypeofLoc(TL.getTypeofLoc());
3058 NewTL.setLParenLoc(TL.getLParenLoc());
3059 NewTL.setRParenLoc(TL.getRParenLoc());
3060 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003061
3062 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063}
Mike Stump11289f42009-09-09 15:08:12 +00003064
3065template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003066QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003067 DecltypeTypeLoc TL,
3068 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003069 DecltypeType *T = TL.getTypePtr();
3070
Douglas Gregore922c772009-08-04 22:27:00 +00003071 // decltype expressions are not potentially evaluated contexts
3072 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003073
Douglas Gregord6ff3322009-08-04 16:50:30 +00003074 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3075 if (E.isInvalid())
3076 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003077
John McCall550e0c22009-10-21 00:40:46 +00003078 QualType Result = TL.getType();
3079 if (getDerived().AlwaysRebuild() ||
3080 E.get() != T->getUnderlyingExpr()) {
3081 Result = getDerived().RebuildDecltypeType(move(E));
3082 if (Result.isNull())
3083 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084 }
John McCall550e0c22009-10-21 00:40:46 +00003085 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003086
John McCall550e0c22009-10-21 00:40:46 +00003087 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3088 NewTL.setNameLoc(TL.getNameLoc());
3089
3090 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091}
3092
3093template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003094QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003095 RecordTypeLoc TL,
3096 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003097 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003098 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003099 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3100 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 if (!Record)
3102 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 QualType Result = TL.getType();
3105 if (getDerived().AlwaysRebuild() ||
3106 Record != T->getDecl()) {
3107 Result = getDerived().RebuildRecordType(Record);
3108 if (Result.isNull())
3109 return QualType();
3110 }
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3113 NewTL.setNameLoc(TL.getNameLoc());
3114
3115 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003116}
Mike Stump11289f42009-09-09 15:08:12 +00003117
3118template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003119QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003120 EnumTypeLoc TL,
3121 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003122 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003123 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003124 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3125 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003126 if (!Enum)
3127 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003128
John McCall550e0c22009-10-21 00:40:46 +00003129 QualType Result = TL.getType();
3130 if (getDerived().AlwaysRebuild() ||
3131 Enum != T->getDecl()) {
3132 Result = getDerived().RebuildEnumType(Enum);
3133 if (Result.isNull())
3134 return QualType();
3135 }
Mike Stump11289f42009-09-09 15:08:12 +00003136
John McCall550e0c22009-10-21 00:40:46 +00003137 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3138 NewTL.setNameLoc(TL.getNameLoc());
3139
3140 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003141}
John McCallfcc33b02009-09-05 00:15:47 +00003142
John McCalle78aac42010-03-10 03:28:59 +00003143template<typename Derived>
3144QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3145 TypeLocBuilder &TLB,
3146 InjectedClassNameTypeLoc TL,
3147 QualType ObjectType) {
3148 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3149 TL.getTypePtr()->getDecl());
3150 if (!D) return QualType();
3151
3152 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3153 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3154 return T;
3155}
3156
Mike Stump11289f42009-09-09 15:08:12 +00003157
Douglas Gregord6ff3322009-08-04 16:50:30 +00003158template<typename Derived>
3159QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003160 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003161 TemplateTypeParmTypeLoc TL,
3162 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003163 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003164}
3165
Mike Stump11289f42009-09-09 15:08:12 +00003166template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003167QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003168 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003169 SubstTemplateTypeParmTypeLoc TL,
3170 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003171 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003172}
3173
3174template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003175QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3176 const TemplateSpecializationType *TST,
3177 QualType ObjectType) {
3178 // FIXME: this entire method is a temporary workaround; callers
3179 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003180
John McCall0ad16662009-10-29 08:12:44 +00003181 // Fake up a TemplateSpecializationTypeLoc.
3182 TypeLocBuilder TLB;
3183 TemplateSpecializationTypeLoc TL
3184 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3185
John McCall0d07eb32009-10-29 18:45:58 +00003186 SourceLocation BaseLoc = getDerived().getBaseLocation();
3187
3188 TL.setTemplateNameLoc(BaseLoc);
3189 TL.setLAngleLoc(BaseLoc);
3190 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003191 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3192 const TemplateArgument &TA = TST->getArg(i);
3193 TemplateArgumentLoc TAL;
3194 getDerived().InventTemplateArgumentLoc(TA, TAL);
3195 TL.setArgLocInfo(i, TAL.getLocInfo());
3196 }
3197
3198 TypeLocBuilder IgnoredTLB;
3199 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003200}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003201
Douglas Gregorc59e5612009-10-19 22:04:39 +00003202template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003203QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003204 TypeLocBuilder &TLB,
3205 TemplateSpecializationTypeLoc TL,
3206 QualType ObjectType) {
3207 const TemplateSpecializationType *T = TL.getTypePtr();
3208
Mike Stump11289f42009-09-09 15:08:12 +00003209 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003210 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003211 if (Template.isNull())
3212 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003213
John McCall6b51f282009-11-23 01:53:49 +00003214 TemplateArgumentListInfo NewTemplateArgs;
3215 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3216 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3217
3218 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3219 TemplateArgumentLoc Loc;
3220 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003221 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003222 NewTemplateArgs.addArgument(Loc);
3223 }
Mike Stump11289f42009-09-09 15:08:12 +00003224
John McCall0ad16662009-10-29 08:12:44 +00003225 // FIXME: maybe don't rebuild if all the template arguments are the same.
3226
3227 QualType Result =
3228 getDerived().RebuildTemplateSpecializationType(Template,
3229 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003230 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003231
3232 if (!Result.isNull()) {
3233 TemplateSpecializationTypeLoc NewTL
3234 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3235 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3236 NewTL.setLAngleLoc(TL.getLAngleLoc());
3237 NewTL.setRAngleLoc(TL.getRAngleLoc());
3238 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3239 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003240 }
Mike Stump11289f42009-09-09 15:08:12 +00003241
John McCall0ad16662009-10-29 08:12:44 +00003242 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003243}
Mike Stump11289f42009-09-09 15:08:12 +00003244
3245template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003246QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003247TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3248 ElaboratedTypeLoc TL,
3249 QualType ObjectType) {
Abramo Bagnarae9f4d6e2010-05-14 14:14:23 +00003250 QualType Named = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3251 if (Named.isNull())
3252 return QualType();
3253
Abramo Bagnara6150c882010-05-11 21:36:43 +00003254 ElaboratedType *T = TL.getTypePtr();
3255
3256 NestedNameSpecifier *NNS = 0;
3257 // NOTE: the qualifier in an ElaboratedType is optional.
3258 if (T->getQualifier() != 0) {
3259 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarae9f4d6e2010-05-14 14:14:23 +00003260 /* FIXME */ SourceRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003261 ObjectType);
3262 if (!NNS)
3263 return QualType();
3264 }
Mike Stump11289f42009-09-09 15:08:12 +00003265
John McCall550e0c22009-10-21 00:40:46 +00003266 QualType Result = TL.getType();
3267 if (getDerived().AlwaysRebuild() ||
3268 NNS != T->getQualifier() ||
3269 Named != T->getNamedType()) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003270 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, Named);
John McCall550e0c22009-10-21 00:40:46 +00003271 if (Result.isNull())
3272 return QualType();
3273 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003274
Abramo Bagnara6150c882010-05-11 21:36:43 +00003275 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae9f4d6e2010-05-14 14:14:23 +00003276 NewTL.setKeywordLoc(TL.getKeywordLoc());
John McCall550e0c22009-10-21 00:40:46 +00003277
3278 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003279}
Mike Stump11289f42009-09-09 15:08:12 +00003280
3281template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003282QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3283 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003284 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003285 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003286
3287 /* FIXME: preserve source information better than this */
3288 SourceRange SR(TL.getNameLoc());
3289
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003291 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003292 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 if (!NNS)
3294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003295
John McCall550e0c22009-10-21 00:40:46 +00003296 QualType Result;
3297
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003299 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300 = getDerived().TransformType(QualType(TemplateId, 0));
3301 if (NewTemplateId.isNull())
3302 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003303
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304 if (!getDerived().AlwaysRebuild() &&
3305 NNS == T->getQualifier() &&
3306 NewTemplateId == QualType(TemplateId, 0))
3307 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003308
Alexis Hunta8136cc2010-05-05 15:23:54 +00003309 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003310 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003311 } else {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003312 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003313 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314 }
John McCall550e0c22009-10-21 00:40:46 +00003315 if (Result.isNull())
3316 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317
Abramo Bagnarae9f4d6e2010-05-14 14:14:23 +00003318 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3319 QualType NamedT = ElabT->getNamedType();
3320 if (isa<TypedefType>(NamedT)) {
3321 TypedefTypeLoc NamedTLoc = TLB.push<TypedefTypeLoc>(NamedT);
3322 NamedTLoc.setNameLoc(TL.getNameLoc());
3323 }
3324 else if (isa<RecordType>(NamedT)) {
3325 RecordTypeLoc NamedTLoc = TLB.push<RecordTypeLoc>(NamedT);
3326 NamedTLoc.setNameLoc(TL.getNameLoc());
3327 }
3328 else if (isa<EnumType>(NamedT)) {
3329 EnumTypeLoc NamedTLoc = TLB.push<EnumTypeLoc>(NamedT);
3330 NamedTLoc.setNameLoc(TL.getNameLoc());
3331 }
3332 else if (isa<TemplateSpecializationType>(NamedT)) {
3333 TemplateSpecializationTypeLoc NamedTLoc
3334 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3335 // FIXME: fill locations
3336 NamedTLoc.initializeLocal(SourceLocation());
3337 }
3338 else
3339 llvm_unreachable("Unexpected type");
3340 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3341 NewTL.setKeywordLoc(TL.getKeywordLoc());
3342 }
3343 else {
3344 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3345 NewTL.setKeywordLoc(TL.getKeywordLoc());
3346 NewTL.setNameLoc(TL.getNameLoc());
3347 }
John McCall550e0c22009-10-21 00:40:46 +00003348 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349}
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregord6ff3322009-08-04 16:50:30 +00003351template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003352QualType
3353TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003354 ObjCInterfaceTypeLoc TL,
3355 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003356 // ObjCInterfaceType is never dependent.
3357 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003358}
Mike Stump11289f42009-09-09 15:08:12 +00003359
3360template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003361QualType
3362TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003363 ObjCObjectPointerTypeLoc TL,
3364 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003365 // ObjCObjectPointerType is never dependent.
3366 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003367}
3368
Douglas Gregord6ff3322009-08-04 16:50:30 +00003369//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003370// Statement transformation
3371//===----------------------------------------------------------------------===//
3372template<typename Derived>
3373Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003374TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3375 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003376}
3377
3378template<typename Derived>
3379Sema::OwningStmtResult
3380TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3381 return getDerived().TransformCompoundStmt(S, false);
3382}
3383
3384template<typename Derived>
3385Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003386TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003387 bool IsStmtExpr) {
3388 bool SubStmtChanged = false;
3389 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3390 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3391 B != BEnd; ++B) {
3392 OwningStmtResult Result = getDerived().TransformStmt(*B);
3393 if (Result.isInvalid())
3394 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003395
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3397 Statements.push_back(Result.takeAs<Stmt>());
3398 }
Mike Stump11289f42009-09-09 15:08:12 +00003399
Douglas Gregorebe10102009-08-20 07:17:43 +00003400 if (!getDerived().AlwaysRebuild() &&
3401 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003402 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003403
3404 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3405 move_arg(Statements),
3406 S->getRBracLoc(),
3407 IsStmtExpr);
3408}
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregorebe10102009-08-20 07:17:43 +00003410template<typename Derived>
3411Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003412TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003413 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3414 {
3415 // The case value expressions are not potentially evaluated.
3416 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003417
Eli Friedman06577382009-11-19 03:14:00 +00003418 // Transform the left-hand case value.
3419 LHS = getDerived().TransformExpr(S->getLHS());
3420 if (LHS.isInvalid())
3421 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003422
Eli Friedman06577382009-11-19 03:14:00 +00003423 // Transform the right-hand case value (for the GNU case-range extension).
3424 RHS = getDerived().TransformExpr(S->getRHS());
3425 if (RHS.isInvalid())
3426 return SemaRef.StmtError();
3427 }
Mike Stump11289f42009-09-09 15:08:12 +00003428
Douglas Gregorebe10102009-08-20 07:17:43 +00003429 // Build the case statement.
3430 // Case statements are always rebuilt so that they will attached to their
3431 // transformed switch statement.
3432 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3433 move(LHS),
3434 S->getEllipsisLoc(),
3435 move(RHS),
3436 S->getColonLoc());
3437 if (Case.isInvalid())
3438 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregorebe10102009-08-20 07:17:43 +00003440 // Transform the statement following the case
3441 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3442 if (SubStmt.isInvalid())
3443 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003444
Douglas Gregorebe10102009-08-20 07:17:43 +00003445 // Attach the body to the case statement
3446 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3447}
3448
3449template<typename Derived>
3450Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003451TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003452 // Transform the statement following the default case
3453 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3454 if (SubStmt.isInvalid())
3455 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003456
Douglas Gregorebe10102009-08-20 07:17:43 +00003457 // Default statements are always rebuilt
3458 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3459 move(SubStmt));
3460}
Mike Stump11289f42009-09-09 15:08:12 +00003461
Douglas Gregorebe10102009-08-20 07:17:43 +00003462template<typename Derived>
3463Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003464TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003465 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3466 if (SubStmt.isInvalid())
3467 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003468
Douglas Gregorebe10102009-08-20 07:17:43 +00003469 // FIXME: Pass the real colon location in.
3470 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3471 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3472 move(SubStmt));
3473}
Mike Stump11289f42009-09-09 15:08:12 +00003474
Douglas Gregorebe10102009-08-20 07:17:43 +00003475template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003476Sema::OwningStmtResult
3477TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003478 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003479 OwningExprResult Cond(SemaRef);
3480 VarDecl *ConditionVar = 0;
3481 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003482 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003483 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003484 getDerived().TransformDefinition(
3485 S->getConditionVariable()->getLocation(),
3486 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003487 if (!ConditionVar)
3488 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003489 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003490 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003491
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003492 if (Cond.isInvalid())
3493 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003494
3495 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003496 if (S->getCond()) {
3497 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3498 S->getIfLoc(),
3499 move(Cond));
3500 if (CondE.isInvalid())
3501 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003502
Douglas Gregor6d319c62010-05-08 23:34:38 +00003503 Cond = move(CondE);
3504 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003505 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003506
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003507 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3508 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3509 return SemaRef.StmtError();
3510
Douglas Gregorebe10102009-08-20 07:17:43 +00003511 // Transform the "then" branch.
3512 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3513 if (Then.isInvalid())
3514 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003515
Douglas Gregorebe10102009-08-20 07:17:43 +00003516 // Transform the "else" branch.
3517 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3518 if (Else.isInvalid())
3519 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003520
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003522 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003523 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 Then.get() == S->getThen() &&
3525 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003526 return SemaRef.Owned(S->Retain());
3527
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003528 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003529 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003530 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003531}
3532
3533template<typename Derived>
3534Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003535TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003537 OwningExprResult Cond(SemaRef);
3538 VarDecl *ConditionVar = 0;
3539 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003540 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003541 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003542 getDerived().TransformDefinition(
3543 S->getConditionVariable()->getLocation(),
3544 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003545 if (!ConditionVar)
3546 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003547 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003548 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003549
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003550 if (Cond.isInvalid())
3551 return SemaRef.StmtError();
3552 }
Mike Stump11289f42009-09-09 15:08:12 +00003553
Douglas Gregorebe10102009-08-20 07:17:43 +00003554 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003555 OwningStmtResult Switch
3556 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3557 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 if (Switch.isInvalid())
3559 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregorebe10102009-08-20 07:17:43 +00003561 // Transform the body of the switch statement.
3562 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3563 if (Body.isInvalid())
3564 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregorebe10102009-08-20 07:17:43 +00003566 // Complete the switch statement.
3567 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3568 move(Body));
3569}
Mike Stump11289f42009-09-09 15:08:12 +00003570
Douglas Gregorebe10102009-08-20 07:17:43 +00003571template<typename Derived>
3572Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003573TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003575 OwningExprResult Cond(SemaRef);
3576 VarDecl *ConditionVar = 0;
3577 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003578 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003579 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003580 getDerived().TransformDefinition(
3581 S->getConditionVariable()->getLocation(),
3582 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003583 if (!ConditionVar)
3584 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003586 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003587
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003588 if (Cond.isInvalid())
3589 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003590
3591 if (S->getCond()) {
3592 // Convert the condition to a boolean value.
3593 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003594 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003595 move(Cond));
3596 if (CondE.isInvalid())
3597 return getSema().StmtError();
3598 Cond = move(CondE);
3599 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003600 }
Mike Stump11289f42009-09-09 15:08:12 +00003601
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003602 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3603 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3604 return SemaRef.StmtError();
3605
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 // Transform the body
3607 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3608 if (Body.isInvalid())
3609 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregorebe10102009-08-20 07:17:43 +00003611 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003612 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003613 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003614 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003615 return SemaRef.Owned(S->Retain());
3616
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003617 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003618 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003619}
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621template<typename Derived>
3622Sema::OwningStmtResult
3623TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 // Transform the body
3625 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3626 if (Body.isInvalid())
3627 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003628
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003629 // Transform the condition
3630 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3631 if (Cond.isInvalid())
3632 return SemaRef.StmtError();
3633
Douglas Gregorebe10102009-08-20 07:17:43 +00003634 if (!getDerived().AlwaysRebuild() &&
3635 Cond.get() == S->getCond() &&
3636 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003637 return SemaRef.Owned(S->Retain());
3638
Douglas Gregorebe10102009-08-20 07:17:43 +00003639 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3640 /*FIXME:*/S->getWhileLoc(), move(Cond),
3641 S->getRParenLoc());
3642}
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregorebe10102009-08-20 07:17:43 +00003644template<typename Derived>
3645Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003646TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 // Transform the initialization statement
3648 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3649 if (Init.isInvalid())
3650 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregorebe10102009-08-20 07:17:43 +00003652 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003653 OwningExprResult Cond(SemaRef);
3654 VarDecl *ConditionVar = 0;
3655 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003656 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003657 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003658 getDerived().TransformDefinition(
3659 S->getConditionVariable()->getLocation(),
3660 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003661 if (!ConditionVar)
3662 return SemaRef.StmtError();
3663 } else {
3664 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003665
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003666 if (Cond.isInvalid())
3667 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003668
3669 if (S->getCond()) {
3670 // Convert the condition to a boolean value.
3671 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3672 S->getForLoc(),
3673 move(Cond));
3674 if (CondE.isInvalid())
3675 return getSema().StmtError();
3676
3677 Cond = move(CondE);
3678 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003679 }
Mike Stump11289f42009-09-09 15:08:12 +00003680
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003681 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3682 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3683 return SemaRef.StmtError();
3684
Douglas Gregorebe10102009-08-20 07:17:43 +00003685 // Transform the increment
3686 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3687 if (Inc.isInvalid())
3688 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003689
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003690 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3691 if (S->getInc() && !FullInc->get())
3692 return SemaRef.StmtError();
3693
Douglas Gregorebe10102009-08-20 07:17:43 +00003694 // Transform the body
3695 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3696 if (Body.isInvalid())
3697 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregorebe10102009-08-20 07:17:43 +00003699 if (!getDerived().AlwaysRebuild() &&
3700 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003701 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003702 Inc.get() == S->getInc() &&
3703 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003704 return SemaRef.Owned(S->Retain());
3705
Douglas Gregorebe10102009-08-20 07:17:43 +00003706 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003707 move(Init), FullCond, ConditionVar,
3708 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003709}
3710
3711template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003712Sema::OwningStmtResult
3713TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003715 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003716 S->getLabel());
3717}
3718
3719template<typename Derived>
3720Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003721TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3723 if (Target.isInvalid())
3724 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003725
Douglas Gregorebe10102009-08-20 07:17:43 +00003726 if (!getDerived().AlwaysRebuild() &&
3727 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003728 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003729
3730 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3731 move(Target));
3732}
3733
3734template<typename Derived>
3735Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003736TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3737 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003738}
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740template<typename Derived>
3741Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003742TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3743 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003744}
Mike Stump11289f42009-09-09 15:08:12 +00003745
Douglas Gregorebe10102009-08-20 07:17:43 +00003746template<typename Derived>
3747Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003748TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003749 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3750 if (Result.isInvalid())
3751 return SemaRef.StmtError();
3752
Mike Stump11289f42009-09-09 15:08:12 +00003753 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003754 // to tell whether the return type of the function has changed.
3755 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3756}
Mike Stump11289f42009-09-09 15:08:12 +00003757
Douglas Gregorebe10102009-08-20 07:17:43 +00003758template<typename Derived>
3759Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003760TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 bool DeclChanged = false;
3762 llvm::SmallVector<Decl *, 4> Decls;
3763 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3764 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003765 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3766 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003767 if (!Transformed)
3768 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 if (Transformed != *D)
3771 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 Decls.push_back(Transformed);
3774 }
Mike Stump11289f42009-09-09 15:08:12 +00003775
Douglas Gregorebe10102009-08-20 07:17:43 +00003776 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003777 return SemaRef.Owned(S->Retain());
3778
3779 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 S->getStartLoc(), S->getEndLoc());
3781}
Mike Stump11289f42009-09-09 15:08:12 +00003782
Douglas Gregorebe10102009-08-20 07:17:43 +00003783template<typename Derived>
3784Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003785TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003786 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003787 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003788}
3789
3790template<typename Derived>
3791Sema::OwningStmtResult
3792TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003793
Anders Carlssonaaeef072010-01-24 05:50:09 +00003794 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3795 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003796 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003797
Anders Carlssonaaeef072010-01-24 05:50:09 +00003798 OwningExprResult AsmString(SemaRef);
3799 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3800
3801 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003802
Anders Carlssonaaeef072010-01-24 05:50:09 +00003803 // Go through the outputs.
3804 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003805 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003806
Anders Carlssonaaeef072010-01-24 05:50:09 +00003807 // No need to transform the constraint literal.
3808 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003809
Anders Carlssonaaeef072010-01-24 05:50:09 +00003810 // Transform the output expr.
3811 Expr *OutputExpr = S->getOutputExpr(I);
3812 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3813 if (Result.isInvalid())
3814 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003815
Anders Carlssonaaeef072010-01-24 05:50:09 +00003816 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003817
Anders Carlssonaaeef072010-01-24 05:50:09 +00003818 Exprs.push_back(Result.takeAs<Expr>());
3819 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003820
Anders Carlssonaaeef072010-01-24 05:50:09 +00003821 // Go through the inputs.
3822 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003823 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003824
Anders Carlssonaaeef072010-01-24 05:50:09 +00003825 // No need to transform the constraint literal.
3826 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003827
Anders Carlssonaaeef072010-01-24 05:50:09 +00003828 // Transform the input expr.
3829 Expr *InputExpr = S->getInputExpr(I);
3830 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3831 if (Result.isInvalid())
3832 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003833
Anders Carlssonaaeef072010-01-24 05:50:09 +00003834 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003835
Anders Carlssonaaeef072010-01-24 05:50:09 +00003836 Exprs.push_back(Result.takeAs<Expr>());
3837 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003838
Anders Carlssonaaeef072010-01-24 05:50:09 +00003839 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3840 return SemaRef.Owned(S->Retain());
3841
3842 // Go through the clobbers.
3843 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3844 Clobbers.push_back(S->getClobber(I)->Retain());
3845
3846 // No need to transform the asm string literal.
3847 AsmString = SemaRef.Owned(S->getAsmString());
3848
3849 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3850 S->isSimple(),
3851 S->isVolatile(),
3852 S->getNumOutputs(),
3853 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003854 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003855 move_arg(Constraints),
3856 move_arg(Exprs),
3857 move(AsmString),
3858 move_arg(Clobbers),
3859 S->getRParenLoc(),
3860 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003861}
3862
3863
3864template<typename Derived>
3865Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003866TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003867 // Transform the body of the @try.
3868 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3869 if (TryBody.isInvalid())
3870 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003871
Douglas Gregor96c79492010-04-23 22:50:49 +00003872 // Transform the @catch statements (if present).
3873 bool AnyCatchChanged = false;
3874 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3875 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3876 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003877 if (Catch.isInvalid())
3878 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003879 if (Catch.get() != S->getCatchStmt(I))
3880 AnyCatchChanged = true;
3881 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003882 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003883
Douglas Gregor306de2f2010-04-22 23:59:56 +00003884 // Transform the @finally statement (if present).
3885 OwningStmtResult Finally(SemaRef);
3886 if (S->getFinallyStmt()) {
3887 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3888 if (Finally.isInvalid())
3889 return SemaRef.StmtError();
3890 }
3891
3892 // If nothing changed, just retain this statement.
3893 if (!getDerived().AlwaysRebuild() &&
3894 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003895 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003896 Finally.get() == S->getFinallyStmt())
3897 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003898
Douglas Gregor306de2f2010-04-22 23:59:56 +00003899 // Build a new statement.
3900 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003901 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003902}
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregorebe10102009-08-20 07:17:43 +00003904template<typename Derived>
3905Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003906TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003907 // Transform the @catch parameter, if there is one.
3908 VarDecl *Var = 0;
3909 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3910 TypeSourceInfo *TSInfo = 0;
3911 if (FromVar->getTypeSourceInfo()) {
3912 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3913 if (!TSInfo)
3914 return SemaRef.StmtError();
3915 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003916
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003917 QualType T;
3918 if (TSInfo)
3919 T = TSInfo->getType();
3920 else {
3921 T = getDerived().TransformType(FromVar->getType());
3922 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003923 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003924 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003925
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003926 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3927 if (!Var)
3928 return SemaRef.StmtError();
3929 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003930
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003931 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3932 if (Body.isInvalid())
3933 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003934
3935 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003936 S->getRParenLoc(),
3937 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003938}
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregorebe10102009-08-20 07:17:43 +00003940template<typename Derived>
3941Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003942TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003943 // Transform the body.
3944 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3945 if (Body.isInvalid())
3946 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003947
Douglas Gregor306de2f2010-04-22 23:59:56 +00003948 // If nothing changed, just retain this statement.
3949 if (!getDerived().AlwaysRebuild() &&
3950 Body.get() == S->getFinallyBody())
3951 return SemaRef.Owned(S->Retain());
3952
3953 // Build a new statement.
3954 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3955 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003956}
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregorebe10102009-08-20 07:17:43 +00003958template<typename Derived>
3959Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003960TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003961 OwningExprResult Operand(SemaRef);
3962 if (S->getThrowExpr()) {
3963 Operand = getDerived().TransformExpr(S->getThrowExpr());
3964 if (Operand.isInvalid())
3965 return getSema().StmtError();
3966 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003967
Douglas Gregor2900c162010-04-22 21:44:01 +00003968 if (!getDerived().AlwaysRebuild() &&
3969 Operand.get() == S->getThrowExpr())
3970 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003971
Douglas Gregor2900c162010-04-22 21:44:01 +00003972 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003973}
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregorebe10102009-08-20 07:17:43 +00003975template<typename Derived>
3976Sema::OwningStmtResult
3977TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003978 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003979 // Transform the object we are locking.
3980 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3981 if (Object.isInvalid())
3982 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
Douglas Gregor6148de72010-04-22 22:01:21 +00003984 // Transform the body.
3985 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3986 if (Body.isInvalid())
3987 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003988
Douglas Gregor6148de72010-04-22 22:01:21 +00003989 // If nothing change, just retain the current statement.
3990 if (!getDerived().AlwaysRebuild() &&
3991 Object.get() == S->getSynchExpr() &&
3992 Body.get() == S->getSynchBody())
3993 return SemaRef.Owned(S->Retain());
3994
3995 // Build a new statement.
3996 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3997 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003998}
3999
4000template<typename Derived>
4001Sema::OwningStmtResult
4002TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004003 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004004 // Transform the element statement.
4005 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4006 if (Element.isInvalid())
4007 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004008
Douglas Gregorf68a5082010-04-22 23:10:45 +00004009 // Transform the collection expression.
4010 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4011 if (Collection.isInvalid())
4012 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004013
Douglas Gregorf68a5082010-04-22 23:10:45 +00004014 // Transform the body.
4015 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4016 if (Body.isInvalid())
4017 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004018
Douglas Gregorf68a5082010-04-22 23:10:45 +00004019 // If nothing changed, just retain this statement.
4020 if (!getDerived().AlwaysRebuild() &&
4021 Element.get() == S->getElement() &&
4022 Collection.get() == S->getCollection() &&
4023 Body.get() == S->getBody())
4024 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004025
Douglas Gregorf68a5082010-04-22 23:10:45 +00004026 // Build a new statement.
4027 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4028 /*FIXME:*/S->getForLoc(),
4029 move(Element),
4030 move(Collection),
4031 S->getRParenLoc(),
4032 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004033}
4034
4035
4036template<typename Derived>
4037Sema::OwningStmtResult
4038TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4039 // Transform the exception declaration, if any.
4040 VarDecl *Var = 0;
4041 if (S->getExceptionDecl()) {
4042 VarDecl *ExceptionDecl = S->getExceptionDecl();
4043 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4044 ExceptionDecl->getDeclName());
4045
4046 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4047 if (T.isNull())
4048 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004049
Douglas Gregorebe10102009-08-20 07:17:43 +00004050 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4051 T,
John McCallbcd03502009-12-07 02:54:59 +00004052 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004053 ExceptionDecl->getIdentifier(),
4054 ExceptionDecl->getLocation(),
4055 /*FIXME: Inaccurate*/
4056 SourceRange(ExceptionDecl->getLocation()));
4057 if (!Var || Var->isInvalidDecl()) {
4058 if (Var)
4059 Var->Destroy(SemaRef.Context);
4060 return SemaRef.StmtError();
4061 }
4062 }
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregorebe10102009-08-20 07:17:43 +00004064 // Transform the actual exception handler.
4065 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4066 if (Handler.isInvalid()) {
4067 if (Var)
4068 Var->Destroy(SemaRef.Context);
4069 return SemaRef.StmtError();
4070 }
Mike Stump11289f42009-09-09 15:08:12 +00004071
Douglas Gregorebe10102009-08-20 07:17:43 +00004072 if (!getDerived().AlwaysRebuild() &&
4073 !Var &&
4074 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004075 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004076
4077 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4078 Var,
4079 move(Handler));
4080}
Mike Stump11289f42009-09-09 15:08:12 +00004081
Douglas Gregorebe10102009-08-20 07:17:43 +00004082template<typename Derived>
4083Sema::OwningStmtResult
4084TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4085 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004086 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004087 = getDerived().TransformCompoundStmt(S->getTryBlock());
4088 if (TryBlock.isInvalid())
4089 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregorebe10102009-08-20 07:17:43 +00004091 // Transform the handlers.
4092 bool HandlerChanged = false;
4093 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4094 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004095 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004096 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4097 if (Handler.isInvalid())
4098 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004099
Douglas Gregorebe10102009-08-20 07:17:43 +00004100 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4101 Handlers.push_back(Handler.takeAs<Stmt>());
4102 }
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregorebe10102009-08-20 07:17:43 +00004104 if (!getDerived().AlwaysRebuild() &&
4105 TryBlock.get() == S->getTryBlock() &&
4106 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004107 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004108
4109 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004110 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004111}
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregorebe10102009-08-20 07:17:43 +00004113//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004114// Expression transformation
4115//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004116template<typename Derived>
4117Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004118TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004119 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004120}
Mike Stump11289f42009-09-09 15:08:12 +00004121
4122template<typename Derived>
4123Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004124TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004125 NestedNameSpecifier *Qualifier = 0;
4126 if (E->getQualifier()) {
4127 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004128 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004129 if (!Qualifier)
4130 return SemaRef.ExprError();
4131 }
John McCallce546572009-12-08 09:08:17 +00004132
4133 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004134 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4135 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004136 if (!ND)
4137 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004138
Alexis Hunta8136cc2010-05-05 15:23:54 +00004139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004140 Qualifier == E->getQualifier() &&
4141 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004142 !E->hasExplicitTemplateArgumentList()) {
4143
4144 // Mark it referenced in the new context regardless.
4145 // FIXME: this is a bit instantiation-specific.
4146 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4147
Mike Stump11289f42009-09-09 15:08:12 +00004148 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004149 }
John McCallce546572009-12-08 09:08:17 +00004150
4151 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4152 if (E->hasExplicitTemplateArgumentList()) {
4153 TemplateArgs = &TransArgs;
4154 TransArgs.setLAngleLoc(E->getLAngleLoc());
4155 TransArgs.setRAngleLoc(E->getRAngleLoc());
4156 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4157 TemplateArgumentLoc Loc;
4158 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4159 return SemaRef.ExprError();
4160 TransArgs.addArgument(Loc);
4161 }
4162 }
4163
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004164 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004165 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004166}
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004169Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004170TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004171 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregora16548e2009-08-11 05:31:07 +00004174template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004175Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004176TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004178}
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregora16548e2009-08-11 05:31:07 +00004180template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004181Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004182TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004183 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004184}
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregora16548e2009-08-11 05:31:07 +00004186template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004187Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004188TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004189 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004190}
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004193Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004194TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004195 return SemaRef.Owned(E->Retain());
4196}
4197
4198template<typename Derived>
4199Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004200TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004201 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4202 if (SubExpr.isInvalid())
4203 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004204
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004206 return SemaRef.Owned(E->Retain());
4207
4208 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004209 E->getRParen());
4210}
4211
Mike Stump11289f42009-09-09 15:08:12 +00004212template<typename Derived>
4213Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004214TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4215 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 if (SubExpr.isInvalid())
4217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004220 return SemaRef.Owned(E->Retain());
4221
Douglas Gregora16548e2009-08-11 05:31:07 +00004222 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4223 E->getOpcode(),
4224 move(SubExpr));
4225}
Mike Stump11289f42009-09-09 15:08:12 +00004226
Douglas Gregora16548e2009-08-11 05:31:07 +00004227template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004228Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004229TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4230 // Transform the type.
4231 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4232 if (!Type)
4233 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004234
Douglas Gregor882211c2010-04-28 22:16:22 +00004235 // Transform all of the components into components similar to what the
4236 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004237 // FIXME: It would be slightly more efficient in the non-dependent case to
4238 // just map FieldDecls, rather than requiring the rebuilder to look for
4239 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004240 // template code that we don't care.
4241 bool ExprChanged = false;
4242 typedef Action::OffsetOfComponent Component;
4243 typedef OffsetOfExpr::OffsetOfNode Node;
4244 llvm::SmallVector<Component, 4> Components;
4245 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4246 const Node &ON = E->getComponent(I);
4247 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004248 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004249 Comp.LocStart = ON.getRange().getBegin();
4250 Comp.LocEnd = ON.getRange().getEnd();
4251 switch (ON.getKind()) {
4252 case Node::Array: {
4253 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4254 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4255 if (Index.isInvalid())
4256 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004257
Douglas Gregor882211c2010-04-28 22:16:22 +00004258 ExprChanged = ExprChanged || Index.get() != FromIndex;
4259 Comp.isBrackets = true;
4260 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4261 break;
4262 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004263
Douglas Gregor882211c2010-04-28 22:16:22 +00004264 case Node::Field:
4265 case Node::Identifier:
4266 Comp.isBrackets = false;
4267 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004268 if (!Comp.U.IdentInfo)
4269 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004270
Douglas Gregor882211c2010-04-28 22:16:22 +00004271 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004272
Douglas Gregord1702062010-04-29 00:18:15 +00004273 case Node::Base:
4274 // Will be recomputed during the rebuild.
4275 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004276 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004277
Douglas Gregor882211c2010-04-28 22:16:22 +00004278 Components.push_back(Comp);
4279 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004280
Douglas Gregor882211c2010-04-28 22:16:22 +00004281 // If nothing changed, retain the existing expression.
4282 if (!getDerived().AlwaysRebuild() &&
4283 Type == E->getTypeSourceInfo() &&
4284 !ExprChanged)
4285 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004286
Douglas Gregor882211c2010-04-28 22:16:22 +00004287 // Build a new offsetof expression.
4288 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4289 Components.data(), Components.size(),
4290 E->getRParenLoc());
4291}
4292
4293template<typename Derived>
4294Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004295TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004296 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004297 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004298
John McCallbcd03502009-12-07 02:54:59 +00004299 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004300 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004302
John McCall4c98fd82009-11-04 07:28:41 +00004303 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004305
John McCall4c98fd82009-11-04 07:28:41 +00004306 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004307 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 E->getSourceRange());
4309 }
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004312 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 // C++0x [expr.sizeof]p1:
4314 // The operand is either an expression, which is an unevaluated operand
4315 // [...]
4316 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004317
Douglas Gregora16548e2009-08-11 05:31:07 +00004318 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4319 if (SubExpr.isInvalid())
4320 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4323 return SemaRef.Owned(E->Retain());
4324 }
Mike Stump11289f42009-09-09 15:08:12 +00004325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4327 E->isSizeOf(),
4328 E->getSourceRange());
4329}
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregora16548e2009-08-11 05:31:07 +00004331template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004332Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004333TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4335 if (LHS.isInvalid())
4336 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4339 if (RHS.isInvalid())
4340 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004341
4342
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 if (!getDerived().AlwaysRebuild() &&
4344 LHS.get() == E->getLHS() &&
4345 RHS.get() == E->getRHS())
4346 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4349 /*FIXME:*/E->getLHS()->getLocStart(),
4350 move(RHS),
4351 E->getRBracketLoc());
4352}
Mike Stump11289f42009-09-09 15:08:12 +00004353
4354template<typename Derived>
4355Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004356TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 // Transform the callee.
4358 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4359 if (Callee.isInvalid())
4360 return SemaRef.ExprError();
4361
4362 // Transform arguments.
4363 bool ArgChanged = false;
4364 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4365 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4366 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4367 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4368 if (Arg.isInvalid())
4369 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004370
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 // FIXME: Wrong source location information for the ','.
4372 FakeCommaLocs.push_back(
4373 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004374
4375 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 Args.push_back(Arg.takeAs<Expr>());
4377 }
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 if (!getDerived().AlwaysRebuild() &&
4380 Callee.get() == E->getCallee() &&
4381 !ArgChanged)
4382 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004385 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4387 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4388 move_arg(Args),
4389 FakeCommaLocs.data(),
4390 E->getRParenLoc());
4391}
Mike Stump11289f42009-09-09 15:08:12 +00004392
4393template<typename Derived>
4394Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004395TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4397 if (Base.isInvalid())
4398 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004399
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004400 NestedNameSpecifier *Qualifier = 0;
4401 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004402 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004403 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004404 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004405 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004406 return SemaRef.ExprError();
4407 }
Mike Stump11289f42009-09-09 15:08:12 +00004408
Eli Friedman2cfcef62009-12-04 06:40:45 +00004409 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004410 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4411 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 if (!Member)
4413 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004414
John McCall16df1e52010-03-30 21:47:33 +00004415 NamedDecl *FoundDecl = E->getFoundDecl();
4416 if (FoundDecl == E->getMemberDecl()) {
4417 FoundDecl = Member;
4418 } else {
4419 FoundDecl = cast_or_null<NamedDecl>(
4420 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4421 if (!FoundDecl)
4422 return SemaRef.ExprError();
4423 }
4424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 if (!getDerived().AlwaysRebuild() &&
4426 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004427 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004428 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004429 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004430 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004431
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004432 // Mark it referenced in the new context regardless.
4433 // FIXME: this is a bit instantiation-specific.
4434 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004435 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004436 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004437
John McCall6b51f282009-11-23 01:53:49 +00004438 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004439 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004440 TransArgs.setLAngleLoc(E->getLAngleLoc());
4441 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004442 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004443 TemplateArgumentLoc Loc;
4444 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004445 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004446 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004447 }
4448 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 // FIXME: Bogus source location for the operator
4451 SourceLocation FakeOperatorLoc
4452 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4453
John McCall38836f02010-01-15 08:34:02 +00004454 // FIXME: to do this check properly, we will need to preserve the
4455 // first-qualifier-in-scope here, just in case we had a dependent
4456 // base (and therefore couldn't do the check) and a
4457 // nested-name-qualifier (and therefore could do the lookup).
4458 NamedDecl *FirstQualifierInScope = 0;
4459
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4461 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004462 Qualifier,
4463 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004465 Member,
John McCall16df1e52010-03-30 21:47:33 +00004466 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004467 (E->hasExplicitTemplateArgumentList()
4468 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004469 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004470}
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregora16548e2009-08-11 05:31:07 +00004472template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004473Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004474TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004475 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4476 if (LHS.isInvalid())
4477 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4480 if (RHS.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 LHS.get() == E->getLHS() &&
4485 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004486 return SemaRef.Owned(E->Retain());
4487
Douglas Gregora16548e2009-08-11 05:31:07 +00004488 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4489 move(LHS), move(RHS));
4490}
4491
Mike Stump11289f42009-09-09 15:08:12 +00004492template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004493Sema::OwningExprResult
4494TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004495 CompoundAssignOperator *E) {
4496 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004497}
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004500Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004501TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4503 if (Cond.isInvalid())
4504 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4507 if (LHS.isInvalid())
4508 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregora16548e2009-08-11 05:31:07 +00004510 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4511 if (RHS.isInvalid())
4512 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004513
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 if (!getDerived().AlwaysRebuild() &&
4515 Cond.get() == E->getCond() &&
4516 LHS.get() == E->getLHS() &&
4517 RHS.get() == E->getRHS())
4518 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004519
4520 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004521 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004522 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004523 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 move(RHS));
4525}
Mike Stump11289f42009-09-09 15:08:12 +00004526
4527template<typename Derived>
4528Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004529TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004530 // Implicit casts are eliminated during transformation, since they
4531 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004532 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004533}
Mike Stump11289f42009-09-09 15:08:12 +00004534
Douglas Gregora16548e2009-08-11 05:31:07 +00004535template<typename Derived>
4536Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004537TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004538 TypeSourceInfo *OldT;
4539 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 {
4541 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004542 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004543 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4544 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004545
John McCall97513962010-01-15 18:39:57 +00004546 OldT = E->getTypeInfoAsWritten();
4547 NewT = getDerived().TransformType(OldT);
4548 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 return SemaRef.ExprError();
4550 }
Mike Stump11289f42009-09-09 15:08:12 +00004551
Douglas Gregor6131b442009-12-12 18:16:41 +00004552 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004553 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 if (SubExpr.isInvalid())
4555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004556
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004558 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004560 return SemaRef.Owned(E->Retain());
4561
John McCall97513962010-01-15 18:39:57 +00004562 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4563 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 E->getRParenLoc(),
4565 move(SubExpr));
4566}
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004569Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004570TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004571 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4572 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4573 if (!NewT)
4574 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004575
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4577 if (Init.isInvalid())
4578 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004581 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004583 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004584
John McCall5d7aa7f2010-01-19 22:33:45 +00004585 // Note: the expression type doesn't necessarily match the
4586 // type-as-written, but that's okay, because it should always be
4587 // derivable from the initializer.
4588
John McCalle15bbff2010-01-18 19:35:47 +00004589 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 /*FIXME:*/E->getInitializer()->getLocEnd(),
4591 move(Init));
4592}
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregora16548e2009-08-11 05:31:07 +00004594template<typename Derived>
4595Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004596TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4598 if (Base.isInvalid())
4599 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 if (!getDerived().AlwaysRebuild() &&
4602 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004603 return SemaRef.Owned(E->Retain());
4604
Douglas Gregora16548e2009-08-11 05:31:07 +00004605 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004606 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4608 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4609 E->getAccessorLoc(),
4610 E->getAccessor());
4611}
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregora16548e2009-08-11 05:31:07 +00004613template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004614Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004615TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4619 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4620 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4621 if (Init.isInvalid())
4622 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004623
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 InitChanged = InitChanged || Init.get() != E->getInit(I);
4625 Inits.push_back(Init.takeAs<Expr>());
4626 }
Mike Stump11289f42009-09-09 15:08:12 +00004627
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004629 return SemaRef.Owned(E->Retain());
4630
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004632 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004633}
Mike Stump11289f42009-09-09 15:08:12 +00004634
Douglas Gregora16548e2009-08-11 05:31:07 +00004635template<typename Derived>
4636Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004637TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregorebe10102009-08-20 07:17:43 +00004640 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4642 if (Init.isInvalid())
4643 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregorebe10102009-08-20 07:17:43 +00004645 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4647 bool ExprChanged = false;
4648 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4649 DEnd = E->designators_end();
4650 D != DEnd; ++D) {
4651 if (D->isFieldDesignator()) {
4652 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4653 D->getDotLoc(),
4654 D->getFieldLoc()));
4655 continue;
4656 }
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 if (D->isArrayDesignator()) {
4659 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4660 if (Index.isInvalid())
4661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004662
4663 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4667 ArrayExprs.push_back(Index.release());
4668 continue;
4669 }
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004672 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4674 if (Start.isInvalid())
4675 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4678 if (End.isInvalid())
4679 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004680
4681 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 End.get(),
4683 D->getLBracketLoc(),
4684 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4687 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 ArrayExprs.push_back(Start.release());
4690 ArrayExprs.push_back(End.release());
4691 }
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 if (!getDerived().AlwaysRebuild() &&
4694 Init.get() == E->getInit() &&
4695 !ExprChanged)
4696 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4699 E->getEqualOrColonLoc(),
4700 E->usesGNUSyntax(), move(Init));
4701}
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004704Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004705TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004706 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004707 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004708
Douglas Gregor3da3c062009-10-28 00:29:27 +00004709 // FIXME: Will we ever have proper type location here? Will we actually
4710 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 QualType T = getDerived().TransformType(E->getType());
4712 if (T.isNull())
4713 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 if (!getDerived().AlwaysRebuild() &&
4716 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004717 return SemaRef.Owned(E->Retain());
4718
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 return getDerived().RebuildImplicitValueInitExpr(T);
4720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004723Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004724TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 // FIXME: Do we want the type as written?
4726 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 {
4729 // FIXME: Source location isn't quite accurate.
4730 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4731 T = getDerived().TransformType(E->getType());
4732 if (T.isNull())
4733 return SemaRef.ExprError();
4734 }
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4737 if (SubExpr.isInvalid())
4738 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004739
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 if (!getDerived().AlwaysRebuild() &&
4741 T == E->getType() &&
4742 SubExpr.get() == E->getSubExpr())
4743 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004744
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4746 T, E->getRParenLoc());
4747}
4748
4749template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004750Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004751TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 bool ArgumentChanged = false;
4753 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4754 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4755 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4756 if (Init.isInvalid())
4757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4760 Inits.push_back(Init.takeAs<Expr>());
4761 }
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4764 move_arg(Inits),
4765 E->getRParenLoc());
4766}
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregora16548e2009-08-11 05:31:07 +00004768/// \brief Transform an address-of-label expression.
4769///
4770/// By default, the transformation of an address-of-label expression always
4771/// rebuilds the expression, so that the label identifier can be resolved to
4772/// the corresponding label statement by semantic analysis.
4773template<typename Derived>
4774Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004775TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4777 E->getLabel());
4778}
Mike Stump11289f42009-09-09 15:08:12 +00004779
4780template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004781Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004783 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4785 if (SubStmt.isInvalid())
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 if (!getDerived().AlwaysRebuild() &&
4789 SubStmt.get() == E->getSubStmt())
4790 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004791
4792 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 move(SubStmt),
4794 E->getRParenLoc());
4795}
Mike Stump11289f42009-09-09 15:08:12 +00004796
Douglas Gregora16548e2009-08-11 05:31:07 +00004797template<typename Derived>
4798Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004799TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 QualType T1, T2;
4801 {
4802 // FIXME: Source location isn't quite accurate.
4803 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 T1 = getDerived().TransformType(E->getArgType1());
4806 if (T1.isNull())
4807 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004808
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 T2 = getDerived().TransformType(E->getArgType2());
4810 if (T2.isNull())
4811 return SemaRef.ExprError();
4812 }
4813
4814 if (!getDerived().AlwaysRebuild() &&
4815 T1 == E->getArgType1() &&
4816 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004817 return SemaRef.Owned(E->Retain());
4818
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4820 T1, T2, E->getRParenLoc());
4821}
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregora16548e2009-08-11 05:31:07 +00004823template<typename Derived>
4824Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004825TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4827 if (Cond.isInvalid())
4828 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4831 if (LHS.isInvalid())
4832 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4835 if (RHS.isInvalid())
4836 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 if (!getDerived().AlwaysRebuild() &&
4839 Cond.get() == E->getCond() &&
4840 LHS.get() == E->getLHS() &&
4841 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004842 return SemaRef.Owned(E->Retain());
4843
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4845 move(Cond), move(LHS), move(RHS),
4846 E->getRParenLoc());
4847}
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregora16548e2009-08-11 05:31:07 +00004849template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004850Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004851TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004852 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004853}
4854
4855template<typename Derived>
4856Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004857TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004858 switch (E->getOperator()) {
4859 case OO_New:
4860 case OO_Delete:
4861 case OO_Array_New:
4862 case OO_Array_Delete:
4863 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4864 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004865
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004866 case OO_Call: {
4867 // This is a call to an object's operator().
4868 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4869
4870 // Transform the object itself.
4871 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4872 if (Object.isInvalid())
4873 return SemaRef.ExprError();
4874
4875 // FIXME: Poor location information
4876 SourceLocation FakeLParenLoc
4877 = SemaRef.PP.getLocForEndOfToken(
4878 static_cast<Expr *>(Object.get())->getLocEnd());
4879
4880 // Transform the call arguments.
4881 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4882 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4883 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004884 if (getDerived().DropCallArgument(E->getArg(I)))
4885 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004886
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004887 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4888 if (Arg.isInvalid())
4889 return SemaRef.ExprError();
4890
4891 // FIXME: Poor source location information.
4892 SourceLocation FakeCommaLoc
4893 = SemaRef.PP.getLocForEndOfToken(
4894 static_cast<Expr *>(Arg.get())->getLocEnd());
4895 FakeCommaLocs.push_back(FakeCommaLoc);
4896 Args.push_back(Arg.release());
4897 }
4898
4899 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4900 move_arg(Args),
4901 FakeCommaLocs.data(),
4902 E->getLocEnd());
4903 }
4904
4905#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4906 case OO_##Name:
4907#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4908#include "clang/Basic/OperatorKinds.def"
4909 case OO_Subscript:
4910 // Handled below.
4911 break;
4912
4913 case OO_Conditional:
4914 llvm_unreachable("conditional operator is not actually overloadable");
4915 return SemaRef.ExprError();
4916
4917 case OO_None:
4918 case NUM_OVERLOADED_OPERATORS:
4919 llvm_unreachable("not an overloaded operator?");
4920 return SemaRef.ExprError();
4921 }
4922
Douglas Gregora16548e2009-08-11 05:31:07 +00004923 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4924 if (Callee.isInvalid())
4925 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004926
John McCall47f29ea2009-12-08 09:21:05 +00004927 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 if (First.isInvalid())
4929 return SemaRef.ExprError();
4930
4931 OwningExprResult Second(SemaRef);
4932 if (E->getNumArgs() == 2) {
4933 Second = getDerived().TransformExpr(E->getArg(1));
4934 if (Second.isInvalid())
4935 return SemaRef.ExprError();
4936 }
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 if (!getDerived().AlwaysRebuild() &&
4939 Callee.get() == E->getCallee() &&
4940 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004941 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4942 return SemaRef.Owned(E->Retain());
4943
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4945 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004946 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 move(First),
4948 move(Second));
4949}
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregora16548e2009-08-11 05:31:07 +00004951template<typename Derived>
4952Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004953TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4954 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004955}
Mike Stump11289f42009-09-09 15:08:12 +00004956
Douglas Gregora16548e2009-08-11 05:31:07 +00004957template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004958Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004959TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004960 TypeSourceInfo *OldT;
4961 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004962 {
4963 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004964 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4966 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCall97513962010-01-15 18:39:57 +00004968 OldT = E->getTypeInfoAsWritten();
4969 NewT = getDerived().TransformType(OldT);
4970 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004971 return SemaRef.ExprError();
4972 }
Mike Stump11289f42009-09-09 15:08:12 +00004973
Douglas Gregor6131b442009-12-12 18:16:41 +00004974 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004975 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004976 if (SubExpr.isInvalid())
4977 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004978
Douglas Gregora16548e2009-08-11 05:31:07 +00004979 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004980 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004981 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004982 return SemaRef.Owned(E->Retain());
4983
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004985 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4987 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4988 SourceLocation FakeRParenLoc
4989 = SemaRef.PP.getLocForEndOfToken(
4990 E->getSubExpr()->getSourceRange().getEnd());
4991 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004992 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004994 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004995 FakeRAngleLoc,
4996 FakeRAngleLoc,
4997 move(SubExpr),
4998 FakeRParenLoc);
4999}
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregora16548e2009-08-11 05:31:07 +00005001template<typename Derived>
5002Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005003TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5004 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005005}
Mike Stump11289f42009-09-09 15:08:12 +00005006
5007template<typename Derived>
5008Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005009TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5010 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005011}
5012
Douglas Gregora16548e2009-08-11 05:31:07 +00005013template<typename Derived>
5014Sema::OwningExprResult
5015TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005016 CXXReinterpretCastExpr *E) {
5017 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005018}
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregora16548e2009-08-11 05:31:07 +00005020template<typename Derived>
5021Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005022TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5023 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005024}
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregora16548e2009-08-11 05:31:07 +00005026template<typename Derived>
5027Sema::OwningExprResult
5028TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005029 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005030 TypeSourceInfo *OldT;
5031 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 {
5033 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005034
John McCall97513962010-01-15 18:39:57 +00005035 OldT = E->getTypeInfoAsWritten();
5036 NewT = getDerived().TransformType(OldT);
5037 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 return SemaRef.ExprError();
5039 }
Mike Stump11289f42009-09-09 15:08:12 +00005040
Douglas Gregor6131b442009-12-12 18:16:41 +00005041 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005042 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 if (SubExpr.isInvalid())
5044 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005047 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005049 return SemaRef.Owned(E->Retain());
5050
Douglas Gregora16548e2009-08-11 05:31:07 +00005051 // FIXME: The end of the type's source range is wrong
5052 return getDerived().RebuildCXXFunctionalCastExpr(
5053 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005054 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 /*FIXME:*/E->getSubExpr()->getLocStart(),
5056 move(SubExpr),
5057 E->getRParenLoc());
5058}
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregora16548e2009-08-11 05:31:07 +00005060template<typename Derived>
5061Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005062TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005064 TypeSourceInfo *TInfo
5065 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5066 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005070 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005072
Douglas Gregor9da64192010-04-26 22:37:10 +00005073 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5074 E->getLocStart(),
5075 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 E->getLocEnd());
5077 }
Mike Stump11289f42009-09-09 15:08:12 +00005078
Douglas Gregora16548e2009-08-11 05:31:07 +00005079 // We don't know whether the expression is potentially evaluated until
5080 // after we perform semantic analysis, so the expression is potentially
5081 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005082 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5086 if (SubExpr.isInvalid())
5087 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 if (!getDerived().AlwaysRebuild() &&
5090 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005091 return SemaRef.Owned(E->Retain());
5092
Douglas Gregor9da64192010-04-26 22:37:10 +00005093 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5094 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 move(SubExpr),
5096 E->getLocEnd());
5097}
5098
5099template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005100Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005101TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005102 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005103}
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregora16548e2009-08-11 05:31:07 +00005105template<typename Derived>
5106Sema::OwningExprResult
5107TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005108 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005109 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005110}
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112template<typename Derived>
5113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 QualType T = getDerived().TransformType(E->getType());
5118 if (T.isNull())
5119 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 if (!getDerived().AlwaysRebuild() &&
5122 T == E->getType())
5123 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005124
Douglas Gregorb15af892010-01-07 23:12:05 +00005125 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005126}
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregora16548e2009-08-11 05:31:07 +00005128template<typename Derived>
5129Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005130TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5132 if (SubExpr.isInvalid())
5133 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 if (!getDerived().AlwaysRebuild() &&
5136 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005137 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005138
5139 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5140}
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregora16548e2009-08-11 05:31:07 +00005142template<typename Derived>
5143Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005144TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005145 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005146 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5147 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 if (!Param)
5149 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005150
Chandler Carruth794da4c2010-02-08 06:42:49 +00005151 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005152 Param == E->getParam())
5153 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregor033f6752009-12-23 23:03:06 +00005155 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005156}
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregora16548e2009-08-11 05:31:07 +00005158template<typename Derived>
5159Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005160TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5162
5163 QualType T = getDerived().TransformType(E->getType());
5164 if (T.isNull())
5165 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (!getDerived().AlwaysRebuild() &&
5168 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005169 return SemaRef.Owned(E->Retain());
5170
5171 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 /*FIXME:*/E->getTypeBeginLoc(),
5173 T,
5174 E->getRParenLoc());
5175}
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177template<typename Derived>
5178Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005179TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 // Transform the type that we're allocating
5181 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5182 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5183 if (AllocType.isNull())
5184 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregora16548e2009-08-11 05:31:07 +00005186 // Transform the size of the array we're allocating (if any).
5187 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5188 if (ArraySize.isInvalid())
5189 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregora16548e2009-08-11 05:31:07 +00005191 // Transform the placement arguments (if any).
5192 bool ArgumentChanged = false;
5193 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5194 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5195 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5196 if (Arg.isInvalid())
5197 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005198
Douglas Gregora16548e2009-08-11 05:31:07 +00005199 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5200 PlacementArgs.push_back(Arg.take());
5201 }
Mike Stump11289f42009-09-09 15:08:12 +00005202
Douglas Gregorebe10102009-08-20 07:17:43 +00005203 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5205 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5206 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5207 if (Arg.isInvalid())
5208 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregora16548e2009-08-11 05:31:07 +00005210 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5211 ConstructorArgs.push_back(Arg.take());
5212 }
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregord2d9da02010-02-26 00:38:10 +00005214 // Transform constructor, new operator, and delete operator.
5215 CXXConstructorDecl *Constructor = 0;
5216 if (E->getConstructor()) {
5217 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005218 getDerived().TransformDecl(E->getLocStart(),
5219 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005220 if (!Constructor)
5221 return SemaRef.ExprError();
5222 }
5223
5224 FunctionDecl *OperatorNew = 0;
5225 if (E->getOperatorNew()) {
5226 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005227 getDerived().TransformDecl(E->getLocStart(),
5228 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005229 if (!OperatorNew)
5230 return SemaRef.ExprError();
5231 }
5232
5233 FunctionDecl *OperatorDelete = 0;
5234 if (E->getOperatorDelete()) {
5235 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005236 getDerived().TransformDecl(E->getLocStart(),
5237 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005238 if (!OperatorDelete)
5239 return SemaRef.ExprError();
5240 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005241
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 if (!getDerived().AlwaysRebuild() &&
5243 AllocType == E->getAllocatedType() &&
5244 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005245 Constructor == E->getConstructor() &&
5246 OperatorNew == E->getOperatorNew() &&
5247 OperatorDelete == E->getOperatorDelete() &&
5248 !ArgumentChanged) {
5249 // Mark any declarations we need as referenced.
5250 // FIXME: instantiation-specific.
5251 if (Constructor)
5252 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5253 if (OperatorNew)
5254 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5255 if (OperatorDelete)
5256 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005257 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005258 }
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005260 if (!ArraySize.get()) {
5261 // If no array size was specified, but the new expression was
5262 // instantiated with an array type (e.g., "new T" where T is
5263 // instantiated with "int[4]"), extract the outer bound from the
5264 // array type as our array size. We do this with constant and
5265 // dependently-sized array types.
5266 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5267 if (!ArrayT) {
5268 // Do nothing
5269 } else if (const ConstantArrayType *ConsArrayT
5270 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005272 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005273 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005274 SemaRef.Context.getSizeType(),
5275 /*FIXME:*/E->getLocStart()));
5276 AllocType = ConsArrayT->getElementType();
5277 } else if (const DependentSizedArrayType *DepArrayT
5278 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5279 if (DepArrayT->getSizeExpr()) {
5280 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5281 AllocType = DepArrayT->getElementType();
5282 }
5283 }
5284 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005285 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5286 E->isGlobalNew(),
5287 /*FIXME:*/E->getLocStart(),
5288 move_arg(PlacementArgs),
5289 /*FIXME:*/E->getLocStart(),
5290 E->isParenTypeId(),
5291 AllocType,
5292 /*FIXME:*/E->getLocStart(),
5293 /*FIXME:*/SourceRange(),
5294 move(ArraySize),
5295 /*FIXME:*/E->getLocStart(),
5296 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005297 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005298}
Mike Stump11289f42009-09-09 15:08:12 +00005299
Douglas Gregora16548e2009-08-11 05:31:07 +00005300template<typename Derived>
5301Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005302TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005303 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5304 if (Operand.isInvalid())
5305 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregord2d9da02010-02-26 00:38:10 +00005307 // Transform the delete operator, if known.
5308 FunctionDecl *OperatorDelete = 0;
5309 if (E->getOperatorDelete()) {
5310 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005311 getDerived().TransformDecl(E->getLocStart(),
5312 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005313 if (!OperatorDelete)
5314 return SemaRef.ExprError();
5315 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005318 Operand.get() == E->getArgument() &&
5319 OperatorDelete == E->getOperatorDelete()) {
5320 // Mark any declarations we need as referenced.
5321 // FIXME: instantiation-specific.
5322 if (OperatorDelete)
5323 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005324 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005325 }
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregora16548e2009-08-11 05:31:07 +00005327 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5328 E->isGlobalDelete(),
5329 E->isArrayForm(),
5330 move(Operand));
5331}
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregora16548e2009-08-11 05:31:07 +00005333template<typename Derived>
5334Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005335TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005336 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005337 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5338 if (Base.isInvalid())
5339 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregor678f90d2010-02-25 01:56:36 +00005341 Sema::TypeTy *ObjectTypePtr = 0;
5342 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005343 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005344 E->getOperatorLoc(),
5345 E->isArrow()? tok::arrow : tok::period,
5346 ObjectTypePtr,
5347 MayBePseudoDestructor);
5348 if (Base.isInvalid())
5349 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005350
Douglas Gregor678f90d2010-02-25 01:56:36 +00005351 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005352 NestedNameSpecifier *Qualifier
5353 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005354 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005355 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005356 if (E->getQualifier() && !Qualifier)
5357 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregor678f90d2010-02-25 01:56:36 +00005359 PseudoDestructorTypeStorage Destroyed;
5360 if (E->getDestroyedTypeInfo()) {
5361 TypeSourceInfo *DestroyedTypeInfo
5362 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5363 if (!DestroyedTypeInfo)
5364 return SemaRef.ExprError();
5365 Destroyed = DestroyedTypeInfo;
5366 } else if (ObjectType->isDependentType()) {
5367 // We aren't likely to be able to resolve the identifier down to a type
5368 // now anyway, so just retain the identifier.
5369 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5370 E->getDestroyedTypeLoc());
5371 } else {
5372 // Look for a destructor known with the given name.
5373 CXXScopeSpec SS;
5374 if (Qualifier) {
5375 SS.setScopeRep(Qualifier);
5376 SS.setRange(E->getQualifierRange());
5377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
Douglas Gregor678f90d2010-02-25 01:56:36 +00005379 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5380 *E->getDestroyedTypeIdentifier(),
5381 E->getDestroyedTypeLoc(),
5382 /*Scope=*/0,
5383 SS, ObjectTypePtr,
5384 false);
5385 if (!T)
5386 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005387
Douglas Gregor678f90d2010-02-25 01:56:36 +00005388 Destroyed
5389 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5390 E->getDestroyedTypeLoc());
5391 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005392
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005393 TypeSourceInfo *ScopeTypeInfo = 0;
5394 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005395 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005396 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005397 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005398 return SemaRef.ExprError();
5399 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005400
Douglas Gregorad8a3362009-09-04 17:36:40 +00005401 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5402 E->getOperatorLoc(),
5403 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005404 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005405 E->getQualifierRange(),
5406 ScopeTypeInfo,
5407 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005408 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005409 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005410}
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregorad8a3362009-09-04 17:36:40 +00005412template<typename Derived>
5413Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005414TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005415 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005416 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5417
5418 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5419 Sema::LookupOrdinaryName);
5420
5421 // Transform all the decls.
5422 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5423 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005424 NamedDecl *InstD = static_cast<NamedDecl*>(
5425 getDerived().TransformDecl(Old->getNameLoc(),
5426 *I));
John McCall84d87672009-12-10 09:41:52 +00005427 if (!InstD) {
5428 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5429 // This can happen because of dependent hiding.
5430 if (isa<UsingShadowDecl>(*I))
5431 continue;
5432 else
5433 return SemaRef.ExprError();
5434 }
John McCalle66edc12009-11-24 19:00:30 +00005435
5436 // Expand using declarations.
5437 if (isa<UsingDecl>(InstD)) {
5438 UsingDecl *UD = cast<UsingDecl>(InstD);
5439 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5440 E = UD->shadow_end(); I != E; ++I)
5441 R.addDecl(*I);
5442 continue;
5443 }
5444
5445 R.addDecl(InstD);
5446 }
5447
5448 // Resolve a kind, but don't do any further analysis. If it's
5449 // ambiguous, the callee needs to deal with it.
5450 R.resolveKind();
5451
5452 // Rebuild the nested-name qualifier, if present.
5453 CXXScopeSpec SS;
5454 NestedNameSpecifier *Qualifier = 0;
5455 if (Old->getQualifier()) {
5456 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005457 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005458 if (!Qualifier)
5459 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005460
John McCalle66edc12009-11-24 19:00:30 +00005461 SS.setScopeRep(Qualifier);
5462 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005463 }
5464
Douglas Gregor9262f472010-04-27 18:19:34 +00005465 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005466 CXXRecordDecl *NamingClass
5467 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5468 Old->getNameLoc(),
5469 Old->getNamingClass()));
5470 if (!NamingClass)
5471 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005472
Douglas Gregorda7be082010-04-27 16:10:10 +00005473 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005474 }
5475
5476 // If we have no template arguments, it's a normal declaration name.
5477 if (!Old->hasExplicitTemplateArgs())
5478 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5479
5480 // If we have template arguments, rebuild them, then rebuild the
5481 // templateid expression.
5482 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5483 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5484 TemplateArgumentLoc Loc;
5485 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5486 return SemaRef.ExprError();
5487 TransArgs.addArgument(Loc);
5488 }
5489
5490 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5491 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005492}
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregora16548e2009-08-11 05:31:07 +00005494template<typename Derived>
5495Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005496TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005497 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 QualType T = getDerived().TransformType(E->getQueriedType());
5500 if (T.isNull())
5501 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005502
Douglas Gregora16548e2009-08-11 05:31:07 +00005503 if (!getDerived().AlwaysRebuild() &&
5504 T == E->getQueriedType())
5505 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregora16548e2009-08-11 05:31:07 +00005507 // FIXME: Bad location information
5508 SourceLocation FakeLParenLoc
5509 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005510
5511 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 E->getLocStart(),
5513 /*FIXME:*/FakeLParenLoc,
5514 T,
5515 E->getLocEnd());
5516}
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518template<typename Derived>
5519Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005520TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005521 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005523 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005524 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 if (!NNS)
5526 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005527
5528 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005529 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5530 if (!Name)
5531 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCalle66edc12009-11-24 19:00:30 +00005533 if (!E->hasExplicitTemplateArgs()) {
5534 if (!getDerived().AlwaysRebuild() &&
5535 NNS == E->getQualifier() &&
5536 Name == E->getDeclName())
5537 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005538
John McCalle66edc12009-11-24 19:00:30 +00005539 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5540 E->getQualifierRange(),
5541 Name, E->getLocation(),
5542 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005543 }
John McCall6b51f282009-11-23 01:53:49 +00005544
5545 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005547 TemplateArgumentLoc Loc;
5548 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005550 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005551 }
5552
John McCalle66edc12009-11-24 19:00:30 +00005553 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5554 E->getQualifierRange(),
5555 Name, E->getLocation(),
5556 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005557}
5558
5559template<typename Derived>
5560Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005561TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005562 // CXXConstructExprs are always implicit, so when we have a
5563 // 1-argument construction we just transform that argument.
5564 if (E->getNumArgs() == 1 ||
5565 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5566 return getDerived().TransformExpr(E->getArg(0));
5567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5569
5570 QualType T = getDerived().TransformType(E->getType());
5571 if (T.isNull())
5572 return SemaRef.ExprError();
5573
5574 CXXConstructorDecl *Constructor
5575 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005576 getDerived().TransformDecl(E->getLocStart(),
5577 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005578 if (!Constructor)
5579 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 bool ArgumentChanged = false;
5582 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005583 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 ArgEnd = E->arg_end();
5585 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005586 if (getDerived().DropCallArgument(*Arg)) {
5587 ArgumentChanged = true;
5588 break;
5589 }
5590
Douglas Gregora16548e2009-08-11 05:31:07 +00005591 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5592 if (TransArg.isInvalid())
5593 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005594
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5596 Args.push_back(TransArg.takeAs<Expr>());
5597 }
5598
5599 if (!getDerived().AlwaysRebuild() &&
5600 T == E->getType() &&
5601 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005602 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005603 // Mark the constructor as referenced.
5604 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005605 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005607 }
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregordb121ba2009-12-14 16:27:04 +00005609 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5610 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 move_arg(Args));
5612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregora16548e2009-08-11 05:31:07 +00005614/// \brief Transform a C++ temporary-binding expression.
5615///
Douglas Gregor363b1512009-12-24 18:51:59 +00005616/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5617/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005618template<typename Derived>
5619Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005621 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005622}
Mike Stump11289f42009-09-09 15:08:12 +00005623
Anders Carlssonba6c4372010-01-29 02:39:32 +00005624/// \brief Transform a C++ reference-binding expression.
5625///
5626/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5627/// transform the subexpression and return that.
5628template<typename Derived>
5629Sema::OwningExprResult
5630TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5631 return getDerived().TransformExpr(E->getSubExpr());
5632}
5633
Mike Stump11289f42009-09-09 15:08:12 +00005634/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005635/// be destroyed after the expression is evaluated.
5636///
Douglas Gregor363b1512009-12-24 18:51:59 +00005637/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5638/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005639template<typename Derived>
5640Sema::OwningExprResult
5641TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005642 CXXExprWithTemporaries *E) {
5643 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005644}
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646template<typename Derived>
5647Sema::OwningExprResult
5648TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005649 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5651 QualType T = getDerived().TransformType(E->getType());
5652 if (T.isNull())
5653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 CXXConstructorDecl *Constructor
5656 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005657 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005658 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 if (!Constructor)
5660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 bool ArgumentChanged = false;
5663 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5664 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005665 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 ArgEnd = E->arg_end();
5667 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +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((Expr *)TransArg.release());
5679 }
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 if (!getDerived().AlwaysRebuild() &&
5682 T == E->getType() &&
5683 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005684 !ArgumentChanged) {
5685 // FIXME: Instantiation-specific
5686 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005687 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005688 }
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregora16548e2009-08-11 05:31:07 +00005690 // FIXME: Bogus location information
5691 SourceLocation CommaLoc;
5692 if (Args.size() > 1) {
5693 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005694 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5696 }
5697 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5698 T,
5699 /*FIXME:*/E->getTypeBeginLoc(),
5700 move_arg(Args),
5701 &CommaLoc,
5702 E->getLocEnd());
5703}
Mike Stump11289f42009-09-09 15:08:12 +00005704
Douglas Gregora16548e2009-08-11 05:31:07 +00005705template<typename Derived>
5706Sema::OwningExprResult
5707TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005708 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5710 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5711 if (T.isNull())
5712 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 bool ArgumentChanged = false;
5715 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5716 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5717 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5718 ArgEnd = E->arg_end();
5719 Arg != ArgEnd; ++Arg) {
5720 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5721 if (TransArg.isInvalid())
5722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5725 FakeCommaLocs.push_back(
5726 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5727 Args.push_back(TransArg.takeAs<Expr>());
5728 }
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (!getDerived().AlwaysRebuild() &&
5731 T == E->getTypeAsWritten() &&
5732 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005733 return SemaRef.Owned(E->Retain());
5734
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 // FIXME: we're faking the locations of the commas
5736 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5737 T,
5738 E->getLParenLoc(),
5739 move_arg(Args),
5740 FakeCommaLocs.data(),
5741 E->getRParenLoc());
5742}
Mike Stump11289f42009-09-09 15:08:12 +00005743
Douglas Gregora16548e2009-08-11 05:31:07 +00005744template<typename Derived>
5745Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005746TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005747 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005749 OwningExprResult Base(SemaRef, (Expr*) 0);
5750 Expr *OldBase;
5751 QualType BaseType;
5752 QualType ObjectType;
5753 if (!E->isImplicitAccess()) {
5754 OldBase = E->getBase();
5755 Base = getDerived().TransformExpr(OldBase);
5756 if (Base.isInvalid())
5757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005758
John McCall2d74de92009-12-01 22:10:20 +00005759 // Start the member reference and compute the object's type.
5760 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005761 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005762 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5763 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005764 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005765 ObjectTy,
5766 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005767 if (Base.isInvalid())
5768 return SemaRef.ExprError();
5769
5770 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5771 BaseType = ((Expr*) Base.get())->getType();
5772 } else {
5773 OldBase = 0;
5774 BaseType = getDerived().TransformType(E->getBaseType());
5775 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5776 }
Mike Stump11289f42009-09-09 15:08:12 +00005777
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005778 // Transform the first part of the nested-name-specifier that qualifies
5779 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005780 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005781 = getDerived().TransformFirstQualifierInScope(
5782 E->getFirstQualifierFoundInScope(),
5783 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005785 NestedNameSpecifier *Qualifier = 0;
5786 if (E->getQualifier()) {
5787 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5788 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005789 ObjectType,
5790 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005791 if (!Qualifier)
5792 return SemaRef.ExprError();
5793 }
Mike Stump11289f42009-09-09 15:08:12 +00005794
5795 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005796 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005797 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005798 if (!Name)
5799 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005800
John McCall2d74de92009-12-01 22:10:20 +00005801 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005802 // This is a reference to a member without an explicitly-specified
5803 // template argument list. Optimize for this common case.
5804 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005805 Base.get() == OldBase &&
5806 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005807 Qualifier == E->getQualifier() &&
5808 Name == E->getMember() &&
5809 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005810 return SemaRef.Owned(E->Retain());
5811
John McCall8cd78132009-11-19 22:55:06 +00005812 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005813 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005814 E->isArrow(),
5815 E->getOperatorLoc(),
5816 Qualifier,
5817 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005818 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005819 Name,
5820 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005821 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005822 }
5823
John McCall6b51f282009-11-23 01:53:49 +00005824 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005825 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005826 TemplateArgumentLoc Loc;
5827 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005828 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005829 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005830 }
Mike Stump11289f42009-09-09 15:08:12 +00005831
John McCall8cd78132009-11-19 22:55:06 +00005832 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005833 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005834 E->isArrow(),
5835 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005836 Qualifier,
5837 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005838 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005839 Name,
5840 E->getMemberLoc(),
5841 &TransArgs);
5842}
5843
5844template<typename Derived>
5845Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005846TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005847 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005848 OwningExprResult Base(SemaRef, (Expr*) 0);
5849 QualType BaseType;
5850 if (!Old->isImplicitAccess()) {
5851 Base = getDerived().TransformExpr(Old->getBase());
5852 if (Base.isInvalid())
5853 return SemaRef.ExprError();
5854 BaseType = ((Expr*) Base.get())->getType();
5855 } else {
5856 BaseType = getDerived().TransformType(Old->getBaseType());
5857 }
John McCall10eae182009-11-30 22:42:35 +00005858
5859 NestedNameSpecifier *Qualifier = 0;
5860 if (Old->getQualifier()) {
5861 Qualifier
5862 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005863 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005864 if (Qualifier == 0)
5865 return SemaRef.ExprError();
5866 }
5867
5868 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5869 Sema::LookupOrdinaryName);
5870
5871 // Transform all the decls.
5872 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5873 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005874 NamedDecl *InstD = static_cast<NamedDecl*>(
5875 getDerived().TransformDecl(Old->getMemberLoc(),
5876 *I));
John McCall84d87672009-12-10 09:41:52 +00005877 if (!InstD) {
5878 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5879 // This can happen because of dependent hiding.
5880 if (isa<UsingShadowDecl>(*I))
5881 continue;
5882 else
5883 return SemaRef.ExprError();
5884 }
John McCall10eae182009-11-30 22:42:35 +00005885
5886 // Expand using declarations.
5887 if (isa<UsingDecl>(InstD)) {
5888 UsingDecl *UD = cast<UsingDecl>(InstD);
5889 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5890 E = UD->shadow_end(); I != E; ++I)
5891 R.addDecl(*I);
5892 continue;
5893 }
5894
5895 R.addDecl(InstD);
5896 }
5897
5898 R.resolveKind();
5899
Douglas Gregor9262f472010-04-27 18:19:34 +00005900 // Determine the naming class.
5901 if (!Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005902 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005903 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005904 Old->getMemberLoc(),
5905 Old->getNamingClass()));
5906 if (!NamingClass)
5907 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005908
Douglas Gregorda7be082010-04-27 16:10:10 +00005909 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005910 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005911
John McCall10eae182009-11-30 22:42:35 +00005912 TemplateArgumentListInfo TransArgs;
5913 if (Old->hasExplicitTemplateArgs()) {
5914 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5915 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5916 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5917 TemplateArgumentLoc Loc;
5918 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5919 Loc))
5920 return SemaRef.ExprError();
5921 TransArgs.addArgument(Loc);
5922 }
5923 }
John McCall38836f02010-01-15 08:34:02 +00005924
5925 // FIXME: to do this check properly, we will need to preserve the
5926 // first-qualifier-in-scope here, just in case we had a dependent
5927 // base (and therefore couldn't do the check) and a
5928 // nested-name-qualifier (and therefore could do the lookup).
5929 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005930
John McCall10eae182009-11-30 22:42:35 +00005931 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005932 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005933 Old->getOperatorLoc(),
5934 Old->isArrow(),
5935 Qualifier,
5936 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005937 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005938 R,
5939 (Old->hasExplicitTemplateArgs()
5940 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005941}
5942
5943template<typename Derived>
5944Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005945TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005946 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005947}
5948
Mike Stump11289f42009-09-09 15:08:12 +00005949template<typename Derived>
5950Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005951TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005952 TypeSourceInfo *EncodedTypeInfo
5953 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5954 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005955 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005956
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005958 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005959 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005960
5961 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005962 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 E->getRParenLoc());
5964}
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregora16548e2009-08-11 05:31:07 +00005966template<typename Derived>
5967Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005968TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005969 // Transform arguments.
5970 bool ArgChanged = false;
5971 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5972 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5973 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5974 if (Arg.isInvalid())
5975 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005976
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005977 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5978 Args.push_back(Arg.takeAs<Expr>());
5979 }
5980
5981 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5982 // Class message: transform the receiver type.
5983 TypeSourceInfo *ReceiverTypeInfo
5984 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5985 if (!ReceiverTypeInfo)
5986 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005987
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005988 // If nothing changed, just retain the existing message send.
5989 if (!getDerived().AlwaysRebuild() &&
5990 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5991 return SemaRef.Owned(E->Retain());
5992
5993 // Build a new class message send.
5994 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5995 E->getSelector(),
5996 E->getMethodDecl(),
5997 E->getLeftLoc(),
5998 move_arg(Args),
5999 E->getRightLoc());
6000 }
6001
6002 // Instance message: transform the receiver
6003 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6004 "Only class and instance messages may be instantiated");
6005 OwningExprResult Receiver
6006 = getDerived().TransformExpr(E->getInstanceReceiver());
6007 if (Receiver.isInvalid())
6008 return SemaRef.ExprError();
6009
6010 // If nothing changed, just retain the existing message send.
6011 if (!getDerived().AlwaysRebuild() &&
6012 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6013 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006014
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006015 // Build a new instance message send.
6016 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6017 E->getSelector(),
6018 E->getMethodDecl(),
6019 E->getLeftLoc(),
6020 move_arg(Args),
6021 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006022}
6023
Mike Stump11289f42009-09-09 15:08:12 +00006024template<typename Derived>
6025Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006026TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006027 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006028}
6029
Mike Stump11289f42009-09-09 15:08:12 +00006030template<typename Derived>
6031Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006032TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006033 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006034}
6035
Mike Stump11289f42009-09-09 15:08:12 +00006036template<typename Derived>
6037Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006038TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006039 // Transform the base expression.
6040 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6041 if (Base.isInvalid())
6042 return SemaRef.ExprError();
6043
6044 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006045
Douglas Gregord51d90d2010-04-26 20:11:03 +00006046 // If nothing changed, just retain the existing expression.
6047 if (!getDerived().AlwaysRebuild() &&
6048 Base.get() == E->getBase())
6049 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006050
Douglas Gregord51d90d2010-04-26 20:11:03 +00006051 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6052 E->getLocation(),
6053 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006054}
6055
Mike Stump11289f42009-09-09 15:08:12 +00006056template<typename Derived>
6057Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006058TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006059 // Transform the base expression.
6060 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6061 if (Base.isInvalid())
6062 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006063
Douglas Gregor9faee212010-04-26 20:47:02 +00006064 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006065
Douglas Gregor9faee212010-04-26 20:47:02 +00006066 // If nothing changed, just retain the existing expression.
6067 if (!getDerived().AlwaysRebuild() &&
6068 Base.get() == E->getBase())
6069 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
Douglas Gregor9faee212010-04-26 20:47:02 +00006071 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6072 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006073}
6074
Mike Stump11289f42009-09-09 15:08:12 +00006075template<typename Derived>
6076Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006077TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006078 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006079 // If this implicit setter/getter refers to class methods, it cannot have any
6080 // dependent parts. Just retain the existing declaration.
6081 if (E->getInterfaceDecl())
6082 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006083
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006084 // Transform the base expression.
6085 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6086 if (Base.isInvalid())
6087 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006088
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006089 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006091 // If nothing changed, just retain the existing expression.
6092 if (!getDerived().AlwaysRebuild() &&
6093 Base.get() == E->getBase())
6094 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006095
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006096 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6097 E->getGetterMethod(),
6098 E->getType(),
6099 E->getSetterMethod(),
6100 E->getLocation(),
6101 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006102
Douglas Gregora16548e2009-08-11 05:31:07 +00006103}
6104
Mike Stump11289f42009-09-09 15:08:12 +00006105template<typename Derived>
6106Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006107TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006108 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006109 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110}
6111
Mike Stump11289f42009-09-09 15:08:12 +00006112template<typename Derived>
6113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006115 // Transform the base expression.
6116 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6117 if (Base.isInvalid())
6118 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006119
Douglas Gregord51d90d2010-04-26 20:11:03 +00006120 // If nothing changed, just retain the existing expression.
6121 if (!getDerived().AlwaysRebuild() &&
6122 Base.get() == E->getBase())
6123 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006124
Douglas Gregord51d90d2010-04-26 20:11:03 +00006125 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6126 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006127}
6128
Mike Stump11289f42009-09-09 15:08:12 +00006129template<typename Derived>
6130Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 bool ArgumentChanged = false;
6133 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6134 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6135 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6136 if (SubExpr.isInvalid())
6137 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006138
Douglas Gregora16548e2009-08-11 05:31:07 +00006139 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6140 SubExprs.push_back(SubExpr.takeAs<Expr>());
6141 }
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 if (!getDerived().AlwaysRebuild() &&
6144 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006145 return SemaRef.Owned(E->Retain());
6146
Douglas Gregora16548e2009-08-11 05:31:07 +00006147 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6148 move_arg(SubExprs),
6149 E->getRParenLoc());
6150}
6151
Mike Stump11289f42009-09-09 15:08:12 +00006152template<typename Derived>
6153Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006154TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006155 // FIXME: Implement this!
6156 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006157 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006158}
6159
Mike Stump11289f42009-09-09 15:08:12 +00006160template<typename Derived>
6161Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006162TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 // FIXME: Implement this!
6164 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006165 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006166}
Mike Stump11289f42009-09-09 15:08:12 +00006167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006169// Type reconstruction
6170//===----------------------------------------------------------------------===//
6171
Mike Stump11289f42009-09-09 15:08:12 +00006172template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006173QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6174 SourceLocation Star) {
6175 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006176 getDerived().getBaseEntity());
6177}
6178
Mike Stump11289f42009-09-09 15:08:12 +00006179template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006180QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6181 SourceLocation Star) {
6182 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006183 getDerived().getBaseEntity());
6184}
6185
Mike Stump11289f42009-09-09 15:08:12 +00006186template<typename Derived>
6187QualType
John McCall70dd5f62009-10-30 00:06:24 +00006188TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6189 bool WrittenAsLValue,
6190 SourceLocation Sigil) {
6191 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6192 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006193}
6194
6195template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006196QualType
John McCall70dd5f62009-10-30 00:06:24 +00006197TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6198 QualType ClassType,
6199 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006200 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006201 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006202}
6203
6204template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006205QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006206TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6207 ArrayType::ArraySizeModifier SizeMod,
6208 const llvm::APInt *Size,
6209 Expr *SizeExpr,
6210 unsigned IndexTypeQuals,
6211 SourceRange BracketsRange) {
6212 if (SizeExpr || !Size)
6213 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6214 IndexTypeQuals, BracketsRange,
6215 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006216
6217 QualType Types[] = {
6218 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6219 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6220 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006221 };
6222 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6223 QualType SizeType;
6224 for (unsigned I = 0; I != NumTypes; ++I)
6225 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6226 SizeType = Types[I];
6227 break;
6228 }
Mike Stump11289f42009-09-09 15:08:12 +00006229
Douglas Gregord6ff3322009-08-04 16:50:30 +00006230 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006231 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006232 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006233 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006234}
Mike Stump11289f42009-09-09 15:08:12 +00006235
Douglas Gregord6ff3322009-08-04 16:50:30 +00006236template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006237QualType
6238TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006239 ArrayType::ArraySizeModifier SizeMod,
6240 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006241 unsigned IndexTypeQuals,
6242 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006243 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006244 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006245}
6246
6247template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006248QualType
Mike Stump11289f42009-09-09 15:08:12 +00006249TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006250 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006251 unsigned IndexTypeQuals,
6252 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006253 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006254 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006255}
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregord6ff3322009-08-04 16:50:30 +00006257template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006258QualType
6259TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006260 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006261 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006262 unsigned IndexTypeQuals,
6263 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006264 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006265 SizeExpr.takeAs<Expr>(),
6266 IndexTypeQuals, BracketsRange);
6267}
6268
6269template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006270QualType
6271TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006272 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006273 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006274 unsigned IndexTypeQuals,
6275 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006276 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006277 SizeExpr.takeAs<Expr>(),
6278 IndexTypeQuals, BracketsRange);
6279}
6280
6281template<typename Derived>
6282QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006283 unsigned NumElements,
6284 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006285 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006286 return SemaRef.Context.getVectorType(ElementType, NumElements,
6287 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006288}
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregord6ff3322009-08-04 16:50:30 +00006290template<typename Derived>
6291QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6292 unsigned NumElements,
6293 SourceLocation AttributeLoc) {
6294 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6295 NumElements, true);
6296 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006297 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006298 AttributeLoc);
6299 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6300 AttributeLoc);
6301}
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregord6ff3322009-08-04 16:50:30 +00006303template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006304QualType
6305TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006307 SourceLocation AttributeLoc) {
6308 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6309}
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregord6ff3322009-08-04 16:50:30 +00006311template<typename Derived>
6312QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006313 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006314 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006315 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006316 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006317 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006318 Quals,
6319 getDerived().getBaseLocation(),
6320 getDerived().getBaseEntity());
6321}
Mike Stump11289f42009-09-09 15:08:12 +00006322
Douglas Gregord6ff3322009-08-04 16:50:30 +00006323template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006324QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6325 return SemaRef.Context.getFunctionNoProtoType(T);
6326}
6327
6328template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006329QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6330 assert(D && "no decl found");
6331 if (D->isInvalidDecl()) return QualType();
6332
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006333 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006334 TypeDecl *Ty;
6335 if (isa<UsingDecl>(D)) {
6336 UsingDecl *Using = cast<UsingDecl>(D);
6337 assert(Using->isTypeName() &&
6338 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6339
6340 // A valid resolved using typename decl points to exactly one type decl.
6341 assert(++Using->shadow_begin() == Using->shadow_end());
6342 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006343
John McCallb96ec562009-12-04 22:46:56 +00006344 } else {
6345 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6346 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6347 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6348 }
6349
6350 return SemaRef.Context.getTypeDeclType(Ty);
6351}
6352
6353template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006354QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006355 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6356}
6357
6358template<typename Derived>
6359QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6360 return SemaRef.Context.getTypeOfType(Underlying);
6361}
6362
6363template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006364QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006365 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6366}
6367
6368template<typename Derived>
6369QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006370 TemplateName Template,
6371 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006372 const TemplateArgumentListInfo &TemplateArgs) {
6373 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006374}
Mike Stump11289f42009-09-09 15:08:12 +00006375
Douglas Gregor1135c352009-08-06 05:28:30 +00006376template<typename Derived>
6377NestedNameSpecifier *
6378TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6379 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006380 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006381 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006382 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006383 CXXScopeSpec SS;
6384 // FIXME: The source location information is all wrong.
6385 SS.setRange(Range);
6386 SS.setScopeRep(Prefix);
6387 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006388 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006389 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006390 ObjectType,
6391 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006392 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006393}
6394
6395template<typename Derived>
6396NestedNameSpecifier *
6397TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6398 SourceRange Range,
6399 NamespaceDecl *NS) {
6400 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6401}
6402
6403template<typename Derived>
6404NestedNameSpecifier *
6405TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6406 SourceRange Range,
6407 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006408 QualType T) {
6409 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006410 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006411 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006412 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6413 T.getTypePtr());
6414 }
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregor1135c352009-08-06 05:28:30 +00006416 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6417 return 0;
6418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregor71dc5092009-08-06 06:41:21 +00006420template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006421TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006422TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6423 bool TemplateKW,
6424 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006425 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006426 Template);
6427}
6428
6429template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006430TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006431TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006432 const IdentifierInfo &II,
6433 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006434 CXXScopeSpec SS;
6435 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006436 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006437 UnqualifiedId Name;
6438 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006439 return getSema().ActOnDependentTemplateName(
6440 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006441 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006442 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006443 ObjectType.getAsOpaquePtr(),
6444 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006445 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006446}
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregora16548e2009-08-11 05:31:07 +00006448template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006449TemplateName
6450TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6451 OverloadedOperatorKind Operator,
6452 QualType ObjectType) {
6453 CXXScopeSpec SS;
6454 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6455 SS.setScopeRep(Qualifier);
6456 UnqualifiedId Name;
6457 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6458 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6459 Operator, SymbolLocations);
6460 return getSema().ActOnDependentTemplateName(
6461 /*FIXME:*/getDerived().getBaseLocation(),
6462 SS,
6463 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006464 ObjectType.getAsOpaquePtr(),
6465 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006466 .template getAsVal<TemplateName>();
6467}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006468
Douglas Gregor71395fa2009-11-04 00:56:37 +00006469template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006470Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006471TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6472 SourceLocation OpLoc,
6473 ExprArg Callee,
6474 ExprArg First,
6475 ExprArg Second) {
6476 Expr *FirstExpr = (Expr *)First.get();
6477 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006478 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006479 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregora16548e2009-08-11 05:31:07 +00006481 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006482 if (Op == OO_Subscript) {
6483 if (!FirstExpr->getType()->isOverloadableType() &&
6484 !SecondExpr->getType()->isOverloadableType())
6485 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006486 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006487 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006488 } else if (Op == OO_Arrow) {
6489 // -> is never a builtin operation.
6490 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006491 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 if (!FirstExpr->getType()->isOverloadableType()) {
6493 // The argument is not of overloadable type, so try to create a
6494 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006495 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006496 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregora16548e2009-08-11 05:31:07 +00006498 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6499 }
6500 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006501 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 !SecondExpr->getType()->isOverloadableType()) {
6503 // Neither of the arguments is an overloadable type, so try to
6504 // create a built-in binary operation.
6505 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006506 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006507 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6508 if (Result.isInvalid())
6509 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregora16548e2009-08-11 05:31:07 +00006511 First.release();
6512 Second.release();
6513 return move(Result);
6514 }
6515 }
Mike Stump11289f42009-09-09 15:08:12 +00006516
6517 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006519 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006520
John McCalld14a8642009-11-21 08:51:07 +00006521 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6522 assert(ULE->requiresADL());
6523
6524 // FIXME: Do we have to check
6525 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006526 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006527 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006528 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006529 }
Mike Stump11289f42009-09-09 15:08:12 +00006530
Douglas Gregora16548e2009-08-11 05:31:07 +00006531 // Add any functions found via argument-dependent lookup.
6532 Expr *Args[2] = { FirstExpr, SecondExpr };
6533 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 // Create the overloaded operator invocation for unary operators.
6536 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006537 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6539 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6540 }
Mike Stump11289f42009-09-09 15:08:12 +00006541
Sebastian Redladba46e2009-10-29 20:17:01 +00006542 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006543 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6544 OpLoc,
6545 move(First),
6546 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006547
Douglas Gregora16548e2009-08-11 05:31:07 +00006548 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006549 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006550 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006551 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6553 if (Result.isInvalid())
6554 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregora16548e2009-08-11 05:31:07 +00006556 First.release();
6557 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006558 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006559}
Mike Stump11289f42009-09-09 15:08:12 +00006560
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006561template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006562Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006563TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6564 SourceLocation OperatorLoc,
6565 bool isArrow,
6566 NestedNameSpecifier *Qualifier,
6567 SourceRange QualifierRange,
6568 TypeSourceInfo *ScopeType,
6569 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006570 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006571 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006572 CXXScopeSpec SS;
6573 if (Qualifier) {
6574 SS.setRange(QualifierRange);
6575 SS.setScopeRep(Qualifier);
6576 }
6577
6578 Expr *BaseE = (Expr *)Base.get();
6579 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006580 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006581 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006582 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006583 !BaseType->getAs<PointerType>()->getPointeeType()
6584 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006585 // This pseudo-destructor expression is still a pseudo-destructor.
6586 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6587 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006588 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006589 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006590 /*FIXME?*/true);
6591 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006592
Douglas Gregor678f90d2010-02-25 01:56:36 +00006593 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006594 DeclarationName Name
6595 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6596 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006597
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006598 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006599
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006600 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6601 OperatorLoc, isArrow,
6602 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006603 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006604 /*TemplateArgs*/ 0);
6605}
6606
Douglas Gregord6ff3322009-08-04 16:50:30 +00006607} // end namespace clang
6608
6609#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H