blob: 946496ae12ca634851b907226c166899883b038e [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregore677daf2010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000577 // Fall through.
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 case ETK_Typename:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000579 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
Douglas Gregore677daf2010-03-31 22:19:08 +0000580
581 case ETK_Class: Kind = TagDecl::TK_class; break;
582 case ETK_Struct: Kind = TagDecl::TK_struct; break;
583 case ETK_Union: Kind = TagDecl::TK_union; break;
584 case ETK_Enum: Kind = TagDecl::TK_enum; break;
585 }
586
587 // We had a dependent elaborated-type-specifier that as been transformed
588 // into a non-dependent elaborated-type-specifier. Find the tag we're
589 // referring to.
590 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
591 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
592 if (!DC)
593 return QualType();
594
595 TagDecl *Tag = 0;
596 SemaRef.LookupQualifiedName(Result, DC);
597 switch (Result.getResultKind()) {
598 case LookupResult::NotFound:
599 case LookupResult::NotFoundInCurrentInstantiation:
600 break;
601
602 case LookupResult::Found:
603 Tag = Result.getAsSingle<TagDecl>();
604 break;
605
606 case LookupResult::FoundOverloaded:
607 case LookupResult::FoundUnresolvedValue:
608 llvm_unreachable("Tag lookup cannot find non-tags");
609 return QualType();
610
611 case LookupResult::Ambiguous:
612 // Let the LookupResult structure handle ambiguities.
613 return QualType();
614 }
615
616 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000617 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000619 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 return QualType();
621 }
622
623 // FIXME: Terrible location information
624 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
625 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
626 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
627 return QualType();
628 }
629
630 // Build the elaborated-type-specifier type.
631 QualType T = SemaRef.Context.getTypeDeclType(Tag);
632 T = SemaRef.Context.getQualifiedNameType(NNS, T);
633 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000634 }
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregor1135c352009-08-06 05:28:30 +0000636 /// \brief Build a new nested-name-specifier given the prefix and an
637 /// identifier that names the next step in the nested-name-specifier.
638 ///
639 /// By default, performs semantic analysis when building the new
640 /// nested-name-specifier. Subclasses may override this routine to provide
641 /// different behavior.
642 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
643 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000644 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000645 QualType ObjectType,
646 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000647
648 /// \brief Build a new nested-name-specifier given the prefix and the
649 /// namespace named in the next step in the nested-name-specifier.
650 ///
651 /// By default, performs semantic analysis when building the new
652 /// nested-name-specifier. Subclasses may override this routine to provide
653 /// different behavior.
654 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
655 SourceRange Range,
656 NamespaceDecl *NS);
657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// type named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000667 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000668
669 /// \brief Build a new template name given a nested name specifier, a flag
670 /// indicating whether the "template" keyword was provided, and the template
671 /// that the template name refers to.
672 ///
673 /// By default, builds the new template name directly. Subclasses may override
674 /// this routine to provide different behavior.
675 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
676 bool TemplateKW,
677 TemplateDecl *Template);
678
Douglas Gregor71dc5092009-08-06 06:41:21 +0000679 /// \brief Build a new template name given a nested name specifier and the
680 /// name that is referred to as a template.
681 ///
682 /// By default, performs semantic analysis to determine whether the name can
683 /// be resolved to a specific template, then builds the appropriate kind of
684 /// template name. Subclasses may override this routine to provide different
685 /// behavior.
686 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000687 const IdentifierInfo &II,
688 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregor71395fa2009-11-04 00:56:37 +0000690 /// \brief Build a new template name given a nested name specifier and the
691 /// overloaded operator name that is referred to as a template.
692 ///
693 /// By default, performs semantic analysis to determine whether the name can
694 /// be resolved to a specific template, then builds the appropriate kind of
695 /// template name. Subclasses may override this routine to provide different
696 /// behavior.
697 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
698 OverloadedOperatorKind Operator,
699 QualType ObjectType);
700
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 /// \brief Build a new compound statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
706 MultiStmtArg Statements,
707 SourceLocation RBraceLoc,
708 bool IsStmtExpr) {
709 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
710 IsStmtExpr);
711 }
712
713 /// \brief Build a new case statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
718 ExprArg LHS,
719 SourceLocation EllipsisLoc,
720 ExprArg RHS,
721 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000722 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 ColonLoc);
724 }
Mike Stump11289f42009-09-09 15:08:12 +0000725
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 /// \brief Attach the body to a new case statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
730 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
731 getSema().ActOnCaseStmtBody(S.get(), move(Body));
732 return move(S);
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new default statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000742 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /*CurScope=*/0);
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Build a new label statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 IdentifierInfo *Id,
752 SourceLocation ColonLoc,
753 StmtArg SubStmt) {
754 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
755 }
Mike Stump11289f42009-09-09 15:08:12 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new "if" statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000761 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000762 VarDecl *CondVar, StmtArg Then,
763 SourceLocation ElseLoc, StmtArg Else) {
764 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
765 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 }
Mike Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 /// \brief Start building a new switch statement.
769 ///
770 /// By default, performs semantic analysis to build the new statement.
771 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000772 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
773 VarDecl *CondVar) {
774 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 }
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregorebe10102009-08-20 07:17:43 +0000777 /// \brief Attach the body to the switch statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000781 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 StmtArg Switch, StmtArg Body) {
783 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
784 move(Body));
785 }
786
787 /// \brief Build a new while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
792 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000793 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000795 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
796 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 }
Mike Stump11289f42009-09-09 15:08:12 +0000798
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 /// \brief Build a new do-while statement.
800 ///
801 /// By default, performs semantic analysis to build the new statement.
802 /// Subclasses may override this routine to provide different behavior.
803 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
804 SourceLocation WhileLoc,
805 SourceLocation LParenLoc,
806 ExprArg Cond,
807 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000808 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000809 move(Cond), RParenLoc);
810 }
811
812 /// \brief Build a new for statement.
813 ///
814 /// By default, performs semantic analysis to build the new statement.
815 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000816 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000818 StmtArg Init, Sema::FullExprArg Cond,
819 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000821 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
822 DeclPtrTy::make(CondVar),
823 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 }
Mike Stump11289f42009-09-09 15:08:12 +0000825
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 /// \brief Build a new goto statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
831 SourceLocation LabelLoc,
832 LabelStmt *Label) {
833 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
834 }
835
836 /// \brief Build a new indirect goto statement.
837 ///
838 /// By default, performs semantic analysis to build the new statement.
839 /// Subclasses may override this routine to provide different behavior.
840 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
841 SourceLocation StarLoc,
842 ExprArg Target) {
843 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
844 }
Mike Stump11289f42009-09-09 15:08:12 +0000845
Douglas Gregorebe10102009-08-20 07:17:43 +0000846 /// \brief Build a new return statement.
847 ///
848 /// By default, performs semantic analysis to build the new statement.
849 /// Subclasses may override this routine to provide different behavior.
850 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
851 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000852
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregorebe10102009-08-20 07:17:43 +0000856 /// \brief Build a new declaration statement.
857 ///
858 /// By default, performs semantic analysis to build the new statement.
859 /// Subclasses may override this routine to provide different behavior.
860 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000861 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 SourceLocation EndLoc) {
863 return getSema().Owned(
864 new (getSema().Context) DeclStmt(
865 DeclGroupRef::Create(getSema().Context,
866 Decls, NumDecls),
867 StartLoc, EndLoc));
868 }
Mike Stump11289f42009-09-09 15:08:12 +0000869
Anders Carlssonaaeef072010-01-24 05:50:09 +0000870 /// \brief Build a new inline asm statement.
871 ///
872 /// By default, performs semantic analysis to build the new statement.
873 /// Subclasses may override this routine to provide different behavior.
874 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
875 bool IsSimple,
876 bool IsVolatile,
877 unsigned NumOutputs,
878 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000879 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000880 MultiExprArg Constraints,
881 MultiExprArg Exprs,
882 ExprArg AsmString,
883 MultiExprArg Clobbers,
884 SourceLocation RParenLoc,
885 bool MSAsm) {
886 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
887 NumInputs, Names, move(Constraints),
888 move(Exprs), move(AsmString), move(Clobbers),
889 RParenLoc, MSAsm);
890 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000891
892 /// \brief Build a new Objective-C @try statement.
893 ///
894 /// By default, performs semantic analysis to build the new statement.
895 /// Subclasses may override this routine to provide different behavior.
896 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
897 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000898 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000899 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000900 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000901 move(Finally));
902 }
903
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000904 /// \brief Rebuild an Objective-C exception declaration.
905 ///
906 /// By default, performs semantic analysis to build the new declaration.
907 /// Subclasses may override this routine to provide different behavior.
908 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
909 TypeSourceInfo *TInfo, QualType T) {
910 return getSema().BuildObjCExceptionDecl(TInfo, T,
911 ExceptionDecl->getIdentifier(),
912 ExceptionDecl->getLocation());
913 }
914
915 /// \brief Build a new Objective-C @catch statement.
916 ///
917 /// By default, performs semantic analysis to build the new statement.
918 /// Subclasses may override this routine to provide different behavior.
919 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
920 SourceLocation RParenLoc,
921 VarDecl *Var,
922 StmtArg Body) {
923 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
924 Sema::DeclPtrTy::make(Var),
925 move(Body));
926 }
927
Douglas Gregor306de2f2010-04-22 23:59:56 +0000928 /// \brief Build a new Objective-C @finally statement.
929 ///
930 /// By default, performs semantic analysis to build the new statement.
931 /// Subclasses may override this routine to provide different behavior.
932 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
933 StmtArg Body) {
934 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
935 }
Anders Carlssonaaeef072010-01-24 05:50:09 +0000936
Douglas Gregor6148de72010-04-22 22:01:21 +0000937 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
941 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
942 ExprArg Operand) {
943 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
944 }
945
Douglas Gregor6148de72010-04-22 22:01:21 +0000946 /// \brief Build a new Objective-C @synchronized statement.
947 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
951 ExprArg Object,
952 StmtArg Body) {
953 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
954 move(Body));
955 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000956
957 /// \brief Build a new Objective-C fast enumeration statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
961 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
962 SourceLocation LParenLoc,
963 StmtArg Element,
964 ExprArg Collection,
965 SourceLocation RParenLoc,
966 StmtArg Body) {
967 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
968 move(Element),
969 move(Collection),
970 RParenLoc,
971 move(Body));
972 }
Douglas Gregor6148de72010-04-22 22:01:21 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new C++ exception declaration.
975 ///
976 /// By default, performs semantic analysis to build the new decaration.
977 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000978 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000979 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 IdentifierInfo *Name,
981 SourceLocation Loc,
982 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000983 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 TypeRange);
985 }
986
987 /// \brief Build a new C++ catch statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
992 VarDecl *ExceptionDecl,
993 StmtArg Handler) {
994 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000995 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 Handler.takeAs<Stmt>()));
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /// \brief Build a new C++ try statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
1003 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1004 StmtArg TryBlock,
1005 MultiStmtArg Handlers) {
1006 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 /// \brief Build a new expression that references a declaration.
1010 ///
1011 /// By default, performs semantic analysis to build the new expression.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001013 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1014 LookupResult &R,
1015 bool RequiresADL) {
1016 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1017 }
1018
1019
1020 /// \brief Build a new expression that references a declaration.
1021 ///
1022 /// By default, performs semantic analysis to build the new expression.
1023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001024 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1025 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001026 ValueDecl *VD, SourceLocation Loc,
1027 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001028 CXXScopeSpec SS;
1029 SS.setScopeRep(Qualifier);
1030 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001031
1032 // FIXME: loses template args.
1033
1034 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1042 SourceLocation RParen) {
1043 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1044 }
1045
Douglas Gregorad8a3362009-09-04 17:36:40 +00001046 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001047 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// By default, performs semantic analysis to build the new expression.
1049 /// Subclasses may override this routine to provide different behavior.
1050 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1051 SourceLocation OperatorLoc,
1052 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001053 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001054 SourceRange QualifierRange,
1055 TypeSourceInfo *ScopeType,
1056 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001057 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001058 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001061 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1065 UnaryOperator::Opcode Opc,
1066 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001067 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001071 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 /// By default, performs semantic analysis to build the new expression.
1073 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001074 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001075 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001077 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 }
1079
Mike Stump11289f42009-09-09 15:08:12 +00001080 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001081 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001082 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 /// By default, performs semantic analysis to build the new expression.
1084 /// Subclasses may override this routine to provide different behavior.
1085 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1086 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001087 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1089 OpLoc, isSizeOf, R);
1090 if (Result.isInvalid())
1091 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 SubExpr.release();
1094 return move(Result);
1095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// By default, performs semantic analysis to build the new expression.
1100 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001101 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 SourceLocation LBracketLoc,
1103 ExprArg RHS,
1104 SourceLocation RBracketLoc) {
1105 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001106 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 RBracketLoc);
1108 }
1109
1110 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
1114 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1115 MultiExprArg Args,
1116 SourceLocation *CommaLocs,
1117 SourceLocation RParenLoc) {
1118 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1119 move(Args), CommaLocs, RParenLoc);
1120 }
1121
1122 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001123 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// By default, performs semantic analysis to build the new expression.
1125 /// Subclasses may override this routine to provide different behavior.
1126 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001127 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001128 NestedNameSpecifier *Qualifier,
1129 SourceRange QualifierRange,
1130 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001131 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001132 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001133 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001134 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001135 if (!Member->getDeclName()) {
1136 // We have a reference to an unnamed field.
1137 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001139 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001140 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1141 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001142 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001143
Mike Stump11289f42009-09-09 15:08:12 +00001144 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001145 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001146 Member, MemberLoc,
1147 cast<FieldDecl>(Member)->getType());
1148 return getSema().Owned(ME);
1149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001151 CXXScopeSpec SS;
1152 if (Qualifier) {
1153 SS.setRange(QualifierRange);
1154 SS.setScopeRep(Qualifier);
1155 }
1156
John McCall2d74de92009-12-01 22:10:20 +00001157 QualType BaseType = ((Expr*) Base.get())->getType();
1158
John McCall16df1e52010-03-30 21:47:33 +00001159 // FIXME: this involves duplicating earlier analysis in a lot of
1160 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001161 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1162 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001163 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001164 R.resolveKind();
1165
John McCall2d74de92009-12-01 22:10:20 +00001166 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1167 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001168 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001169 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregora16548e2009-08-11 05:31:07 +00001172 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001173 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001174 /// By default, performs semantic analysis to build the new expression.
1175 /// Subclasses may override this routine to provide different behavior.
1176 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1177 BinaryOperator::Opcode Opc,
1178 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001179 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1180 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
1182
1183 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
1187 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1188 SourceLocation QuestionLoc,
1189 ExprArg LHS,
1190 SourceLocation ColonLoc,
1191 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001192 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 move(LHS), move(RHS));
1194 }
1195
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001200 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1201 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 SourceLocation RParenLoc,
1203 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001204 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1205 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 }
Mike Stump11289f42009-09-09 15:08:12 +00001207
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001209 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// By default, performs semantic analysis to build the new expression.
1211 /// Subclasses may override this routine to provide different behavior.
1212 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001213 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 SourceLocation RParenLoc,
1215 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001216 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1217 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001224 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 SourceLocation OpLoc,
1226 SourceLocation AccessorLoc,
1227 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001228
John McCall10eae182009-11-30 22:42:35 +00001229 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001230 QualType BaseType = ((Expr*) Base.get())->getType();
1231 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001232 OpLoc, /*IsArrow*/ false,
1233 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001234 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001235 AccessorLoc,
1236 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 }
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001240 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
1243 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1244 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001245 SourceLocation RBraceLoc,
1246 QualType ResultTy) {
1247 OwningExprResult Result
1248 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1249 if (Result.isInvalid() || ResultTy->isDependentType())
1250 return move(Result);
1251
1252 // Patch in the result type we were given, which may have been computed
1253 // when the initial InitListExpr was built.
1254 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1255 ILE->setType(ResultTy);
1256 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1264 MultiExprArg ArrayExprs,
1265 SourceLocation EqualOrColonLoc,
1266 bool GNUSyntax,
1267 ExprArg Init) {
1268 OwningExprResult Result
1269 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1270 move(Init));
1271 if (Result.isInvalid())
1272 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001273
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 ArrayExprs.release();
1275 return move(Result);
1276 }
Mike Stump11289f42009-09-09 15:08:12 +00001277
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001279 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// By default, builds the implicit value initialization without performing
1281 /// any semantic analysis. Subclasses may override this routine to provide
1282 /// different behavior.
1283 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1284 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
1291 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1292 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001293 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 RParenLoc);
1295 }
1296
1297 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001298 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
1301 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1302 MultiExprArg SubExprs,
1303 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001304 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1305 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
Mike Stump11289f42009-09-09 15:08:12 +00001307
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
1310 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// rather than attempting to map the label statement itself.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1314 SourceLocation LabelLoc,
1315 LabelStmt *Label) {
1316 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1324 StmtArg SubStmt,
1325 SourceLocation RParenLoc) {
1326 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1327 }
Mike Stump11289f42009-09-09 15:08:12 +00001328
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// \brief Build a new __builtin_types_compatible_p expression.
1330 ///
1331 /// By default, performs semantic analysis to build the new expression.
1332 /// Subclasses may override this routine to provide different behavior.
1333 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1334 QualType T1, QualType T2,
1335 SourceLocation RParenLoc) {
1336 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1337 T1.getAsOpaquePtr(),
1338 T2.getAsOpaquePtr(),
1339 RParenLoc);
1340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new __builtin_choose_expr expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
1346 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1347 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1348 SourceLocation RParenLoc) {
1349 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1350 move(Cond), move(LHS), move(RHS),
1351 RParenLoc);
1352 }
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new overloaded operator call expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// The semantic analysis provides the behavior of template instantiation,
1358 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001359 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 /// argument-dependent lookup, etc. Subclasses may override this routine to
1361 /// provide different behavior.
1362 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1363 SourceLocation OpLoc,
1364 ExprArg Callee,
1365 ExprArg First,
1366 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001367
1368 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// reinterpret_cast.
1370 ///
1371 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001372 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// Subclasses may override this routine to provide different behavior.
1374 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1375 Stmt::StmtClass Class,
1376 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001377 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 SourceLocation RAngleLoc,
1379 SourceLocation LParenLoc,
1380 ExprArg SubExpr,
1381 SourceLocation RParenLoc) {
1382 switch (Class) {
1383 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001384 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001385 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 move(SubExpr), RParenLoc);
1387
1388 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001389 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001390 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001392
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001394 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001395 RAngleLoc, LParenLoc,
1396 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 default:
1405 assert(false && "Invalid C++ named cast");
1406 break;
1407 }
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 return getSema().ExprError();
1410 }
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// \brief Build a new C++ static_cast expression.
1413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
1416 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1417 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001418 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 SourceLocation RAngleLoc,
1420 SourceLocation LParenLoc,
1421 ExprArg SubExpr,
1422 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001423 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1424 TInfo, move(SubExpr),
1425 SourceRange(LAngleLoc, RAngleLoc),
1426 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 }
1428
1429 /// \brief Build a new C++ dynamic_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1434 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
1438 ExprArg SubExpr,
1439 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1441 TInfo, move(SubExpr),
1442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ reinterpret_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1451 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
1455 ExprArg SubExpr,
1456 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1458 TInfo, move(SubExpr),
1459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ const_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1468 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
1472 ExprArg SubExpr,
1473 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1475 TInfo, move(SubExpr),
1476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
Mike Stump11289f42009-09-09 15:08:12 +00001479
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// \brief Build a new C++ functional-style cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
1484 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001485 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 SourceLocation LParenLoc,
1487 ExprArg SubExpr,
1488 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001489 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001491 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001493 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001494 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 RParenLoc);
1496 }
Mike Stump11289f42009-09-09 15:08:12 +00001497
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// \brief Build a new C++ typeid(type) expression.
1499 ///
1500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
1502 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1503 SourceLocation LParenLoc,
1504 QualType T,
1505 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001506 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 T.getAsOpaquePtr(), RParenLoc);
1508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new C++ typeid(expr) expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
1514 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1515 SourceLocation LParenLoc,
1516 ExprArg Operand,
1517 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001518 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1520 RParenLoc);
1521 if (Result.isInvalid())
1522 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1525 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001526 }
1527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new C++ "this" expression.
1529 ///
1530 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001531 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001533 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001534 QualType ThisType,
1535 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001537 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1538 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 }
1540
1541 /// \brief Build a new C++ throw expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
1545 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1546 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1547 }
1548
1549 /// \brief Build a new C++ default-argument expression.
1550 ///
1551 /// By default, builds a new default-argument expression, which does not
1552 /// require any semantic analysis. Subclasses may override this routine to
1553 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001554 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1555 ParmVarDecl *Param) {
1556 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1557 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
1559
1560 /// \brief Build a new C++ zero-initialization expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001564 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 SourceLocation LParenLoc,
1566 QualType T,
1567 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001568 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1569 T.getAsOpaquePtr(), LParenLoc,
1570 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 0, RParenLoc);
1572 }
Mike Stump11289f42009-09-09 15:08:12 +00001573
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// \brief Build a new C++ "new" expression.
1575 ///
1576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001578 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 bool UseGlobal,
1580 SourceLocation PlacementLParen,
1581 MultiExprArg PlacementArgs,
1582 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001583 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 QualType AllocType,
1585 SourceLocation TypeLoc,
1586 SourceRange TypeRange,
1587 ExprArg ArraySize,
1588 SourceLocation ConstructorLParen,
1589 MultiExprArg ConstructorArgs,
1590 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001591 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 PlacementLParen,
1593 move(PlacementArgs),
1594 PlacementRParen,
1595 ParenTypeId,
1596 AllocType,
1597 TypeLoc,
1598 TypeRange,
1599 move(ArraySize),
1600 ConstructorLParen,
1601 move(ConstructorArgs),
1602 ConstructorRParen);
1603 }
Mike Stump11289f42009-09-09 15:08:12 +00001604
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// \brief Build a new C++ "delete" expression.
1606 ///
1607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
1609 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1610 bool IsGlobalDelete,
1611 bool IsArrayForm,
1612 ExprArg Operand) {
1613 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1614 move(Operand));
1615 }
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 /// \brief Build a new unary type trait expression.
1618 ///
1619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
1621 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1622 SourceLocation StartLoc,
1623 SourceLocation LParenLoc,
1624 QualType T,
1625 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001626 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 T.getAsOpaquePtr(), RParenLoc);
1628 }
1629
Mike Stump11289f42009-09-09 15:08:12 +00001630 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 /// expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001635 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 SourceRange QualifierRange,
1637 DeclarationName Name,
1638 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001639 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 CXXScopeSpec SS;
1641 SS.setRange(QualifierRange);
1642 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001643
1644 if (TemplateArgs)
1645 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1646 *TemplateArgs);
1647
1648 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
1650
1651 /// \brief Build a new template-id expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001655 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1656 LookupResult &R,
1657 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001658 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001659 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 }
1661
1662 /// \brief Build a new object-construction expression.
1663 ///
1664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
1666 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001667 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 CXXConstructorDecl *Constructor,
1669 bool IsElidable,
1670 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001671 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1672 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1673 ConvertedArgs))
1674 return getSema().ExprError();
1675
1676 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1677 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new object-construction expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1685 QualType T,
1686 SourceLocation LParenLoc,
1687 MultiExprArg Args,
1688 SourceLocation *Commas,
1689 SourceLocation RParenLoc) {
1690 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1691 T.getAsOpaquePtr(),
1692 LParenLoc,
1693 move(Args),
1694 Commas,
1695 RParenLoc);
1696 }
1697
1698 /// \brief Build a new object-construction expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
1702 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1703 QualType T,
1704 SourceLocation LParenLoc,
1705 MultiExprArg Args,
1706 SourceLocation *Commas,
1707 SourceLocation RParenLoc) {
1708 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1709 /*FIXME*/LParenLoc),
1710 T.getAsOpaquePtr(),
1711 LParenLoc,
1712 move(Args),
1713 Commas,
1714 RParenLoc);
1715 }
Mike Stump11289f42009-09-09 15:08:12 +00001716
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// \brief Build a new member reference expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001721 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001722 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 bool IsArrow,
1724 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001725 NestedNameSpecifier *Qualifier,
1726 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001727 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001729 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001730 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001732 SS.setRange(QualifierRange);
1733 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001734
John McCall2d74de92009-12-01 22:10:20 +00001735 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1736 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001737 SS, FirstQualifierInScope,
1738 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
1740
John McCall10eae182009-11-30 22:42:35 +00001741 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001745 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001746 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001747 SourceLocation OperatorLoc,
1748 bool IsArrow,
1749 NestedNameSpecifier *Qualifier,
1750 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001751 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001752 LookupResult &R,
1753 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001754 CXXScopeSpec SS;
1755 SS.setRange(QualifierRange);
1756 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001757
John McCall2d74de92009-12-01 22:10:20 +00001758 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1759 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001760 SS, FirstQualifierInScope,
1761 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001762 }
Mike Stump11289f42009-09-09 15:08:12 +00001763
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// \brief Build a new Objective-C @encode expression.
1765 ///
1766 /// By default, performs semantic analysis to build the new expression.
1767 /// Subclasses may override this routine to provide different behavior.
1768 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001769 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001771 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001773 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001774
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001775 /// \brief Build a new Objective-C class message.
1776 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1777 Selector Sel,
1778 ObjCMethodDecl *Method,
1779 SourceLocation LBracLoc,
1780 MultiExprArg Args,
1781 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001782 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1783 ReceiverTypeInfo->getType(),
1784 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001785 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001786 move(Args));
1787 }
1788
1789 /// \brief Build a new Objective-C instance message.
1790 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1791 Selector Sel,
1792 ObjCMethodDecl *Method,
1793 SourceLocation LBracLoc,
1794 MultiExprArg Args,
1795 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001796 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1797 return SemaRef.BuildInstanceMessage(move(Receiver),
1798 ReceiverType,
1799 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001800 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001801 move(Args));
1802 }
1803
Douglas Gregord51d90d2010-04-26 20:11:03 +00001804 /// \brief Build a new Objective-C ivar reference expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
1808 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1809 SourceLocation IvarLoc,
1810 bool IsArrow, bool IsFreeIvar) {
1811 // FIXME: We lose track of the IsFreeIvar bit.
1812 CXXScopeSpec SS;
1813 Expr *Base = BaseArg.takeAs<Expr>();
1814 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1815 Sema::LookupMemberName);
1816 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1817 /*FIME:*/IvarLoc,
1818 SS, DeclPtrTy());
1819 if (Result.isInvalid())
1820 return getSema().ExprError();
1821
1822 if (Result.get())
1823 return move(Result);
1824
1825 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1826 Base->getType(),
1827 /*FIXME:*/IvarLoc, IsArrow, SS,
1828 /*FirstQualifierInScope=*/0,
1829 R,
1830 /*TemplateArgs=*/0);
1831 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001832
1833 /// \brief Build a new Objective-C property reference expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
1837 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
1838 ObjCPropertyDecl *Property,
1839 SourceLocation PropertyLoc) {
1840 CXXScopeSpec SS;
1841 Expr *Base = BaseArg.takeAs<Expr>();
1842 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1843 Sema::LookupMemberName);
1844 bool IsArrow = false;
1845 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1846 /*FIME:*/PropertyLoc,
1847 SS, DeclPtrTy());
1848 if (Result.isInvalid())
1849 return getSema().ExprError();
1850
1851 if (Result.get())
1852 return move(Result);
1853
1854 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1855 Base->getType(),
1856 /*FIXME:*/PropertyLoc, IsArrow,
1857 SS,
1858 /*FirstQualifierInScope=*/0,
1859 R,
1860 /*TemplateArgs=*/0);
1861 }
1862
Douglas Gregord51d90d2010-04-26 20:11:03 +00001863 /// \brief Build a new Objective-C "isa" expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
1867 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1868 bool IsArrow) {
1869 CXXScopeSpec SS;
1870 Expr *Base = BaseArg.takeAs<Expr>();
1871 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1872 Sema::LookupMemberName);
1873 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1874 /*FIME:*/IsaLoc,
1875 SS, DeclPtrTy());
1876 if (Result.isInvalid())
1877 return getSema().ExprError();
1878
1879 if (Result.get())
1880 return move(Result);
1881
1882 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
1883 Base->getType(),
1884 /*FIXME:*/IsaLoc, IsArrow, SS,
1885 /*FirstQualifierInScope=*/0,
1886 R,
1887 /*TemplateArgs=*/0);
1888 }
1889
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// \brief Build a new shuffle vector expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
1894 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1895 MultiExprArg SubExprs,
1896 SourceLocation RParenLoc) {
1897 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001898 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1900 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1901 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1902 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001903
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 // Build a reference to the __builtin_shufflevector builtin
1905 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001906 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001908 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001910
1911 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 unsigned NumSubExprs = SubExprs.size();
1913 Expr **Subs = (Expr **)SubExprs.release();
1914 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1915 Subs, NumSubExprs,
1916 Builtin->getResultType(),
1917 RParenLoc);
1918 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001919
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 // Type-check the __builtin_shufflevector expression.
1921 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1922 if (Result.isInvalid())
1923 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001926 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001928};
Douglas Gregora16548e2009-08-11 05:31:07 +00001929
Douglas Gregorebe10102009-08-20 07:17:43 +00001930template<typename Derived>
1931Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1932 if (!S)
1933 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregorebe10102009-08-20 07:17:43 +00001935 switch (S->getStmtClass()) {
1936 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001937
Douglas Gregorebe10102009-08-20 07:17:43 +00001938 // Transform individual statement nodes
1939#define STMT(Node, Parent) \
1940 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1941#define EXPR(Node, Parent)
1942#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001943
Douglas Gregorebe10102009-08-20 07:17:43 +00001944 // Transform expressions by calling TransformExpr.
1945#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001946#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001947#define EXPR(Node, Parent) case Stmt::Node##Class:
1948#include "clang/AST/StmtNodes.def"
1949 {
1950 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1951 if (E.isInvalid())
1952 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001953
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001954 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956 }
1957
Douglas Gregorebe10102009-08-20 07:17:43 +00001958 return SemaRef.Owned(S->Retain());
1959}
Mike Stump11289f42009-09-09 15:08:12 +00001960
1961
Douglas Gregore922c772009-08-04 22:27:00 +00001962template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001963Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 if (!E)
1965 return SemaRef.Owned(E);
1966
1967 switch (E->getStmtClass()) {
1968 case Stmt::NoStmtClass: break;
1969#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001970#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001971#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001972 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001973#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001974 }
1975
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001977}
1978
1979template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001980NestedNameSpecifier *
1981TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001982 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001983 QualType ObjectType,
1984 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001985 if (!NNS)
1986 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregorebe10102009-08-20 07:17:43 +00001988 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001989 NestedNameSpecifier *Prefix = NNS->getPrefix();
1990 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001991 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001992 ObjectType,
1993 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001994 if (!Prefix)
1995 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001996
1997 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001998 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001999 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002000 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002001 }
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregor1135c352009-08-06 05:28:30 +00002003 switch (NNS->getKind()) {
2004 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002005 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002006 "Identifier nested-name-specifier with no prefix or object type");
2007 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2008 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002009 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002010
2011 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002012 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002013 ObjectType,
2014 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002015
Douglas Gregor1135c352009-08-06 05:28:30 +00002016 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002017 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002018 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002019 getDerived().TransformDecl(Range.getBegin(),
2020 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002021 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002022 Prefix == NNS->getPrefix() &&
2023 NS == NNS->getAsNamespace())
2024 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2027 }
Mike Stump11289f42009-09-09 15:08:12 +00002028
Douglas Gregor1135c352009-08-06 05:28:30 +00002029 case NestedNameSpecifier::Global:
2030 // There is no meaningful transformation that one could perform on the
2031 // global scope.
2032 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002033
Douglas Gregor1135c352009-08-06 05:28:30 +00002034 case NestedNameSpecifier::TypeSpecWithTemplate:
2035 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002036 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002037 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2038 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002039 if (T.isNull())
2040 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 if (!getDerived().AlwaysRebuild() &&
2043 Prefix == NNS->getPrefix() &&
2044 T == QualType(NNS->getAsType(), 0))
2045 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002046
2047 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2048 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002049 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002050 }
2051 }
Mike Stump11289f42009-09-09 15:08:12 +00002052
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002054 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002055}
2056
2057template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002058DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002059TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002060 SourceLocation Loc,
2061 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002062 if (!Name)
2063 return Name;
2064
2065 switch (Name.getNameKind()) {
2066 case DeclarationName::Identifier:
2067 case DeclarationName::ObjCZeroArgSelector:
2068 case DeclarationName::ObjCOneArgSelector:
2069 case DeclarationName::ObjCMultiArgSelector:
2070 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002071 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002072 case DeclarationName::CXXUsingDirective:
2073 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002074
Douglas Gregorf816bd72009-09-03 22:13:48 +00002075 case DeclarationName::CXXConstructorName:
2076 case DeclarationName::CXXDestructorName:
2077 case DeclarationName::CXXConversionFunctionName: {
2078 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00002079 QualType T = getDerived().TransformType(Name.getCXXNameType(),
2080 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002081 if (T.isNull())
2082 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002083
Douglas Gregorf816bd72009-09-03 22:13:48 +00002084 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002085 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002086 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002087 }
Mike Stump11289f42009-09-09 15:08:12 +00002088 }
2089
Douglas Gregorf816bd72009-09-03 22:13:48 +00002090 return DeclarationName();
2091}
2092
2093template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002094TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002095TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2096 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002097 SourceLocation Loc = getDerived().getBaseLocation();
2098
Douglas Gregor71dc5092009-08-06 06:41:21 +00002099 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002100 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002101 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002102 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2103 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002104 if (!NNS)
2105 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002106
Douglas Gregor71dc5092009-08-06 06:41:21 +00002107 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002108 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002109 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002110 if (!TransTemplate)
2111 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002112
Douglas Gregor71dc5092009-08-06 06:41:21 +00002113 if (!getDerived().AlwaysRebuild() &&
2114 NNS == QTN->getQualifier() &&
2115 TransTemplate == Template)
2116 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregor71dc5092009-08-06 06:41:21 +00002118 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2119 TransTemplate);
2120 }
Mike Stump11289f42009-09-09 15:08:12 +00002121
John McCalle66edc12009-11-24 19:00:30 +00002122 // These should be getting filtered out before they make it into the AST.
2123 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002124 }
Mike Stump11289f42009-09-09 15:08:12 +00002125
Douglas Gregor71dc5092009-08-06 06:41:21 +00002126 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002127 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002128 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002129 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2130 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002131 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002132 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002133
Douglas Gregor71dc5092009-08-06 06:41:21 +00002134 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002135 NNS == DTN->getQualifier() &&
2136 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002137 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002138
Douglas Gregor71395fa2009-11-04 00:56:37 +00002139 if (DTN->isIdentifier())
2140 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2141 ObjectType);
2142
2143 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2144 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002145 }
Mike Stump11289f42009-09-09 15:08:12 +00002146
Douglas Gregor71dc5092009-08-06 06:41:21 +00002147 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002148 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002149 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002150 if (!TransTemplate)
2151 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregor71dc5092009-08-06 06:41:21 +00002153 if (!getDerived().AlwaysRebuild() &&
2154 TransTemplate == Template)
2155 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregor71dc5092009-08-06 06:41:21 +00002157 return TemplateName(TransTemplate);
2158 }
Mike Stump11289f42009-09-09 15:08:12 +00002159
John McCalle66edc12009-11-24 19:00:30 +00002160 // These should be getting filtered out before they reach the AST.
2161 assert(false && "overloaded function decl survived to here");
2162 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002163}
2164
2165template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002166void TreeTransform<Derived>::InventTemplateArgumentLoc(
2167 const TemplateArgument &Arg,
2168 TemplateArgumentLoc &Output) {
2169 SourceLocation Loc = getDerived().getBaseLocation();
2170 switch (Arg.getKind()) {
2171 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002172 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002173 break;
2174
2175 case TemplateArgument::Type:
2176 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002177 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002178
2179 break;
2180
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002181 case TemplateArgument::Template:
2182 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2183 break;
2184
John McCall0ad16662009-10-29 08:12:44 +00002185 case TemplateArgument::Expression:
2186 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2187 break;
2188
2189 case TemplateArgument::Declaration:
2190 case TemplateArgument::Integral:
2191 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002192 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002193 break;
2194 }
2195}
2196
2197template<typename Derived>
2198bool TreeTransform<Derived>::TransformTemplateArgument(
2199 const TemplateArgumentLoc &Input,
2200 TemplateArgumentLoc &Output) {
2201 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002202 switch (Arg.getKind()) {
2203 case TemplateArgument::Null:
2204 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002205 Output = Input;
2206 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregore922c772009-08-04 22:27:00 +00002208 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002209 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002210 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002211 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002212
2213 DI = getDerived().TransformType(DI);
2214 if (!DI) return true;
2215
2216 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2217 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002218 }
Mike Stump11289f42009-09-09 15:08:12 +00002219
Douglas Gregore922c772009-08-04 22:27:00 +00002220 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002221 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002222 DeclarationName Name;
2223 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2224 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002225 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002226 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002227 if (!D) return true;
2228
John McCall0d07eb32009-10-29 18:45:58 +00002229 Expr *SourceExpr = Input.getSourceDeclExpression();
2230 if (SourceExpr) {
2231 EnterExpressionEvaluationContext Unevaluated(getSema(),
2232 Action::Unevaluated);
2233 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2234 if (E.isInvalid())
2235 SourceExpr = NULL;
2236 else {
2237 SourceExpr = E.takeAs<Expr>();
2238 SourceExpr->Retain();
2239 }
2240 }
2241
2242 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002243 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002244 }
Mike Stump11289f42009-09-09 15:08:12 +00002245
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002246 case TemplateArgument::Template: {
2247 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2248 TemplateName Template
2249 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2250 if (Template.isNull())
2251 return true;
2252
2253 Output = TemplateArgumentLoc(TemplateArgument(Template),
2254 Input.getTemplateQualifierRange(),
2255 Input.getTemplateNameLoc());
2256 return false;
2257 }
2258
Douglas Gregore922c772009-08-04 22:27:00 +00002259 case TemplateArgument::Expression: {
2260 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002261 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002262 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002263
John McCall0ad16662009-10-29 08:12:44 +00002264 Expr *InputExpr = Input.getSourceExpression();
2265 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2266
2267 Sema::OwningExprResult E
2268 = getDerived().TransformExpr(InputExpr);
2269 if (E.isInvalid()) return true;
2270
2271 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002272 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002273 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2274 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002275 }
Mike Stump11289f42009-09-09 15:08:12 +00002276
Douglas Gregore922c772009-08-04 22:27:00 +00002277 case TemplateArgument::Pack: {
2278 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2279 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002280 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002281 AEnd = Arg.pack_end();
2282 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002283
John McCall0ad16662009-10-29 08:12:44 +00002284 // FIXME: preserve source information here when we start
2285 // caring about parameter packs.
2286
John McCall0d07eb32009-10-29 18:45:58 +00002287 TemplateArgumentLoc InputArg;
2288 TemplateArgumentLoc OutputArg;
2289 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2290 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002291 return true;
2292
John McCall0d07eb32009-10-29 18:45:58 +00002293 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002294 }
2295 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002296 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002297 true);
John McCall0d07eb32009-10-29 18:45:58 +00002298 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002299 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002300 }
2301 }
Mike Stump11289f42009-09-09 15:08:12 +00002302
Douglas Gregore922c772009-08-04 22:27:00 +00002303 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002304 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002305}
2306
Douglas Gregord6ff3322009-08-04 16:50:30 +00002307//===----------------------------------------------------------------------===//
2308// Type transformation
2309//===----------------------------------------------------------------------===//
2310
2311template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002312QualType TreeTransform<Derived>::TransformType(QualType T,
2313 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002314 if (getDerived().AlreadyTransformed(T))
2315 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002316
John McCall550e0c22009-10-21 00:40:46 +00002317 // Temporary workaround. All of these transformations should
2318 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002319 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002320 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002321
Douglas Gregorfe17d252010-02-16 19:09:40 +00002322 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002323
John McCall550e0c22009-10-21 00:40:46 +00002324 if (!NewDI)
2325 return QualType();
2326
2327 return NewDI->getType();
2328}
2329
2330template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002331TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2332 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002333 if (getDerived().AlreadyTransformed(DI->getType()))
2334 return DI;
2335
2336 TypeLocBuilder TLB;
2337
2338 TypeLoc TL = DI->getTypeLoc();
2339 TLB.reserve(TL.getFullDataSize());
2340
Douglas Gregorfe17d252010-02-16 19:09:40 +00002341 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002342 if (Result.isNull())
2343 return 0;
2344
John McCallbcd03502009-12-07 02:54:59 +00002345 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002346}
2347
2348template<typename Derived>
2349QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002350TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2351 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002352 switch (T.getTypeLocClass()) {
2353#define ABSTRACT_TYPELOC(CLASS, PARENT)
2354#define TYPELOC(CLASS, PARENT) \
2355 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002356 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2357 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002358#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002359 }
Mike Stump11289f42009-09-09 15:08:12 +00002360
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002361 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002362 return QualType();
2363}
2364
2365/// FIXME: By default, this routine adds type qualifiers only to types
2366/// that can have qualifiers, and silently suppresses those qualifiers
2367/// that are not permitted (e.g., qualifiers on reference or function
2368/// types). This is the right thing for template instantiation, but
2369/// probably not for other clients.
2370template<typename Derived>
2371QualType
2372TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002373 QualifiedTypeLoc T,
2374 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002375 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002376
Douglas Gregorfe17d252010-02-16 19:09:40 +00002377 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2378 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002379 if (Result.isNull())
2380 return QualType();
2381
2382 // Silently suppress qualifiers if the result type can't be qualified.
2383 // FIXME: this is the right thing for template instantiation, but
2384 // probably not for other clients.
2385 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002387
John McCall550e0c22009-10-21 00:40:46 +00002388 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2389
2390 TLB.push<QualifiedTypeLoc>(Result);
2391
2392 // No location information to preserve.
2393
2394 return Result;
2395}
2396
2397template <class TyLoc> static inline
2398QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2399 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2400 NewT.setNameLoc(T.getNameLoc());
2401 return T.getType();
2402}
2403
John McCall550e0c22009-10-21 00:40:46 +00002404template<typename Derived>
2405QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002406 BuiltinTypeLoc T,
2407 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002408 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2409 NewT.setBuiltinLoc(T.getBuiltinLoc());
2410 if (T.needsExtraLocalData())
2411 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2412 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002413}
Mike Stump11289f42009-09-09 15:08:12 +00002414
Douglas Gregord6ff3322009-08-04 16:50:30 +00002415template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002416QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002417 ComplexTypeLoc T,
2418 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002419 // FIXME: recurse?
2420 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002421}
Mike Stump11289f42009-09-09 15:08:12 +00002422
Douglas Gregord6ff3322009-08-04 16:50:30 +00002423template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002424QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002425 PointerTypeLoc TL,
2426 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002427 QualType PointeeType
2428 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2429 if (PointeeType.isNull())
2430 return QualType();
2431
2432 QualType Result = TL.getType();
2433 if (PointeeType->isObjCInterfaceType()) {
2434 // A dependent pointer type 'T *' has is being transformed such
2435 // that an Objective-C class type is being replaced for 'T'. The
2436 // resulting pointer type is an ObjCObjectPointerType, not a
2437 // PointerType.
2438 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2439 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2440 const_cast<ObjCProtocolDecl **>(
2441 IFace->qual_begin()),
2442 IFace->getNumProtocols());
2443
2444 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2445 NewT.setStarLoc(TL.getSigilLoc());
2446 NewT.setHasProtocolsAsWritten(false);
2447 NewT.setLAngleLoc(SourceLocation());
2448 NewT.setRAngleLoc(SourceLocation());
2449 NewT.setHasBaseTypeAsWritten(true);
2450 return Result;
2451 }
2452
2453 if (getDerived().AlwaysRebuild() ||
2454 PointeeType != TL.getPointeeLoc().getType()) {
2455 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2456 if (Result.isNull())
2457 return QualType();
2458 }
2459
2460 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2461 NewT.setSigilLoc(TL.getSigilLoc());
2462 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002463}
Mike Stump11289f42009-09-09 15:08:12 +00002464
2465template<typename Derived>
2466QualType
John McCall550e0c22009-10-21 00:40:46 +00002467TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002468 BlockPointerTypeLoc TL,
2469 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002470 QualType PointeeType
2471 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2472 if (PointeeType.isNull())
2473 return QualType();
2474
2475 QualType Result = TL.getType();
2476 if (getDerived().AlwaysRebuild() ||
2477 PointeeType != TL.getPointeeLoc().getType()) {
2478 Result = getDerived().RebuildBlockPointerType(PointeeType,
2479 TL.getSigilLoc());
2480 if (Result.isNull())
2481 return QualType();
2482 }
2483
Douglas Gregor049211a2010-04-22 16:50:51 +00002484 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002485 NewT.setSigilLoc(TL.getSigilLoc());
2486 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002487}
2488
John McCall70dd5f62009-10-30 00:06:24 +00002489/// Transforms a reference type. Note that somewhat paradoxically we
2490/// don't care whether the type itself is an l-value type or an r-value
2491/// type; we only care if the type was *written* as an l-value type
2492/// or an r-value type.
2493template<typename Derived>
2494QualType
2495TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002496 ReferenceTypeLoc TL,
2497 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002498 const ReferenceType *T = TL.getTypePtr();
2499
2500 // Note that this works with the pointee-as-written.
2501 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2502 if (PointeeType.isNull())
2503 return QualType();
2504
2505 QualType Result = TL.getType();
2506 if (getDerived().AlwaysRebuild() ||
2507 PointeeType != T->getPointeeTypeAsWritten()) {
2508 Result = getDerived().RebuildReferenceType(PointeeType,
2509 T->isSpelledAsLValue(),
2510 TL.getSigilLoc());
2511 if (Result.isNull())
2512 return QualType();
2513 }
2514
2515 // r-value references can be rebuilt as l-value references.
2516 ReferenceTypeLoc NewTL;
2517 if (isa<LValueReferenceType>(Result))
2518 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2519 else
2520 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2521 NewTL.setSigilLoc(TL.getSigilLoc());
2522
2523 return Result;
2524}
2525
Mike Stump11289f42009-09-09 15:08:12 +00002526template<typename Derived>
2527QualType
John McCall550e0c22009-10-21 00:40:46 +00002528TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002529 LValueReferenceTypeLoc TL,
2530 QualType ObjectType) {
2531 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002532}
2533
Mike Stump11289f42009-09-09 15:08:12 +00002534template<typename Derived>
2535QualType
John McCall550e0c22009-10-21 00:40:46 +00002536TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002537 RValueReferenceTypeLoc TL,
2538 QualType ObjectType) {
2539 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540}
Mike Stump11289f42009-09-09 15:08:12 +00002541
Douglas Gregord6ff3322009-08-04 16:50:30 +00002542template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002543QualType
John McCall550e0c22009-10-21 00:40:46 +00002544TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002545 MemberPointerTypeLoc TL,
2546 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002547 MemberPointerType *T = TL.getTypePtr();
2548
2549 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002550 if (PointeeType.isNull())
2551 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002552
John McCall550e0c22009-10-21 00:40:46 +00002553 // TODO: preserve source information for this.
2554 QualType ClassType
2555 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002556 if (ClassType.isNull())
2557 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002558
John McCall550e0c22009-10-21 00:40:46 +00002559 QualType Result = TL.getType();
2560 if (getDerived().AlwaysRebuild() ||
2561 PointeeType != T->getPointeeType() ||
2562 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002563 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2564 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002565 if (Result.isNull())
2566 return QualType();
2567 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002568
John McCall550e0c22009-10-21 00:40:46 +00002569 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2570 NewTL.setSigilLoc(TL.getSigilLoc());
2571
2572 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002573}
2574
Mike Stump11289f42009-09-09 15:08:12 +00002575template<typename Derived>
2576QualType
John McCall550e0c22009-10-21 00:40:46 +00002577TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002578 ConstantArrayTypeLoc TL,
2579 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002580 ConstantArrayType *T = TL.getTypePtr();
2581 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582 if (ElementType.isNull())
2583 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002584
John McCall550e0c22009-10-21 00:40:46 +00002585 QualType Result = TL.getType();
2586 if (getDerived().AlwaysRebuild() ||
2587 ElementType != T->getElementType()) {
2588 Result = getDerived().RebuildConstantArrayType(ElementType,
2589 T->getSizeModifier(),
2590 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002591 T->getIndexTypeCVRQualifiers(),
2592 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002593 if (Result.isNull())
2594 return QualType();
2595 }
2596
2597 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2598 NewTL.setLBracketLoc(TL.getLBracketLoc());
2599 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002600
John McCall550e0c22009-10-21 00:40:46 +00002601 Expr *Size = TL.getSizeExpr();
2602 if (Size) {
2603 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2604 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2605 }
2606 NewTL.setSizeExpr(Size);
2607
2608 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002609}
Mike Stump11289f42009-09-09 15:08:12 +00002610
Douglas Gregord6ff3322009-08-04 16:50:30 +00002611template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002612QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002613 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002614 IncompleteArrayTypeLoc TL,
2615 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002616 IncompleteArrayType *T = TL.getTypePtr();
2617 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002618 if (ElementType.isNull())
2619 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002620
John McCall550e0c22009-10-21 00:40:46 +00002621 QualType Result = TL.getType();
2622 if (getDerived().AlwaysRebuild() ||
2623 ElementType != T->getElementType()) {
2624 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002626 T->getIndexTypeCVRQualifiers(),
2627 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002628 if (Result.isNull())
2629 return QualType();
2630 }
2631
2632 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2633 NewTL.setLBracketLoc(TL.getLBracketLoc());
2634 NewTL.setRBracketLoc(TL.getRBracketLoc());
2635 NewTL.setSizeExpr(0);
2636
2637 return Result;
2638}
2639
2640template<typename Derived>
2641QualType
2642TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002643 VariableArrayTypeLoc TL,
2644 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002645 VariableArrayType *T = TL.getTypePtr();
2646 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2647 if (ElementType.isNull())
2648 return QualType();
2649
2650 // Array bounds are not potentially evaluated contexts
2651 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2652
2653 Sema::OwningExprResult SizeResult
2654 = getDerived().TransformExpr(T->getSizeExpr());
2655 if (SizeResult.isInvalid())
2656 return QualType();
2657
2658 Expr *Size = static_cast<Expr*>(SizeResult.get());
2659
2660 QualType Result = TL.getType();
2661 if (getDerived().AlwaysRebuild() ||
2662 ElementType != T->getElementType() ||
2663 Size != T->getSizeExpr()) {
2664 Result = getDerived().RebuildVariableArrayType(ElementType,
2665 T->getSizeModifier(),
2666 move(SizeResult),
2667 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002668 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002669 if (Result.isNull())
2670 return QualType();
2671 }
2672 else SizeResult.take();
2673
2674 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2675 NewTL.setLBracketLoc(TL.getLBracketLoc());
2676 NewTL.setRBracketLoc(TL.getRBracketLoc());
2677 NewTL.setSizeExpr(Size);
2678
2679 return Result;
2680}
2681
2682template<typename Derived>
2683QualType
2684TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002685 DependentSizedArrayTypeLoc TL,
2686 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002687 DependentSizedArrayType *T = TL.getTypePtr();
2688 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2689 if (ElementType.isNull())
2690 return QualType();
2691
2692 // Array bounds are not potentially evaluated contexts
2693 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2694
2695 Sema::OwningExprResult SizeResult
2696 = getDerived().TransformExpr(T->getSizeExpr());
2697 if (SizeResult.isInvalid())
2698 return QualType();
2699
2700 Expr *Size = static_cast<Expr*>(SizeResult.get());
2701
2702 QualType Result = TL.getType();
2703 if (getDerived().AlwaysRebuild() ||
2704 ElementType != T->getElementType() ||
2705 Size != T->getSizeExpr()) {
2706 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2707 T->getSizeModifier(),
2708 move(SizeResult),
2709 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002710 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002711 if (Result.isNull())
2712 return QualType();
2713 }
2714 else SizeResult.take();
2715
2716 // We might have any sort of array type now, but fortunately they
2717 // all have the same location layout.
2718 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2719 NewTL.setLBracketLoc(TL.getLBracketLoc());
2720 NewTL.setRBracketLoc(TL.getRBracketLoc());
2721 NewTL.setSizeExpr(Size);
2722
2723 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002724}
Mike Stump11289f42009-09-09 15:08:12 +00002725
2726template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002727QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002728 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002729 DependentSizedExtVectorTypeLoc TL,
2730 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002731 DependentSizedExtVectorType *T = TL.getTypePtr();
2732
2733 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734 QualType ElementType = getDerived().TransformType(T->getElementType());
2735 if (ElementType.isNull())
2736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002737
Douglas Gregore922c772009-08-04 22:27:00 +00002738 // Vector sizes are not potentially evaluated contexts
2739 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2740
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2742 if (Size.isInvalid())
2743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002744
John McCall550e0c22009-10-21 00:40:46 +00002745 QualType Result = TL.getType();
2746 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002747 ElementType != T->getElementType() ||
2748 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002749 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750 move(Size),
2751 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002752 if (Result.isNull())
2753 return QualType();
2754 }
2755 else Size.take();
2756
2757 // Result might be dependent or not.
2758 if (isa<DependentSizedExtVectorType>(Result)) {
2759 DependentSizedExtVectorTypeLoc NewTL
2760 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2761 NewTL.setNameLoc(TL.getNameLoc());
2762 } else {
2763 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2764 NewTL.setNameLoc(TL.getNameLoc());
2765 }
2766
2767 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768}
Mike Stump11289f42009-09-09 15:08:12 +00002769
2770template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002771QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002772 VectorTypeLoc TL,
2773 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002774 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775 QualType ElementType = getDerived().TransformType(T->getElementType());
2776 if (ElementType.isNull())
2777 return QualType();
2778
John McCall550e0c22009-10-21 00:40:46 +00002779 QualType Result = TL.getType();
2780 if (getDerived().AlwaysRebuild() ||
2781 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002782 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2783 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002784 if (Result.isNull())
2785 return QualType();
2786 }
2787
2788 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2789 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002790
John McCall550e0c22009-10-21 00:40:46 +00002791 return Result;
2792}
2793
2794template<typename Derived>
2795QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002796 ExtVectorTypeLoc TL,
2797 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002798 VectorType *T = TL.getTypePtr();
2799 QualType ElementType = getDerived().TransformType(T->getElementType());
2800 if (ElementType.isNull())
2801 return QualType();
2802
2803 QualType Result = TL.getType();
2804 if (getDerived().AlwaysRebuild() ||
2805 ElementType != T->getElementType()) {
2806 Result = getDerived().RebuildExtVectorType(ElementType,
2807 T->getNumElements(),
2808 /*FIXME*/ SourceLocation());
2809 if (Result.isNull())
2810 return QualType();
2811 }
2812
2813 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2814 NewTL.setNameLoc(TL.getNameLoc());
2815
2816 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002817}
Mike Stump11289f42009-09-09 15:08:12 +00002818
2819template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002820ParmVarDecl *
2821TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2822 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2823 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2824 if (!NewDI)
2825 return 0;
2826
2827 if (NewDI == OldDI)
2828 return OldParm;
2829 else
2830 return ParmVarDecl::Create(SemaRef.Context,
2831 OldParm->getDeclContext(),
2832 OldParm->getLocation(),
2833 OldParm->getIdentifier(),
2834 NewDI->getType(),
2835 NewDI,
2836 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002837 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002838 /* DefArg */ NULL);
2839}
2840
2841template<typename Derived>
2842bool TreeTransform<Derived>::
2843 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2844 llvm::SmallVectorImpl<QualType> &PTypes,
2845 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2846 FunctionProtoType *T = TL.getTypePtr();
2847
2848 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2849 ParmVarDecl *OldParm = TL.getArg(i);
2850
2851 QualType NewType;
2852 ParmVarDecl *NewParm;
2853
2854 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002855 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2856 if (!NewParm)
2857 return true;
2858 NewType = NewParm->getType();
2859
2860 // Deal with the possibility that we don't have a parameter
2861 // declaration for this parameter.
2862 } else {
2863 NewParm = 0;
2864
2865 QualType OldType = T->getArgType(i);
2866 NewType = getDerived().TransformType(OldType);
2867 if (NewType.isNull())
2868 return true;
2869 }
2870
2871 PTypes.push_back(NewType);
2872 PVars.push_back(NewParm);
2873 }
2874
2875 return false;
2876}
2877
2878template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002879QualType
John McCall550e0c22009-10-21 00:40:46 +00002880TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002881 FunctionProtoTypeLoc TL,
2882 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002883 FunctionProtoType *T = TL.getTypePtr();
2884 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002885 if (ResultType.isNull())
2886 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002887
John McCall550e0c22009-10-21 00:40:46 +00002888 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002889 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002890 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002891 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2892 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002893
John McCall550e0c22009-10-21 00:40:46 +00002894 QualType Result = TL.getType();
2895 if (getDerived().AlwaysRebuild() ||
2896 ResultType != T->getResultType() ||
2897 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2898 Result = getDerived().RebuildFunctionProtoType(ResultType,
2899 ParamTypes.data(),
2900 ParamTypes.size(),
2901 T->isVariadic(),
2902 T->getTypeQuals());
2903 if (Result.isNull())
2904 return QualType();
2905 }
Mike Stump11289f42009-09-09 15:08:12 +00002906
John McCall550e0c22009-10-21 00:40:46 +00002907 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2908 NewTL.setLParenLoc(TL.getLParenLoc());
2909 NewTL.setRParenLoc(TL.getRParenLoc());
2910 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2911 NewTL.setArg(i, ParamDecls[i]);
2912
2913 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002914}
Mike Stump11289f42009-09-09 15:08:12 +00002915
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916template<typename Derived>
2917QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002918 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002919 FunctionNoProtoTypeLoc TL,
2920 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002921 FunctionNoProtoType *T = TL.getTypePtr();
2922 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2923 if (ResultType.isNull())
2924 return QualType();
2925
2926 QualType Result = TL.getType();
2927 if (getDerived().AlwaysRebuild() ||
2928 ResultType != T->getResultType())
2929 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2930
2931 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2932 NewTL.setLParenLoc(TL.getLParenLoc());
2933 NewTL.setRParenLoc(TL.getRParenLoc());
2934
2935 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002936}
Mike Stump11289f42009-09-09 15:08:12 +00002937
John McCallb96ec562009-12-04 22:46:56 +00002938template<typename Derived> QualType
2939TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002940 UnresolvedUsingTypeLoc TL,
2941 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002942 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002943 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002944 if (!D)
2945 return QualType();
2946
2947 QualType Result = TL.getType();
2948 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2949 Result = getDerived().RebuildUnresolvedUsingType(D);
2950 if (Result.isNull())
2951 return QualType();
2952 }
2953
2954 // We might get an arbitrary type spec type back. We should at
2955 // least always get a type spec type, though.
2956 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2957 NewTL.setNameLoc(TL.getNameLoc());
2958
2959 return Result;
2960}
2961
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002963QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002964 TypedefTypeLoc TL,
2965 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002966 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002967 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002968 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2969 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970 if (!Typedef)
2971 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002972
John McCall550e0c22009-10-21 00:40:46 +00002973 QualType Result = TL.getType();
2974 if (getDerived().AlwaysRebuild() ||
2975 Typedef != T->getDecl()) {
2976 Result = getDerived().RebuildTypedefType(Typedef);
2977 if (Result.isNull())
2978 return QualType();
2979 }
Mike Stump11289f42009-09-09 15:08:12 +00002980
John McCall550e0c22009-10-21 00:40:46 +00002981 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2982 NewTL.setNameLoc(TL.getNameLoc());
2983
2984 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002985}
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002988QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002989 TypeOfExprTypeLoc TL,
2990 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002991 // typeof expressions are not potentially evaluated contexts
2992 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002993
John McCalle8595032010-01-13 20:03:27 +00002994 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995 if (E.isInvalid())
2996 return QualType();
2997
John McCall550e0c22009-10-21 00:40:46 +00002998 QualType Result = TL.getType();
2999 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003000 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003001 Result = getDerived().RebuildTypeOfExprType(move(E));
3002 if (Result.isNull())
3003 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003004 }
John McCall550e0c22009-10-21 00:40:46 +00003005 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003006
John McCall550e0c22009-10-21 00:40:46 +00003007 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003008 NewTL.setTypeofLoc(TL.getTypeofLoc());
3009 NewTL.setLParenLoc(TL.getLParenLoc());
3010 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003011
3012 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013}
Mike Stump11289f42009-09-09 15:08:12 +00003014
3015template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003016QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003017 TypeOfTypeLoc TL,
3018 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003019 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3020 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3021 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003023
John McCall550e0c22009-10-21 00:40:46 +00003024 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003025 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3026 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003027 if (Result.isNull())
3028 return QualType();
3029 }
Mike Stump11289f42009-09-09 15:08:12 +00003030
John McCall550e0c22009-10-21 00:40:46 +00003031 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003032 NewTL.setTypeofLoc(TL.getTypeofLoc());
3033 NewTL.setLParenLoc(TL.getLParenLoc());
3034 NewTL.setRParenLoc(TL.getRParenLoc());
3035 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003042 DecltypeTypeLoc TL,
3043 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003044 DecltypeType *T = TL.getTypePtr();
3045
Douglas Gregore922c772009-08-04 22:27:00 +00003046 // decltype expressions are not potentially evaluated contexts
3047 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003048
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3050 if (E.isInvalid())
3051 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003052
John McCall550e0c22009-10-21 00:40:46 +00003053 QualType Result = TL.getType();
3054 if (getDerived().AlwaysRebuild() ||
3055 E.get() != T->getUnderlyingExpr()) {
3056 Result = getDerived().RebuildDecltypeType(move(E));
3057 if (Result.isNull())
3058 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003059 }
John McCall550e0c22009-10-21 00:40:46 +00003060 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003061
John McCall550e0c22009-10-21 00:40:46 +00003062 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3063 NewTL.setNameLoc(TL.getNameLoc());
3064
3065 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003066}
3067
3068template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003069QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003070 RecordTypeLoc TL,
3071 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003072 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003074 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3075 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 if (!Record)
3077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall550e0c22009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
3080 if (getDerived().AlwaysRebuild() ||
3081 Record != T->getDecl()) {
3082 Result = getDerived().RebuildRecordType(Record);
3083 if (Result.isNull())
3084 return QualType();
3085 }
Mike Stump11289f42009-09-09 15:08:12 +00003086
John McCall550e0c22009-10-21 00:40:46 +00003087 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3088 NewTL.setNameLoc(TL.getNameLoc());
3089
3090 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091}
Mike Stump11289f42009-09-09 15:08:12 +00003092
3093template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003094QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003095 EnumTypeLoc TL,
3096 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003097 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003098 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003099 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3100 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 if (!Enum)
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 Enum != T->getDecl()) {
3107 Result = getDerived().RebuildEnumType(Enum);
3108 if (Result.isNull())
3109 return QualType();
3110 }
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3113 NewTL.setNameLoc(TL.getNameLoc());
3114
3115 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003116}
John McCallfcc33b02009-09-05 00:15:47 +00003117
3118template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003119QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003120 ElaboratedTypeLoc TL,
3121 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003122 ElaboratedType *T = TL.getTypePtr();
3123
3124 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003125 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3126 if (Underlying.isNull())
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 Underlying != T->getUnderlyingType()) {
3132 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3133 if (Result.isNull())
3134 return QualType();
3135 }
Mike Stump11289f42009-09-09 15:08:12 +00003136
John McCall550e0c22009-10-21 00:40:46 +00003137 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3138 NewTL.setNameLoc(TL.getNameLoc());
3139
3140 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003141}
Mike Stump11289f42009-09-09 15:08:12 +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}
3201
3202template<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
3247TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003248 QualifiedNameTypeLoc TL,
3249 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003250 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251 NestedNameSpecifier *NNS
3252 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003253 SourceRange(),
3254 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255 if (!NNS)
3256 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003257
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258 QualType Named = getDerived().TransformType(T->getNamedType());
3259 if (Named.isNull())
3260 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003261
John McCall550e0c22009-10-21 00:40:46 +00003262 QualType Result = TL.getType();
3263 if (getDerived().AlwaysRebuild() ||
3264 NNS != T->getQualifier() ||
3265 Named != T->getNamedType()) {
3266 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3267 if (Result.isNull())
3268 return QualType();
3269 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003270
John McCall550e0c22009-10-21 00:40:46 +00003271 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3272 NewTL.setNameLoc(TL.getNameLoc());
3273
3274 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003275}
Mike Stump11289f42009-09-09 15:08:12 +00003276
3277template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003278QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3279 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003280 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003281 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003282
3283 /* FIXME: preserve source information better than this */
3284 SourceRange SR(TL.getNameLoc());
3285
Douglas Gregord6ff3322009-08-04 16:50:30 +00003286 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003287 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003288 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003289 if (!NNS)
3290 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003291
John McCall550e0c22009-10-21 00:40:46 +00003292 QualType Result;
3293
Douglas Gregord6ff3322009-08-04 16:50:30 +00003294 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003295 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296 = getDerived().TransformType(QualType(TemplateId, 0));
3297 if (NewTemplateId.isNull())
3298 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003299
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300 if (!getDerived().AlwaysRebuild() &&
3301 NNS == T->getQualifier() &&
3302 NewTemplateId == QualType(TemplateId, 0))
3303 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003304
Douglas Gregor02085352010-03-31 20:19:30 +00003305 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3306 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003307 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003308 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3309 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310 }
John McCall550e0c22009-10-21 00:40:46 +00003311 if (Result.isNull())
3312 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003314 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003315 NewTL.setNameLoc(TL.getNameLoc());
3316
3317 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003318}
Mike Stump11289f42009-09-09 15:08:12 +00003319
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003321QualType
3322TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003323 ObjCInterfaceTypeLoc TL,
3324 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003325 // ObjCInterfaceType is never dependent.
3326 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327}
Mike Stump11289f42009-09-09 15:08:12 +00003328
3329template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003330QualType
3331TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003332 ObjCObjectPointerTypeLoc TL,
3333 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003334 // ObjCObjectPointerType is never dependent.
3335 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003336}
3337
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003339// Statement transformation
3340//===----------------------------------------------------------------------===//
3341template<typename Derived>
3342Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003343TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3344 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003345}
3346
3347template<typename Derived>
3348Sema::OwningStmtResult
3349TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3350 return getDerived().TransformCompoundStmt(S, false);
3351}
3352
3353template<typename Derived>
3354Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003355TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003356 bool IsStmtExpr) {
3357 bool SubStmtChanged = false;
3358 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3359 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3360 B != BEnd; ++B) {
3361 OwningStmtResult Result = getDerived().TransformStmt(*B);
3362 if (Result.isInvalid())
3363 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003364
Douglas Gregorebe10102009-08-20 07:17:43 +00003365 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3366 Statements.push_back(Result.takeAs<Stmt>());
3367 }
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 if (!getDerived().AlwaysRebuild() &&
3370 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003371 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003372
3373 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3374 move_arg(Statements),
3375 S->getRBracLoc(),
3376 IsStmtExpr);
3377}
Mike Stump11289f42009-09-09 15:08:12 +00003378
Douglas Gregorebe10102009-08-20 07:17:43 +00003379template<typename Derived>
3380Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003381TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003382 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3383 {
3384 // The case value expressions are not potentially evaluated.
3385 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003386
Eli Friedman06577382009-11-19 03:14:00 +00003387 // Transform the left-hand case value.
3388 LHS = getDerived().TransformExpr(S->getLHS());
3389 if (LHS.isInvalid())
3390 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003391
Eli Friedman06577382009-11-19 03:14:00 +00003392 // Transform the right-hand case value (for the GNU case-range extension).
3393 RHS = getDerived().TransformExpr(S->getRHS());
3394 if (RHS.isInvalid())
3395 return SemaRef.StmtError();
3396 }
Mike Stump11289f42009-09-09 15:08:12 +00003397
Douglas Gregorebe10102009-08-20 07:17:43 +00003398 // Build the case statement.
3399 // Case statements are always rebuilt so that they will attached to their
3400 // transformed switch statement.
3401 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3402 move(LHS),
3403 S->getEllipsisLoc(),
3404 move(RHS),
3405 S->getColonLoc());
3406 if (Case.isInvalid())
3407 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003408
Douglas Gregorebe10102009-08-20 07:17:43 +00003409 // Transform the statement following the case
3410 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3411 if (SubStmt.isInvalid())
3412 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003413
Douglas Gregorebe10102009-08-20 07:17:43 +00003414 // Attach the body to the case statement
3415 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3416}
3417
3418template<typename Derived>
3419Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003420TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003421 // Transform the statement following the default case
3422 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3423 if (SubStmt.isInvalid())
3424 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003425
Douglas Gregorebe10102009-08-20 07:17:43 +00003426 // Default statements are always rebuilt
3427 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3428 move(SubStmt));
3429}
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregorebe10102009-08-20 07:17:43 +00003431template<typename Derived>
3432Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003433TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3435 if (SubStmt.isInvalid())
3436 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003437
Douglas Gregorebe10102009-08-20 07:17:43 +00003438 // FIXME: Pass the real colon location in.
3439 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3440 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3441 move(SubStmt));
3442}
Mike Stump11289f42009-09-09 15:08:12 +00003443
Douglas Gregorebe10102009-08-20 07:17:43 +00003444template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003445Sema::OwningStmtResult
3446TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003447 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003448 OwningExprResult Cond(SemaRef);
3449 VarDecl *ConditionVar = 0;
3450 if (S->getConditionVariable()) {
3451 ConditionVar
3452 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003453 getDerived().TransformDefinition(
3454 S->getConditionVariable()->getLocation(),
3455 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003456 if (!ConditionVar)
3457 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003458 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003459 Cond = getDerived().TransformExpr(S->getCond());
3460
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003461 if (Cond.isInvalid())
3462 return SemaRef.StmtError();
3463 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003464
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003465 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 // Transform the "then" branch.
3468 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3469 if (Then.isInvalid())
3470 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003471
Douglas Gregorebe10102009-08-20 07:17:43 +00003472 // Transform the "else" branch.
3473 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3474 if (Else.isInvalid())
3475 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003476
Douglas Gregorebe10102009-08-20 07:17:43 +00003477 if (!getDerived().AlwaysRebuild() &&
3478 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003479 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003480 Then.get() == S->getThen() &&
3481 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003482 return SemaRef.Owned(S->Retain());
3483
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003484 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3485 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003486 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003487}
3488
3489template<typename Derived>
3490Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003491TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003492 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003493 OwningExprResult Cond(SemaRef);
3494 VarDecl *ConditionVar = 0;
3495 if (S->getConditionVariable()) {
3496 ConditionVar
3497 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003498 getDerived().TransformDefinition(
3499 S->getConditionVariable()->getLocation(),
3500 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003501 if (!ConditionVar)
3502 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003503 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003504 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003505
3506 if (Cond.isInvalid())
3507 return SemaRef.StmtError();
3508 }
Mike Stump11289f42009-09-09 15:08:12 +00003509
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003510 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003511
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003513 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3514 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003515 if (Switch.isInvalid())
3516 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003517
Douglas Gregorebe10102009-08-20 07:17:43 +00003518 // Transform the body of the switch statement.
3519 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3520 if (Body.isInvalid())
3521 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 // Complete the switch statement.
3524 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3525 move(Body));
3526}
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregorebe10102009-08-20 07:17:43 +00003528template<typename Derived>
3529Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003530TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003532 OwningExprResult Cond(SemaRef);
3533 VarDecl *ConditionVar = 0;
3534 if (S->getConditionVariable()) {
3535 ConditionVar
3536 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003537 getDerived().TransformDefinition(
3538 S->getConditionVariable()->getLocation(),
3539 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003540 if (!ConditionVar)
3541 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003542 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003543 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003544
3545 if (Cond.isInvalid())
3546 return SemaRef.StmtError();
3547 }
Mike Stump11289f42009-09-09 15:08:12 +00003548
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003549 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003550
Douglas Gregorebe10102009-08-20 07:17:43 +00003551 // Transform the body
3552 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3553 if (Body.isInvalid())
3554 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003555
Douglas Gregorebe10102009-08-20 07:17:43 +00003556 if (!getDerived().AlwaysRebuild() &&
3557 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003558 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003559 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003560 return SemaRef.Owned(S->Retain());
3561
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003562 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3563 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003564}
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregorebe10102009-08-20 07:17:43 +00003566template<typename Derived>
3567Sema::OwningStmtResult
3568TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3569 // Transform the condition
3570 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3571 if (Cond.isInvalid())
3572 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 // Transform the body
3575 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3576 if (Body.isInvalid())
3577 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003578
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 if (!getDerived().AlwaysRebuild() &&
3580 Cond.get() == S->getCond() &&
3581 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003582 return SemaRef.Owned(S->Retain());
3583
Douglas Gregorebe10102009-08-20 07:17:43 +00003584 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3585 /*FIXME:*/S->getWhileLoc(), move(Cond),
3586 S->getRParenLoc());
3587}
Mike Stump11289f42009-09-09 15:08:12 +00003588
Douglas Gregorebe10102009-08-20 07:17:43 +00003589template<typename Derived>
3590Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003591TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003592 // Transform the initialization statement
3593 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3594 if (Init.isInvalid())
3595 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003596
Douglas Gregorebe10102009-08-20 07:17:43 +00003597 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003598 OwningExprResult Cond(SemaRef);
3599 VarDecl *ConditionVar = 0;
3600 if (S->getConditionVariable()) {
3601 ConditionVar
3602 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003603 getDerived().TransformDefinition(
3604 S->getConditionVariable()->getLocation(),
3605 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003606 if (!ConditionVar)
3607 return SemaRef.StmtError();
3608 } else {
3609 Cond = getDerived().TransformExpr(S->getCond());
3610
3611 if (Cond.isInvalid())
3612 return SemaRef.StmtError();
3613 }
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregorebe10102009-08-20 07:17:43 +00003615 // Transform the increment
3616 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3617 if (Inc.isInvalid())
3618 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003619
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 // Transform the body
3621 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3622 if (Body.isInvalid())
3623 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003624
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 if (!getDerived().AlwaysRebuild() &&
3626 Init.get() == S->getInit() &&
3627 Cond.get() == S->getCond() &&
3628 Inc.get() == S->getInc() &&
3629 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003630 return SemaRef.Owned(S->Retain());
3631
Douglas Gregorebe10102009-08-20 07:17:43 +00003632 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003633 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003634 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003635 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003636 S->getRParenLoc(), move(Body));
3637}
3638
3639template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003640Sema::OwningStmtResult
3641TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003643 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003644 S->getLabel());
3645}
3646
3647template<typename Derived>
3648Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003649TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003650 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3651 if (Target.isInvalid())
3652 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 if (!getDerived().AlwaysRebuild() &&
3655 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003656 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003657
3658 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3659 move(Target));
3660}
3661
3662template<typename Derived>
3663Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003664TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3665 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003666}
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregorebe10102009-08-20 07:17:43 +00003668template<typename Derived>
3669Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003670TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3671 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003672}
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregorebe10102009-08-20 07:17:43 +00003674template<typename Derived>
3675Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003676TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003677 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3678 if (Result.isInvalid())
3679 return SemaRef.StmtError();
3680
Mike Stump11289f42009-09-09 15:08:12 +00003681 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003682 // to tell whether the return type of the function has changed.
3683 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3684}
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregorebe10102009-08-20 07:17:43 +00003686template<typename Derived>
3687Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003688TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003689 bool DeclChanged = false;
3690 llvm::SmallVector<Decl *, 4> Decls;
3691 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3692 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003693 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3694 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003695 if (!Transformed)
3696 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003697
Douglas Gregorebe10102009-08-20 07:17:43 +00003698 if (Transformed != *D)
3699 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701 Decls.push_back(Transformed);
3702 }
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003705 return SemaRef.Owned(S->Retain());
3706
3707 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 S->getStartLoc(), S->getEndLoc());
3709}
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregorebe10102009-08-20 07:17:43 +00003711template<typename Derived>
3712Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003715 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003716}
3717
3718template<typename Derived>
3719Sema::OwningStmtResult
3720TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003721
3722 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3723 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003724 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003725
Anders Carlssonaaeef072010-01-24 05:50:09 +00003726 OwningExprResult AsmString(SemaRef);
3727 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3728
3729 bool ExprsChanged = false;
3730
3731 // Go through the outputs.
3732 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003733 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003734
Anders Carlssonaaeef072010-01-24 05:50:09 +00003735 // No need to transform the constraint literal.
3736 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3737
3738 // Transform the output expr.
3739 Expr *OutputExpr = S->getOutputExpr(I);
3740 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3741 if (Result.isInvalid())
3742 return SemaRef.StmtError();
3743
3744 ExprsChanged |= Result.get() != OutputExpr;
3745
3746 Exprs.push_back(Result.takeAs<Expr>());
3747 }
3748
3749 // Go through the inputs.
3750 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003751 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003752
Anders Carlssonaaeef072010-01-24 05:50:09 +00003753 // No need to transform the constraint literal.
3754 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3755
3756 // Transform the input expr.
3757 Expr *InputExpr = S->getInputExpr(I);
3758 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3759 if (Result.isInvalid())
3760 return SemaRef.StmtError();
3761
3762 ExprsChanged |= Result.get() != InputExpr;
3763
3764 Exprs.push_back(Result.takeAs<Expr>());
3765 }
3766
3767 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3768 return SemaRef.Owned(S->Retain());
3769
3770 // Go through the clobbers.
3771 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3772 Clobbers.push_back(S->getClobber(I)->Retain());
3773
3774 // No need to transform the asm string literal.
3775 AsmString = SemaRef.Owned(S->getAsmString());
3776
3777 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3778 S->isSimple(),
3779 S->isVolatile(),
3780 S->getNumOutputs(),
3781 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003782 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003783 move_arg(Constraints),
3784 move_arg(Exprs),
3785 move(AsmString),
3786 move_arg(Clobbers),
3787 S->getRParenLoc(),
3788 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003789}
3790
3791
3792template<typename Derived>
3793Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003794TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003795 // Transform the body of the @try.
3796 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3797 if (TryBody.isInvalid())
3798 return SemaRef.StmtError();
3799
Douglas Gregor96c79492010-04-23 22:50:49 +00003800 // Transform the @catch statements (if present).
3801 bool AnyCatchChanged = false;
3802 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3803 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3804 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003805 if (Catch.isInvalid())
3806 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003807 if (Catch.get() != S->getCatchStmt(I))
3808 AnyCatchChanged = true;
3809 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003810 }
3811
3812 // Transform the @finally statement (if present).
3813 OwningStmtResult Finally(SemaRef);
3814 if (S->getFinallyStmt()) {
3815 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3816 if (Finally.isInvalid())
3817 return SemaRef.StmtError();
3818 }
3819
3820 // If nothing changed, just retain this statement.
3821 if (!getDerived().AlwaysRebuild() &&
3822 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003823 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003824 Finally.get() == S->getFinallyStmt())
3825 return SemaRef.Owned(S->Retain());
3826
3827 // Build a new statement.
3828 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003829 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003830}
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregorebe10102009-08-20 07:17:43 +00003832template<typename Derived>
3833Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003834TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003835 // Transform the @catch parameter, if there is one.
3836 VarDecl *Var = 0;
3837 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3838 TypeSourceInfo *TSInfo = 0;
3839 if (FromVar->getTypeSourceInfo()) {
3840 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3841 if (!TSInfo)
3842 return SemaRef.StmtError();
3843 }
3844
3845 QualType T;
3846 if (TSInfo)
3847 T = TSInfo->getType();
3848 else {
3849 T = getDerived().TransformType(FromVar->getType());
3850 if (T.isNull())
3851 return SemaRef.StmtError();
3852 }
3853
3854 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3855 if (!Var)
3856 return SemaRef.StmtError();
3857 }
3858
3859 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3860 if (Body.isInvalid())
3861 return SemaRef.StmtError();
3862
3863 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
3864 S->getRParenLoc(),
3865 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003866}
Mike Stump11289f42009-09-09 15:08:12 +00003867
Douglas Gregorebe10102009-08-20 07:17:43 +00003868template<typename Derived>
3869Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003870TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003871 // Transform the body.
3872 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3873 if (Body.isInvalid())
3874 return SemaRef.StmtError();
3875
3876 // If nothing changed, just retain this statement.
3877 if (!getDerived().AlwaysRebuild() &&
3878 Body.get() == S->getFinallyBody())
3879 return SemaRef.Owned(S->Retain());
3880
3881 // Build a new statement.
3882 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3883 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003884}
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregorebe10102009-08-20 07:17:43 +00003886template<typename Derived>
3887Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003888TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003889 OwningExprResult Operand(SemaRef);
3890 if (S->getThrowExpr()) {
3891 Operand = getDerived().TransformExpr(S->getThrowExpr());
3892 if (Operand.isInvalid())
3893 return getSema().StmtError();
3894 }
3895
3896 if (!getDerived().AlwaysRebuild() &&
3897 Operand.get() == S->getThrowExpr())
3898 return getSema().Owned(S->Retain());
3899
3900 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003901}
Mike Stump11289f42009-09-09 15:08:12 +00003902
Douglas Gregorebe10102009-08-20 07:17:43 +00003903template<typename Derived>
3904Sema::OwningStmtResult
3905TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003906 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003907 // Transform the object we are locking.
3908 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3909 if (Object.isInvalid())
3910 return SemaRef.StmtError();
3911
3912 // Transform the body.
3913 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3914 if (Body.isInvalid())
3915 return SemaRef.StmtError();
3916
3917 // If nothing change, just retain the current statement.
3918 if (!getDerived().AlwaysRebuild() &&
3919 Object.get() == S->getSynchExpr() &&
3920 Body.get() == S->getSynchBody())
3921 return SemaRef.Owned(S->Retain());
3922
3923 // Build a new statement.
3924 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3925 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003926}
3927
3928template<typename Derived>
3929Sema::OwningStmtResult
3930TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003931 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003932 // Transform the element statement.
3933 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3934 if (Element.isInvalid())
3935 return SemaRef.StmtError();
3936
3937 // Transform the collection expression.
3938 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3939 if (Collection.isInvalid())
3940 return SemaRef.StmtError();
3941
3942 // Transform the body.
3943 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3944 if (Body.isInvalid())
3945 return SemaRef.StmtError();
3946
3947 // If nothing changed, just retain this statement.
3948 if (!getDerived().AlwaysRebuild() &&
3949 Element.get() == S->getElement() &&
3950 Collection.get() == S->getCollection() &&
3951 Body.get() == S->getBody())
3952 return SemaRef.Owned(S->Retain());
3953
3954 // Build a new statement.
3955 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3956 /*FIXME:*/S->getForLoc(),
3957 move(Element),
3958 move(Collection),
3959 S->getRParenLoc(),
3960 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003961}
3962
3963
3964template<typename Derived>
3965Sema::OwningStmtResult
3966TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3967 // Transform the exception declaration, if any.
3968 VarDecl *Var = 0;
3969 if (S->getExceptionDecl()) {
3970 VarDecl *ExceptionDecl = S->getExceptionDecl();
3971 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3972 ExceptionDecl->getDeclName());
3973
3974 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3975 if (T.isNull())
3976 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregorebe10102009-08-20 07:17:43 +00003978 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3979 T,
John McCallbcd03502009-12-07 02:54:59 +00003980 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003981 ExceptionDecl->getIdentifier(),
3982 ExceptionDecl->getLocation(),
3983 /*FIXME: Inaccurate*/
3984 SourceRange(ExceptionDecl->getLocation()));
3985 if (!Var || Var->isInvalidDecl()) {
3986 if (Var)
3987 Var->Destroy(SemaRef.Context);
3988 return SemaRef.StmtError();
3989 }
3990 }
Mike Stump11289f42009-09-09 15:08:12 +00003991
Douglas Gregorebe10102009-08-20 07:17:43 +00003992 // Transform the actual exception handler.
3993 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3994 if (Handler.isInvalid()) {
3995 if (Var)
3996 Var->Destroy(SemaRef.Context);
3997 return SemaRef.StmtError();
3998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregorebe10102009-08-20 07:17:43 +00004000 if (!getDerived().AlwaysRebuild() &&
4001 !Var &&
4002 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004003 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004004
4005 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4006 Var,
4007 move(Handler));
4008}
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregorebe10102009-08-20 07:17:43 +00004010template<typename Derived>
4011Sema::OwningStmtResult
4012TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4013 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004014 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004015 = getDerived().TransformCompoundStmt(S->getTryBlock());
4016 if (TryBlock.isInvalid())
4017 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004018
Douglas Gregorebe10102009-08-20 07:17:43 +00004019 // Transform the handlers.
4020 bool HandlerChanged = false;
4021 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4022 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004023 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004024 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4025 if (Handler.isInvalid())
4026 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregorebe10102009-08-20 07:17:43 +00004028 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4029 Handlers.push_back(Handler.takeAs<Stmt>());
4030 }
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregorebe10102009-08-20 07:17:43 +00004032 if (!getDerived().AlwaysRebuild() &&
4033 TryBlock.get() == S->getTryBlock() &&
4034 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004035 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004036
4037 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004038 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004039}
Mike Stump11289f42009-09-09 15:08:12 +00004040
Douglas Gregorebe10102009-08-20 07:17:43 +00004041//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004042// Expression transformation
4043//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004044template<typename Derived>
4045Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004046TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004047 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004048}
Mike Stump11289f42009-09-09 15:08:12 +00004049
4050template<typename Derived>
4051Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004052TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004053 NestedNameSpecifier *Qualifier = 0;
4054 if (E->getQualifier()) {
4055 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004056 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004057 if (!Qualifier)
4058 return SemaRef.ExprError();
4059 }
John McCallce546572009-12-08 09:08:17 +00004060
4061 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004062 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4063 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 if (!ND)
4065 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004066
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004067 if (!getDerived().AlwaysRebuild() &&
4068 Qualifier == E->getQualifier() &&
4069 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004070 !E->hasExplicitTemplateArgumentList()) {
4071
4072 // Mark it referenced in the new context regardless.
4073 // FIXME: this is a bit instantiation-specific.
4074 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4075
Mike Stump11289f42009-09-09 15:08:12 +00004076 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004077 }
John McCallce546572009-12-08 09:08:17 +00004078
4079 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4080 if (E->hasExplicitTemplateArgumentList()) {
4081 TemplateArgs = &TransArgs;
4082 TransArgs.setLAngleLoc(E->getLAngleLoc());
4083 TransArgs.setRAngleLoc(E->getRAngleLoc());
4084 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4085 TemplateArgumentLoc Loc;
4086 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4087 return SemaRef.ExprError();
4088 TransArgs.addArgument(Loc);
4089 }
4090 }
4091
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004092 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004093 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004094}
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregora16548e2009-08-11 05:31:07 +00004096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004097Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004098TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004099 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004100}
Mike Stump11289f42009-09-09 15:08:12 +00004101
Douglas Gregora16548e2009-08-11 05:31:07 +00004102template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004103Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004104TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004105 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004106}
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004109Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004110TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004111 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004112}
Mike Stump11289f42009-09-09 15:08:12 +00004113
Douglas Gregora16548e2009-08-11 05:31:07 +00004114template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004115Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004116TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004117 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004118}
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregora16548e2009-08-11 05:31:07 +00004120template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004121Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004122TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004123 return SemaRef.Owned(E->Retain());
4124}
4125
4126template<typename Derived>
4127Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004128TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004129 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4130 if (SubExpr.isInvalid())
4131 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004134 return SemaRef.Owned(E->Retain());
4135
4136 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004137 E->getRParen());
4138}
4139
Mike Stump11289f42009-09-09 15:08:12 +00004140template<typename Derived>
4141Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004142TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4143 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004144 if (SubExpr.isInvalid())
4145 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004148 return SemaRef.Owned(E->Retain());
4149
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4151 E->getOpcode(),
4152 move(SubExpr));
4153}
Mike Stump11289f42009-09-09 15:08:12 +00004154
Douglas Gregora16548e2009-08-11 05:31:07 +00004155template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004156Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004157TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004158 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004159 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004160
John McCallbcd03502009-12-07 02:54:59 +00004161 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004162 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004163 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004164
John McCall4c98fd82009-11-04 07:28:41 +00004165 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004166 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004167
John McCall4c98fd82009-11-04 07:28:41 +00004168 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004169 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004170 E->getSourceRange());
4171 }
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregora16548e2009-08-11 05:31:07 +00004173 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004174 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004175 // C++0x [expr.sizeof]p1:
4176 // The operand is either an expression, which is an unevaluated operand
4177 // [...]
4178 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregora16548e2009-08-11 05:31:07 +00004180 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4181 if (SubExpr.isInvalid())
4182 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregora16548e2009-08-11 05:31:07 +00004184 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4185 return SemaRef.Owned(E->Retain());
4186 }
Mike Stump11289f42009-09-09 15:08:12 +00004187
Douglas Gregora16548e2009-08-11 05:31:07 +00004188 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4189 E->isSizeOf(),
4190 E->getSourceRange());
4191}
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004194Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004195TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4197 if (LHS.isInvalid())
4198 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregora16548e2009-08-11 05:31:07 +00004200 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4201 if (RHS.isInvalid())
4202 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004203
4204
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 if (!getDerived().AlwaysRebuild() &&
4206 LHS.get() == E->getLHS() &&
4207 RHS.get() == E->getRHS())
4208 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004209
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4211 /*FIXME:*/E->getLHS()->getLocStart(),
4212 move(RHS),
4213 E->getRBracketLoc());
4214}
Mike Stump11289f42009-09-09 15:08:12 +00004215
4216template<typename Derived>
4217Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004218TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 // Transform the callee.
4220 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4221 if (Callee.isInvalid())
4222 return SemaRef.ExprError();
4223
4224 // Transform arguments.
4225 bool ArgChanged = false;
4226 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4227 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4228 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4229 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4230 if (Arg.isInvalid())
4231 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregora16548e2009-08-11 05:31:07 +00004233 // FIXME: Wrong source location information for the ','.
4234 FakeCommaLocs.push_back(
4235 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004236
4237 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004238 Args.push_back(Arg.takeAs<Expr>());
4239 }
Mike Stump11289f42009-09-09 15:08:12 +00004240
Douglas Gregora16548e2009-08-11 05:31:07 +00004241 if (!getDerived().AlwaysRebuild() &&
4242 Callee.get() == E->getCallee() &&
4243 !ArgChanged)
4244 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004245
Douglas Gregora16548e2009-08-11 05:31:07 +00004246 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004247 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004248 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4249 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4250 move_arg(Args),
4251 FakeCommaLocs.data(),
4252 E->getRParenLoc());
4253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
4255template<typename Derived>
4256Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004257TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4259 if (Base.isInvalid())
4260 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004262 NestedNameSpecifier *Qualifier = 0;
4263 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004264 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004265 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004266 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004267 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004268 return SemaRef.ExprError();
4269 }
Mike Stump11289f42009-09-09 15:08:12 +00004270
Eli Friedman2cfcef62009-12-04 06:40:45 +00004271 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004272 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4273 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 if (!Member)
4275 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004276
John McCall16df1e52010-03-30 21:47:33 +00004277 NamedDecl *FoundDecl = E->getFoundDecl();
4278 if (FoundDecl == E->getMemberDecl()) {
4279 FoundDecl = Member;
4280 } else {
4281 FoundDecl = cast_or_null<NamedDecl>(
4282 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4283 if (!FoundDecl)
4284 return SemaRef.ExprError();
4285 }
4286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287 if (!getDerived().AlwaysRebuild() &&
4288 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004289 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004290 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004291 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004292 !E->hasExplicitTemplateArgumentList()) {
4293
4294 // Mark it referenced in the new context regardless.
4295 // FIXME: this is a bit instantiation-specific.
4296 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004297 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004298 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004299
John McCall6b51f282009-11-23 01:53:49 +00004300 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004301 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004302 TransArgs.setLAngleLoc(E->getLAngleLoc());
4303 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004304 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004305 TemplateArgumentLoc Loc;
4306 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004307 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004308 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004309 }
4310 }
4311
Douglas Gregora16548e2009-08-11 05:31:07 +00004312 // FIXME: Bogus source location for the operator
4313 SourceLocation FakeOperatorLoc
4314 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4315
John McCall38836f02010-01-15 08:34:02 +00004316 // FIXME: to do this check properly, we will need to preserve the
4317 // first-qualifier-in-scope here, just in case we had a dependent
4318 // base (and therefore couldn't do the check) and a
4319 // nested-name-qualifier (and therefore could do the lookup).
4320 NamedDecl *FirstQualifierInScope = 0;
4321
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4323 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004324 Qualifier,
4325 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004327 Member,
John McCall16df1e52010-03-30 21:47:33 +00004328 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004329 (E->hasExplicitTemplateArgumentList()
4330 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004331 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004332}
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregora16548e2009-08-11 05:31:07 +00004334template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004335Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004336TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004337 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4338 if (LHS.isInvalid())
4339 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4342 if (RHS.isInvalid())
4343 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 if (!getDerived().AlwaysRebuild() &&
4346 LHS.get() == E->getLHS() &&
4347 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004348 return SemaRef.Owned(E->Retain());
4349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4351 move(LHS), move(RHS));
4352}
4353
Mike Stump11289f42009-09-09 15:08:12 +00004354template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004355Sema::OwningExprResult
4356TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004357 CompoundAssignOperator *E) {
4358 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004359}
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004362Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004363TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4365 if (Cond.isInvalid())
4366 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004367
Douglas Gregora16548e2009-08-11 05:31:07 +00004368 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4369 if (LHS.isInvalid())
4370 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4373 if (RHS.isInvalid())
4374 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004375
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 if (!getDerived().AlwaysRebuild() &&
4377 Cond.get() == E->getCond() &&
4378 LHS.get() == E->getLHS() &&
4379 RHS.get() == E->getRHS())
4380 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004381
4382 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004383 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004384 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004385 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 move(RHS));
4387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
4389template<typename Derived>
4390Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004391TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004392 // Implicit casts are eliminated during transformation, since they
4393 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004394 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004400 TypeSourceInfo *OldT;
4401 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 {
4403 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004404 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004405 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4406 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004407
John McCall97513962010-01-15 18:39:57 +00004408 OldT = E->getTypeInfoAsWritten();
4409 NewT = getDerived().TransformType(OldT);
4410 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 return SemaRef.ExprError();
4412 }
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregor6131b442009-12-12 18:16:41 +00004414 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004415 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 if (SubExpr.isInvalid())
4417 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004418
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004420 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004422 return SemaRef.Owned(E->Retain());
4423
John McCall97513962010-01-15 18:39:57 +00004424 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4425 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 E->getRParenLoc(),
4427 move(SubExpr));
4428}
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004431Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004432TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004433 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4434 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4435 if (!NewT)
4436 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004437
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4439 if (Init.isInvalid())
4440 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004443 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004445 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004446
John McCall5d7aa7f2010-01-19 22:33:45 +00004447 // Note: the expression type doesn't necessarily match the
4448 // type-as-written, but that's okay, because it should always be
4449 // derivable from the initializer.
4450
John McCalle15bbff2010-01-18 19:35:47 +00004451 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 /*FIXME:*/E->getInitializer()->getLocEnd(),
4453 move(Init));
4454}
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456template<typename Derived>
4457Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004458TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4460 if (Base.isInvalid())
4461 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 if (!getDerived().AlwaysRebuild() &&
4464 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004465 return SemaRef.Owned(E->Retain());
4466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004468 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004469 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4470 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4471 E->getAccessorLoc(),
4472 E->getAccessor());
4473}
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregora16548e2009-08-11 05:31:07 +00004475template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004476Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004477TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004479
Douglas Gregora16548e2009-08-11 05:31:07 +00004480 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4481 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4482 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4483 if (Init.isInvalid())
4484 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregora16548e2009-08-11 05:31:07 +00004486 InitChanged = InitChanged || Init.get() != E->getInit(I);
4487 Inits.push_back(Init.takeAs<Expr>());
4488 }
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004491 return SemaRef.Owned(E->Retain());
4492
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004494 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004495}
Mike Stump11289f42009-09-09 15:08:12 +00004496
Douglas Gregora16548e2009-08-11 05:31:07 +00004497template<typename Derived>
4498Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004499TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004501
Douglas Gregorebe10102009-08-20 07:17:43 +00004502 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004503 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4504 if (Init.isInvalid())
4505 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregorebe10102009-08-20 07:17:43 +00004507 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4509 bool ExprChanged = false;
4510 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4511 DEnd = E->designators_end();
4512 D != DEnd; ++D) {
4513 if (D->isFieldDesignator()) {
4514 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4515 D->getDotLoc(),
4516 D->getFieldLoc()));
4517 continue;
4518 }
Mike Stump11289f42009-09-09 15:08:12 +00004519
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 if (D->isArrayDesignator()) {
4521 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4522 if (Index.isInvalid())
4523 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004524
4525 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregora16548e2009-08-11 05:31:07 +00004528 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4529 ArrayExprs.push_back(Index.release());
4530 continue;
4531 }
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004534 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4536 if (Start.isInvalid())
4537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4540 if (End.isInvalid())
4541 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004542
4543 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 End.get(),
4545 D->getLBracketLoc(),
4546 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4549 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 ArrayExprs.push_back(Start.release());
4552 ArrayExprs.push_back(End.release());
4553 }
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 if (!getDerived().AlwaysRebuild() &&
4556 Init.get() == E->getInit() &&
4557 !ExprChanged)
4558 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004559
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4561 E->getEqualOrColonLoc(),
4562 E->usesGNUSyntax(), move(Init));
4563}
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004566Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004567TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004568 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004569 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4570
4571 // FIXME: Will we ever have proper type location here? Will we actually
4572 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 QualType T = getDerived().TransformType(E->getType());
4574 if (T.isNull())
4575 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004576
Douglas Gregora16548e2009-08-11 05:31:07 +00004577 if (!getDerived().AlwaysRebuild() &&
4578 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004579 return SemaRef.Owned(E->Retain());
4580
Douglas Gregora16548e2009-08-11 05:31:07 +00004581 return getDerived().RebuildImplicitValueInitExpr(T);
4582}
Mike Stump11289f42009-09-09 15:08:12 +00004583
Douglas Gregora16548e2009-08-11 05:31:07 +00004584template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004585Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004586TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 // FIXME: Do we want the type as written?
4588 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004589
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 {
4591 // FIXME: Source location isn't quite accurate.
4592 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4593 T = getDerived().TransformType(E->getType());
4594 if (T.isNull())
4595 return SemaRef.ExprError();
4596 }
Mike Stump11289f42009-09-09 15:08:12 +00004597
Douglas Gregora16548e2009-08-11 05:31:07 +00004598 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4599 if (SubExpr.isInvalid())
4600 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 if (!getDerived().AlwaysRebuild() &&
4603 T == E->getType() &&
4604 SubExpr.get() == E->getSubExpr())
4605 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004606
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4608 T, E->getRParenLoc());
4609}
4610
4611template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004612Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004613TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 bool ArgumentChanged = false;
4615 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4616 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4617 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4618 if (Init.isInvalid())
4619 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4622 Inits.push_back(Init.takeAs<Expr>());
4623 }
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4626 move_arg(Inits),
4627 E->getRParenLoc());
4628}
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregora16548e2009-08-11 05:31:07 +00004630/// \brief Transform an address-of-label expression.
4631///
4632/// By default, the transformation of an address-of-label expression always
4633/// rebuilds the expression, so that the label identifier can be resolved to
4634/// the corresponding label statement by semantic analysis.
4635template<typename Derived>
4636Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004637TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4639 E->getLabel());
4640}
Mike Stump11289f42009-09-09 15:08:12 +00004641
4642template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004643Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004644TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004645 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4647 if (SubStmt.isInvalid())
4648 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 if (!getDerived().AlwaysRebuild() &&
4651 SubStmt.get() == E->getSubStmt())
4652 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004653
4654 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 move(SubStmt),
4656 E->getRParenLoc());
4657}
Mike Stump11289f42009-09-09 15:08:12 +00004658
Douglas Gregora16548e2009-08-11 05:31:07 +00004659template<typename Derived>
4660Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004661TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 QualType T1, T2;
4663 {
4664 // FIXME: Source location isn't quite accurate.
4665 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 T1 = getDerived().TransformType(E->getArgType1());
4668 if (T1.isNull())
4669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 T2 = getDerived().TransformType(E->getArgType2());
4672 if (T2.isNull())
4673 return SemaRef.ExprError();
4674 }
4675
4676 if (!getDerived().AlwaysRebuild() &&
4677 T1 == E->getArgType1() &&
4678 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004679 return SemaRef.Owned(E->Retain());
4680
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4682 T1, T2, E->getRParenLoc());
4683}
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685template<typename Derived>
4686Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004687TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4689 if (Cond.isInvalid())
4690 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4693 if (LHS.isInvalid())
4694 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregora16548e2009-08-11 05:31:07 +00004696 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4697 if (RHS.isInvalid())
4698 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 if (!getDerived().AlwaysRebuild() &&
4701 Cond.get() == E->getCond() &&
4702 LHS.get() == E->getLHS() &&
4703 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004704 return SemaRef.Owned(E->Retain());
4705
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4707 move(Cond), move(LHS), move(RHS),
4708 E->getRParenLoc());
4709}
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004712Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004713TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004714 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004715}
4716
4717template<typename Derived>
4718Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004719TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004720 switch (E->getOperator()) {
4721 case OO_New:
4722 case OO_Delete:
4723 case OO_Array_New:
4724 case OO_Array_Delete:
4725 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4726 return SemaRef.ExprError();
4727
4728 case OO_Call: {
4729 // This is a call to an object's operator().
4730 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4731
4732 // Transform the object itself.
4733 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4734 if (Object.isInvalid())
4735 return SemaRef.ExprError();
4736
4737 // FIXME: Poor location information
4738 SourceLocation FakeLParenLoc
4739 = SemaRef.PP.getLocForEndOfToken(
4740 static_cast<Expr *>(Object.get())->getLocEnd());
4741
4742 // Transform the call arguments.
4743 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4744 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4745 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004746 if (getDerived().DropCallArgument(E->getArg(I)))
4747 break;
4748
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004749 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4750 if (Arg.isInvalid())
4751 return SemaRef.ExprError();
4752
4753 // FIXME: Poor source location information.
4754 SourceLocation FakeCommaLoc
4755 = SemaRef.PP.getLocForEndOfToken(
4756 static_cast<Expr *>(Arg.get())->getLocEnd());
4757 FakeCommaLocs.push_back(FakeCommaLoc);
4758 Args.push_back(Arg.release());
4759 }
4760
4761 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4762 move_arg(Args),
4763 FakeCommaLocs.data(),
4764 E->getLocEnd());
4765 }
4766
4767#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4768 case OO_##Name:
4769#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4770#include "clang/Basic/OperatorKinds.def"
4771 case OO_Subscript:
4772 // Handled below.
4773 break;
4774
4775 case OO_Conditional:
4776 llvm_unreachable("conditional operator is not actually overloadable");
4777 return SemaRef.ExprError();
4778
4779 case OO_None:
4780 case NUM_OVERLOADED_OPERATORS:
4781 llvm_unreachable("not an overloaded operator?");
4782 return SemaRef.ExprError();
4783 }
4784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4786 if (Callee.isInvalid())
4787 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004788
John McCall47f29ea2009-12-08 09:21:05 +00004789 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 if (First.isInvalid())
4791 return SemaRef.ExprError();
4792
4793 OwningExprResult Second(SemaRef);
4794 if (E->getNumArgs() == 2) {
4795 Second = getDerived().TransformExpr(E->getArg(1));
4796 if (Second.isInvalid())
4797 return SemaRef.ExprError();
4798 }
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 if (!getDerived().AlwaysRebuild() &&
4801 Callee.get() == E->getCallee() &&
4802 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004803 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4804 return SemaRef.Owned(E->Retain());
4805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4807 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004808 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 move(First),
4810 move(Second));
4811}
Mike Stump11289f42009-09-09 15:08:12 +00004812
Douglas Gregora16548e2009-08-11 05:31:07 +00004813template<typename Derived>
4814Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004815TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4816 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004817}
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregora16548e2009-08-11 05:31:07 +00004819template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004820Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004821TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004822 TypeSourceInfo *OldT;
4823 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 {
4825 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004826 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4828 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004829
John McCall97513962010-01-15 18:39:57 +00004830 OldT = E->getTypeInfoAsWritten();
4831 NewT = getDerived().TransformType(OldT);
4832 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 return SemaRef.ExprError();
4834 }
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregor6131b442009-12-12 18:16:41 +00004836 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004837 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 if (SubExpr.isInvalid())
4839 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004840
Douglas Gregora16548e2009-08-11 05:31:07 +00004841 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004842 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004843 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004844 return SemaRef.Owned(E->Retain());
4845
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004847 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004848 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4849 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4850 SourceLocation FakeRParenLoc
4851 = SemaRef.PP.getLocForEndOfToken(
4852 E->getSubExpr()->getSourceRange().getEnd());
4853 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004854 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004855 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004856 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004857 FakeRAngleLoc,
4858 FakeRAngleLoc,
4859 move(SubExpr),
4860 FakeRParenLoc);
4861}
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863template<typename Derived>
4864Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004865TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4866 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004867}
Mike Stump11289f42009-09-09 15:08:12 +00004868
4869template<typename Derived>
4870Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004871TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4872 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004873}
4874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875template<typename Derived>
4876Sema::OwningExprResult
4877TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004878 CXXReinterpretCastExpr *E) {
4879 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004880}
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregora16548e2009-08-11 05:31:07 +00004882template<typename Derived>
4883Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004884TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4885 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004886}
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888template<typename Derived>
4889Sema::OwningExprResult
4890TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004891 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004892 TypeSourceInfo *OldT;
4893 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 {
4895 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004896
John McCall97513962010-01-15 18:39:57 +00004897 OldT = E->getTypeInfoAsWritten();
4898 NewT = getDerived().TransformType(OldT);
4899 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004900 return SemaRef.ExprError();
4901 }
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregor6131b442009-12-12 18:16:41 +00004903 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004904 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004905 if (SubExpr.isInvalid())
4906 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004909 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004911 return SemaRef.Owned(E->Retain());
4912
Douglas Gregora16548e2009-08-11 05:31:07 +00004913 // FIXME: The end of the type's source range is wrong
4914 return getDerived().RebuildCXXFunctionalCastExpr(
4915 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004916 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004917 /*FIXME:*/E->getSubExpr()->getLocStart(),
4918 move(SubExpr),
4919 E->getRParenLoc());
4920}
Mike Stump11289f42009-09-09 15:08:12 +00004921
Douglas Gregora16548e2009-08-11 05:31:07 +00004922template<typename Derived>
4923Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004924TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 if (E->isTypeOperand()) {
4926 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 QualType T = getDerived().TransformType(E->getTypeOperand());
4929 if (T.isNull())
4930 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004931
Douglas Gregora16548e2009-08-11 05:31:07 +00004932 if (!getDerived().AlwaysRebuild() &&
4933 T == E->getTypeOperand())
4934 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004935
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4937 /*FIXME:*/E->getLocStart(),
4938 T,
4939 E->getLocEnd());
4940 }
Mike Stump11289f42009-09-09 15:08:12 +00004941
Douglas Gregora16548e2009-08-11 05:31:07 +00004942 // We don't know whether the expression is potentially evaluated until
4943 // after we perform semantic analysis, so the expression is potentially
4944 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004945 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004946 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004947
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4949 if (SubExpr.isInvalid())
4950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 if (!getDerived().AlwaysRebuild() &&
4953 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004954 return SemaRef.Owned(E->Retain());
4955
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4957 /*FIXME:*/E->getLocStart(),
4958 move(SubExpr),
4959 E->getLocEnd());
4960}
4961
4962template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004963Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004964TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004965 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004966}
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregora16548e2009-08-11 05:31:07 +00004968template<typename Derived>
4969Sema::OwningExprResult
4970TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004971 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004972 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004973}
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregora16548e2009-08-11 05:31:07 +00004975template<typename Derived>
4976Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004977TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregora16548e2009-08-11 05:31:07 +00004980 QualType T = getDerived().TransformType(E->getType());
4981 if (T.isNull())
4982 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004983
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 if (!getDerived().AlwaysRebuild() &&
4985 T == E->getType())
4986 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregorb15af892010-01-07 23:12:05 +00004988 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004989}
Mike Stump11289f42009-09-09 15:08:12 +00004990
Douglas Gregora16548e2009-08-11 05:31:07 +00004991template<typename Derived>
4992Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004993TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4995 if (SubExpr.isInvalid())
4996 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004997
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 if (!getDerived().AlwaysRebuild() &&
4999 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005000 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005001
5002 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005template<typename Derived>
5006Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005007TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005008 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005009 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5010 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (!Param)
5012 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005013
Chandler Carruth794da4c2010-02-08 06:42:49 +00005014 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 Param == E->getParam())
5016 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregor033f6752009-12-23 23:03:06 +00005018 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005019}
Mike Stump11289f42009-09-09 15:08:12 +00005020
Douglas Gregora16548e2009-08-11 05:31:07 +00005021template<typename Derived>
5022Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005023TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5025
5026 QualType T = getDerived().TransformType(E->getType());
5027 if (T.isNull())
5028 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregora16548e2009-08-11 05:31:07 +00005030 if (!getDerived().AlwaysRebuild() &&
5031 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005032 return SemaRef.Owned(E->Retain());
5033
5034 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 /*FIXME:*/E->getTypeBeginLoc(),
5036 T,
5037 E->getRParenLoc());
5038}
Mike Stump11289f42009-09-09 15:08:12 +00005039
Douglas Gregora16548e2009-08-11 05:31:07 +00005040template<typename Derived>
5041Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005042TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 // Transform the type that we're allocating
5044 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5045 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5046 if (AllocType.isNull())
5047 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005048
Douglas Gregora16548e2009-08-11 05:31:07 +00005049 // Transform the size of the array we're allocating (if any).
5050 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5051 if (ArraySize.isInvalid())
5052 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005053
Douglas Gregora16548e2009-08-11 05:31:07 +00005054 // Transform the placement arguments (if any).
5055 bool ArgumentChanged = false;
5056 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5057 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5058 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5059 if (Arg.isInvalid())
5060 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5063 PlacementArgs.push_back(Arg.take());
5064 }
Mike Stump11289f42009-09-09 15:08:12 +00005065
Douglas Gregorebe10102009-08-20 07:17:43 +00005066 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5068 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5069 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5070 if (Arg.isInvalid())
5071 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005072
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5074 ConstructorArgs.push_back(Arg.take());
5075 }
Mike Stump11289f42009-09-09 15:08:12 +00005076
Douglas Gregord2d9da02010-02-26 00:38:10 +00005077 // Transform constructor, new operator, and delete operator.
5078 CXXConstructorDecl *Constructor = 0;
5079 if (E->getConstructor()) {
5080 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005081 getDerived().TransformDecl(E->getLocStart(),
5082 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005083 if (!Constructor)
5084 return SemaRef.ExprError();
5085 }
5086
5087 FunctionDecl *OperatorNew = 0;
5088 if (E->getOperatorNew()) {
5089 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005090 getDerived().TransformDecl(E->getLocStart(),
5091 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005092 if (!OperatorNew)
5093 return SemaRef.ExprError();
5094 }
5095
5096 FunctionDecl *OperatorDelete = 0;
5097 if (E->getOperatorDelete()) {
5098 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005099 getDerived().TransformDecl(E->getLocStart(),
5100 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005101 if (!OperatorDelete)
5102 return SemaRef.ExprError();
5103 }
5104
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 if (!getDerived().AlwaysRebuild() &&
5106 AllocType == E->getAllocatedType() &&
5107 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005108 Constructor == E->getConstructor() &&
5109 OperatorNew == E->getOperatorNew() &&
5110 OperatorDelete == E->getOperatorDelete() &&
5111 !ArgumentChanged) {
5112 // Mark any declarations we need as referenced.
5113 // FIXME: instantiation-specific.
5114 if (Constructor)
5115 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5116 if (OperatorNew)
5117 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5118 if (OperatorDelete)
5119 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005120 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005121 }
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005123 if (!ArraySize.get()) {
5124 // If no array size was specified, but the new expression was
5125 // instantiated with an array type (e.g., "new T" where T is
5126 // instantiated with "int[4]"), extract the outer bound from the
5127 // array type as our array size. We do this with constant and
5128 // dependently-sized array types.
5129 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5130 if (!ArrayT) {
5131 // Do nothing
5132 } else if (const ConstantArrayType *ConsArrayT
5133 = dyn_cast<ConstantArrayType>(ArrayT)) {
5134 ArraySize
5135 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
5136 ConsArrayT->getSize(),
5137 SemaRef.Context.getSizeType(),
5138 /*FIXME:*/E->getLocStart()));
5139 AllocType = ConsArrayT->getElementType();
5140 } else if (const DependentSizedArrayType *DepArrayT
5141 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5142 if (DepArrayT->getSizeExpr()) {
5143 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5144 AllocType = DepArrayT->getElementType();
5145 }
5146 }
5147 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5149 E->isGlobalNew(),
5150 /*FIXME:*/E->getLocStart(),
5151 move_arg(PlacementArgs),
5152 /*FIXME:*/E->getLocStart(),
5153 E->isParenTypeId(),
5154 AllocType,
5155 /*FIXME:*/E->getLocStart(),
5156 /*FIXME:*/SourceRange(),
5157 move(ArraySize),
5158 /*FIXME:*/E->getLocStart(),
5159 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005160 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005161}
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregora16548e2009-08-11 05:31:07 +00005163template<typename Derived>
5164Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005165TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005166 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5167 if (Operand.isInvalid())
5168 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregord2d9da02010-02-26 00:38:10 +00005170 // Transform the delete operator, if known.
5171 FunctionDecl *OperatorDelete = 0;
5172 if (E->getOperatorDelete()) {
5173 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005174 getDerived().TransformDecl(E->getLocStart(),
5175 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005176 if (!OperatorDelete)
5177 return SemaRef.ExprError();
5178 }
5179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005181 Operand.get() == E->getArgument() &&
5182 OperatorDelete == E->getOperatorDelete()) {
5183 // Mark any declarations we need as referenced.
5184 // FIXME: instantiation-specific.
5185 if (OperatorDelete)
5186 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005187 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005188 }
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5191 E->isGlobalDelete(),
5192 E->isArrayForm(),
5193 move(Operand));
5194}
Mike Stump11289f42009-09-09 15:08:12 +00005195
Douglas Gregora16548e2009-08-11 05:31:07 +00005196template<typename Derived>
5197Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005198TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005199 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005200 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5201 if (Base.isInvalid())
5202 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005203
Douglas Gregor678f90d2010-02-25 01:56:36 +00005204 Sema::TypeTy *ObjectTypePtr = 0;
5205 bool MayBePseudoDestructor = false;
5206 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5207 E->getOperatorLoc(),
5208 E->isArrow()? tok::arrow : tok::period,
5209 ObjectTypePtr,
5210 MayBePseudoDestructor);
5211 if (Base.isInvalid())
5212 return SemaRef.ExprError();
5213
5214 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005215 NestedNameSpecifier *Qualifier
5216 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005217 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005218 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005219 if (E->getQualifier() && !Qualifier)
5220 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005221
Douglas Gregor678f90d2010-02-25 01:56:36 +00005222 PseudoDestructorTypeStorage Destroyed;
5223 if (E->getDestroyedTypeInfo()) {
5224 TypeSourceInfo *DestroyedTypeInfo
5225 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5226 if (!DestroyedTypeInfo)
5227 return SemaRef.ExprError();
5228 Destroyed = DestroyedTypeInfo;
5229 } else if (ObjectType->isDependentType()) {
5230 // We aren't likely to be able to resolve the identifier down to a type
5231 // now anyway, so just retain the identifier.
5232 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5233 E->getDestroyedTypeLoc());
5234 } else {
5235 // Look for a destructor known with the given name.
5236 CXXScopeSpec SS;
5237 if (Qualifier) {
5238 SS.setScopeRep(Qualifier);
5239 SS.setRange(E->getQualifierRange());
5240 }
5241
5242 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5243 *E->getDestroyedTypeIdentifier(),
5244 E->getDestroyedTypeLoc(),
5245 /*Scope=*/0,
5246 SS, ObjectTypePtr,
5247 false);
5248 if (!T)
5249 return SemaRef.ExprError();
5250
5251 Destroyed
5252 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5253 E->getDestroyedTypeLoc());
5254 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005255
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005256 TypeSourceInfo *ScopeTypeInfo = 0;
5257 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005258 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5259 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005260 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005261 return SemaRef.ExprError();
5262 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005263
Douglas Gregorad8a3362009-09-04 17:36:40 +00005264 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5265 E->getOperatorLoc(),
5266 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005267 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005268 E->getQualifierRange(),
5269 ScopeTypeInfo,
5270 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005271 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005272 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005273}
Mike Stump11289f42009-09-09 15:08:12 +00005274
Douglas Gregorad8a3362009-09-04 17:36:40 +00005275template<typename Derived>
5276Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005277TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005278 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005279 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5280
5281 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5282 Sema::LookupOrdinaryName);
5283
5284 // Transform all the decls.
5285 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5286 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005287 NamedDecl *InstD = static_cast<NamedDecl*>(
5288 getDerived().TransformDecl(Old->getNameLoc(),
5289 *I));
John McCall84d87672009-12-10 09:41:52 +00005290 if (!InstD) {
5291 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5292 // This can happen because of dependent hiding.
5293 if (isa<UsingShadowDecl>(*I))
5294 continue;
5295 else
5296 return SemaRef.ExprError();
5297 }
John McCalle66edc12009-11-24 19:00:30 +00005298
5299 // Expand using declarations.
5300 if (isa<UsingDecl>(InstD)) {
5301 UsingDecl *UD = cast<UsingDecl>(InstD);
5302 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5303 E = UD->shadow_end(); I != E; ++I)
5304 R.addDecl(*I);
5305 continue;
5306 }
5307
5308 R.addDecl(InstD);
5309 }
5310
5311 // Resolve a kind, but don't do any further analysis. If it's
5312 // ambiguous, the callee needs to deal with it.
5313 R.resolveKind();
5314
5315 // Rebuild the nested-name qualifier, if present.
5316 CXXScopeSpec SS;
5317 NestedNameSpecifier *Qualifier = 0;
5318 if (Old->getQualifier()) {
5319 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005320 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005321 if (!Qualifier)
5322 return SemaRef.ExprError();
5323
5324 SS.setScopeRep(Qualifier);
5325 SS.setRange(Old->getQualifierRange());
5326 }
5327
5328 // If we have no template arguments, it's a normal declaration name.
5329 if (!Old->hasExplicitTemplateArgs())
5330 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5331
5332 // If we have template arguments, rebuild them, then rebuild the
5333 // templateid expression.
5334 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5335 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5336 TemplateArgumentLoc Loc;
5337 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5338 return SemaRef.ExprError();
5339 TransArgs.addArgument(Loc);
5340 }
5341
5342 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5343 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005344}
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregora16548e2009-08-11 05:31:07 +00005346template<typename Derived>
5347Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005348TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005349 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005350
Douglas Gregora16548e2009-08-11 05:31:07 +00005351 QualType T = getDerived().TransformType(E->getQueriedType());
5352 if (T.isNull())
5353 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 if (!getDerived().AlwaysRebuild() &&
5356 T == E->getQueriedType())
5357 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359 // FIXME: Bad location information
5360 SourceLocation FakeLParenLoc
5361 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005362
5363 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005364 E->getLocStart(),
5365 /*FIXME:*/FakeLParenLoc,
5366 T,
5367 E->getLocEnd());
5368}
Mike Stump11289f42009-09-09 15:08:12 +00005369
Douglas Gregora16548e2009-08-11 05:31:07 +00005370template<typename Derived>
5371Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005372TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005373 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005374 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005375 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005376 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005377 if (!NNS)
5378 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005379
5380 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005381 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5382 if (!Name)
5383 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005384
John McCalle66edc12009-11-24 19:00:30 +00005385 if (!E->hasExplicitTemplateArgs()) {
5386 if (!getDerived().AlwaysRebuild() &&
5387 NNS == E->getQualifier() &&
5388 Name == E->getDeclName())
5389 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005390
John McCalle66edc12009-11-24 19:00:30 +00005391 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5392 E->getQualifierRange(),
5393 Name, E->getLocation(),
5394 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005395 }
John McCall6b51f282009-11-23 01:53:49 +00005396
5397 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005399 TemplateArgumentLoc Loc;
5400 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005401 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005402 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 }
5404
John McCalle66edc12009-11-24 19:00:30 +00005405 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5406 E->getQualifierRange(),
5407 Name, E->getLocation(),
5408 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005409}
5410
5411template<typename Derived>
5412Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005413TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005414 // CXXConstructExprs are always implicit, so when we have a
5415 // 1-argument construction we just transform that argument.
5416 if (E->getNumArgs() == 1 ||
5417 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5418 return getDerived().TransformExpr(E->getArg(0));
5419
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5421
5422 QualType T = getDerived().TransformType(E->getType());
5423 if (T.isNull())
5424 return SemaRef.ExprError();
5425
5426 CXXConstructorDecl *Constructor
5427 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005428 getDerived().TransformDecl(E->getLocStart(),
5429 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005430 if (!Constructor)
5431 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 bool ArgumentChanged = false;
5434 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005435 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005436 ArgEnd = E->arg_end();
5437 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005438 if (getDerived().DropCallArgument(*Arg)) {
5439 ArgumentChanged = true;
5440 break;
5441 }
5442
Douglas Gregora16548e2009-08-11 05:31:07 +00005443 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5444 if (TransArg.isInvalid())
5445 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5448 Args.push_back(TransArg.takeAs<Expr>());
5449 }
5450
5451 if (!getDerived().AlwaysRebuild() &&
5452 T == E->getType() &&
5453 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005454 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005455 // Mark the constructor as referenced.
5456 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005457 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005458 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005459 }
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregordb121ba2009-12-14 16:27:04 +00005461 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5462 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 move_arg(Args));
5464}
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregora16548e2009-08-11 05:31:07 +00005466/// \brief Transform a C++ temporary-binding expression.
5467///
Douglas Gregor363b1512009-12-24 18:51:59 +00005468/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5469/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005470template<typename Derived>
5471Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005472TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005473 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Anders Carlssonba6c4372010-01-29 02:39:32 +00005476/// \brief Transform a C++ reference-binding expression.
5477///
5478/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5479/// transform the subexpression and return that.
5480template<typename Derived>
5481Sema::OwningExprResult
5482TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5483 return getDerived().TransformExpr(E->getSubExpr());
5484}
5485
Mike Stump11289f42009-09-09 15:08:12 +00005486/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005487/// be destroyed after the expression is evaluated.
5488///
Douglas Gregor363b1512009-12-24 18:51:59 +00005489/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5490/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005491template<typename Derived>
5492Sema::OwningExprResult
5493TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005494 CXXExprWithTemporaries *E) {
5495 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005496}
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregora16548e2009-08-11 05:31:07 +00005498template<typename Derived>
5499Sema::OwningExprResult
5500TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005501 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005502 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5503 QualType T = getDerived().TransformType(E->getType());
5504 if (T.isNull())
5505 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregora16548e2009-08-11 05:31:07 +00005507 CXXConstructorDecl *Constructor
5508 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005509 getDerived().TransformDecl(E->getLocStart(),
5510 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005511 if (!Constructor)
5512 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 bool ArgumentChanged = false;
5515 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5516 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005517 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 ArgEnd = E->arg_end();
5519 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005520 if (getDerived().DropCallArgument(*Arg)) {
5521 ArgumentChanged = true;
5522 break;
5523 }
5524
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5526 if (TransArg.isInvalid())
5527 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5530 Args.push_back((Expr *)TransArg.release());
5531 }
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 if (!getDerived().AlwaysRebuild() &&
5534 T == E->getType() &&
5535 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005536 !ArgumentChanged) {
5537 // FIXME: Instantiation-specific
5538 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005539 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005540 }
Mike Stump11289f42009-09-09 15:08:12 +00005541
Douglas Gregora16548e2009-08-11 05:31:07 +00005542 // FIXME: Bogus location information
5543 SourceLocation CommaLoc;
5544 if (Args.size() > 1) {
5545 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005546 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005547 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5548 }
5549 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5550 T,
5551 /*FIXME:*/E->getTypeBeginLoc(),
5552 move_arg(Args),
5553 &CommaLoc,
5554 E->getLocEnd());
5555}
Mike Stump11289f42009-09-09 15:08:12 +00005556
Douglas Gregora16548e2009-08-11 05:31:07 +00005557template<typename Derived>
5558Sema::OwningExprResult
5559TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005560 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5562 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5563 if (T.isNull())
5564 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005565
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 bool ArgumentChanged = false;
5567 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5568 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5569 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5570 ArgEnd = E->arg_end();
5571 Arg != ArgEnd; ++Arg) {
5572 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5573 if (TransArg.isInvalid())
5574 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005575
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5577 FakeCommaLocs.push_back(
5578 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5579 Args.push_back(TransArg.takeAs<Expr>());
5580 }
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 if (!getDerived().AlwaysRebuild() &&
5583 T == E->getTypeAsWritten() &&
5584 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005585 return SemaRef.Owned(E->Retain());
5586
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 // FIXME: we're faking the locations of the commas
5588 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5589 T,
5590 E->getLParenLoc(),
5591 move_arg(Args),
5592 FakeCommaLocs.data(),
5593 E->getRParenLoc());
5594}
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregora16548e2009-08-11 05:31:07 +00005596template<typename Derived>
5597Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005598TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005599 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005601 OwningExprResult Base(SemaRef, (Expr*) 0);
5602 Expr *OldBase;
5603 QualType BaseType;
5604 QualType ObjectType;
5605 if (!E->isImplicitAccess()) {
5606 OldBase = E->getBase();
5607 Base = getDerived().TransformExpr(OldBase);
5608 if (Base.isInvalid())
5609 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005610
John McCall2d74de92009-12-01 22:10:20 +00005611 // Start the member reference and compute the object's type.
5612 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005613 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005614 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5615 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005616 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005617 ObjectTy,
5618 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005619 if (Base.isInvalid())
5620 return SemaRef.ExprError();
5621
5622 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5623 BaseType = ((Expr*) Base.get())->getType();
5624 } else {
5625 OldBase = 0;
5626 BaseType = getDerived().TransformType(E->getBaseType());
5627 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5628 }
Mike Stump11289f42009-09-09 15:08:12 +00005629
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005630 // Transform the first part of the nested-name-specifier that qualifies
5631 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005632 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005633 = getDerived().TransformFirstQualifierInScope(
5634 E->getFirstQualifierFoundInScope(),
5635 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005637 NestedNameSpecifier *Qualifier = 0;
5638 if (E->getQualifier()) {
5639 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5640 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005641 ObjectType,
5642 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005643 if (!Qualifier)
5644 return SemaRef.ExprError();
5645 }
Mike Stump11289f42009-09-09 15:08:12 +00005646
5647 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005648 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005649 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005650 if (!Name)
5651 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCall2d74de92009-12-01 22:10:20 +00005653 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005654 // This is a reference to a member without an explicitly-specified
5655 // template argument list. Optimize for this common case.
5656 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005657 Base.get() == OldBase &&
5658 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005659 Qualifier == E->getQualifier() &&
5660 Name == E->getMember() &&
5661 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005662 return SemaRef.Owned(E->Retain());
5663
John McCall8cd78132009-11-19 22:55:06 +00005664 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005665 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005666 E->isArrow(),
5667 E->getOperatorLoc(),
5668 Qualifier,
5669 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005670 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005671 Name,
5672 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005673 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005674 }
5675
John McCall6b51f282009-11-23 01:53:49 +00005676 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005677 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005678 TemplateArgumentLoc Loc;
5679 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005680 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005681 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005682 }
Mike Stump11289f42009-09-09 15:08:12 +00005683
John McCall8cd78132009-11-19 22:55:06 +00005684 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005685 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 E->isArrow(),
5687 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005688 Qualifier,
5689 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005690 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005691 Name,
5692 E->getMemberLoc(),
5693 &TransArgs);
5694}
5695
5696template<typename Derived>
5697Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005698TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005699 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005700 OwningExprResult Base(SemaRef, (Expr*) 0);
5701 QualType BaseType;
5702 if (!Old->isImplicitAccess()) {
5703 Base = getDerived().TransformExpr(Old->getBase());
5704 if (Base.isInvalid())
5705 return SemaRef.ExprError();
5706 BaseType = ((Expr*) Base.get())->getType();
5707 } else {
5708 BaseType = getDerived().TransformType(Old->getBaseType());
5709 }
John McCall10eae182009-11-30 22:42:35 +00005710
5711 NestedNameSpecifier *Qualifier = 0;
5712 if (Old->getQualifier()) {
5713 Qualifier
5714 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005715 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005716 if (Qualifier == 0)
5717 return SemaRef.ExprError();
5718 }
5719
5720 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5721 Sema::LookupOrdinaryName);
5722
5723 // Transform all the decls.
5724 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5725 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005726 NamedDecl *InstD = static_cast<NamedDecl*>(
5727 getDerived().TransformDecl(Old->getMemberLoc(),
5728 *I));
John McCall84d87672009-12-10 09:41:52 +00005729 if (!InstD) {
5730 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5731 // This can happen because of dependent hiding.
5732 if (isa<UsingShadowDecl>(*I))
5733 continue;
5734 else
5735 return SemaRef.ExprError();
5736 }
John McCall10eae182009-11-30 22:42:35 +00005737
5738 // Expand using declarations.
5739 if (isa<UsingDecl>(InstD)) {
5740 UsingDecl *UD = cast<UsingDecl>(InstD);
5741 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5742 E = UD->shadow_end(); I != E; ++I)
5743 R.addDecl(*I);
5744 continue;
5745 }
5746
5747 R.addDecl(InstD);
5748 }
5749
5750 R.resolveKind();
5751
5752 TemplateArgumentListInfo TransArgs;
5753 if (Old->hasExplicitTemplateArgs()) {
5754 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5755 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5756 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5757 TemplateArgumentLoc Loc;
5758 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5759 Loc))
5760 return SemaRef.ExprError();
5761 TransArgs.addArgument(Loc);
5762 }
5763 }
John McCall38836f02010-01-15 08:34:02 +00005764
5765 // FIXME: to do this check properly, we will need to preserve the
5766 // first-qualifier-in-scope here, just in case we had a dependent
5767 // base (and therefore couldn't do the check) and a
5768 // nested-name-qualifier (and therefore could do the lookup).
5769 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005770
5771 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005772 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005773 Old->getOperatorLoc(),
5774 Old->isArrow(),
5775 Qualifier,
5776 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005777 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005778 R,
5779 (Old->hasExplicitTemplateArgs()
5780 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005781}
5782
5783template<typename Derived>
5784Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005785TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005786 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005787}
5788
Mike Stump11289f42009-09-09 15:08:12 +00005789template<typename Derived>
5790Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005791TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005792 TypeSourceInfo *EncodedTypeInfo
5793 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5794 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005798 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005799 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005800
5801 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005802 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 E->getRParenLoc());
5804}
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregora16548e2009-08-11 05:31:07 +00005806template<typename Derived>
5807Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005808TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005809 // Transform arguments.
5810 bool ArgChanged = false;
5811 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5812 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5813 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5814 if (Arg.isInvalid())
5815 return SemaRef.ExprError();
5816
5817 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5818 Args.push_back(Arg.takeAs<Expr>());
5819 }
5820
5821 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5822 // Class message: transform the receiver type.
5823 TypeSourceInfo *ReceiverTypeInfo
5824 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5825 if (!ReceiverTypeInfo)
5826 return SemaRef.ExprError();
5827
5828 // If nothing changed, just retain the existing message send.
5829 if (!getDerived().AlwaysRebuild() &&
5830 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5831 return SemaRef.Owned(E->Retain());
5832
5833 // Build a new class message send.
5834 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5835 E->getSelector(),
5836 E->getMethodDecl(),
5837 E->getLeftLoc(),
5838 move_arg(Args),
5839 E->getRightLoc());
5840 }
5841
5842 // Instance message: transform the receiver
5843 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5844 "Only class and instance messages may be instantiated");
5845 OwningExprResult Receiver
5846 = getDerived().TransformExpr(E->getInstanceReceiver());
5847 if (Receiver.isInvalid())
5848 return SemaRef.ExprError();
5849
5850 // If nothing changed, just retain the existing message send.
5851 if (!getDerived().AlwaysRebuild() &&
5852 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5853 return SemaRef.Owned(E->Retain());
5854
5855 // Build a new instance message send.
5856 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5857 E->getSelector(),
5858 E->getMethodDecl(),
5859 E->getLeftLoc(),
5860 move_arg(Args),
5861 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005862}
5863
Mike Stump11289f42009-09-09 15:08:12 +00005864template<typename Derived>
5865Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005866TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005867 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005868}
5869
Mike Stump11289f42009-09-09 15:08:12 +00005870template<typename Derived>
5871Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005872TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005873 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005874}
5875
Mike Stump11289f42009-09-09 15:08:12 +00005876template<typename Derived>
5877Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005878TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005879 // Transform the base expression.
5880 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5881 if (Base.isInvalid())
5882 return SemaRef.ExprError();
5883
5884 // We don't need to transform the ivar; it will never change.
5885
5886 // If nothing changed, just retain the existing expression.
5887 if (!getDerived().AlwaysRebuild() &&
5888 Base.get() == E->getBase())
5889 return SemaRef.Owned(E->Retain());
5890
5891 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
5892 E->getLocation(),
5893 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00005894}
5895
Mike Stump11289f42009-09-09 15:08:12 +00005896template<typename Derived>
5897Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005898TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00005899 // Transform the base expression.
5900 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5901 if (Base.isInvalid())
5902 return SemaRef.ExprError();
5903
5904 // We don't need to transform the property; it will never change.
5905
5906 // If nothing changed, just retain the existing expression.
5907 if (!getDerived().AlwaysRebuild() &&
5908 Base.get() == E->getBase())
5909 return SemaRef.Owned(E->Retain());
5910
5911 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
5912 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00005913}
5914
Mike Stump11289f42009-09-09 15:08:12 +00005915template<typename Derived>
5916Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005917TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005918 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 // FIXME: Implement this!
5920 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005921 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005922}
5923
Mike Stump11289f42009-09-09 15:08:12 +00005924template<typename Derived>
5925Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005926TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005927 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005928 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005929}
5930
Mike Stump11289f42009-09-09 15:08:12 +00005931template<typename Derived>
5932Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005933TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00005934 // Transform the base expression.
5935 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5936 if (Base.isInvalid())
5937 return SemaRef.ExprError();
5938
5939 // If nothing changed, just retain the existing expression.
5940 if (!getDerived().AlwaysRebuild() &&
5941 Base.get() == E->getBase())
5942 return SemaRef.Owned(E->Retain());
5943
5944 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
5945 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00005946}
5947
Mike Stump11289f42009-09-09 15:08:12 +00005948template<typename Derived>
5949Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005950TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005951 bool ArgumentChanged = false;
5952 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5953 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5954 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5955 if (SubExpr.isInvalid())
5956 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregora16548e2009-08-11 05:31:07 +00005958 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5959 SubExprs.push_back(SubExpr.takeAs<Expr>());
5960 }
Mike Stump11289f42009-09-09 15:08:12 +00005961
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 if (!getDerived().AlwaysRebuild() &&
5963 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005964 return SemaRef.Owned(E->Retain());
5965
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5967 move_arg(SubExprs),
5968 E->getRParenLoc());
5969}
5970
Mike Stump11289f42009-09-09 15:08:12 +00005971template<typename Derived>
5972Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005973TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005974 // FIXME: Implement this!
5975 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005976 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005977}
5978
Mike Stump11289f42009-09-09 15:08:12 +00005979template<typename Derived>
5980Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005982 // FIXME: Implement this!
5983 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005984 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985}
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregora16548e2009-08-11 05:31:07 +00005987//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005988// Type reconstruction
5989//===----------------------------------------------------------------------===//
5990
Mike Stump11289f42009-09-09 15:08:12 +00005991template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005992QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5993 SourceLocation Star) {
5994 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005995 getDerived().getBaseEntity());
5996}
5997
Mike Stump11289f42009-09-09 15:08:12 +00005998template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005999QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6000 SourceLocation Star) {
6001 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006002 getDerived().getBaseEntity());
6003}
6004
Mike Stump11289f42009-09-09 15:08:12 +00006005template<typename Derived>
6006QualType
John McCall70dd5f62009-10-30 00:06:24 +00006007TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6008 bool WrittenAsLValue,
6009 SourceLocation Sigil) {
6010 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6011 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006012}
6013
6014template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006015QualType
John McCall70dd5f62009-10-30 00:06:24 +00006016TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6017 QualType ClassType,
6018 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006019 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006020 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006021}
6022
6023template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006024QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006025TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6026 ArrayType::ArraySizeModifier SizeMod,
6027 const llvm::APInt *Size,
6028 Expr *SizeExpr,
6029 unsigned IndexTypeQuals,
6030 SourceRange BracketsRange) {
6031 if (SizeExpr || !Size)
6032 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6033 IndexTypeQuals, BracketsRange,
6034 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006035
6036 QualType Types[] = {
6037 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6038 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6039 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006040 };
6041 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6042 QualType SizeType;
6043 for (unsigned I = 0; I != NumTypes; ++I)
6044 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6045 SizeType = Types[I];
6046 break;
6047 }
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregord6ff3322009-08-04 16:50:30 +00006049 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006050 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006051 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006052 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006053}
Mike Stump11289f42009-09-09 15:08:12 +00006054
Douglas Gregord6ff3322009-08-04 16:50:30 +00006055template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006056QualType
6057TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006058 ArrayType::ArraySizeModifier SizeMod,
6059 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006060 unsigned IndexTypeQuals,
6061 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006062 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006063 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006064}
6065
6066template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006067QualType
Mike Stump11289f42009-09-09 15:08:12 +00006068TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006069 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006070 unsigned IndexTypeQuals,
6071 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006072 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006073 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006074}
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregord6ff3322009-08-04 16:50:30 +00006076template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006077QualType
6078TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006079 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006080 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006081 unsigned IndexTypeQuals,
6082 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006083 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006084 SizeExpr.takeAs<Expr>(),
6085 IndexTypeQuals, BracketsRange);
6086}
6087
6088template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006089QualType
6090TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006091 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006092 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006093 unsigned IndexTypeQuals,
6094 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006095 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006096 SizeExpr.takeAs<Expr>(),
6097 IndexTypeQuals, BracketsRange);
6098}
6099
6100template<typename Derived>
6101QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006102 unsigned NumElements,
6103 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006104 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006105 return SemaRef.Context.getVectorType(ElementType, NumElements,
6106 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006107}
Mike Stump11289f42009-09-09 15:08:12 +00006108
Douglas Gregord6ff3322009-08-04 16:50:30 +00006109template<typename Derived>
6110QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6111 unsigned NumElements,
6112 SourceLocation AttributeLoc) {
6113 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6114 NumElements, true);
6115 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006116 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006117 AttributeLoc);
6118 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6119 AttributeLoc);
6120}
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregord6ff3322009-08-04 16:50:30 +00006122template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006123QualType
6124TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006125 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006126 SourceLocation AttributeLoc) {
6127 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6128}
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregord6ff3322009-08-04 16:50:30 +00006130template<typename Derived>
6131QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006132 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006133 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006134 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006135 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006136 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006137 Quals,
6138 getDerived().getBaseLocation(),
6139 getDerived().getBaseEntity());
6140}
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregord6ff3322009-08-04 16:50:30 +00006142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006143QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6144 return SemaRef.Context.getFunctionNoProtoType(T);
6145}
6146
6147template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006148QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6149 assert(D && "no decl found");
6150 if (D->isInvalidDecl()) return QualType();
6151
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006152 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006153 TypeDecl *Ty;
6154 if (isa<UsingDecl>(D)) {
6155 UsingDecl *Using = cast<UsingDecl>(D);
6156 assert(Using->isTypeName() &&
6157 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6158
6159 // A valid resolved using typename decl points to exactly one type decl.
6160 assert(++Using->shadow_begin() == Using->shadow_end());
6161 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6162
6163 } else {
6164 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6165 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6166 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6167 }
6168
6169 return SemaRef.Context.getTypeDeclType(Ty);
6170}
6171
6172template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006173QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006174 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6175}
6176
6177template<typename Derived>
6178QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6179 return SemaRef.Context.getTypeOfType(Underlying);
6180}
6181
6182template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006183QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006184 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6185}
6186
6187template<typename Derived>
6188QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006189 TemplateName Template,
6190 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006191 const TemplateArgumentListInfo &TemplateArgs) {
6192 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006193}
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregor1135c352009-08-06 05:28:30 +00006195template<typename Derived>
6196NestedNameSpecifier *
6197TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6198 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006199 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006200 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006201 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006202 CXXScopeSpec SS;
6203 // FIXME: The source location information is all wrong.
6204 SS.setRange(Range);
6205 SS.setScopeRep(Prefix);
6206 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006207 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006208 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006209 ObjectType,
6210 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006211 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006212}
6213
6214template<typename Derived>
6215NestedNameSpecifier *
6216TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6217 SourceRange Range,
6218 NamespaceDecl *NS) {
6219 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6220}
6221
6222template<typename Derived>
6223NestedNameSpecifier *
6224TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6225 SourceRange Range,
6226 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006227 QualType T) {
6228 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006229 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006230 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006231 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6232 T.getTypePtr());
6233 }
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregor1135c352009-08-06 05:28:30 +00006235 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6236 return 0;
6237}
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregor71dc5092009-08-06 06:41:21 +00006239template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006240TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006241TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6242 bool TemplateKW,
6243 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006244 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006245 Template);
6246}
6247
6248template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006249TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006250TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006251 const IdentifierInfo &II,
6252 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006253 CXXScopeSpec SS;
6254 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006255 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006256 UnqualifiedId Name;
6257 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006258 return getSema().ActOnDependentTemplateName(
6259 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006260 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006261 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006262 ObjectType.getAsOpaquePtr(),
6263 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006264 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006265}
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregora16548e2009-08-11 05:31:07 +00006267template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006268TemplateName
6269TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6270 OverloadedOperatorKind Operator,
6271 QualType ObjectType) {
6272 CXXScopeSpec SS;
6273 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6274 SS.setScopeRep(Qualifier);
6275 UnqualifiedId Name;
6276 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6277 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6278 Operator, SymbolLocations);
6279 return getSema().ActOnDependentTemplateName(
6280 /*FIXME:*/getDerived().getBaseLocation(),
6281 SS,
6282 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006283 ObjectType.getAsOpaquePtr(),
6284 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006285 .template getAsVal<TemplateName>();
6286}
6287
6288template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006289Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006290TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6291 SourceLocation OpLoc,
6292 ExprArg Callee,
6293 ExprArg First,
6294 ExprArg Second) {
6295 Expr *FirstExpr = (Expr *)First.get();
6296 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006297 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregora16548e2009-08-11 05:31:07 +00006300 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006301 if (Op == OO_Subscript) {
6302 if (!FirstExpr->getType()->isOverloadableType() &&
6303 !SecondExpr->getType()->isOverloadableType())
6304 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006305 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006306 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006307 } else if (Op == OO_Arrow) {
6308 // -> is never a builtin operation.
6309 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006310 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006311 if (!FirstExpr->getType()->isOverloadableType()) {
6312 // The argument is not of overloadable type, so try to create a
6313 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006314 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006315 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006316
Douglas Gregora16548e2009-08-11 05:31:07 +00006317 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6318 }
6319 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006320 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006321 !SecondExpr->getType()->isOverloadableType()) {
6322 // Neither of the arguments is an overloadable type, so try to
6323 // create a built-in binary operation.
6324 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006325 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6327 if (Result.isInvalid())
6328 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregora16548e2009-08-11 05:31:07 +00006330 First.release();
6331 Second.release();
6332 return move(Result);
6333 }
6334 }
Mike Stump11289f42009-09-09 15:08:12 +00006335
6336 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006337 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006338 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006339
John McCalld14a8642009-11-21 08:51:07 +00006340 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6341 assert(ULE->requiresADL());
6342
6343 // FIXME: Do we have to check
6344 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006345 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006346 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006347 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006348 }
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 // Add any functions found via argument-dependent lookup.
6351 Expr *Args[2] = { FirstExpr, SecondExpr };
6352 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006353
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 // Create the overloaded operator invocation for unary operators.
6355 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006356 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006357 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6358 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6359 }
Mike Stump11289f42009-09-09 15:08:12 +00006360
Sebastian Redladba46e2009-10-29 20:17:01 +00006361 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006362 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6363 OpLoc,
6364 move(First),
6365 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006366
Douglas Gregora16548e2009-08-11 05:31:07 +00006367 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006368 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006369 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006370 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006371 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6372 if (Result.isInvalid())
6373 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregora16548e2009-08-11 05:31:07 +00006375 First.release();
6376 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006377 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006378}
Mike Stump11289f42009-09-09 15:08:12 +00006379
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006380template<typename Derived>
6381Sema::OwningExprResult
6382TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6383 SourceLocation OperatorLoc,
6384 bool isArrow,
6385 NestedNameSpecifier *Qualifier,
6386 SourceRange QualifierRange,
6387 TypeSourceInfo *ScopeType,
6388 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006389 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006390 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006391 CXXScopeSpec SS;
6392 if (Qualifier) {
6393 SS.setRange(QualifierRange);
6394 SS.setScopeRep(Qualifier);
6395 }
6396
6397 Expr *BaseE = (Expr *)Base.get();
6398 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006399 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006400 (!isArrow && !BaseType->getAs<RecordType>()) ||
6401 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006402 !BaseType->getAs<PointerType>()->getPointeeType()
6403 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006404 // This pseudo-destructor expression is still a pseudo-destructor.
6405 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6406 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006407 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006408 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006409 /*FIXME?*/true);
6410 }
6411
Douglas Gregor678f90d2010-02-25 01:56:36 +00006412 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006413 DeclarationName Name
6414 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6415 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6416
6417 // FIXME: the ScopeType should be tacked onto SS.
6418
6419 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6420 OperatorLoc, isArrow,
6421 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006422 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006423 /*TemplateArgs*/ 0);
6424}
6425
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426} // end namespace clang
6427
6428#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H