blob: 69994cd1d2f919c672dd6307dfcd7378ed19d166 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
Alexis Hunta8136cc2010-05-05 15:23:54 +000099
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000253 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Alexis Hunta8136cc2010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Alexis Hunta8136cc2010-05-05 15:23:54 +0000336 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
Mike Stump11289f42009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000499 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500
Mike Stump11289f42009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000510 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000533 /// By default, builds a new DependentNameType type from the
534 /// nested-name-specifier and the given type. Subclasses may override
535 /// this routine to provide different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000536 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000538 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000539 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000540 CXXScopeSpec SS;
541 SS.setScopeRep(NNS);
542 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000543 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000546
547 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000548 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549
550 /// \brief Build a new typename type that refers to an identifier.
551 ///
552 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000553 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000555 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000556 NestedNameSpecifier *NNS,
557 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000558 SourceLocation KeywordLoc,
559 SourceRange NNSRange,
560 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000561 CXXScopeSpec SS;
562 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000563 SS.setRange(NNSRange);
564
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 if (NNS->isDependent()) {
566 // If the name is still dependent, just build a new dependent name type.
567 if (!SemaRef.computeDeclContext(SS))
568 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
569 }
570
Abramo Bagnara6150c882010-05-11 21:36:43 +0000571 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
573 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000574
575 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
576
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 // into a non-dependent elaborated-type-specifier. Find the tag we're
579 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000580 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
582 if (!DC)
583 return QualType();
584
585 TagDecl *Tag = 0;
586 SemaRef.LookupQualifiedName(Result, DC);
587 switch (Result.getResultKind()) {
588 case LookupResult::NotFound:
589 case LookupResult::NotFoundInCurrentInstantiation:
590 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000591
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 case LookupResult::Found:
593 Tag = Result.getAsSingle<TagDecl>();
594 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000595
Douglas Gregore677daf2010-03-31 22:19:08 +0000596 case LookupResult::FoundOverloaded:
597 case LookupResult::FoundUnresolvedValue:
598 llvm_unreachable("Tag lookup cannot find non-tags");
599 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000600
Douglas Gregore677daf2010-03-31 22:19:08 +0000601 case LookupResult::Ambiguous:
602 // Let the LookupResult structure handle ambiguities.
603 return QualType();
604 }
605
606 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000607 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000608 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000609 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 return QualType();
611 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000612
Abramo Bagnarad7548482010-05-19 21:37:53 +0000613 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
614 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
616 return QualType();
617 }
618
619 // Build the elaborated-type-specifier type.
620 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000621 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000622 }
Mike Stump11289f42009-09-09 15:08:12 +0000623
Douglas Gregor1135c352009-08-06 05:28:30 +0000624 /// \brief Build a new nested-name-specifier given the prefix and an
625 /// identifier that names the next step in the nested-name-specifier.
626 ///
627 /// By default, performs semantic analysis when building the new
628 /// nested-name-specifier. Subclasses may override this routine to provide
629 /// different behavior.
630 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
631 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000632 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000633 QualType ObjectType,
634 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000635
636 /// \brief Build a new nested-name-specifier given the prefix and the
637 /// namespace named in 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,
644 NamespaceDecl *NS);
645
646 /// \brief Build a new nested-name-specifier given the prefix and the
647 /// type named in the next step in the nested-name-specifier.
648 ///
649 /// By default, performs semantic analysis when building the new
650 /// nested-name-specifier. Subclasses may override this routine to provide
651 /// different behavior.
652 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653 SourceRange Range,
654 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000655 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000656
657 /// \brief Build a new template name given a nested name specifier, a flag
658 /// indicating whether the "template" keyword was provided, and the template
659 /// that the template name refers to.
660 ///
661 /// By default, builds the new template name directly. Subclasses may override
662 /// this routine to provide different behavior.
663 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
664 bool TemplateKW,
665 TemplateDecl *Template);
666
Douglas Gregor71dc5092009-08-06 06:41:21 +0000667 /// \brief Build a new template name given a nested name specifier and the
668 /// name that is referred to as a template.
669 ///
670 /// By default, performs semantic analysis to determine whether the name can
671 /// be resolved to a specific template, then builds the appropriate kind of
672 /// template name. Subclasses may override this routine to provide different
673 /// behavior.
674 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000675 const IdentifierInfo &II,
676 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000677
Douglas Gregor71395fa2009-11-04 00:56:37 +0000678 /// \brief Build a new template name given a nested name specifier and the
679 /// overloaded operator name that is referred to as a template.
680 ///
681 /// By default, performs semantic analysis to determine whether the name can
682 /// be resolved to a specific template, then builds the appropriate kind of
683 /// template name. Subclasses may override this routine to provide different
684 /// behavior.
685 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686 OverloadedOperatorKind Operator,
687 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000688
Douglas Gregorebe10102009-08-20 07:17:43 +0000689 /// \brief Build a new compound statement.
690 ///
691 /// By default, performs semantic analysis to build the new statement.
692 /// Subclasses may override this routine to provide different behavior.
693 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
694 MultiStmtArg Statements,
695 SourceLocation RBraceLoc,
696 bool IsStmtExpr) {
697 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
698 IsStmtExpr);
699 }
700
701 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
706 ExprArg LHS,
707 SourceLocation EllipsisLoc,
708 ExprArg RHS,
709 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000710 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000711 ColonLoc);
712 }
Mike Stump11289f42009-09-09 15:08:12 +0000713
Douglas Gregorebe10102009-08-20 07:17:43 +0000714 /// \brief Attach the body to a new case statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
719 getSema().ActOnCaseStmtBody(S.get(), move(Body));
720 return move(S);
721 }
Mike Stump11289f42009-09-09 15:08:12 +0000722
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 /// \brief Build a new default statement.
724 ///
725 /// By default, performs semantic analysis to build the new statement.
726 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000727 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 SourceLocation ColonLoc,
729 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000730 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 /*CurScope=*/0);
732 }
Mike Stump11289f42009-09-09 15:08:12 +0000733
Douglas Gregorebe10102009-08-20 07:17:43 +0000734 /// \brief Build a new label statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000738 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 IdentifierInfo *Id,
740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
742 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
743 }
Mike Stump11289f42009-09-09 15:08:12 +0000744
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 /// \brief Build a new "if" statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000749 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000750 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000751 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000752 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000753 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 }
Mike Stump11289f42009-09-09 15:08:12 +0000755
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 /// \brief Start building a new switch statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000760 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
761 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000762 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000763 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
764 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 }
Mike Stump11289f42009-09-09 15:08:12 +0000766
Douglas Gregorebe10102009-08-20 07:17:43 +0000767 /// \brief Attach the body to the switch statement.
768 ///
769 /// By default, performs semantic analysis to build the new statement.
770 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000771 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 StmtArg Switch, StmtArg Body) {
773 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
774 move(Body));
775 }
776
777 /// \brief Build a new while statement.
778 ///
779 /// By default, performs semantic analysis to build the new statement.
780 /// Subclasses may override this routine to provide different behavior.
781 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000782 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000783 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000785 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000786 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 }
Mike Stump11289f42009-09-09 15:08:12 +0000788
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 /// \brief Build a new do-while statement.
790 ///
791 /// By default, performs semantic analysis to build the new statement.
792 /// Subclasses may override this routine to provide different behavior.
793 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
794 SourceLocation WhileLoc,
795 SourceLocation LParenLoc,
796 ExprArg Cond,
797 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000798 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000799 move(Cond), RParenLoc);
800 }
801
802 /// \brief Build a new for statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000806 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000808 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000809 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000811 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000812 DeclPtrTy::make(CondVar),
813 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 }
Mike Stump11289f42009-09-09 15:08:12 +0000815
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 /// \brief Build a new goto statement.
817 ///
818 /// By default, performs semantic analysis to build the new statement.
819 /// Subclasses may override this routine to provide different behavior.
820 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
821 SourceLocation LabelLoc,
822 LabelStmt *Label) {
823 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
824 }
825
826 /// \brief Build a new indirect 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 RebuildIndirectGotoStmt(SourceLocation GotoLoc,
831 SourceLocation StarLoc,
832 ExprArg Target) {
833 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
834 }
Mike Stump11289f42009-09-09 15:08:12 +0000835
Douglas Gregorebe10102009-08-20 07:17:43 +0000836 /// \brief Build a new return 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 RebuildReturnStmt(SourceLocation ReturnLoc,
841 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000842
Douglas Gregorebe10102009-08-20 07:17:43 +0000843 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
844 }
Mike Stump11289f42009-09-09 15:08:12 +0000845
Douglas Gregorebe10102009-08-20 07:17:43 +0000846 /// \brief Build a new declaration 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 RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000851 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 SourceLocation EndLoc) {
853 return getSema().Owned(
854 new (getSema().Context) DeclStmt(
855 DeclGroupRef::Create(getSema().Context,
856 Decls, NumDecls),
857 StartLoc, EndLoc));
858 }
Mike Stump11289f42009-09-09 15:08:12 +0000859
Anders Carlssonaaeef072010-01-24 05:50:09 +0000860 /// \brief Build a new inline asm statement.
861 ///
862 /// By default, performs semantic analysis to build the new statement.
863 /// Subclasses may override this routine to provide different behavior.
864 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
865 bool IsSimple,
866 bool IsVolatile,
867 unsigned NumOutputs,
868 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000869 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000870 MultiExprArg Constraints,
871 MultiExprArg Exprs,
872 ExprArg AsmString,
873 MultiExprArg Clobbers,
874 SourceLocation RParenLoc,
875 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000876 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000877 NumInputs, Names, move(Constraints),
878 move(Exprs), move(AsmString), move(Clobbers),
879 RParenLoc, MSAsm);
880 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000881
882 /// \brief Build a new Objective-C @try statement.
883 ///
884 /// By default, performs semantic analysis to build the new statement.
885 /// Subclasses may override this routine to provide different behavior.
886 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
887 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000888 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000889 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000890 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000891 move(Finally));
892 }
893
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000894 /// \brief Rebuild an Objective-C exception declaration.
895 ///
896 /// By default, performs semantic analysis to build the new declaration.
897 /// Subclasses may override this routine to provide different behavior.
898 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
899 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000900 return getSema().BuildObjCExceptionDecl(TInfo, T,
901 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000902 ExceptionDecl->getLocation());
903 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000904
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000905 /// \brief Build a new Objective-C @catch statement.
906 ///
907 /// By default, performs semantic analysis to build the new statement.
908 /// Subclasses may override this routine to provide different behavior.
909 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
910 SourceLocation RParenLoc,
911 VarDecl *Var,
912 StmtArg Body) {
913 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
914 Sema::DeclPtrTy::make(Var),
915 move(Body));
916 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000917
Douglas Gregor306de2f2010-04-22 23:59:56 +0000918 /// \brief Build a new Objective-C @finally statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
922 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
923 StmtArg Body) {
924 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
925 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000926
Douglas Gregor6148de72010-04-22 22:01:21 +0000927 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000928 ///
929 /// By default, performs semantic analysis to build the new statement.
930 /// Subclasses may override this routine to provide different behavior.
931 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
932 ExprArg Operand) {
933 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
934 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000935
Douglas Gregor6148de72010-04-22 22:01:21 +0000936 /// \brief Build a new Objective-C @synchronized statement.
937 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000938 /// By default, performs semantic analysis to build the new statement.
939 /// Subclasses may override this routine to provide different behavior.
940 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
941 ExprArg Object,
942 StmtArg Body) {
943 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
944 move(Body));
945 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000946
947 /// \brief Build a new Objective-C fast enumeration statement.
948 ///
949 /// By default, performs semantic analysis to build the new statement.
950 /// Subclasses may override this routine to provide different behavior.
951 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
952 SourceLocation LParenLoc,
953 StmtArg Element,
954 ExprArg Collection,
955 SourceLocation RParenLoc,
956 StmtArg Body) {
957 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000958 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000959 move(Collection),
960 RParenLoc,
961 move(Body));
962 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000963
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 /// \brief Build a new C++ exception declaration.
965 ///
966 /// By default, performs semantic analysis to build the new decaration.
967 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000968 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000969 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 IdentifierInfo *Name,
971 SourceLocation Loc,
972 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000973 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 TypeRange);
975 }
976
977 /// \brief Build a new C++ catch statement.
978 ///
979 /// By default, performs semantic analysis to build the new statement.
980 /// Subclasses may override this routine to provide different behavior.
981 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
982 VarDecl *ExceptionDecl,
983 StmtArg Handler) {
984 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000985 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 Handler.takeAs<Stmt>()));
987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 /// \brief Build a new C++ try statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
993 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
994 StmtArg TryBlock,
995 MultiStmtArg Handlers) {
996 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregora16548e2009-08-11 05:31:07 +0000999 /// \brief Build a new expression that references a declaration.
1000 ///
1001 /// By default, performs semantic analysis to build the new expression.
1002 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001003 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1004 LookupResult &R,
1005 bool RequiresADL) {
1006 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1007 }
1008
1009
1010 /// \brief Build a new expression that references a declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001014 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1015 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001016 ValueDecl *VD, SourceLocation Loc,
1017 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001018 CXXScopeSpec SS;
1019 SS.setScopeRep(Qualifier);
1020 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001021
1022 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001023
John McCallce546572009-12-08 09:08:17 +00001024 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 }
Mike Stump11289f42009-09-09 15:08:12 +00001026
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001028 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
1031 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1032 SourceLocation RParen) {
1033 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1034 }
1035
Douglas Gregorad8a3362009-09-04 17:36:40 +00001036 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001037 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001038 /// By default, performs semantic analysis to build the new expression.
1039 /// Subclasses may override this routine to provide different behavior.
1040 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1041 SourceLocation OperatorLoc,
1042 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001043 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001044 SourceRange QualifierRange,
1045 TypeSourceInfo *ScopeType,
1046 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001047 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001048 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001049
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001051 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
1054 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1055 UnaryOperator::Opcode Opc,
1056 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001057 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 }
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregor882211c2010-04-28 22:16:22 +00001060 /// \brief Build a new builtin offsetof expression.
1061 ///
1062 /// By default, performs semantic analysis to build the new expression.
1063 /// Subclasses may override this routine to provide different behavior.
1064 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1065 TypeSourceInfo *Type,
1066 Action::OffsetOfComponent *Components,
1067 unsigned NumComponents,
1068 SourceLocation RParenLoc) {
1069 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1070 NumComponents, RParenLoc);
1071 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001072
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001074 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001075 /// By default, performs semantic analysis to build the new expression.
1076 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001077 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001078 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001079 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001080 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001081 }
1082
Mike Stump11289f42009-09-09 15:08:12 +00001083 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001085 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 /// By default, performs semantic analysis to build the new expression.
1087 /// Subclasses may override this routine to provide different behavior.
1088 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1089 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001090 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1092 OpLoc, isSizeOf, R);
1093 if (Result.isInvalid())
1094 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001095
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 SubExpr.release();
1097 return move(Result);
1098 }
Mike Stump11289f42009-09-09 15:08:12 +00001099
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001101 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// By default, performs semantic analysis to build the new expression.
1103 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001104 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 SourceLocation LBracketLoc,
1106 ExprArg RHS,
1107 SourceLocation RBracketLoc) {
1108 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001109 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 RBracketLoc);
1111 }
1112
1113 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001114 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
1117 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1118 MultiExprArg Args,
1119 SourceLocation *CommaLocs,
1120 SourceLocation RParenLoc) {
1121 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1122 move(Args), CommaLocs, RParenLoc);
1123 }
1124
1125 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001126 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 /// By default, performs semantic analysis to build the new expression.
1128 /// Subclasses may override this routine to provide different behavior.
1129 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001130 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001131 NestedNameSpecifier *Qualifier,
1132 SourceRange QualifierRange,
1133 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001134 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001135 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001136 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001137 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001138 if (!Member->getDeclName()) {
1139 // We have a reference to an unnamed field.
1140 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001142 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001143 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1144 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001145 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001146
Mike Stump11289f42009-09-09 15:08:12 +00001147 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001148 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001149 Member, MemberLoc,
1150 cast<FieldDecl>(Member)->getType());
1151 return getSema().Owned(ME);
1152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001154 CXXScopeSpec SS;
1155 if (Qualifier) {
1156 SS.setRange(QualifierRange);
1157 SS.setScopeRep(Qualifier);
1158 }
1159
John McCall2d74de92009-12-01 22:10:20 +00001160 QualType BaseType = ((Expr*) Base.get())->getType();
1161
John McCall16df1e52010-03-30 21:47:33 +00001162 // FIXME: this involves duplicating earlier analysis in a lot of
1163 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001164 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1165 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001166 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001167 R.resolveKind();
1168
John McCall2d74de92009-12-01 22:10:20 +00001169 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1170 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001171 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001172 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 }
Mike Stump11289f42009-09-09 15:08:12 +00001174
Douglas Gregora16548e2009-08-11 05:31:07 +00001175 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001176 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001177 /// By default, performs semantic analysis to build the new expression.
1178 /// Subclasses may override this routine to provide different behavior.
1179 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1180 BinaryOperator::Opcode Opc,
1181 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001182 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001183 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001184 }
1185
1186 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001187 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
1190 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1191 SourceLocation QuestionLoc,
1192 ExprArg LHS,
1193 SourceLocation ColonLoc,
1194 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001195 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 move(LHS), move(RHS));
1197 }
1198
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001200 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 /// By default, performs semantic analysis to build the new expression.
1202 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001203 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1204 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 SourceLocation RParenLoc,
1206 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001207 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1208 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 }
Mike Stump11289f42009-09-09 15:08:12 +00001210
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
1215 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001216 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 SourceLocation RParenLoc,
1218 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001219 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1220 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 }
Mike Stump11289f42009-09-09 15:08:12 +00001222
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// By default, performs semantic analysis to build the new expression.
1226 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001227 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 SourceLocation OpLoc,
1229 SourceLocation AccessorLoc,
1230 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001231
John McCall10eae182009-11-30 22:42:35 +00001232 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001233 QualType BaseType = ((Expr*) Base.get())->getType();
1234 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001235 OpLoc, /*IsArrow*/ false,
1236 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001237 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001238 AccessorLoc,
1239 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001243 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
1246 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1247 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001248 SourceLocation RBraceLoc,
1249 QualType ResultTy) {
1250 OwningExprResult Result
1251 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1252 if (Result.isInvalid() || ResultTy->isDependentType())
1253 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001254
Douglas Gregord3d93062009-11-09 17:16:50 +00001255 // Patch in the result type we were given, which may have been computed
1256 // when the initial InitListExpr was built.
1257 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1258 ILE->setType(ResultTy);
1259 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 }
Mike Stump11289f42009-09-09 15:08:12 +00001261
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001263 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 /// By default, performs semantic analysis to build the new expression.
1265 /// Subclasses may override this routine to provide different behavior.
1266 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1267 MultiExprArg ArrayExprs,
1268 SourceLocation EqualOrColonLoc,
1269 bool GNUSyntax,
1270 ExprArg Init) {
1271 OwningExprResult Result
1272 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1273 move(Init));
1274 if (Result.isInvalid())
1275 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001276
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 ArrayExprs.release();
1278 return move(Result);
1279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001282 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// By default, builds the implicit value initialization without performing
1284 /// any semantic analysis. Subclasses may override this routine to provide
1285 /// different behavior.
1286 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1287 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1288 }
Mike Stump11289f42009-09-09 15:08:12 +00001289
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001291 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1295 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001296 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 RParenLoc);
1298 }
1299
1300 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
1304 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1305 MultiExprArg SubExprs,
1306 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001307 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001308 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 }
Mike Stump11289f42009-09-09 15:08:12 +00001310
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
1313 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 /// rather than attempting to map the label statement itself.
1315 /// Subclasses may override this routine to provide different behavior.
1316 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1317 SourceLocation LabelLoc,
1318 LabelStmt *Label) {
1319 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1320 }
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001323 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1327 StmtArg SubStmt,
1328 SourceLocation RParenLoc) {
1329 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new __builtin_types_compatible_p expression.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1337 QualType T1, QualType T2,
1338 SourceLocation RParenLoc) {
1339 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1340 T1.getAsOpaquePtr(),
1341 T2.getAsOpaquePtr(),
1342 RParenLoc);
1343 }
Mike Stump11289f42009-09-09 15:08:12 +00001344
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// \brief Build a new __builtin_choose_expr expression.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
1349 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1350 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1351 SourceLocation RParenLoc) {
1352 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1353 move(Cond), move(LHS), move(RHS),
1354 RParenLoc);
1355 }
Mike Stump11289f42009-09-09 15:08:12 +00001356
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// \brief Build a new overloaded operator call expression.
1358 ///
1359 /// By default, performs semantic analysis to build the new expression.
1360 /// The semantic analysis provides the behavior of template instantiation,
1361 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001362 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 /// argument-dependent lookup, etc. Subclasses may override this routine to
1364 /// provide different behavior.
1365 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1366 SourceLocation OpLoc,
1367 ExprArg Callee,
1368 ExprArg First,
1369 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001370
1371 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// reinterpret_cast.
1373 ///
1374 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001375 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// Subclasses may override this routine to provide different behavior.
1377 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1378 Stmt::StmtClass Class,
1379 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001380 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 SourceLocation RAngleLoc,
1382 SourceLocation LParenLoc,
1383 ExprArg SubExpr,
1384 SourceLocation RParenLoc) {
1385 switch (Class) {
1386 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001387 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001388 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 move(SubExpr), RParenLoc);
1390
1391 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001392 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001393 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001395
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001397 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001398 RAngleLoc, LParenLoc,
1399 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001401
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001403 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001404 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001406
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 default:
1408 assert(false && "Invalid C++ named cast");
1409 break;
1410 }
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 return getSema().ExprError();
1413 }
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 /// \brief Build a new C++ static_cast expression.
1416 ///
1417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
1419 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1420 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001421 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 SourceLocation RAngleLoc,
1423 SourceLocation LParenLoc,
1424 ExprArg SubExpr,
1425 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001426 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1427 TInfo, move(SubExpr),
1428 SourceRange(LAngleLoc, RAngleLoc),
1429 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 }
1431
1432 /// \brief Build a new C++ dynamic_cast expression.
1433 ///
1434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
1436 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1437 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001438 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation RAngleLoc,
1440 SourceLocation LParenLoc,
1441 ExprArg SubExpr,
1442 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001443 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1444 TInfo, move(SubExpr),
1445 SourceRange(LAngleLoc, RAngleLoc),
1446 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 }
1448
1449 /// \brief Build a new C++ reinterpret_cast expression.
1450 ///
1451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
1453 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1454 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001455 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation RAngleLoc,
1457 SourceLocation LParenLoc,
1458 ExprArg SubExpr,
1459 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001460 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1461 TInfo, move(SubExpr),
1462 SourceRange(LAngleLoc, RAngleLoc),
1463 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 }
1465
1466 /// \brief Build a new C++ const_cast expression.
1467 ///
1468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
1470 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1471 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001472 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 SourceLocation RAngleLoc,
1474 SourceLocation LParenLoc,
1475 ExprArg SubExpr,
1476 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001477 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1478 TInfo, move(SubExpr),
1479 SourceRange(LAngleLoc, RAngleLoc),
1480 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 }
Mike Stump11289f42009-09-09 15:08:12 +00001482
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 /// \brief Build a new C++ functional-style cast expression.
1484 ///
1485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
1487 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001488 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 SourceLocation LParenLoc,
1490 ExprArg SubExpr,
1491 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001492 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001494 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001496 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001497 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 RParenLoc);
1499 }
Mike Stump11289f42009-09-09 15:08:12 +00001500
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// \brief Build a new C++ typeid(type) expression.
1502 ///
1503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001505 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1506 SourceLocation TypeidLoc,
1507 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001509 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001510 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new C++ typeid(expr) expression.
1514 ///
1515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001517 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1518 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 ExprArg Operand,
1520 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001521 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1522 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001523 }
1524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new C++ "this" expression.
1526 ///
1527 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001528 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001530 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001531 QualType ThisType,
1532 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001534 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1535 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 }
1537
1538 /// \brief Build a new C++ throw expression.
1539 ///
1540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
1542 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1543 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1544 }
1545
1546 /// \brief Build a new C++ default-argument expression.
1547 ///
1548 /// By default, builds a new default-argument expression, which does not
1549 /// require any semantic analysis. Subclasses may override this routine to
1550 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001551 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001552 ParmVarDecl *Param) {
1553 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1554 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 }
1556
1557 /// \brief Build a new C++ zero-initialization expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001561 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 SourceLocation LParenLoc,
1563 QualType T,
1564 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001565 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1566 T.getAsOpaquePtr(), LParenLoc,
1567 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 0, RParenLoc);
1569 }
Mike Stump11289f42009-09-09 15:08:12 +00001570
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 /// \brief Build a new C++ "new" expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001575 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 bool UseGlobal,
1577 SourceLocation PlacementLParen,
1578 MultiExprArg PlacementArgs,
1579 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001580 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 QualType AllocType,
1582 SourceLocation TypeLoc,
1583 SourceRange TypeRange,
1584 ExprArg ArraySize,
1585 SourceLocation ConstructorLParen,
1586 MultiExprArg ConstructorArgs,
1587 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001588 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 PlacementLParen,
1590 move(PlacementArgs),
1591 PlacementRParen,
1592 ParenTypeId,
1593 AllocType,
1594 TypeLoc,
1595 TypeRange,
1596 move(ArraySize),
1597 ConstructorLParen,
1598 move(ConstructorArgs),
1599 ConstructorRParen);
1600 }
Mike Stump11289f42009-09-09 15:08:12 +00001601
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 /// \brief Build a new C++ "delete" expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
1606 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1607 bool IsGlobalDelete,
1608 bool IsArrayForm,
1609 ExprArg Operand) {
1610 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1611 move(Operand));
1612 }
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 /// \brief Build a new unary type trait expression.
1615 ///
1616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
1618 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1619 SourceLocation StartLoc,
1620 SourceLocation LParenLoc,
1621 QualType T,
1622 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001623 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 T.getAsOpaquePtr(), RParenLoc);
1625 }
1626
Mike Stump11289f42009-09-09 15:08:12 +00001627 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001632 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 SourceRange QualifierRange,
1634 DeclarationName Name,
1635 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001636 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 CXXScopeSpec SS;
1638 SS.setRange(QualifierRange);
1639 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001640
1641 if (TemplateArgs)
1642 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1643 *TemplateArgs);
1644
1645 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 }
1647
1648 /// \brief Build a new template-id expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001652 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1653 LookupResult &R,
1654 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001655 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001656 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 }
1658
1659 /// \brief Build a new object-construction expression.
1660 ///
1661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
1663 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001664 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 CXXConstructorDecl *Constructor,
1666 bool IsElidable,
1667 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001668 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001669 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001670 ConvertedArgs))
1671 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001672
Douglas Gregordb121ba2009-12-14 16:27:04 +00001673 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1674 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 }
1676
1677 /// \brief Build a new object-construction expression.
1678 ///
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
1681 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1682 QualType T,
1683 SourceLocation LParenLoc,
1684 MultiExprArg Args,
1685 SourceLocation *Commas,
1686 SourceLocation RParenLoc) {
1687 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1688 T.getAsOpaquePtr(),
1689 LParenLoc,
1690 move(Args),
1691 Commas,
1692 RParenLoc);
1693 }
1694
1695 /// \brief Build a new object-construction expression.
1696 ///
1697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
1699 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1700 QualType T,
1701 SourceLocation LParenLoc,
1702 MultiExprArg Args,
1703 SourceLocation *Commas,
1704 SourceLocation RParenLoc) {
1705 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1706 /*FIXME*/LParenLoc),
1707 T.getAsOpaquePtr(),
1708 LParenLoc,
1709 move(Args),
1710 Commas,
1711 RParenLoc);
1712 }
Mike Stump11289f42009-09-09 15:08:12 +00001713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 /// \brief Build a new member reference expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001718 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001719 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 bool IsArrow,
1721 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001722 NestedNameSpecifier *Qualifier,
1723 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001724 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001726 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001727 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001729 SS.setRange(QualifierRange);
1730 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001731
John McCall2d74de92009-12-01 22:10:20 +00001732 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1733 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001734 SS, FirstQualifierInScope,
1735 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 }
1737
John McCall10eae182009-11-30 22:42:35 +00001738 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001742 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001743 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001744 SourceLocation OperatorLoc,
1745 bool IsArrow,
1746 NestedNameSpecifier *Qualifier,
1747 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001748 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001749 LookupResult &R,
1750 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001751 CXXScopeSpec SS;
1752 SS.setRange(QualifierRange);
1753 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001754
John McCall2d74de92009-12-01 22:10:20 +00001755 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1756 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001757 SS, FirstQualifierInScope,
1758 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new Objective-C @encode expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
1765 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001766 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001768 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001770 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001771
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001772 /// \brief Build a new Objective-C class message.
1773 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1774 Selector Sel,
1775 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001776 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001777 MultiExprArg Args,
1778 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001779 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1780 ReceiverTypeInfo->getType(),
1781 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001782 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001783 move(Args));
1784 }
1785
1786 /// \brief Build a new Objective-C instance message.
1787 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1788 Selector Sel,
1789 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001790 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001791 MultiExprArg Args,
1792 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001793 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1794 return SemaRef.BuildInstanceMessage(move(Receiver),
1795 ReceiverType,
1796 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001797 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001798 move(Args));
1799 }
1800
Douglas Gregord51d90d2010-04-26 20:11:03 +00001801 /// \brief Build a new Objective-C ivar reference expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
1805 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1806 SourceLocation IvarLoc,
1807 bool IsArrow, bool IsFreeIvar) {
1808 // FIXME: We lose track of the IsFreeIvar bit.
1809 CXXScopeSpec SS;
1810 Expr *Base = BaseArg.takeAs<Expr>();
1811 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1812 Sema::LookupMemberName);
1813 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1814 /*FIME:*/IvarLoc,
1815 SS, DeclPtrTy());
1816 if (Result.isInvalid())
1817 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001818
Douglas Gregord51d90d2010-04-26 20:11:03 +00001819 if (Result.get())
1820 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001821
1822 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001824 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001825 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001826 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001827 /*TemplateArgs=*/0);
1828 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001829
1830 /// \brief Build a new Objective-C property reference expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001834 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001835 ObjCPropertyDecl *Property,
1836 SourceLocation PropertyLoc) {
1837 CXXScopeSpec SS;
1838 Expr *Base = BaseArg.takeAs<Expr>();
1839 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1840 Sema::LookupMemberName);
1841 bool IsArrow = false;
1842 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1843 /*FIME:*/PropertyLoc,
1844 SS, DeclPtrTy());
1845 if (Result.isInvalid())
1846 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001847
Douglas Gregor9faee212010-04-26 20:47:02 +00001848 if (Result.get())
1849 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001850
1851 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001852 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001853 /*FIXME:*/PropertyLoc, IsArrow,
1854 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001855 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001856 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001857 /*TemplateArgs=*/0);
1858 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001859
1860 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001861 /// expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001864 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001865 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1866 ObjCMethodDecl *Getter,
1867 QualType T,
1868 ObjCMethodDecl *Setter,
1869 SourceLocation NameLoc,
1870 ExprArg Base) {
1871 // Since these expressions can only be value-dependent, we do not need to
1872 // perform semantic analysis again.
1873 return getSema().Owned(
1874 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1875 Setter,
1876 NameLoc,
1877 Base.takeAs<Expr>()));
1878 }
1879
Douglas Gregord51d90d2010-04-26 20:11:03 +00001880 /// \brief Build a new Objective-C "isa" expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
1884 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1885 bool IsArrow) {
1886 CXXScopeSpec SS;
1887 Expr *Base = BaseArg.takeAs<Expr>();
1888 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1889 Sema::LookupMemberName);
1890 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1891 /*FIME:*/IsaLoc,
1892 SS, DeclPtrTy());
1893 if (Result.isInvalid())
1894 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001895
Douglas Gregord51d90d2010-04-26 20:11:03 +00001896 if (Result.get())
1897 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001898
1899 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001901 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001902 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001903 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001904 /*TemplateArgs=*/0);
1905 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001906
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 /// \brief Build a new shuffle vector expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1912 MultiExprArg SubExprs,
1913 SourceLocation RParenLoc) {
1914 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001915 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1917 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1918 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1919 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001920
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 // Build a reference to the __builtin_shufflevector builtin
1922 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001923 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001925 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001927
1928 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 unsigned NumSubExprs = SubExprs.size();
1930 Expr **Subs = (Expr **)SubExprs.release();
1931 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1932 Subs, NumSubExprs,
1933 Builtin->getResultType(),
1934 RParenLoc);
1935 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 // Type-check the __builtin_shufflevector expression.
1938 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1939 if (Result.isInvalid())
1940 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001943 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001945};
Douglas Gregora16548e2009-08-11 05:31:07 +00001946
Douglas Gregorebe10102009-08-20 07:17:43 +00001947template<typename Derived>
1948Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1949 if (!S)
1950 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregorebe10102009-08-20 07:17:43 +00001952 switch (S->getStmtClass()) {
1953 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001954
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 // Transform individual statement nodes
1956#define STMT(Node, Parent) \
1957 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1958#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001959#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregorebe10102009-08-20 07:17:43 +00001961 // Transform expressions by calling TransformExpr.
1962#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001963#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001964#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001965#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001966 {
1967 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1968 if (E.isInvalid())
1969 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001970
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001971 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 }
Mike Stump11289f42009-09-09 15:08:12 +00001973 }
1974
Douglas Gregorebe10102009-08-20 07:17:43 +00001975 return SemaRef.Owned(S->Retain());
1976}
Mike Stump11289f42009-09-09 15:08:12 +00001977
1978
Douglas Gregore922c772009-08-04 22:27:00 +00001979template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001980Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 if (!E)
1982 return SemaRef.Owned(E);
1983
1984 switch (E->getStmtClass()) {
1985 case Stmt::NoStmtClass: break;
1986#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00001987#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001988#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001989 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001990#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001991 }
1992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001994}
1995
1996template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001997NestedNameSpecifier *
1998TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001999 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002000 QualType ObjectType,
2001 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002002 if (!NNS)
2003 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregorebe10102009-08-20 07:17:43 +00002005 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002006 NestedNameSpecifier *Prefix = NNS->getPrefix();
2007 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002008 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002009 ObjectType,
2010 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002011 if (!Prefix)
2012 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002013
2014 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002015 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002016 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002017 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregor1135c352009-08-06 05:28:30 +00002020 switch (NNS->getKind()) {
2021 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002022 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002023 "Identifier nested-name-specifier with no prefix or object type");
2024 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2025 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002027
2028 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002029 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002030 ObjectType,
2031 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002032
Douglas Gregor1135c352009-08-06 05:28:30 +00002033 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002034 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002035 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002036 getDerived().TransformDecl(Range.getBegin(),
2037 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002039 Prefix == NNS->getPrefix() &&
2040 NS == NNS->getAsNamespace())
2041 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002042
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2044 }
Mike Stump11289f42009-09-09 15:08:12 +00002045
Douglas Gregor1135c352009-08-06 05:28:30 +00002046 case NestedNameSpecifier::Global:
2047 // There is no meaningful transformation that one could perform on the
2048 // global scope.
2049 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002050
Douglas Gregor1135c352009-08-06 05:28:30 +00002051 case NestedNameSpecifier::TypeSpecWithTemplate:
2052 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002053 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002054 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2055 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002056 if (T.isNull())
2057 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002058
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 if (!getDerived().AlwaysRebuild() &&
2060 Prefix == NNS->getPrefix() &&
2061 T == QualType(NNS->getAsType(), 0))
2062 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002063
2064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2065 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002066 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002067 }
2068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Douglas Gregor1135c352009-08-06 05:28:30 +00002070 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002071 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002072}
2073
2074template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002075DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002076TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002077 SourceLocation Loc,
2078 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002079 if (!Name)
2080 return Name;
2081
2082 switch (Name.getNameKind()) {
2083 case DeclarationName::Identifier:
2084 case DeclarationName::ObjCZeroArgSelector:
2085 case DeclarationName::ObjCOneArgSelector:
2086 case DeclarationName::ObjCMultiArgSelector:
2087 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002088 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002089 case DeclarationName::CXXUsingDirective:
2090 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002091
Douglas Gregorf816bd72009-09-03 22:13:48 +00002092 case DeclarationName::CXXConstructorName:
2093 case DeclarationName::CXXDestructorName:
2094 case DeclarationName::CXXConversionFunctionName: {
2095 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002096 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002097 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002098 if (T.isNull())
2099 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002100
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002102 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002103 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105 }
2106
Douglas Gregorf816bd72009-09-03 22:13:48 +00002107 return DeclarationName();
2108}
2109
2110template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002111TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002112TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2113 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002114 SourceLocation Loc = getDerived().getBaseLocation();
2115
Douglas Gregor71dc5092009-08-06 06:41:21 +00002116 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002117 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002118 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002119 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2120 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002121 if (!NNS)
2122 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002123
Douglas Gregor71dc5092009-08-06 06:41:21 +00002124 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002125 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002126 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002127 if (!TransTemplate)
2128 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002129
Douglas Gregor71dc5092009-08-06 06:41:21 +00002130 if (!getDerived().AlwaysRebuild() &&
2131 NNS == QTN->getQualifier() &&
2132 TransTemplate == Template)
2133 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002134
Douglas Gregor71dc5092009-08-06 06:41:21 +00002135 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2136 TransTemplate);
2137 }
Mike Stump11289f42009-09-09 15:08:12 +00002138
John McCalle66edc12009-11-24 19:00:30 +00002139 // These should be getting filtered out before they make it into the AST.
2140 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002141 }
Mike Stump11289f42009-09-09 15:08:12 +00002142
Douglas Gregor71dc5092009-08-06 06:41:21 +00002143 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002144 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002145 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002146 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2147 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002148 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002149 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002150
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002152 NNS == DTN->getQualifier() &&
2153 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002155
Douglas Gregor71395fa2009-11-04 00:56:37 +00002156 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002157 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002158 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002159
2160 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002161 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregor71dc5092009-08-06 06:41:21 +00002164 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002165 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002166 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 if (!TransTemplate)
2168 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregor71dc5092009-08-06 06:41:21 +00002170 if (!getDerived().AlwaysRebuild() &&
2171 TransTemplate == Template)
2172 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 return TemplateName(TransTemplate);
2175 }
Mike Stump11289f42009-09-09 15:08:12 +00002176
John McCalle66edc12009-11-24 19:00:30 +00002177 // These should be getting filtered out before they reach the AST.
2178 assert(false && "overloaded function decl survived to here");
2179 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180}
2181
2182template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002183void TreeTransform<Derived>::InventTemplateArgumentLoc(
2184 const TemplateArgument &Arg,
2185 TemplateArgumentLoc &Output) {
2186 SourceLocation Loc = getDerived().getBaseLocation();
2187 switch (Arg.getKind()) {
2188 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002189 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002190 break;
2191
2192 case TemplateArgument::Type:
2193 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002194 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002195
John McCall0ad16662009-10-29 08:12:44 +00002196 break;
2197
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002198 case TemplateArgument::Template:
2199 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2200 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201
John McCall0ad16662009-10-29 08:12:44 +00002202 case TemplateArgument::Expression:
2203 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2204 break;
2205
2206 case TemplateArgument::Declaration:
2207 case TemplateArgument::Integral:
2208 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002209 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002210 break;
2211 }
2212}
2213
2214template<typename Derived>
2215bool TreeTransform<Derived>::TransformTemplateArgument(
2216 const TemplateArgumentLoc &Input,
2217 TemplateArgumentLoc &Output) {
2218 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002219 switch (Arg.getKind()) {
2220 case TemplateArgument::Null:
2221 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002222 Output = Input;
2223 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002224
Douglas Gregore922c772009-08-04 22:27:00 +00002225 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002226 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002227 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002228 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002229
2230 DI = getDerived().TransformType(DI);
2231 if (!DI) return true;
2232
2233 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2234 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002235 }
Mike Stump11289f42009-09-09 15:08:12 +00002236
Douglas Gregore922c772009-08-04 22:27:00 +00002237 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002238 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002239 DeclarationName Name;
2240 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2241 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002242 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002243 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002244 if (!D) return true;
2245
John McCall0d07eb32009-10-29 18:45:58 +00002246 Expr *SourceExpr = Input.getSourceDeclExpression();
2247 if (SourceExpr) {
2248 EnterExpressionEvaluationContext Unevaluated(getSema(),
2249 Action::Unevaluated);
2250 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2251 if (E.isInvalid())
2252 SourceExpr = NULL;
2253 else {
2254 SourceExpr = E.takeAs<Expr>();
2255 SourceExpr->Retain();
2256 }
2257 }
2258
2259 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002260 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002261 }
Mike Stump11289f42009-09-09 15:08:12 +00002262
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002263 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002264 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002265 TemplateName Template
2266 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2267 if (Template.isNull())
2268 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002269
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002270 Output = TemplateArgumentLoc(TemplateArgument(Template),
2271 Input.getTemplateQualifierRange(),
2272 Input.getTemplateNameLoc());
2273 return false;
2274 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002275
Douglas Gregore922c772009-08-04 22:27:00 +00002276 case TemplateArgument::Expression: {
2277 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002278 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002279 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002280
John McCall0ad16662009-10-29 08:12:44 +00002281 Expr *InputExpr = Input.getSourceExpression();
2282 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2283
2284 Sema::OwningExprResult E
2285 = getDerived().TransformExpr(InputExpr);
2286 if (E.isInvalid()) return true;
2287
2288 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002289 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002290 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2291 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002292 }
Mike Stump11289f42009-09-09 15:08:12 +00002293
Douglas Gregore922c772009-08-04 22:27:00 +00002294 case TemplateArgument::Pack: {
2295 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2296 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002297 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002298 AEnd = Arg.pack_end();
2299 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002300
John McCall0ad16662009-10-29 08:12:44 +00002301 // FIXME: preserve source information here when we start
2302 // caring about parameter packs.
2303
John McCall0d07eb32009-10-29 18:45:58 +00002304 TemplateArgumentLoc InputArg;
2305 TemplateArgumentLoc OutputArg;
2306 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2307 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002308 return true;
2309
John McCall0d07eb32009-10-29 18:45:58 +00002310 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002311 }
2312 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002313 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002314 true);
John McCall0d07eb32009-10-29 18:45:58 +00002315 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002316 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002317 }
2318 }
Mike Stump11289f42009-09-09 15:08:12 +00002319
Douglas Gregore922c772009-08-04 22:27:00 +00002320 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002321 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002322}
2323
Douglas Gregord6ff3322009-08-04 16:50:30 +00002324//===----------------------------------------------------------------------===//
2325// Type transformation
2326//===----------------------------------------------------------------------===//
2327
2328template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002329QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002330 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002331 if (getDerived().AlreadyTransformed(T))
2332 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002333
John McCall550e0c22009-10-21 00:40:46 +00002334 // Temporary workaround. All of these transformations should
2335 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002336 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002337 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002338
Douglas Gregorfe17d252010-02-16 19:09:40 +00002339 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002340
John McCall550e0c22009-10-21 00:40:46 +00002341 if (!NewDI)
2342 return QualType();
2343
2344 return NewDI->getType();
2345}
2346
2347template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002348TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2349 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002350 if (getDerived().AlreadyTransformed(DI->getType()))
2351 return DI;
2352
2353 TypeLocBuilder TLB;
2354
2355 TypeLoc TL = DI->getTypeLoc();
2356 TLB.reserve(TL.getFullDataSize());
2357
Douglas Gregorfe17d252010-02-16 19:09:40 +00002358 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002359 if (Result.isNull())
2360 return 0;
2361
John McCallbcd03502009-12-07 02:54:59 +00002362 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002363}
2364
2365template<typename Derived>
2366QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002367TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2368 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002369 switch (T.getTypeLocClass()) {
2370#define ABSTRACT_TYPELOC(CLASS, PARENT)
2371#define TYPELOC(CLASS, PARENT) \
2372 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002373 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2374 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002375#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002376 }
Mike Stump11289f42009-09-09 15:08:12 +00002377
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002378 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002379 return QualType();
2380}
2381
2382/// FIXME: By default, this routine adds type qualifiers only to types
2383/// that can have qualifiers, and silently suppresses those qualifiers
2384/// that are not permitted (e.g., qualifiers on reference or function
2385/// types). This is the right thing for template instantiation, but
2386/// probably not for other clients.
2387template<typename Derived>
2388QualType
2389TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002390 QualifiedTypeLoc T,
2391 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002392 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002393
Douglas Gregorfe17d252010-02-16 19:09:40 +00002394 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2395 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002396 if (Result.isNull())
2397 return QualType();
2398
2399 // Silently suppress qualifiers if the result type can't be qualified.
2400 // FIXME: this is the right thing for template instantiation, but
2401 // probably not for other clients.
2402 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002403 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002404
John McCall550e0c22009-10-21 00:40:46 +00002405 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2406
2407 TLB.push<QualifiedTypeLoc>(Result);
2408
2409 // No location information to preserve.
2410
2411 return Result;
2412}
2413
2414template <class TyLoc> static inline
2415QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2416 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2417 NewT.setNameLoc(T.getNameLoc());
2418 return T.getType();
2419}
2420
John McCall550e0c22009-10-21 00:40:46 +00002421template<typename Derived>
2422QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002423 BuiltinTypeLoc T,
2424 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002425 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2426 NewT.setBuiltinLoc(T.getBuiltinLoc());
2427 if (T.needsExtraLocalData())
2428 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2429 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002430}
Mike Stump11289f42009-09-09 15:08:12 +00002431
Douglas Gregord6ff3322009-08-04 16:50:30 +00002432template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002433QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002434 ComplexTypeLoc T,
2435 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002436 // FIXME: recurse?
2437 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438}
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregord6ff3322009-08-04 16:50:30 +00002440template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002441QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002442 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002443 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002444 QualType PointeeType
2445 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002446 if (PointeeType.isNull())
2447 return QualType();
2448
2449 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002450 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002451 // A dependent pointer type 'T *' has is being transformed such
2452 // that an Objective-C class type is being replaced for 'T'. The
2453 // resulting pointer type is an ObjCObjectPointerType, not a
2454 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002455 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002456
John McCall8b07ec22010-05-15 11:32:37 +00002457 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2458 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002459 return Result;
2460 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002461
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002462 if (getDerived().AlwaysRebuild() ||
2463 PointeeType != TL.getPointeeLoc().getType()) {
2464 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2465 if (Result.isNull())
2466 return QualType();
2467 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002468
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002469 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2470 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002471 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472}
Mike Stump11289f42009-09-09 15:08:12 +00002473
2474template<typename Derived>
2475QualType
John McCall550e0c22009-10-21 00:40:46 +00002476TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002477 BlockPointerTypeLoc TL,
2478 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002479 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002480 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2481 if (PointeeType.isNull())
2482 return QualType();
2483
2484 QualType Result = TL.getType();
2485 if (getDerived().AlwaysRebuild() ||
2486 PointeeType != TL.getPointeeLoc().getType()) {
2487 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002488 TL.getSigilLoc());
2489 if (Result.isNull())
2490 return QualType();
2491 }
2492
Douglas Gregor049211a2010-04-22 16:50:51 +00002493 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002494 NewT.setSigilLoc(TL.getSigilLoc());
2495 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002496}
2497
John McCall70dd5f62009-10-30 00:06:24 +00002498/// Transforms a reference type. Note that somewhat paradoxically we
2499/// don't care whether the type itself is an l-value type or an r-value
2500/// type; we only care if the type was *written* as an l-value type
2501/// or an r-value type.
2502template<typename Derived>
2503QualType
2504TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002505 ReferenceTypeLoc TL,
2506 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002507 const ReferenceType *T = TL.getTypePtr();
2508
2509 // Note that this works with the pointee-as-written.
2510 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2511 if (PointeeType.isNull())
2512 return QualType();
2513
2514 QualType Result = TL.getType();
2515 if (getDerived().AlwaysRebuild() ||
2516 PointeeType != T->getPointeeTypeAsWritten()) {
2517 Result = getDerived().RebuildReferenceType(PointeeType,
2518 T->isSpelledAsLValue(),
2519 TL.getSigilLoc());
2520 if (Result.isNull())
2521 return QualType();
2522 }
2523
2524 // r-value references can be rebuilt as l-value references.
2525 ReferenceTypeLoc NewTL;
2526 if (isa<LValueReferenceType>(Result))
2527 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2528 else
2529 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2530 NewTL.setSigilLoc(TL.getSigilLoc());
2531
2532 return Result;
2533}
2534
Mike Stump11289f42009-09-09 15:08:12 +00002535template<typename Derived>
2536QualType
John McCall550e0c22009-10-21 00:40:46 +00002537TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002538 LValueReferenceTypeLoc TL,
2539 QualType ObjectType) {
2540 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002541}
2542
Mike Stump11289f42009-09-09 15:08:12 +00002543template<typename Derived>
2544QualType
John McCall550e0c22009-10-21 00:40:46 +00002545TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002546 RValueReferenceTypeLoc TL,
2547 QualType ObjectType) {
2548 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002549}
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregord6ff3322009-08-04 16:50:30 +00002551template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002552QualType
John McCall550e0c22009-10-21 00:40:46 +00002553TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002554 MemberPointerTypeLoc TL,
2555 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002556 MemberPointerType *T = TL.getTypePtr();
2557
2558 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002559 if (PointeeType.isNull())
2560 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002561
John McCall550e0c22009-10-21 00:40:46 +00002562 // TODO: preserve source information for this.
2563 QualType ClassType
2564 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565 if (ClassType.isNull())
2566 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002567
John McCall550e0c22009-10-21 00:40:46 +00002568 QualType Result = TL.getType();
2569 if (getDerived().AlwaysRebuild() ||
2570 PointeeType != T->getPointeeType() ||
2571 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002572 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2573 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002574 if (Result.isNull())
2575 return QualType();
2576 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002577
John McCall550e0c22009-10-21 00:40:46 +00002578 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2579 NewTL.setSigilLoc(TL.getSigilLoc());
2580
2581 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582}
2583
Mike Stump11289f42009-09-09 15:08:12 +00002584template<typename Derived>
2585QualType
John McCall550e0c22009-10-21 00:40:46 +00002586TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002587 ConstantArrayTypeLoc TL,
2588 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002589 ConstantArrayType *T = TL.getTypePtr();
2590 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002591 if (ElementType.isNull())
2592 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002593
John McCall550e0c22009-10-21 00:40:46 +00002594 QualType Result = TL.getType();
2595 if (getDerived().AlwaysRebuild() ||
2596 ElementType != T->getElementType()) {
2597 Result = getDerived().RebuildConstantArrayType(ElementType,
2598 T->getSizeModifier(),
2599 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002600 T->getIndexTypeCVRQualifiers(),
2601 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002602 if (Result.isNull())
2603 return QualType();
2604 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002605
John McCall550e0c22009-10-21 00:40:46 +00002606 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2607 NewTL.setLBracketLoc(TL.getLBracketLoc());
2608 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002609
John McCall550e0c22009-10-21 00:40:46 +00002610 Expr *Size = TL.getSizeExpr();
2611 if (Size) {
2612 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2613 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2614 }
2615 NewTL.setSizeExpr(Size);
2616
2617 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002618}
Mike Stump11289f42009-09-09 15:08:12 +00002619
Douglas Gregord6ff3322009-08-04 16:50:30 +00002620template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002621QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002622 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002623 IncompleteArrayTypeLoc TL,
2624 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002625 IncompleteArrayType *T = TL.getTypePtr();
2626 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002627 if (ElementType.isNull())
2628 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002629
John McCall550e0c22009-10-21 00:40:46 +00002630 QualType Result = TL.getType();
2631 if (getDerived().AlwaysRebuild() ||
2632 ElementType != T->getElementType()) {
2633 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002635 T->getIndexTypeCVRQualifiers(),
2636 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002637 if (Result.isNull())
2638 return QualType();
2639 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002640
John McCall550e0c22009-10-21 00:40:46 +00002641 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2642 NewTL.setLBracketLoc(TL.getLBracketLoc());
2643 NewTL.setRBracketLoc(TL.getRBracketLoc());
2644 NewTL.setSizeExpr(0);
2645
2646 return Result;
2647}
2648
2649template<typename Derived>
2650QualType
2651TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002652 VariableArrayTypeLoc TL,
2653 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002654 VariableArrayType *T = TL.getTypePtr();
2655 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2656 if (ElementType.isNull())
2657 return QualType();
2658
2659 // Array bounds are not potentially evaluated contexts
2660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2661
2662 Sema::OwningExprResult SizeResult
2663 = getDerived().TransformExpr(T->getSizeExpr());
2664 if (SizeResult.isInvalid())
2665 return QualType();
2666
2667 Expr *Size = static_cast<Expr*>(SizeResult.get());
2668
2669 QualType Result = TL.getType();
2670 if (getDerived().AlwaysRebuild() ||
2671 ElementType != T->getElementType() ||
2672 Size != T->getSizeExpr()) {
2673 Result = getDerived().RebuildVariableArrayType(ElementType,
2674 T->getSizeModifier(),
2675 move(SizeResult),
2676 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002677 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002678 if (Result.isNull())
2679 return QualType();
2680 }
2681 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002682
John McCall550e0c22009-10-21 00:40:46 +00002683 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2684 NewTL.setLBracketLoc(TL.getLBracketLoc());
2685 NewTL.setRBracketLoc(TL.getRBracketLoc());
2686 NewTL.setSizeExpr(Size);
2687
2688 return Result;
2689}
2690
2691template<typename Derived>
2692QualType
2693TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002694 DependentSizedArrayTypeLoc TL,
2695 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002696 DependentSizedArrayType *T = TL.getTypePtr();
2697 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2698 if (ElementType.isNull())
2699 return QualType();
2700
2701 // Array bounds are not potentially evaluated contexts
2702 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2703
2704 Sema::OwningExprResult SizeResult
2705 = getDerived().TransformExpr(T->getSizeExpr());
2706 if (SizeResult.isInvalid())
2707 return QualType();
2708
2709 Expr *Size = static_cast<Expr*>(SizeResult.get());
2710
2711 QualType Result = TL.getType();
2712 if (getDerived().AlwaysRebuild() ||
2713 ElementType != T->getElementType() ||
2714 Size != T->getSizeExpr()) {
2715 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2716 T->getSizeModifier(),
2717 move(SizeResult),
2718 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002719 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002720 if (Result.isNull())
2721 return QualType();
2722 }
2723 else SizeResult.take();
2724
2725 // We might have any sort of array type now, but fortunately they
2726 // all have the same location layout.
2727 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2728 NewTL.setLBracketLoc(TL.getLBracketLoc());
2729 NewTL.setRBracketLoc(TL.getRBracketLoc());
2730 NewTL.setSizeExpr(Size);
2731
2732 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002733}
Mike Stump11289f42009-09-09 15:08:12 +00002734
2735template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002736QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002737 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002738 DependentSizedExtVectorTypeLoc TL,
2739 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002740 DependentSizedExtVectorType *T = TL.getTypePtr();
2741
2742 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002743 QualType ElementType = getDerived().TransformType(T->getElementType());
2744 if (ElementType.isNull())
2745 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002746
Douglas Gregore922c772009-08-04 22:27:00 +00002747 // Vector sizes are not potentially evaluated contexts
2748 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2749
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2751 if (Size.isInvalid())
2752 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002753
John McCall550e0c22009-10-21 00:40:46 +00002754 QualType Result = TL.getType();
2755 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002756 ElementType != T->getElementType() ||
2757 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002758 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759 move(Size),
2760 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002761 if (Result.isNull())
2762 return QualType();
2763 }
2764 else Size.take();
2765
2766 // Result might be dependent or not.
2767 if (isa<DependentSizedExtVectorType>(Result)) {
2768 DependentSizedExtVectorTypeLoc NewTL
2769 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2770 NewTL.setNameLoc(TL.getNameLoc());
2771 } else {
2772 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2773 NewTL.setNameLoc(TL.getNameLoc());
2774 }
2775
2776 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002777}
Mike Stump11289f42009-09-09 15:08:12 +00002778
2779template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002780QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002781 VectorTypeLoc TL,
2782 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002783 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784 QualType ElementType = getDerived().TransformType(T->getElementType());
2785 if (ElementType.isNull())
2786 return QualType();
2787
John McCall550e0c22009-10-21 00:40:46 +00002788 QualType Result = TL.getType();
2789 if (getDerived().AlwaysRebuild() ||
2790 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002791 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2792 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002793 if (Result.isNull())
2794 return QualType();
2795 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002796
John McCall550e0c22009-10-21 00:40:46 +00002797 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2798 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002799
John McCall550e0c22009-10-21 00:40:46 +00002800 return Result;
2801}
2802
2803template<typename Derived>
2804QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002805 ExtVectorTypeLoc TL,
2806 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002807 VectorType *T = TL.getTypePtr();
2808 QualType ElementType = getDerived().TransformType(T->getElementType());
2809 if (ElementType.isNull())
2810 return QualType();
2811
2812 QualType Result = TL.getType();
2813 if (getDerived().AlwaysRebuild() ||
2814 ElementType != T->getElementType()) {
2815 Result = getDerived().RebuildExtVectorType(ElementType,
2816 T->getNumElements(),
2817 /*FIXME*/ SourceLocation());
2818 if (Result.isNull())
2819 return QualType();
2820 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002821
John McCall550e0c22009-10-21 00:40:46 +00002822 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2823 NewTL.setNameLoc(TL.getNameLoc());
2824
2825 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002826}
Mike Stump11289f42009-09-09 15:08:12 +00002827
2828template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002829ParmVarDecl *
2830TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2831 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2832 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2833 if (!NewDI)
2834 return 0;
2835
2836 if (NewDI == OldDI)
2837 return OldParm;
2838 else
2839 return ParmVarDecl::Create(SemaRef.Context,
2840 OldParm->getDeclContext(),
2841 OldParm->getLocation(),
2842 OldParm->getIdentifier(),
2843 NewDI->getType(),
2844 NewDI,
2845 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002846 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002847 /* DefArg */ NULL);
2848}
2849
2850template<typename Derived>
2851bool TreeTransform<Derived>::
2852 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2853 llvm::SmallVectorImpl<QualType> &PTypes,
2854 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2855 FunctionProtoType *T = TL.getTypePtr();
2856
2857 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2858 ParmVarDecl *OldParm = TL.getArg(i);
2859
2860 QualType NewType;
2861 ParmVarDecl *NewParm;
2862
2863 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002864 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2865 if (!NewParm)
2866 return true;
2867 NewType = NewParm->getType();
2868
2869 // Deal with the possibility that we don't have a parameter
2870 // declaration for this parameter.
2871 } else {
2872 NewParm = 0;
2873
2874 QualType OldType = T->getArgType(i);
2875 NewType = getDerived().TransformType(OldType);
2876 if (NewType.isNull())
2877 return true;
2878 }
2879
2880 PTypes.push_back(NewType);
2881 PVars.push_back(NewParm);
2882 }
2883
2884 return false;
2885}
2886
2887template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002888QualType
John McCall550e0c22009-10-21 00:40:46 +00002889TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002890 FunctionProtoTypeLoc TL,
2891 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002892 // Transform the parameters. We do this first for the benefit of template
2893 // instantiations, so that the ParmVarDecls get/ placed into the template
2894 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002895 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002896 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002897 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2898 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002899
Douglas Gregor14cf7522010-04-30 18:55:50 +00002900 FunctionProtoType *T = TL.getTypePtr();
2901 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2902 if (ResultType.isNull())
2903 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002904
John McCall550e0c22009-10-21 00:40:46 +00002905 QualType Result = TL.getType();
2906 if (getDerived().AlwaysRebuild() ||
2907 ResultType != T->getResultType() ||
2908 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2909 Result = getDerived().RebuildFunctionProtoType(ResultType,
2910 ParamTypes.data(),
2911 ParamTypes.size(),
2912 T->isVariadic(),
2913 T->getTypeQuals());
2914 if (Result.isNull())
2915 return QualType();
2916 }
Mike Stump11289f42009-09-09 15:08:12 +00002917
John McCall550e0c22009-10-21 00:40:46 +00002918 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2919 NewTL.setLParenLoc(TL.getLParenLoc());
2920 NewTL.setRParenLoc(TL.getRParenLoc());
2921 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2922 NewTL.setArg(i, ParamDecls[i]);
2923
2924 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002925}
Mike Stump11289f42009-09-09 15:08:12 +00002926
Douglas Gregord6ff3322009-08-04 16:50:30 +00002927template<typename Derived>
2928QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002929 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002930 FunctionNoProtoTypeLoc TL,
2931 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002932 FunctionNoProtoType *T = TL.getTypePtr();
2933 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2934 if (ResultType.isNull())
2935 return QualType();
2936
2937 QualType Result = TL.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 ResultType != T->getResultType())
2940 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2941
2942 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2943 NewTL.setLParenLoc(TL.getLParenLoc());
2944 NewTL.setRParenLoc(TL.getRParenLoc());
2945
2946 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002947}
Mike Stump11289f42009-09-09 15:08:12 +00002948
John McCallb96ec562009-12-04 22:46:56 +00002949template<typename Derived> QualType
2950TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002951 UnresolvedUsingTypeLoc TL,
2952 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002953 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002954 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002955 if (!D)
2956 return QualType();
2957
2958 QualType Result = TL.getType();
2959 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2960 Result = getDerived().RebuildUnresolvedUsingType(D);
2961 if (Result.isNull())
2962 return QualType();
2963 }
2964
2965 // We might get an arbitrary type spec type back. We should at
2966 // least always get a type spec type, though.
2967 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2968 NewTL.setNameLoc(TL.getNameLoc());
2969
2970 return Result;
2971}
2972
Douglas Gregord6ff3322009-08-04 16:50:30 +00002973template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002974QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002975 TypedefTypeLoc TL,
2976 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002977 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002978 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002979 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2980 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002981 if (!Typedef)
2982 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002983
John McCall550e0c22009-10-21 00:40:46 +00002984 QualType Result = TL.getType();
2985 if (getDerived().AlwaysRebuild() ||
2986 Typedef != T->getDecl()) {
2987 Result = getDerived().RebuildTypedefType(Typedef);
2988 if (Result.isNull())
2989 return QualType();
2990 }
Mike Stump11289f42009-09-09 15:08:12 +00002991
John McCall550e0c22009-10-21 00:40:46 +00002992 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2993 NewTL.setNameLoc(TL.getNameLoc());
2994
2995 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996}
Mike Stump11289f42009-09-09 15:08:12 +00002997
Douglas Gregord6ff3322009-08-04 16:50:30 +00002998template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002999QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003000 TypeOfExprTypeLoc TL,
3001 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003002 // typeof expressions are not potentially evaluated contexts
3003 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003004
John McCalle8595032010-01-13 20:03:27 +00003005 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003006 if (E.isInvalid())
3007 return QualType();
3008
John McCall550e0c22009-10-21 00:40:46 +00003009 QualType Result = TL.getType();
3010 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003011 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003012 Result = getDerived().RebuildTypeOfExprType(move(E));
3013 if (Result.isNull())
3014 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015 }
John McCall550e0c22009-10-21 00:40:46 +00003016 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003017
John McCall550e0c22009-10-21 00:40:46 +00003018 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003019 NewTL.setTypeofLoc(TL.getTypeofLoc());
3020 NewTL.setLParenLoc(TL.getLParenLoc());
3021 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003022
3023 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024}
Mike Stump11289f42009-09-09 15:08:12 +00003025
3026template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003027QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003028 TypeOfTypeLoc TL,
3029 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003030 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3031 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3032 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003034
John McCall550e0c22009-10-21 00:40:46 +00003035 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003036 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3037 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003038 if (Result.isNull())
3039 return QualType();
3040 }
Mike Stump11289f42009-09-09 15:08:12 +00003041
John McCall550e0c22009-10-21 00:40:46 +00003042 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003043 NewTL.setTypeofLoc(TL.getTypeofLoc());
3044 NewTL.setLParenLoc(TL.getLParenLoc());
3045 NewTL.setRParenLoc(TL.getRParenLoc());
3046 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003047
3048 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049}
Mike Stump11289f42009-09-09 15:08:12 +00003050
3051template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003052QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003053 DecltypeTypeLoc TL,
3054 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003055 DecltypeType *T = TL.getTypePtr();
3056
Douglas Gregore922c772009-08-04 22:27:00 +00003057 // decltype expressions are not potentially evaluated contexts
3058 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003059
Douglas Gregord6ff3322009-08-04 16:50:30 +00003060 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3061 if (E.isInvalid())
3062 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003063
John McCall550e0c22009-10-21 00:40:46 +00003064 QualType Result = TL.getType();
3065 if (getDerived().AlwaysRebuild() ||
3066 E.get() != T->getUnderlyingExpr()) {
3067 Result = getDerived().RebuildDecltypeType(move(E));
3068 if (Result.isNull())
3069 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003070 }
John McCall550e0c22009-10-21 00:40:46 +00003071 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003072
John McCall550e0c22009-10-21 00:40:46 +00003073 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3074 NewTL.setNameLoc(TL.getNameLoc());
3075
3076 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077}
3078
3079template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003080QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003081 RecordTypeLoc TL,
3082 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003083 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003085 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3086 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003087 if (!Record)
3088 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003089
John McCall550e0c22009-10-21 00:40:46 +00003090 QualType Result = TL.getType();
3091 if (getDerived().AlwaysRebuild() ||
3092 Record != T->getDecl()) {
3093 Result = getDerived().RebuildRecordType(Record);
3094 if (Result.isNull())
3095 return QualType();
3096 }
Mike Stump11289f42009-09-09 15:08:12 +00003097
John McCall550e0c22009-10-21 00:40:46 +00003098 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3099 NewTL.setNameLoc(TL.getNameLoc());
3100
3101 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102}
Mike Stump11289f42009-09-09 15:08:12 +00003103
3104template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003105QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003106 EnumTypeLoc TL,
3107 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003108 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003109 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003110 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3111 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112 if (!Enum)
3113 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003114
John McCall550e0c22009-10-21 00:40:46 +00003115 QualType Result = TL.getType();
3116 if (getDerived().AlwaysRebuild() ||
3117 Enum != T->getDecl()) {
3118 Result = getDerived().RebuildEnumType(Enum);
3119 if (Result.isNull())
3120 return QualType();
3121 }
Mike Stump11289f42009-09-09 15:08:12 +00003122
John McCall550e0c22009-10-21 00:40:46 +00003123 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3124 NewTL.setNameLoc(TL.getNameLoc());
3125
3126 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127}
John McCallfcc33b02009-09-05 00:15:47 +00003128
John McCalle78aac42010-03-10 03:28:59 +00003129template<typename Derived>
3130QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3131 TypeLocBuilder &TLB,
3132 InjectedClassNameTypeLoc TL,
3133 QualType ObjectType) {
3134 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3135 TL.getTypePtr()->getDecl());
3136 if (!D) return QualType();
3137
3138 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3139 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3140 return T;
3141}
3142
Mike Stump11289f42009-09-09 15:08:12 +00003143
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144template<typename Derived>
3145QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003146 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003147 TemplateTypeParmTypeLoc TL,
3148 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003149 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150}
3151
Mike Stump11289f42009-09-09 15:08:12 +00003152template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003153QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003154 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003155 SubstTemplateTypeParmTypeLoc TL,
3156 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003157 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003158}
3159
3160template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003161QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3162 const TemplateSpecializationType *TST,
3163 QualType ObjectType) {
3164 // FIXME: this entire method is a temporary workaround; callers
3165 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003166
John McCall0ad16662009-10-29 08:12:44 +00003167 // Fake up a TemplateSpecializationTypeLoc.
3168 TypeLocBuilder TLB;
3169 TemplateSpecializationTypeLoc TL
3170 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3171
John McCall0d07eb32009-10-29 18:45:58 +00003172 SourceLocation BaseLoc = getDerived().getBaseLocation();
3173
3174 TL.setTemplateNameLoc(BaseLoc);
3175 TL.setLAngleLoc(BaseLoc);
3176 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003177 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3178 const TemplateArgument &TA = TST->getArg(i);
3179 TemplateArgumentLoc TAL;
3180 getDerived().InventTemplateArgumentLoc(TA, TAL);
3181 TL.setArgLocInfo(i, TAL.getLocInfo());
3182 }
3183
3184 TypeLocBuilder IgnoredTLB;
3185 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003186}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003187
Douglas Gregorc59e5612009-10-19 22:04:39 +00003188template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003189QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003190 TypeLocBuilder &TLB,
3191 TemplateSpecializationTypeLoc TL,
3192 QualType ObjectType) {
3193 const TemplateSpecializationType *T = TL.getTypePtr();
3194
Mike Stump11289f42009-09-09 15:08:12 +00003195 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003196 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003197 if (Template.isNull())
3198 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003199
John McCall6b51f282009-11-23 01:53:49 +00003200 TemplateArgumentListInfo NewTemplateArgs;
3201 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3202 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3203
3204 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3205 TemplateArgumentLoc Loc;
3206 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003207 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003208 NewTemplateArgs.addArgument(Loc);
3209 }
Mike Stump11289f42009-09-09 15:08:12 +00003210
John McCall0ad16662009-10-29 08:12:44 +00003211 // FIXME: maybe don't rebuild if all the template arguments are the same.
3212
3213 QualType Result =
3214 getDerived().RebuildTemplateSpecializationType(Template,
3215 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003216 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003217
3218 if (!Result.isNull()) {
3219 TemplateSpecializationTypeLoc NewTL
3220 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3221 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3222 NewTL.setLAngleLoc(TL.getLAngleLoc());
3223 NewTL.setRAngleLoc(TL.getRAngleLoc());
3224 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3225 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003226 }
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall0ad16662009-10-29 08:12:44 +00003228 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003229}
Mike Stump11289f42009-09-09 15:08:12 +00003230
3231template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003232QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003233TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3234 ElaboratedTypeLoc TL,
3235 QualType ObjectType) {
3236 ElaboratedType *T = TL.getTypePtr();
3237
3238 NestedNameSpecifier *NNS = 0;
3239 // NOTE: the qualifier in an ElaboratedType is optional.
3240 if (T->getQualifier() != 0) {
3241 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003242 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003243 ObjectType);
3244 if (!NNS)
3245 return QualType();
3246 }
Mike Stump11289f42009-09-09 15:08:12 +00003247
Abramo Bagnarad7548482010-05-19 21:37:53 +00003248 QualType NamedT;
3249 // FIXME: this test is meant to workaround a problem (failing assertion)
3250 // occurring if directly executing the code in the else branch.
3251 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3252 TemplateSpecializationTypeLoc OldNamedTL
3253 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3254 const TemplateSpecializationType* OldTST
3255 = OldNamedTL.getType()->getAs<TemplateSpecializationType>();
3256 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3257 if (NamedT.isNull())
3258 return QualType();
3259 TemplateSpecializationTypeLoc NewNamedTL
3260 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3261 NewNamedTL.copy(OldNamedTL);
3262 }
3263 else {
3264 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3265 if (NamedT.isNull())
3266 return QualType();
3267 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003268
John McCall550e0c22009-10-21 00:40:46 +00003269 QualType Result = TL.getType();
3270 if (getDerived().AlwaysRebuild() ||
3271 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003272 NamedT != T->getNamedType()) {
3273 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003274 if (Result.isNull())
3275 return QualType();
3276 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003277
Abramo Bagnara6150c882010-05-11 21:36:43 +00003278 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003279 NewTL.setKeywordLoc(TL.getKeywordLoc());
3280 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003281
3282 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003283}
Mike Stump11289f42009-09-09 15:08:12 +00003284
3285template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003286QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3287 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003288 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003289 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003290
Douglas Gregord6ff3322009-08-04 16:50:30 +00003291 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003292 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3293 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003294 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003295 if (!NNS)
3296 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003297
John McCall550e0c22009-10-21 00:40:46 +00003298 QualType Result;
3299
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003301 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003302 = getDerived().TransformType(QualType(TemplateId, 0));
3303 if (NewTemplateId.isNull())
3304 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003305
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306 if (!getDerived().AlwaysRebuild() &&
3307 NNS == T->getQualifier() &&
3308 NewTemplateId == QualType(TemplateId, 0))
3309 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003310
Abramo Bagnarad7548482010-05-19 21:37:53 +00003311 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003312 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003313 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003314 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3315 T->getIdentifier(),
3316 TL.getKeywordLoc(),
3317 TL.getQualifierRange(),
3318 TL.getNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003319 }
John McCall550e0c22009-10-21 00:40:46 +00003320 if (Result.isNull())
3321 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322
Abramo Bagnarad7548482010-05-19 21:37:53 +00003323 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3324 QualType NamedT = ElabT->getNamedType();
3325 if (isa<TemplateSpecializationType>(NamedT)) {
3326 TemplateSpecializationTypeLoc NamedTLoc
3327 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3328 // FIXME: fill locations
3329 NamedTLoc.initializeLocal(TL.getNameLoc());
3330 } else {
3331 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3332 }
3333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
3336 }
3337 else {
3338 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3339 NewTL.setKeywordLoc(TL.getKeywordLoc());
3340 NewTL.setQualifierRange(TL.getQualifierRange());
3341 NewTL.setNameLoc(TL.getNameLoc());
3342 }
John McCall550e0c22009-10-21 00:40:46 +00003343 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003344}
Mike Stump11289f42009-09-09 15:08:12 +00003345
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003347QualType
3348TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003349 ObjCInterfaceTypeLoc TL,
3350 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003351 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003352 TLB.pushFullCopy(TL);
3353 return TL.getType();
3354}
3355
3356template<typename Derived>
3357QualType
3358TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3359 ObjCObjectTypeLoc TL,
3360 QualType ObjectType) {
3361 // ObjCObjectType is never dependent.
3362 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003363 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003364}
Mike Stump11289f42009-09-09 15:08:12 +00003365
3366template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003367QualType
3368TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003369 ObjCObjectPointerTypeLoc TL,
3370 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003371 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003372 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003373 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003374}
3375
Douglas Gregord6ff3322009-08-04 16:50:30 +00003376//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003377// Statement transformation
3378//===----------------------------------------------------------------------===//
3379template<typename Derived>
3380Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003381TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3382 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003383}
3384
3385template<typename Derived>
3386Sema::OwningStmtResult
3387TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3388 return getDerived().TransformCompoundStmt(S, false);
3389}
3390
3391template<typename Derived>
3392Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003393TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003394 bool IsStmtExpr) {
3395 bool SubStmtChanged = false;
3396 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3397 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3398 B != BEnd; ++B) {
3399 OwningStmtResult Result = getDerived().TransformStmt(*B);
3400 if (Result.isInvalid())
3401 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003402
Douglas Gregorebe10102009-08-20 07:17:43 +00003403 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3404 Statements.push_back(Result.takeAs<Stmt>());
3405 }
Mike Stump11289f42009-09-09 15:08:12 +00003406
Douglas Gregorebe10102009-08-20 07:17:43 +00003407 if (!getDerived().AlwaysRebuild() &&
3408 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003409 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003410
3411 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3412 move_arg(Statements),
3413 S->getRBracLoc(),
3414 IsStmtExpr);
3415}
Mike Stump11289f42009-09-09 15:08:12 +00003416
Douglas Gregorebe10102009-08-20 07:17:43 +00003417template<typename Derived>
3418Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003419TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003420 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3421 {
3422 // The case value expressions are not potentially evaluated.
3423 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003424
Eli Friedman06577382009-11-19 03:14:00 +00003425 // Transform the left-hand case value.
3426 LHS = getDerived().TransformExpr(S->getLHS());
3427 if (LHS.isInvalid())
3428 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003429
Eli Friedman06577382009-11-19 03:14:00 +00003430 // Transform the right-hand case value (for the GNU case-range extension).
3431 RHS = getDerived().TransformExpr(S->getRHS());
3432 if (RHS.isInvalid())
3433 return SemaRef.StmtError();
3434 }
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 // Build the case statement.
3437 // Case statements are always rebuilt so that they will attached to their
3438 // transformed switch statement.
3439 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3440 move(LHS),
3441 S->getEllipsisLoc(),
3442 move(RHS),
3443 S->getColonLoc());
3444 if (Case.isInvalid())
3445 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregorebe10102009-08-20 07:17:43 +00003447 // Transform the statement following the case
3448 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3449 if (SubStmt.isInvalid())
3450 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003451
Douglas Gregorebe10102009-08-20 07:17:43 +00003452 // Attach the body to the case statement
3453 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3454}
3455
3456template<typename Derived>
3457Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003458TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003459 // Transform the statement following the default case
3460 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3461 if (SubStmt.isInvalid())
3462 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003463
Douglas Gregorebe10102009-08-20 07:17:43 +00003464 // Default statements are always rebuilt
3465 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3466 move(SubStmt));
3467}
Mike Stump11289f42009-09-09 15:08:12 +00003468
Douglas Gregorebe10102009-08-20 07:17:43 +00003469template<typename Derived>
3470Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003471TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003472 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3473 if (SubStmt.isInvalid())
3474 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003475
Douglas Gregorebe10102009-08-20 07:17:43 +00003476 // FIXME: Pass the real colon location in.
3477 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3478 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3479 move(SubStmt));
3480}
Mike Stump11289f42009-09-09 15:08:12 +00003481
Douglas Gregorebe10102009-08-20 07:17:43 +00003482template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003483Sema::OwningStmtResult
3484TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003485 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003486 OwningExprResult Cond(SemaRef);
3487 VarDecl *ConditionVar = 0;
3488 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003489 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003490 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003491 getDerived().TransformDefinition(
3492 S->getConditionVariable()->getLocation(),
3493 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003494 if (!ConditionVar)
3495 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003496 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003497 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003498
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003499 if (Cond.isInvalid())
3500 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003501
3502 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003503 if (S->getCond()) {
3504 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3505 S->getIfLoc(),
3506 move(Cond));
3507 if (CondE.isInvalid())
3508 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003509
Douglas Gregor6d319c62010-05-08 23:34:38 +00003510 Cond = move(CondE);
3511 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003512 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003513
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003514 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3515 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3516 return SemaRef.StmtError();
3517
Douglas Gregorebe10102009-08-20 07:17:43 +00003518 // Transform the "then" branch.
3519 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3520 if (Then.isInvalid())
3521 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 // Transform the "else" branch.
3524 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3525 if (Else.isInvalid())
3526 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregorebe10102009-08-20 07:17:43 +00003528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003529 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003530 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 Then.get() == S->getThen() &&
3532 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003533 return SemaRef.Owned(S->Retain());
3534
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003535 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003536 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003537 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003538}
3539
3540template<typename Derived>
3541Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003542TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003543 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003544 OwningExprResult Cond(SemaRef);
3545 VarDecl *ConditionVar = 0;
3546 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003547 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003548 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003549 getDerived().TransformDefinition(
3550 S->getConditionVariable()->getLocation(),
3551 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003552 if (!ConditionVar)
3553 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003554 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003555 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003556
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003557 if (Cond.isInvalid())
3558 return SemaRef.StmtError();
3559 }
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregorebe10102009-08-20 07:17:43 +00003561 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003562 OwningStmtResult Switch
3563 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3564 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003565 if (Switch.isInvalid())
3566 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 // Transform the body of the switch statement.
3569 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3570 if (Body.isInvalid())
3571 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 // Complete the switch statement.
3574 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3575 move(Body));
3576}
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578template<typename Derived>
3579Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003580TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003581 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003582 OwningExprResult Cond(SemaRef);
3583 VarDecl *ConditionVar = 0;
3584 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003585 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003586 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003587 getDerived().TransformDefinition(
3588 S->getConditionVariable()->getLocation(),
3589 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003590 if (!ConditionVar)
3591 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003592 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003593 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003594
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003595 if (Cond.isInvalid())
3596 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003597
3598 if (S->getCond()) {
3599 // Convert the condition to a boolean value.
3600 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003601 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003602 move(Cond));
3603 if (CondE.isInvalid())
3604 return getSema().StmtError();
3605 Cond = move(CondE);
3606 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003607 }
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003609 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3610 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3611 return SemaRef.StmtError();
3612
Douglas Gregorebe10102009-08-20 07:17:43 +00003613 // Transform the body
3614 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3615 if (Body.isInvalid())
3616 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003617
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003619 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003620 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003622 return SemaRef.Owned(S->Retain());
3623
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003624 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003625 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003626}
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628template<typename Derived>
3629Sema::OwningStmtResult
3630TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003631 // Transform the body
3632 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3633 if (Body.isInvalid())
3634 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003635
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003636 // Transform the condition
3637 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3638 if (Cond.isInvalid())
3639 return SemaRef.StmtError();
3640
Douglas Gregorebe10102009-08-20 07:17:43 +00003641 if (!getDerived().AlwaysRebuild() &&
3642 Cond.get() == S->getCond() &&
3643 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003644 return SemaRef.Owned(S->Retain());
3645
Douglas Gregorebe10102009-08-20 07:17:43 +00003646 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3647 /*FIXME:*/S->getWhileLoc(), move(Cond),
3648 S->getRParenLoc());
3649}
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregorebe10102009-08-20 07:17:43 +00003651template<typename Derived>
3652Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003653TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 // Transform the initialization statement
3655 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3656 if (Init.isInvalid())
3657 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003658
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003660 OwningExprResult Cond(SemaRef);
3661 VarDecl *ConditionVar = 0;
3662 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003663 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003664 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003665 getDerived().TransformDefinition(
3666 S->getConditionVariable()->getLocation(),
3667 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003668 if (!ConditionVar)
3669 return SemaRef.StmtError();
3670 } else {
3671 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003672
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003673 if (Cond.isInvalid())
3674 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003675
3676 if (S->getCond()) {
3677 // Convert the condition to a boolean value.
3678 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3679 S->getForLoc(),
3680 move(Cond));
3681 if (CondE.isInvalid())
3682 return getSema().StmtError();
3683
3684 Cond = move(CondE);
3685 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003686 }
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003688 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3689 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3690 return SemaRef.StmtError();
3691
Douglas Gregorebe10102009-08-20 07:17:43 +00003692 // Transform the increment
3693 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3694 if (Inc.isInvalid())
3695 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003697 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3698 if (S->getInc() && !FullInc->get())
3699 return SemaRef.StmtError();
3700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701 // Transform the body
3702 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3703 if (Body.isInvalid())
3704 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003705
Douglas Gregorebe10102009-08-20 07:17:43 +00003706 if (!getDerived().AlwaysRebuild() &&
3707 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003708 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 Inc.get() == S->getInc() &&
3710 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003711 return SemaRef.Owned(S->Retain());
3712
Douglas Gregorebe10102009-08-20 07:17:43 +00003713 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003714 move(Init), FullCond, ConditionVar,
3715 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003716}
3717
3718template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003719Sema::OwningStmtResult
3720TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003721 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003722 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003723 S->getLabel());
3724}
3725
3726template<typename Derived>
3727Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003728TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003729 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3730 if (Target.isInvalid())
3731 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003732
Douglas Gregorebe10102009-08-20 07:17:43 +00003733 if (!getDerived().AlwaysRebuild() &&
3734 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003735 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003736
3737 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3738 move(Target));
3739}
3740
3741template<typename Derived>
3742Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003743TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3744 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003745}
Mike Stump11289f42009-09-09 15:08:12 +00003746
Douglas Gregorebe10102009-08-20 07:17:43 +00003747template<typename Derived>
3748Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003749TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3750 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003751}
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregorebe10102009-08-20 07:17:43 +00003753template<typename Derived>
3754Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003755TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003756 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3757 if (Result.isInvalid())
3758 return SemaRef.StmtError();
3759
Mike Stump11289f42009-09-09 15:08:12 +00003760 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 // to tell whether the return type of the function has changed.
3762 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3763}
Mike Stump11289f42009-09-09 15:08:12 +00003764
Douglas Gregorebe10102009-08-20 07:17:43 +00003765template<typename Derived>
3766Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003767TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003768 bool DeclChanged = false;
3769 llvm::SmallVector<Decl *, 4> Decls;
3770 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3771 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003772 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3773 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003774 if (!Transformed)
3775 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregorebe10102009-08-20 07:17:43 +00003777 if (Transformed != *D)
3778 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003779
Douglas Gregorebe10102009-08-20 07:17:43 +00003780 Decls.push_back(Transformed);
3781 }
Mike Stump11289f42009-09-09 15:08:12 +00003782
Douglas Gregorebe10102009-08-20 07:17:43 +00003783 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003784 return SemaRef.Owned(S->Retain());
3785
3786 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003787 S->getStartLoc(), S->getEndLoc());
3788}
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregorebe10102009-08-20 07:17:43 +00003790template<typename Derived>
3791Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003792TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003793 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003794 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003795}
3796
3797template<typename Derived>
3798Sema::OwningStmtResult
3799TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003800
Anders Carlssonaaeef072010-01-24 05:50:09 +00003801 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3802 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003803 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003804
Anders Carlssonaaeef072010-01-24 05:50:09 +00003805 OwningExprResult AsmString(SemaRef);
3806 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3807
3808 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003809
Anders Carlssonaaeef072010-01-24 05:50:09 +00003810 // Go through the outputs.
3811 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003812 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003813
Anders Carlssonaaeef072010-01-24 05:50:09 +00003814 // No need to transform the constraint literal.
3815 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003816
Anders Carlssonaaeef072010-01-24 05:50:09 +00003817 // Transform the output expr.
3818 Expr *OutputExpr = S->getOutputExpr(I);
3819 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3820 if (Result.isInvalid())
3821 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003822
Anders Carlssonaaeef072010-01-24 05:50:09 +00003823 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003824
Anders Carlssonaaeef072010-01-24 05:50:09 +00003825 Exprs.push_back(Result.takeAs<Expr>());
3826 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003827
Anders Carlssonaaeef072010-01-24 05:50:09 +00003828 // Go through the inputs.
3829 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003830 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003831
Anders Carlssonaaeef072010-01-24 05:50:09 +00003832 // No need to transform the constraint literal.
3833 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003834
Anders Carlssonaaeef072010-01-24 05:50:09 +00003835 // Transform the input expr.
3836 Expr *InputExpr = S->getInputExpr(I);
3837 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3838 if (Result.isInvalid())
3839 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003840
Anders Carlssonaaeef072010-01-24 05:50:09 +00003841 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003842
Anders Carlssonaaeef072010-01-24 05:50:09 +00003843 Exprs.push_back(Result.takeAs<Expr>());
3844 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003845
Anders Carlssonaaeef072010-01-24 05:50:09 +00003846 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3847 return SemaRef.Owned(S->Retain());
3848
3849 // Go through the clobbers.
3850 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3851 Clobbers.push_back(S->getClobber(I)->Retain());
3852
3853 // No need to transform the asm string literal.
3854 AsmString = SemaRef.Owned(S->getAsmString());
3855
3856 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3857 S->isSimple(),
3858 S->isVolatile(),
3859 S->getNumOutputs(),
3860 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003861 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003862 move_arg(Constraints),
3863 move_arg(Exprs),
3864 move(AsmString),
3865 move_arg(Clobbers),
3866 S->getRParenLoc(),
3867 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003868}
3869
3870
3871template<typename Derived>
3872Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003873TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003874 // Transform the body of the @try.
3875 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3876 if (TryBody.isInvalid())
3877 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003878
Douglas Gregor96c79492010-04-23 22:50:49 +00003879 // Transform the @catch statements (if present).
3880 bool AnyCatchChanged = false;
3881 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3882 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3883 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003884 if (Catch.isInvalid())
3885 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003886 if (Catch.get() != S->getCatchStmt(I))
3887 AnyCatchChanged = true;
3888 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003889 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003890
Douglas Gregor306de2f2010-04-22 23:59:56 +00003891 // Transform the @finally statement (if present).
3892 OwningStmtResult Finally(SemaRef);
3893 if (S->getFinallyStmt()) {
3894 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3895 if (Finally.isInvalid())
3896 return SemaRef.StmtError();
3897 }
3898
3899 // If nothing changed, just retain this statement.
3900 if (!getDerived().AlwaysRebuild() &&
3901 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003902 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003903 Finally.get() == S->getFinallyStmt())
3904 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003905
Douglas Gregor306de2f2010-04-22 23:59:56 +00003906 // Build a new statement.
3907 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003908 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003909}
Mike Stump11289f42009-09-09 15:08:12 +00003910
Douglas Gregorebe10102009-08-20 07:17:43 +00003911template<typename Derived>
3912Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003913TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003914 // Transform the @catch parameter, if there is one.
3915 VarDecl *Var = 0;
3916 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3917 TypeSourceInfo *TSInfo = 0;
3918 if (FromVar->getTypeSourceInfo()) {
3919 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3920 if (!TSInfo)
3921 return SemaRef.StmtError();
3922 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003923
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003924 QualType T;
3925 if (TSInfo)
3926 T = TSInfo->getType();
3927 else {
3928 T = getDerived().TransformType(FromVar->getType());
3929 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003930 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003931 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003932
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003933 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3934 if (!Var)
3935 return SemaRef.StmtError();
3936 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003937
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003938 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3939 if (Body.isInvalid())
3940 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003941
3942 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003943 S->getRParenLoc(),
3944 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003945}
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregorebe10102009-08-20 07:17:43 +00003947template<typename Derived>
3948Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003949TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003950 // Transform the body.
3951 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3952 if (Body.isInvalid())
3953 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003954
Douglas Gregor306de2f2010-04-22 23:59:56 +00003955 // If nothing changed, just retain this statement.
3956 if (!getDerived().AlwaysRebuild() &&
3957 Body.get() == S->getFinallyBody())
3958 return SemaRef.Owned(S->Retain());
3959
3960 // Build a new statement.
3961 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3962 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003963}
Mike Stump11289f42009-09-09 15:08:12 +00003964
Douglas Gregorebe10102009-08-20 07:17:43 +00003965template<typename Derived>
3966Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003967TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003968 OwningExprResult Operand(SemaRef);
3969 if (S->getThrowExpr()) {
3970 Operand = getDerived().TransformExpr(S->getThrowExpr());
3971 if (Operand.isInvalid())
3972 return getSema().StmtError();
3973 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003974
Douglas Gregor2900c162010-04-22 21:44:01 +00003975 if (!getDerived().AlwaysRebuild() &&
3976 Operand.get() == S->getThrowExpr())
3977 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003978
Douglas Gregor2900c162010-04-22 21:44:01 +00003979 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003980}
Mike Stump11289f42009-09-09 15:08:12 +00003981
Douglas Gregorebe10102009-08-20 07:17:43 +00003982template<typename Derived>
3983Sema::OwningStmtResult
3984TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003985 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003986 // Transform the object we are locking.
3987 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3988 if (Object.isInvalid())
3989 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990
Douglas Gregor6148de72010-04-22 22:01:21 +00003991 // Transform the body.
3992 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3993 if (Body.isInvalid())
3994 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003995
Douglas Gregor6148de72010-04-22 22:01:21 +00003996 // If nothing change, just retain the current statement.
3997 if (!getDerived().AlwaysRebuild() &&
3998 Object.get() == S->getSynchExpr() &&
3999 Body.get() == S->getSynchBody())
4000 return SemaRef.Owned(S->Retain());
4001
4002 // Build a new statement.
4003 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4004 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004005}
4006
4007template<typename Derived>
4008Sema::OwningStmtResult
4009TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004010 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004011 // Transform the element statement.
4012 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4013 if (Element.isInvalid())
4014 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004015
Douglas Gregorf68a5082010-04-22 23:10:45 +00004016 // Transform the collection expression.
4017 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4018 if (Collection.isInvalid())
4019 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004020
Douglas Gregorf68a5082010-04-22 23:10:45 +00004021 // Transform the body.
4022 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4023 if (Body.isInvalid())
4024 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004025
Douglas Gregorf68a5082010-04-22 23:10:45 +00004026 // If nothing changed, just retain this statement.
4027 if (!getDerived().AlwaysRebuild() &&
4028 Element.get() == S->getElement() &&
4029 Collection.get() == S->getCollection() &&
4030 Body.get() == S->getBody())
4031 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004032
Douglas Gregorf68a5082010-04-22 23:10:45 +00004033 // Build a new statement.
4034 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4035 /*FIXME:*/S->getForLoc(),
4036 move(Element),
4037 move(Collection),
4038 S->getRParenLoc(),
4039 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004040}
4041
4042
4043template<typename Derived>
4044Sema::OwningStmtResult
4045TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4046 // Transform the exception declaration, if any.
4047 VarDecl *Var = 0;
4048 if (S->getExceptionDecl()) {
4049 VarDecl *ExceptionDecl = S->getExceptionDecl();
4050 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4051 ExceptionDecl->getDeclName());
4052
4053 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4054 if (T.isNull())
4055 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregorebe10102009-08-20 07:17:43 +00004057 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4058 T,
John McCallbcd03502009-12-07 02:54:59 +00004059 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004060 ExceptionDecl->getIdentifier(),
4061 ExceptionDecl->getLocation(),
4062 /*FIXME: Inaccurate*/
4063 SourceRange(ExceptionDecl->getLocation()));
4064 if (!Var || Var->isInvalidDecl()) {
4065 if (Var)
4066 Var->Destroy(SemaRef.Context);
4067 return SemaRef.StmtError();
4068 }
4069 }
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregorebe10102009-08-20 07:17:43 +00004071 // Transform the actual exception handler.
4072 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4073 if (Handler.isInvalid()) {
4074 if (Var)
4075 Var->Destroy(SemaRef.Context);
4076 return SemaRef.StmtError();
4077 }
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregorebe10102009-08-20 07:17:43 +00004079 if (!getDerived().AlwaysRebuild() &&
4080 !Var &&
4081 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004082 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004083
4084 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4085 Var,
4086 move(Handler));
4087}
Mike Stump11289f42009-09-09 15:08:12 +00004088
Douglas Gregorebe10102009-08-20 07:17:43 +00004089template<typename Derived>
4090Sema::OwningStmtResult
4091TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4092 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004093 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004094 = getDerived().TransformCompoundStmt(S->getTryBlock());
4095 if (TryBlock.isInvalid())
4096 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004097
Douglas Gregorebe10102009-08-20 07:17:43 +00004098 // Transform the handlers.
4099 bool HandlerChanged = false;
4100 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4101 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004102 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004103 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4104 if (Handler.isInvalid())
4105 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004106
Douglas Gregorebe10102009-08-20 07:17:43 +00004107 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4108 Handlers.push_back(Handler.takeAs<Stmt>());
4109 }
Mike Stump11289f42009-09-09 15:08:12 +00004110
Douglas Gregorebe10102009-08-20 07:17:43 +00004111 if (!getDerived().AlwaysRebuild() &&
4112 TryBlock.get() == S->getTryBlock() &&
4113 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004114 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004115
4116 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004117 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004118}
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregorebe10102009-08-20 07:17:43 +00004120//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004121// Expression transformation
4122//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004123template<typename Derived>
4124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004125TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004126 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004127}
Mike Stump11289f42009-09-09 15:08:12 +00004128
4129template<typename Derived>
4130Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004131TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004132 NestedNameSpecifier *Qualifier = 0;
4133 if (E->getQualifier()) {
4134 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004135 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004136 if (!Qualifier)
4137 return SemaRef.ExprError();
4138 }
John McCallce546572009-12-08 09:08:17 +00004139
4140 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004141 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4142 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004143 if (!ND)
4144 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004145
Alexis Hunta8136cc2010-05-05 15:23:54 +00004146 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004147 Qualifier == E->getQualifier() &&
4148 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004149 !E->hasExplicitTemplateArgumentList()) {
4150
4151 // Mark it referenced in the new context regardless.
4152 // FIXME: this is a bit instantiation-specific.
4153 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4154
Mike Stump11289f42009-09-09 15:08:12 +00004155 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004156 }
John McCallce546572009-12-08 09:08:17 +00004157
4158 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4159 if (E->hasExplicitTemplateArgumentList()) {
4160 TemplateArgs = &TransArgs;
4161 TransArgs.setLAngleLoc(E->getLAngleLoc());
4162 TransArgs.setRAngleLoc(E->getRAngleLoc());
4163 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4164 TemplateArgumentLoc Loc;
4165 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4166 return SemaRef.ExprError();
4167 TransArgs.addArgument(Loc);
4168 }
4169 }
4170
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004171 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004172 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004173}
Mike Stump11289f42009-09-09 15:08:12 +00004174
Douglas Gregora16548e2009-08-11 05:31:07 +00004175template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004176Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004177TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004178 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004179}
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregora16548e2009-08-11 05:31:07 +00004181template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004182Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004183TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004184 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004185}
Mike Stump11289f42009-09-09 15:08:12 +00004186
Douglas Gregora16548e2009-08-11 05:31:07 +00004187template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004188Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004189TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004190 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004191}
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>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004196 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregora16548e2009-08-11 05:31:07 +00004199template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004200Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004201TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004202 return SemaRef.Owned(E->Retain());
4203}
4204
4205template<typename Derived>
4206Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004207TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4209 if (SubExpr.isInvalid())
4210 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004211
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004213 return SemaRef.Owned(E->Retain());
4214
4215 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 E->getRParen());
4217}
4218
Mike Stump11289f42009-09-09 15:08:12 +00004219template<typename Derived>
4220Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004221TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4222 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004223 if (SubExpr.isInvalid())
4224 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004227 return SemaRef.Owned(E->Retain());
4228
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4230 E->getOpcode(),
4231 move(SubExpr));
4232}
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregora16548e2009-08-11 05:31:07 +00004234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004235Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004236TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4237 // Transform the type.
4238 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4239 if (!Type)
4240 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004241
Douglas Gregor882211c2010-04-28 22:16:22 +00004242 // Transform all of the components into components similar to what the
4243 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004244 // FIXME: It would be slightly more efficient in the non-dependent case to
4245 // just map FieldDecls, rather than requiring the rebuilder to look for
4246 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004247 // template code that we don't care.
4248 bool ExprChanged = false;
4249 typedef Action::OffsetOfComponent Component;
4250 typedef OffsetOfExpr::OffsetOfNode Node;
4251 llvm::SmallVector<Component, 4> Components;
4252 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4253 const Node &ON = E->getComponent(I);
4254 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004255 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004256 Comp.LocStart = ON.getRange().getBegin();
4257 Comp.LocEnd = ON.getRange().getEnd();
4258 switch (ON.getKind()) {
4259 case Node::Array: {
4260 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4261 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4262 if (Index.isInvalid())
4263 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004264
Douglas Gregor882211c2010-04-28 22:16:22 +00004265 ExprChanged = ExprChanged || Index.get() != FromIndex;
4266 Comp.isBrackets = true;
4267 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4268 break;
4269 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004270
Douglas Gregor882211c2010-04-28 22:16:22 +00004271 case Node::Field:
4272 case Node::Identifier:
4273 Comp.isBrackets = false;
4274 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004275 if (!Comp.U.IdentInfo)
4276 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004277
Douglas Gregor882211c2010-04-28 22:16:22 +00004278 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004279
Douglas Gregord1702062010-04-29 00:18:15 +00004280 case Node::Base:
4281 // Will be recomputed during the rebuild.
4282 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004283 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004284
Douglas Gregor882211c2010-04-28 22:16:22 +00004285 Components.push_back(Comp);
4286 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004287
Douglas Gregor882211c2010-04-28 22:16:22 +00004288 // If nothing changed, retain the existing expression.
4289 if (!getDerived().AlwaysRebuild() &&
4290 Type == E->getTypeSourceInfo() &&
4291 !ExprChanged)
4292 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004293
Douglas Gregor882211c2010-04-28 22:16:22 +00004294 // Build a new offsetof expression.
4295 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4296 Components.data(), Components.size(),
4297 E->getRParenLoc());
4298}
4299
4300template<typename Derived>
4301Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004302TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004304 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004305
John McCallbcd03502009-12-07 02:54:59 +00004306 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004307 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004309
John McCall4c98fd82009-11-04 07:28:41 +00004310 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004312
John McCall4c98fd82009-11-04 07:28:41 +00004313 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004314 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 E->getSourceRange());
4316 }
Mike Stump11289f42009-09-09 15:08:12 +00004317
Douglas Gregora16548e2009-08-11 05:31:07 +00004318 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004319 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 // C++0x [expr.sizeof]p1:
4321 // The operand is either an expression, which is an unevaluated operand
4322 // [...]
4323 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4326 if (SubExpr.isInvalid())
4327 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4330 return SemaRef.Owned(E->Retain());
4331 }
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4334 E->isSizeOf(),
4335 E->getSourceRange());
4336}
Mike Stump11289f42009-09-09 15:08:12 +00004337
Douglas Gregora16548e2009-08-11 05:31:07 +00004338template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004339Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004340TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4342 if (LHS.isInvalid())
4343 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4346 if (RHS.isInvalid())
4347 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004348
4349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 if (!getDerived().AlwaysRebuild() &&
4351 LHS.get() == E->getLHS() &&
4352 RHS.get() == E->getRHS())
4353 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4356 /*FIXME:*/E->getLHS()->getLocStart(),
4357 move(RHS),
4358 E->getRBracketLoc());
4359}
Mike Stump11289f42009-09-09 15:08:12 +00004360
4361template<typename Derived>
4362Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004363TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 // Transform the callee.
4365 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4366 if (Callee.isInvalid())
4367 return SemaRef.ExprError();
4368
4369 // Transform arguments.
4370 bool ArgChanged = false;
4371 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4372 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4373 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4374 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4375 if (Arg.isInvalid())
4376 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004377
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 // FIXME: Wrong source location information for the ','.
4379 FakeCommaLocs.push_back(
4380 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004381
4382 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 Args.push_back(Arg.takeAs<Expr>());
4384 }
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 if (!getDerived().AlwaysRebuild() &&
4387 Callee.get() == E->getCallee() &&
4388 !ArgChanged)
4389 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004390
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004392 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4394 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4395 move_arg(Args),
4396 FakeCommaLocs.data(),
4397 E->getRParenLoc());
4398}
Mike Stump11289f42009-09-09 15:08:12 +00004399
4400template<typename Derived>
4401Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004402TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4404 if (Base.isInvalid())
4405 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004407 NestedNameSpecifier *Qualifier = 0;
4408 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004409 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004410 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004411 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004412 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004413 return SemaRef.ExprError();
4414 }
Mike Stump11289f42009-09-09 15:08:12 +00004415
Eli Friedman2cfcef62009-12-04 06:40:45 +00004416 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004417 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4418 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 if (!Member)
4420 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004421
John McCall16df1e52010-03-30 21:47:33 +00004422 NamedDecl *FoundDecl = E->getFoundDecl();
4423 if (FoundDecl == E->getMemberDecl()) {
4424 FoundDecl = Member;
4425 } else {
4426 FoundDecl = cast_or_null<NamedDecl>(
4427 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4428 if (!FoundDecl)
4429 return SemaRef.ExprError();
4430 }
4431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 if (!getDerived().AlwaysRebuild() &&
4433 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004434 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004435 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004436 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004437 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004438
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004439 // Mark it referenced in the new context regardless.
4440 // FIXME: this is a bit instantiation-specific.
4441 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004442 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004443 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004444
John McCall6b51f282009-11-23 01:53:49 +00004445 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004446 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004447 TransArgs.setLAngleLoc(E->getLAngleLoc());
4448 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004449 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004450 TemplateArgumentLoc Loc;
4451 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004452 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004453 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004454 }
4455 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004456
Douglas Gregora16548e2009-08-11 05:31:07 +00004457 // FIXME: Bogus source location for the operator
4458 SourceLocation FakeOperatorLoc
4459 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4460
John McCall38836f02010-01-15 08:34:02 +00004461 // FIXME: to do this check properly, we will need to preserve the
4462 // first-qualifier-in-scope here, just in case we had a dependent
4463 // base (and therefore couldn't do the check) and a
4464 // nested-name-qualifier (and therefore could do the lookup).
4465 NamedDecl *FirstQualifierInScope = 0;
4466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4468 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004469 Qualifier,
4470 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004472 Member,
John McCall16df1e52010-03-30 21:47:33 +00004473 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004474 (E->hasExplicitTemplateArgumentList()
4475 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004476 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004477}
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004480Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004481TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4483 if (LHS.isInvalid())
4484 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregora16548e2009-08-11 05:31:07 +00004486 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4487 if (RHS.isInvalid())
4488 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 if (!getDerived().AlwaysRebuild() &&
4491 LHS.get() == E->getLHS() &&
4492 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004493 return SemaRef.Owned(E->Retain());
4494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4496 move(LHS), move(RHS));
4497}
4498
Mike Stump11289f42009-09-09 15:08:12 +00004499template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004500Sema::OwningExprResult
4501TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004502 CompoundAssignOperator *E) {
4503 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004504}
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004507Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4510 if (Cond.isInvalid())
4511 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004512
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4514 if (LHS.isInvalid())
4515 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004516
Douglas Gregora16548e2009-08-11 05:31:07 +00004517 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4518 if (RHS.isInvalid())
4519 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004520
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 if (!getDerived().AlwaysRebuild() &&
4522 Cond.get() == E->getCond() &&
4523 LHS.get() == E->getLHS() &&
4524 RHS.get() == E->getRHS())
4525 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004526
4527 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004528 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004529 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004530 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 move(RHS));
4532}
Mike Stump11289f42009-09-09 15:08:12 +00004533
4534template<typename Derived>
4535Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004536TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004537 // Implicit casts are eliminated during transformation, since they
4538 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004539 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004540}
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542template<typename Derived>
4543Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004544TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004545 TypeSourceInfo *OldT;
4546 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 {
4548 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004549 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004550 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4551 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004552
John McCall97513962010-01-15 18:39:57 +00004553 OldT = E->getTypeInfoAsWritten();
4554 NewT = getDerived().TransformType(OldT);
4555 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004556 return SemaRef.ExprError();
4557 }
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregor6131b442009-12-12 18:16:41 +00004559 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004560 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 if (SubExpr.isInvalid())
4562 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004565 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004567 return SemaRef.Owned(E->Retain());
4568
John McCall97513962010-01-15 18:39:57 +00004569 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4570 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 E->getRParenLoc(),
4572 move(SubExpr));
4573}
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregora16548e2009-08-11 05:31:07 +00004575template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004576Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004577TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004578 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4579 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4580 if (!NewT)
4581 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004582
Douglas Gregora16548e2009-08-11 05:31:07 +00004583 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4584 if (Init.isInvalid())
4585 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004586
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004588 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004589 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004590 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004591
John McCall5d7aa7f2010-01-19 22:33:45 +00004592 // Note: the expression type doesn't necessarily match the
4593 // type-as-written, but that's okay, because it should always be
4594 // derivable from the initializer.
4595
John McCalle15bbff2010-01-18 19:35:47 +00004596 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 /*FIXME:*/E->getInitializer()->getLocEnd(),
4598 move(Init));
4599}
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601template<typename Derived>
4602Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004603TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4605 if (Base.isInvalid())
4606 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004607
Douglas Gregora16548e2009-08-11 05:31:07 +00004608 if (!getDerived().AlwaysRebuild() &&
4609 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004610 return SemaRef.Owned(E->Retain());
4611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004613 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4615 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4616 E->getAccessorLoc(),
4617 E->getAccessor());
4618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregora16548e2009-08-11 05:31:07 +00004620template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004621Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004622TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4626 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4627 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4628 if (Init.isInvalid())
4629 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 InitChanged = InitChanged || Init.get() != E->getInit(I);
4632 Inits.push_back(Init.takeAs<Expr>());
4633 }
Mike Stump11289f42009-09-09 15:08:12 +00004634
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004636 return SemaRef.Owned(E->Retain());
4637
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004639 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004640}
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregora16548e2009-08-11 05:31:07 +00004642template<typename Derived>
4643Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004644TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004645 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregorebe10102009-08-20 07:17:43 +00004647 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4649 if (Init.isInvalid())
4650 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregorebe10102009-08-20 07:17:43 +00004652 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4654 bool ExprChanged = false;
4655 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4656 DEnd = E->designators_end();
4657 D != DEnd; ++D) {
4658 if (D->isFieldDesignator()) {
4659 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4660 D->getDotLoc(),
4661 D->getFieldLoc()));
4662 continue;
4663 }
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 if (D->isArrayDesignator()) {
4666 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4667 if (Index.isInvalid())
4668 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004669
4670 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4674 ArrayExprs.push_back(Index.release());
4675 continue;
4676 }
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004679 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4681 if (Start.isInvalid())
4682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4685 if (End.isInvalid())
4686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004687
4688 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 End.get(),
4690 D->getLBracketLoc(),
4691 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4694 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregora16548e2009-08-11 05:31:07 +00004696 ArrayExprs.push_back(Start.release());
4697 ArrayExprs.push_back(End.release());
4698 }
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 if (!getDerived().AlwaysRebuild() &&
4701 Init.get() == E->getInit() &&
4702 !ExprChanged)
4703 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4706 E->getEqualOrColonLoc(),
4707 E->usesGNUSyntax(), move(Init));
4708}
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004711Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004712TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004713 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004714 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004715
Douglas Gregor3da3c062009-10-28 00:29:27 +00004716 // FIXME: Will we ever have proper type location here? Will we actually
4717 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 QualType T = getDerived().TransformType(E->getType());
4719 if (T.isNull())
4720 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 if (!getDerived().AlwaysRebuild() &&
4723 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004724 return SemaRef.Owned(E->Retain());
4725
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 return getDerived().RebuildImplicitValueInitExpr(T);
4727}
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregora16548e2009-08-11 05:31:07 +00004729template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004730Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004731TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 // FIXME: Do we want the type as written?
4733 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 {
4736 // FIXME: Source location isn't quite accurate.
4737 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4738 T = getDerived().TransformType(E->getType());
4739 if (T.isNull())
4740 return SemaRef.ExprError();
4741 }
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4744 if (SubExpr.isInvalid())
4745 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 if (!getDerived().AlwaysRebuild() &&
4748 T == E->getType() &&
4749 SubExpr.get() == E->getSubExpr())
4750 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4753 T, E->getRParenLoc());
4754}
4755
4756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004757Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004758TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 bool ArgumentChanged = false;
4760 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4761 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4762 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4763 if (Init.isInvalid())
4764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4767 Inits.push_back(Init.takeAs<Expr>());
4768 }
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4771 move_arg(Inits),
4772 E->getRParenLoc());
4773}
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775/// \brief Transform an address-of-label expression.
4776///
4777/// By default, the transformation of an address-of-label expression always
4778/// rebuilds the expression, so that the label identifier can be resolved to
4779/// the corresponding label statement by semantic analysis.
4780template<typename Derived>
4781Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4784 E->getLabel());
4785}
Mike Stump11289f42009-09-09 15:08:12 +00004786
4787template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004788Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004789TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004790 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4792 if (SubStmt.isInvalid())
4793 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 if (!getDerived().AlwaysRebuild() &&
4796 SubStmt.get() == E->getSubStmt())
4797 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004798
4799 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 move(SubStmt),
4801 E->getRParenLoc());
4802}
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregora16548e2009-08-11 05:31:07 +00004804template<typename Derived>
4805Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004806TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 QualType T1, T2;
4808 {
4809 // FIXME: Source location isn't quite accurate.
4810 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004811
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 T1 = getDerived().TransformType(E->getArgType1());
4813 if (T1.isNull())
4814 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004815
Douglas Gregora16548e2009-08-11 05:31:07 +00004816 T2 = getDerived().TransformType(E->getArgType2());
4817 if (T2.isNull())
4818 return SemaRef.ExprError();
4819 }
4820
4821 if (!getDerived().AlwaysRebuild() &&
4822 T1 == E->getArgType1() &&
4823 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004824 return SemaRef.Owned(E->Retain());
4825
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4827 T1, T2, E->getRParenLoc());
4828}
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830template<typename Derived>
4831Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004832TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4834 if (Cond.isInvalid())
4835 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4838 if (LHS.isInvalid())
4839 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004840
Douglas Gregora16548e2009-08-11 05:31:07 +00004841 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4842 if (RHS.isInvalid())
4843 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 if (!getDerived().AlwaysRebuild() &&
4846 Cond.get() == E->getCond() &&
4847 LHS.get() == E->getLHS() &&
4848 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004849 return SemaRef.Owned(E->Retain());
4850
Douglas Gregora16548e2009-08-11 05:31:07 +00004851 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4852 move(Cond), move(LHS), move(RHS),
4853 E->getRParenLoc());
4854}
Mike Stump11289f42009-09-09 15:08:12 +00004855
Douglas Gregora16548e2009-08-11 05:31:07 +00004856template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004857Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004859 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004860}
4861
4862template<typename Derived>
4863Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004864TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004865 switch (E->getOperator()) {
4866 case OO_New:
4867 case OO_Delete:
4868 case OO_Array_New:
4869 case OO_Array_Delete:
4870 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4871 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004872
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004873 case OO_Call: {
4874 // This is a call to an object's operator().
4875 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4876
4877 // Transform the object itself.
4878 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4879 if (Object.isInvalid())
4880 return SemaRef.ExprError();
4881
4882 // FIXME: Poor location information
4883 SourceLocation FakeLParenLoc
4884 = SemaRef.PP.getLocForEndOfToken(
4885 static_cast<Expr *>(Object.get())->getLocEnd());
4886
4887 // Transform the call arguments.
4888 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4889 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4890 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004891 if (getDerived().DropCallArgument(E->getArg(I)))
4892 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004893
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004894 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4895 if (Arg.isInvalid())
4896 return SemaRef.ExprError();
4897
4898 // FIXME: Poor source location information.
4899 SourceLocation FakeCommaLoc
4900 = SemaRef.PP.getLocForEndOfToken(
4901 static_cast<Expr *>(Arg.get())->getLocEnd());
4902 FakeCommaLocs.push_back(FakeCommaLoc);
4903 Args.push_back(Arg.release());
4904 }
4905
4906 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4907 move_arg(Args),
4908 FakeCommaLocs.data(),
4909 E->getLocEnd());
4910 }
4911
4912#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4913 case OO_##Name:
4914#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4915#include "clang/Basic/OperatorKinds.def"
4916 case OO_Subscript:
4917 // Handled below.
4918 break;
4919
4920 case OO_Conditional:
4921 llvm_unreachable("conditional operator is not actually overloadable");
4922 return SemaRef.ExprError();
4923
4924 case OO_None:
4925 case NUM_OVERLOADED_OPERATORS:
4926 llvm_unreachable("not an overloaded operator?");
4927 return SemaRef.ExprError();
4928 }
4929
Douglas Gregora16548e2009-08-11 05:31:07 +00004930 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4931 if (Callee.isInvalid())
4932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
John McCall47f29ea2009-12-08 09:21:05 +00004934 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 if (First.isInvalid())
4936 return SemaRef.ExprError();
4937
4938 OwningExprResult Second(SemaRef);
4939 if (E->getNumArgs() == 2) {
4940 Second = getDerived().TransformExpr(E->getArg(1));
4941 if (Second.isInvalid())
4942 return SemaRef.ExprError();
4943 }
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregora16548e2009-08-11 05:31:07 +00004945 if (!getDerived().AlwaysRebuild() &&
4946 Callee.get() == E->getCallee() &&
4947 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004948 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4949 return SemaRef.Owned(E->Retain());
4950
Douglas Gregora16548e2009-08-11 05:31:07 +00004951 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4952 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004953 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 move(First),
4955 move(Second));
4956}
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregora16548e2009-08-11 05:31:07 +00004958template<typename Derived>
4959Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004960TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4961 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004962}
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregora16548e2009-08-11 05:31:07 +00004964template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004965Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004966TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004967 TypeSourceInfo *OldT;
4968 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004969 {
4970 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004971 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4973 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCall97513962010-01-15 18:39:57 +00004975 OldT = E->getTypeInfoAsWritten();
4976 NewT = getDerived().TransformType(OldT);
4977 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 return SemaRef.ExprError();
4979 }
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregor6131b442009-12-12 18:16:41 +00004981 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004982 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004983 if (SubExpr.isInvalid())
4984 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004987 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004988 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004989 return SemaRef.Owned(E->Retain());
4990
Douglas Gregora16548e2009-08-11 05:31:07 +00004991 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004992 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4994 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4995 SourceLocation FakeRParenLoc
4996 = SemaRef.PP.getLocForEndOfToken(
4997 E->getSubExpr()->getSourceRange().getEnd());
4998 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004999 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005001 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005002 FakeRAngleLoc,
5003 FakeRAngleLoc,
5004 move(SubExpr),
5005 FakeRParenLoc);
5006}
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregora16548e2009-08-11 05:31:07 +00005008template<typename Derived>
5009Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005010TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5011 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005012}
Mike Stump11289f42009-09-09 15:08:12 +00005013
5014template<typename Derived>
5015Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005016TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5017 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005018}
5019
Douglas Gregora16548e2009-08-11 05:31:07 +00005020template<typename Derived>
5021Sema::OwningExprResult
5022TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005023 CXXReinterpretCastExpr *E) {
5024 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005025}
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregora16548e2009-08-11 05:31:07 +00005027template<typename Derived>
5028Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005029TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5030 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregora16548e2009-08-11 05:31:07 +00005033template<typename Derived>
5034Sema::OwningExprResult
5035TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005036 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005037 TypeSourceInfo *OldT;
5038 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005039 {
5040 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005041
John McCall97513962010-01-15 18:39:57 +00005042 OldT = E->getTypeInfoAsWritten();
5043 NewT = getDerived().TransformType(OldT);
5044 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 return SemaRef.ExprError();
5046 }
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregor6131b442009-12-12 18:16:41 +00005048 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005049 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 if (SubExpr.isInvalid())
5051 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005052
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005054 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005056 return SemaRef.Owned(E->Retain());
5057
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 // FIXME: The end of the type's source range is wrong
5059 return getDerived().RebuildCXXFunctionalCastExpr(
5060 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005061 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 /*FIXME:*/E->getSubExpr()->getLocStart(),
5063 move(SubExpr),
5064 E->getRParenLoc());
5065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067template<typename Derived>
5068Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005071 TypeSourceInfo *TInfo
5072 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5073 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005077 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005078 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregor9da64192010-04-26 22:37:10 +00005080 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5081 E->getLocStart(),
5082 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 E->getLocEnd());
5084 }
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 // We don't know whether the expression is potentially evaluated until
5087 // after we perform semantic analysis, so the expression is potentially
5088 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005089 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005090 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005091
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5093 if (SubExpr.isInvalid())
5094 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 if (!getDerived().AlwaysRebuild() &&
5097 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005098 return SemaRef.Owned(E->Retain());
5099
Douglas Gregor9da64192010-04-26 22:37:10 +00005100 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5101 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 move(SubExpr),
5103 E->getLocEnd());
5104}
5105
5106template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005107Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005108TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005109 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005110}
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112template<typename Derived>
5113Sema::OwningExprResult
5114TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005115 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005116 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005117}
Mike Stump11289f42009-09-09 15:08:12 +00005118
Douglas Gregora16548e2009-08-11 05:31:07 +00005119template<typename Derived>
5120Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005121TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005123
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 QualType T = getDerived().TransformType(E->getType());
5125 if (T.isNull())
5126 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 if (!getDerived().AlwaysRebuild() &&
5129 T == E->getType())
5130 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregorb15af892010-01-07 23:12:05 +00005132 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005133}
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135template<typename Derived>
5136Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005137TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005138 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5139 if (SubExpr.isInvalid())
5140 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 if (!getDerived().AlwaysRebuild() &&
5143 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005144 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005145
5146 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5147}
Mike Stump11289f42009-09-09 15:08:12 +00005148
Douglas Gregora16548e2009-08-11 05:31:07 +00005149template<typename Derived>
5150Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005151TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005152 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005153 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5154 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 if (!Param)
5156 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005157
Chandler Carruth794da4c2010-02-08 06:42:49 +00005158 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 Param == E->getParam())
5160 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregor033f6752009-12-23 23:03:06 +00005162 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005163}
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165template<typename Derived>
5166Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005167TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5169
5170 QualType T = getDerived().TransformType(E->getType());
5171 if (T.isNull())
5172 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005173
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 if (!getDerived().AlwaysRebuild() &&
5175 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005176 return SemaRef.Owned(E->Retain());
5177
5178 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005179 /*FIXME:*/E->getTypeBeginLoc(),
5180 T,
5181 E->getRParenLoc());
5182}
Mike Stump11289f42009-09-09 15:08:12 +00005183
Douglas Gregora16548e2009-08-11 05:31:07 +00005184template<typename Derived>
5185Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005186TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 // Transform the type that we're allocating
5188 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5189 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5190 if (AllocType.isNull())
5191 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 // Transform the size of the array we're allocating (if any).
5194 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5195 if (ArraySize.isInvalid())
5196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 // Transform the placement arguments (if any).
5199 bool ArgumentChanged = false;
5200 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5201 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5202 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5203 if (Arg.isInvalid())
5204 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005205
Douglas Gregora16548e2009-08-11 05:31:07 +00005206 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5207 PlacementArgs.push_back(Arg.take());
5208 }
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregorebe10102009-08-20 07:17:43 +00005210 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005211 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5212 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5213 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5214 if (Arg.isInvalid())
5215 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5218 ConstructorArgs.push_back(Arg.take());
5219 }
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregord2d9da02010-02-26 00:38:10 +00005221 // Transform constructor, new operator, and delete operator.
5222 CXXConstructorDecl *Constructor = 0;
5223 if (E->getConstructor()) {
5224 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005225 getDerived().TransformDecl(E->getLocStart(),
5226 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005227 if (!Constructor)
5228 return SemaRef.ExprError();
5229 }
5230
5231 FunctionDecl *OperatorNew = 0;
5232 if (E->getOperatorNew()) {
5233 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005234 getDerived().TransformDecl(E->getLocStart(),
5235 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005236 if (!OperatorNew)
5237 return SemaRef.ExprError();
5238 }
5239
5240 FunctionDecl *OperatorDelete = 0;
5241 if (E->getOperatorDelete()) {
5242 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005243 getDerived().TransformDecl(E->getLocStart(),
5244 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005245 if (!OperatorDelete)
5246 return SemaRef.ExprError();
5247 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005248
Douglas Gregora16548e2009-08-11 05:31:07 +00005249 if (!getDerived().AlwaysRebuild() &&
5250 AllocType == E->getAllocatedType() &&
5251 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005252 Constructor == E->getConstructor() &&
5253 OperatorNew == E->getOperatorNew() &&
5254 OperatorDelete == E->getOperatorDelete() &&
5255 !ArgumentChanged) {
5256 // Mark any declarations we need as referenced.
5257 // FIXME: instantiation-specific.
5258 if (Constructor)
5259 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5260 if (OperatorNew)
5261 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5262 if (OperatorDelete)
5263 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005264 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005265 }
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005267 if (!ArraySize.get()) {
5268 // If no array size was specified, but the new expression was
5269 // instantiated with an array type (e.g., "new T" where T is
5270 // instantiated with "int[4]"), extract the outer bound from the
5271 // array type as our array size. We do this with constant and
5272 // dependently-sized array types.
5273 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5274 if (!ArrayT) {
5275 // Do nothing
5276 } else if (const ConstantArrayType *ConsArrayT
5277 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005278 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005279 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005280 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005281 SemaRef.Context.getSizeType(),
5282 /*FIXME:*/E->getLocStart()));
5283 AllocType = ConsArrayT->getElementType();
5284 } else if (const DependentSizedArrayType *DepArrayT
5285 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5286 if (DepArrayT->getSizeExpr()) {
5287 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5288 AllocType = DepArrayT->getElementType();
5289 }
5290 }
5291 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005292 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5293 E->isGlobalNew(),
5294 /*FIXME:*/E->getLocStart(),
5295 move_arg(PlacementArgs),
5296 /*FIXME:*/E->getLocStart(),
5297 E->isParenTypeId(),
5298 AllocType,
5299 /*FIXME:*/E->getLocStart(),
5300 /*FIXME:*/SourceRange(),
5301 move(ArraySize),
5302 /*FIXME:*/E->getLocStart(),
5303 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005304 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005305}
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregora16548e2009-08-11 05:31:07 +00005307template<typename Derived>
5308Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005309TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5311 if (Operand.isInvalid())
5312 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregord2d9da02010-02-26 00:38:10 +00005314 // Transform the delete operator, if known.
5315 FunctionDecl *OperatorDelete = 0;
5316 if (E->getOperatorDelete()) {
5317 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005318 getDerived().TransformDecl(E->getLocStart(),
5319 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005320 if (!OperatorDelete)
5321 return SemaRef.ExprError();
5322 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005325 Operand.get() == E->getArgument() &&
5326 OperatorDelete == E->getOperatorDelete()) {
5327 // Mark any declarations we need as referenced.
5328 // FIXME: instantiation-specific.
5329 if (OperatorDelete)
5330 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005331 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005332 }
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregora16548e2009-08-11 05:31:07 +00005334 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5335 E->isGlobalDelete(),
5336 E->isArrayForm(),
5337 move(Operand));
5338}
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregora16548e2009-08-11 05:31:07 +00005340template<typename Derived>
5341Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005342TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005343 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005344 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5345 if (Base.isInvalid())
5346 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregor678f90d2010-02-25 01:56:36 +00005348 Sema::TypeTy *ObjectTypePtr = 0;
5349 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005350 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005351 E->getOperatorLoc(),
5352 E->isArrow()? tok::arrow : tok::period,
5353 ObjectTypePtr,
5354 MayBePseudoDestructor);
5355 if (Base.isInvalid())
5356 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005357
Douglas Gregor678f90d2010-02-25 01:56:36 +00005358 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005359 NestedNameSpecifier *Qualifier
5360 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005361 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005362 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005363 if (E->getQualifier() && !Qualifier)
5364 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregor678f90d2010-02-25 01:56:36 +00005366 PseudoDestructorTypeStorage Destroyed;
5367 if (E->getDestroyedTypeInfo()) {
5368 TypeSourceInfo *DestroyedTypeInfo
5369 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5370 if (!DestroyedTypeInfo)
5371 return SemaRef.ExprError();
5372 Destroyed = DestroyedTypeInfo;
5373 } else if (ObjectType->isDependentType()) {
5374 // We aren't likely to be able to resolve the identifier down to a type
5375 // now anyway, so just retain the identifier.
5376 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5377 E->getDestroyedTypeLoc());
5378 } else {
5379 // Look for a destructor known with the given name.
5380 CXXScopeSpec SS;
5381 if (Qualifier) {
5382 SS.setScopeRep(Qualifier);
5383 SS.setRange(E->getQualifierRange());
5384 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005385
Douglas Gregor678f90d2010-02-25 01:56:36 +00005386 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5387 *E->getDestroyedTypeIdentifier(),
5388 E->getDestroyedTypeLoc(),
5389 /*Scope=*/0,
5390 SS, ObjectTypePtr,
5391 false);
5392 if (!T)
5393 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005394
Douglas Gregor678f90d2010-02-25 01:56:36 +00005395 Destroyed
5396 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5397 E->getDestroyedTypeLoc());
5398 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005399
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005400 TypeSourceInfo *ScopeTypeInfo = 0;
5401 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005402 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005403 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005404 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005405 return SemaRef.ExprError();
5406 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005407
Douglas Gregorad8a3362009-09-04 17:36:40 +00005408 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5409 E->getOperatorLoc(),
5410 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005411 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005412 E->getQualifierRange(),
5413 ScopeTypeInfo,
5414 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005415 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005416 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005417}
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregorad8a3362009-09-04 17:36:40 +00005419template<typename Derived>
5420Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005421TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005422 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005423 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5424
5425 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5426 Sema::LookupOrdinaryName);
5427
5428 // Transform all the decls.
5429 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5430 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005431 NamedDecl *InstD = static_cast<NamedDecl*>(
5432 getDerived().TransformDecl(Old->getNameLoc(),
5433 *I));
John McCall84d87672009-12-10 09:41:52 +00005434 if (!InstD) {
5435 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5436 // This can happen because of dependent hiding.
5437 if (isa<UsingShadowDecl>(*I))
5438 continue;
5439 else
5440 return SemaRef.ExprError();
5441 }
John McCalle66edc12009-11-24 19:00:30 +00005442
5443 // Expand using declarations.
5444 if (isa<UsingDecl>(InstD)) {
5445 UsingDecl *UD = cast<UsingDecl>(InstD);
5446 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5447 E = UD->shadow_end(); I != E; ++I)
5448 R.addDecl(*I);
5449 continue;
5450 }
5451
5452 R.addDecl(InstD);
5453 }
5454
5455 // Resolve a kind, but don't do any further analysis. If it's
5456 // ambiguous, the callee needs to deal with it.
5457 R.resolveKind();
5458
5459 // Rebuild the nested-name qualifier, if present.
5460 CXXScopeSpec SS;
5461 NestedNameSpecifier *Qualifier = 0;
5462 if (Old->getQualifier()) {
5463 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005464 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005465 if (!Qualifier)
5466 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
John McCalle66edc12009-11-24 19:00:30 +00005468 SS.setScopeRep(Qualifier);
5469 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005470 }
5471
Douglas Gregor9262f472010-04-27 18:19:34 +00005472 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005473 CXXRecordDecl *NamingClass
5474 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5475 Old->getNameLoc(),
5476 Old->getNamingClass()));
5477 if (!NamingClass)
5478 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005479
Douglas Gregorda7be082010-04-27 16:10:10 +00005480 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005481 }
5482
5483 // If we have no template arguments, it's a normal declaration name.
5484 if (!Old->hasExplicitTemplateArgs())
5485 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5486
5487 // If we have template arguments, rebuild them, then rebuild the
5488 // templateid expression.
5489 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5490 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5491 TemplateArgumentLoc Loc;
5492 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5493 return SemaRef.ExprError();
5494 TransArgs.addArgument(Loc);
5495 }
5496
5497 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5498 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005499}
Mike Stump11289f42009-09-09 15:08:12 +00005500
Douglas Gregora16548e2009-08-11 05:31:07 +00005501template<typename Derived>
5502Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005503TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005504 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 QualType T = getDerived().TransformType(E->getQueriedType());
5507 if (T.isNull())
5508 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005509
Douglas Gregora16548e2009-08-11 05:31:07 +00005510 if (!getDerived().AlwaysRebuild() &&
5511 T == E->getQueriedType())
5512 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 // FIXME: Bad location information
5515 SourceLocation FakeLParenLoc
5516 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005517
5518 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005519 E->getLocStart(),
5520 /*FIXME:*/FakeLParenLoc,
5521 T,
5522 E->getLocEnd());
5523}
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregora16548e2009-08-11 05:31:07 +00005525template<typename Derived>
5526Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005527TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005528 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005530 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005531 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005532 if (!NNS)
5533 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005534
5535 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005536 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5537 if (!Name)
5538 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005539
John McCalle66edc12009-11-24 19:00:30 +00005540 if (!E->hasExplicitTemplateArgs()) {
5541 if (!getDerived().AlwaysRebuild() &&
5542 NNS == E->getQualifier() &&
5543 Name == E->getDeclName())
5544 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005545
John McCalle66edc12009-11-24 19:00:30 +00005546 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5547 E->getQualifierRange(),
5548 Name, E->getLocation(),
5549 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005550 }
John McCall6b51f282009-11-23 01:53:49 +00005551
5552 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005554 TemplateArgumentLoc Loc;
5555 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005557 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 }
5559
John McCalle66edc12009-11-24 19:00:30 +00005560 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5561 E->getQualifierRange(),
5562 Name, E->getLocation(),
5563 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005564}
5565
5566template<typename Derived>
5567Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005568TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005569 // CXXConstructExprs are always implicit, so when we have a
5570 // 1-argument construction we just transform that argument.
5571 if (E->getNumArgs() == 1 ||
5572 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5573 return getDerived().TransformExpr(E->getArg(0));
5574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5576
5577 QualType T = getDerived().TransformType(E->getType());
5578 if (T.isNull())
5579 return SemaRef.ExprError();
5580
5581 CXXConstructorDecl *Constructor
5582 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005583 getDerived().TransformDecl(E->getLocStart(),
5584 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 if (!Constructor)
5586 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005587
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 bool ArgumentChanged = false;
5589 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005590 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005591 ArgEnd = E->arg_end();
5592 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005593 if (getDerived().DropCallArgument(*Arg)) {
5594 ArgumentChanged = true;
5595 break;
5596 }
5597
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5599 if (TransArg.isInvalid())
5600 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5603 Args.push_back(TransArg.takeAs<Expr>());
5604 }
5605
5606 if (!getDerived().AlwaysRebuild() &&
5607 T == E->getType() &&
5608 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005609 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005610 // Mark the constructor as referenced.
5611 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005612 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005614 }
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregordb121ba2009-12-14 16:27:04 +00005616 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5617 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005618 move_arg(Args));
5619}
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregora16548e2009-08-11 05:31:07 +00005621/// \brief Transform a C++ temporary-binding expression.
5622///
Douglas Gregor363b1512009-12-24 18:51:59 +00005623/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5624/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005625template<typename Derived>
5626Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005627TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005628 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005629}
Mike Stump11289f42009-09-09 15:08:12 +00005630
Anders Carlssonba6c4372010-01-29 02:39:32 +00005631/// \brief Transform a C++ reference-binding expression.
5632///
5633/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5634/// transform the subexpression and return that.
5635template<typename Derived>
5636Sema::OwningExprResult
5637TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5638 return getDerived().TransformExpr(E->getSubExpr());
5639}
5640
Mike Stump11289f42009-09-09 15:08:12 +00005641/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005642/// be destroyed after the expression is evaluated.
5643///
Douglas Gregor363b1512009-12-24 18:51:59 +00005644/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5645/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005646template<typename Derived>
5647Sema::OwningExprResult
5648TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005649 CXXExprWithTemporaries *E) {
5650 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005651}
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregora16548e2009-08-11 05:31:07 +00005653template<typename Derived>
5654Sema::OwningExprResult
5655TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005656 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5658 QualType T = getDerived().TransformType(E->getType());
5659 if (T.isNull())
5660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 CXXConstructorDecl *Constructor
5663 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005664 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005665 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 if (!Constructor)
5667 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 bool ArgumentChanged = false;
5670 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5671 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005672 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 ArgEnd = E->arg_end();
5674 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005675 if (getDerived().DropCallArgument(*Arg)) {
5676 ArgumentChanged = true;
5677 break;
5678 }
5679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5681 if (TransArg.isInvalid())
5682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5685 Args.push_back((Expr *)TransArg.release());
5686 }
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 if (!getDerived().AlwaysRebuild() &&
5689 T == E->getType() &&
5690 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005691 !ArgumentChanged) {
5692 // FIXME: Instantiation-specific
5693 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005694 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 // FIXME: Bogus location information
5698 SourceLocation CommaLoc;
5699 if (Args.size() > 1) {
5700 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005701 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005702 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5703 }
5704 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5705 T,
5706 /*FIXME:*/E->getTypeBeginLoc(),
5707 move_arg(Args),
5708 &CommaLoc,
5709 E->getLocEnd());
5710}
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712template<typename Derived>
5713Sema::OwningExprResult
5714TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005715 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5717 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5718 if (T.isNull())
5719 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 bool ArgumentChanged = false;
5722 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5723 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5724 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5725 ArgEnd = E->arg_end();
5726 Arg != ArgEnd; ++Arg) {
5727 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5728 if (TransArg.isInvalid())
5729 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005730
Douglas Gregora16548e2009-08-11 05:31:07 +00005731 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5732 FakeCommaLocs.push_back(
5733 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5734 Args.push_back(TransArg.takeAs<Expr>());
5735 }
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 if (!getDerived().AlwaysRebuild() &&
5738 T == E->getTypeAsWritten() &&
5739 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005740 return SemaRef.Owned(E->Retain());
5741
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 // FIXME: we're faking the locations of the commas
5743 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5744 T,
5745 E->getLParenLoc(),
5746 move_arg(Args),
5747 FakeCommaLocs.data(),
5748 E->getRParenLoc());
5749}
Mike Stump11289f42009-09-09 15:08:12 +00005750
Douglas Gregora16548e2009-08-11 05:31:07 +00005751template<typename Derived>
5752Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005753TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005754 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005756 OwningExprResult Base(SemaRef, (Expr*) 0);
5757 Expr *OldBase;
5758 QualType BaseType;
5759 QualType ObjectType;
5760 if (!E->isImplicitAccess()) {
5761 OldBase = E->getBase();
5762 Base = getDerived().TransformExpr(OldBase);
5763 if (Base.isInvalid())
5764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005765
John McCall2d74de92009-12-01 22:10:20 +00005766 // Start the member reference and compute the object's type.
5767 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005768 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005769 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5770 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005771 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005772 ObjectTy,
5773 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005774 if (Base.isInvalid())
5775 return SemaRef.ExprError();
5776
5777 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5778 BaseType = ((Expr*) Base.get())->getType();
5779 } else {
5780 OldBase = 0;
5781 BaseType = getDerived().TransformType(E->getBaseType());
5782 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5783 }
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005785 // Transform the first part of the nested-name-specifier that qualifies
5786 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005787 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005788 = getDerived().TransformFirstQualifierInScope(
5789 E->getFirstQualifierFoundInScope(),
5790 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005792 NestedNameSpecifier *Qualifier = 0;
5793 if (E->getQualifier()) {
5794 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5795 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005796 ObjectType,
5797 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005798 if (!Qualifier)
5799 return SemaRef.ExprError();
5800 }
Mike Stump11289f42009-09-09 15:08:12 +00005801
5802 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005803 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005804 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005805 if (!Name)
5806 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005807
John McCall2d74de92009-12-01 22:10:20 +00005808 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005809 // This is a reference to a member without an explicitly-specified
5810 // template argument list. Optimize for this common case.
5811 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005812 Base.get() == OldBase &&
5813 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005814 Qualifier == E->getQualifier() &&
5815 Name == E->getMember() &&
5816 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005817 return SemaRef.Owned(E->Retain());
5818
John McCall8cd78132009-11-19 22:55:06 +00005819 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005820 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005821 E->isArrow(),
5822 E->getOperatorLoc(),
5823 Qualifier,
5824 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005825 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005826 Name,
5827 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005828 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005829 }
5830
John McCall6b51f282009-11-23 01:53:49 +00005831 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005832 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005833 TemplateArgumentLoc Loc;
5834 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005835 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005836 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005837 }
Mike Stump11289f42009-09-09 15:08:12 +00005838
John McCall8cd78132009-11-19 22:55:06 +00005839 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005840 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 E->isArrow(),
5842 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005843 Qualifier,
5844 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005845 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005846 Name,
5847 E->getMemberLoc(),
5848 &TransArgs);
5849}
5850
5851template<typename Derived>
5852Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005853TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005854 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005855 OwningExprResult Base(SemaRef, (Expr*) 0);
5856 QualType BaseType;
5857 if (!Old->isImplicitAccess()) {
5858 Base = getDerived().TransformExpr(Old->getBase());
5859 if (Base.isInvalid())
5860 return SemaRef.ExprError();
5861 BaseType = ((Expr*) Base.get())->getType();
5862 } else {
5863 BaseType = getDerived().TransformType(Old->getBaseType());
5864 }
John McCall10eae182009-11-30 22:42:35 +00005865
5866 NestedNameSpecifier *Qualifier = 0;
5867 if (Old->getQualifier()) {
5868 Qualifier
5869 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005870 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005871 if (Qualifier == 0)
5872 return SemaRef.ExprError();
5873 }
5874
5875 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5876 Sema::LookupOrdinaryName);
5877
5878 // Transform all the decls.
5879 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5880 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005881 NamedDecl *InstD = static_cast<NamedDecl*>(
5882 getDerived().TransformDecl(Old->getMemberLoc(),
5883 *I));
John McCall84d87672009-12-10 09:41:52 +00005884 if (!InstD) {
5885 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5886 // This can happen because of dependent hiding.
5887 if (isa<UsingShadowDecl>(*I))
5888 continue;
5889 else
5890 return SemaRef.ExprError();
5891 }
John McCall10eae182009-11-30 22:42:35 +00005892
5893 // Expand using declarations.
5894 if (isa<UsingDecl>(InstD)) {
5895 UsingDecl *UD = cast<UsingDecl>(InstD);
5896 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5897 E = UD->shadow_end(); I != E; ++I)
5898 R.addDecl(*I);
5899 continue;
5900 }
5901
5902 R.addDecl(InstD);
5903 }
5904
5905 R.resolveKind();
5906
Douglas Gregor9262f472010-04-27 18:19:34 +00005907 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005908 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005909 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005910 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005911 Old->getMemberLoc(),
5912 Old->getNamingClass()));
5913 if (!NamingClass)
5914 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005915
Douglas Gregorda7be082010-04-27 16:10:10 +00005916 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005917 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005918
John McCall10eae182009-11-30 22:42:35 +00005919 TemplateArgumentListInfo TransArgs;
5920 if (Old->hasExplicitTemplateArgs()) {
5921 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5922 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5923 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5924 TemplateArgumentLoc Loc;
5925 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5926 Loc))
5927 return SemaRef.ExprError();
5928 TransArgs.addArgument(Loc);
5929 }
5930 }
John McCall38836f02010-01-15 08:34:02 +00005931
5932 // FIXME: to do this check properly, we will need to preserve the
5933 // first-qualifier-in-scope here, just in case we had a dependent
5934 // base (and therefore couldn't do the check) and a
5935 // nested-name-qualifier (and therefore could do the lookup).
5936 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005937
John McCall10eae182009-11-30 22:42:35 +00005938 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005939 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005940 Old->getOperatorLoc(),
5941 Old->isArrow(),
5942 Qualifier,
5943 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005944 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005945 R,
5946 (Old->hasExplicitTemplateArgs()
5947 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005948}
5949
5950template<typename Derived>
5951Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005952TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005953 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005954}
5955
Mike Stump11289f42009-09-09 15:08:12 +00005956template<typename Derived>
5957Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005958TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005959 TypeSourceInfo *EncodedTypeInfo
5960 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5961 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005963
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005965 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005966 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005967
5968 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005969 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 E->getRParenLoc());
5971}
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973template<typename Derived>
5974Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005975TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005976 // Transform arguments.
5977 bool ArgChanged = false;
5978 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5979 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5980 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5981 if (Arg.isInvalid())
5982 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005983
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005984 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5985 Args.push_back(Arg.takeAs<Expr>());
5986 }
5987
5988 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5989 // Class message: transform the receiver type.
5990 TypeSourceInfo *ReceiverTypeInfo
5991 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5992 if (!ReceiverTypeInfo)
5993 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005994
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005995 // If nothing changed, just retain the existing message send.
5996 if (!getDerived().AlwaysRebuild() &&
5997 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5998 return SemaRef.Owned(E->Retain());
5999
6000 // Build a new class message send.
6001 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6002 E->getSelector(),
6003 E->getMethodDecl(),
6004 E->getLeftLoc(),
6005 move_arg(Args),
6006 E->getRightLoc());
6007 }
6008
6009 // Instance message: transform the receiver
6010 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6011 "Only class and instance messages may be instantiated");
6012 OwningExprResult Receiver
6013 = getDerived().TransformExpr(E->getInstanceReceiver());
6014 if (Receiver.isInvalid())
6015 return SemaRef.ExprError();
6016
6017 // If nothing changed, just retain the existing message send.
6018 if (!getDerived().AlwaysRebuild() &&
6019 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6020 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006021
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006022 // Build a new instance message send.
6023 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6024 E->getSelector(),
6025 E->getMethodDecl(),
6026 E->getLeftLoc(),
6027 move_arg(Args),
6028 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006029}
6030
Mike Stump11289f42009-09-09 15:08:12 +00006031template<typename Derived>
6032Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006033TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006034 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006035}
6036
Mike Stump11289f42009-09-09 15:08:12 +00006037template<typename Derived>
6038Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006039TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006040 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006041}
6042
Mike Stump11289f42009-09-09 15:08:12 +00006043template<typename Derived>
6044Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006045TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006046 // Transform the base expression.
6047 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6048 if (Base.isInvalid())
6049 return SemaRef.ExprError();
6050
6051 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006052
Douglas Gregord51d90d2010-04-26 20:11:03 +00006053 // If nothing changed, just retain the existing expression.
6054 if (!getDerived().AlwaysRebuild() &&
6055 Base.get() == E->getBase())
6056 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006057
Douglas Gregord51d90d2010-04-26 20:11:03 +00006058 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6059 E->getLocation(),
6060 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006061}
6062
Mike Stump11289f42009-09-09 15:08:12 +00006063template<typename Derived>
6064Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006066 // Transform the base expression.
6067 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6068 if (Base.isInvalid())
6069 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
Douglas Gregor9faee212010-04-26 20:47:02 +00006071 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006072
Douglas Gregor9faee212010-04-26 20:47:02 +00006073 // If nothing changed, just retain the existing expression.
6074 if (!getDerived().AlwaysRebuild() &&
6075 Base.get() == E->getBase())
6076 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006077
Douglas Gregor9faee212010-04-26 20:47:02 +00006078 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6079 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006080}
6081
Mike Stump11289f42009-09-09 15:08:12 +00006082template<typename Derived>
6083Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006084TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006085 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006086 // If this implicit setter/getter refers to class methods, it cannot have any
6087 // dependent parts. Just retain the existing declaration.
6088 if (E->getInterfaceDecl())
6089 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006091 // Transform the base expression.
6092 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6093 if (Base.isInvalid())
6094 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006095
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006096 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006097
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006098 // If nothing changed, just retain the existing expression.
6099 if (!getDerived().AlwaysRebuild() &&
6100 Base.get() == E->getBase())
6101 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006102
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006103 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6104 E->getGetterMethod(),
6105 E->getType(),
6106 E->getSetterMethod(),
6107 E->getLocation(),
6108 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006109
Douglas Gregora16548e2009-08-11 05:31:07 +00006110}
6111
Mike Stump11289f42009-09-09 15:08:12 +00006112template<typename Derived>
6113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006115 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006116 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006117}
6118
Mike Stump11289f42009-09-09 15:08:12 +00006119template<typename Derived>
6120Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006121TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006122 // Transform the base expression.
6123 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6124 if (Base.isInvalid())
6125 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006126
Douglas Gregord51d90d2010-04-26 20:11:03 +00006127 // If nothing changed, just retain the existing expression.
6128 if (!getDerived().AlwaysRebuild() &&
6129 Base.get() == E->getBase())
6130 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006131
Douglas Gregord51d90d2010-04-26 20:11:03 +00006132 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6133 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006134}
6135
Mike Stump11289f42009-09-09 15:08:12 +00006136template<typename Derived>
6137Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006138TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006139 bool ArgumentChanged = false;
6140 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6141 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6142 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6143 if (SubExpr.isInvalid())
6144 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006145
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6147 SubExprs.push_back(SubExpr.takeAs<Expr>());
6148 }
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 if (!getDerived().AlwaysRebuild() &&
6151 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006152 return SemaRef.Owned(E->Retain());
6153
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6155 move_arg(SubExprs),
6156 E->getRParenLoc());
6157}
6158
Mike Stump11289f42009-09-09 15:08:12 +00006159template<typename Derived>
6160Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006162 // FIXME: Implement this!
6163 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006164 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165}
6166
Mike Stump11289f42009-09-09 15:08:12 +00006167template<typename Derived>
6168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 // FIXME: Implement this!
6171 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006172 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006173}
Mike Stump11289f42009-09-09 15:08:12 +00006174
Douglas Gregora16548e2009-08-11 05:31:07 +00006175//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006176// Type reconstruction
6177//===----------------------------------------------------------------------===//
6178
Mike Stump11289f42009-09-09 15:08:12 +00006179template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006180QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6181 SourceLocation Star) {
6182 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006183 getDerived().getBaseEntity());
6184}
6185
Mike Stump11289f42009-09-09 15:08:12 +00006186template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006187QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6188 SourceLocation Star) {
6189 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006190 getDerived().getBaseEntity());
6191}
6192
Mike Stump11289f42009-09-09 15:08:12 +00006193template<typename Derived>
6194QualType
John McCall70dd5f62009-10-30 00:06:24 +00006195TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6196 bool WrittenAsLValue,
6197 SourceLocation Sigil) {
6198 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6199 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006200}
6201
6202template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006203QualType
John McCall70dd5f62009-10-30 00:06:24 +00006204TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6205 QualType ClassType,
6206 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006207 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006208 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006209}
6210
6211template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006212QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006213TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6214 ArrayType::ArraySizeModifier SizeMod,
6215 const llvm::APInt *Size,
6216 Expr *SizeExpr,
6217 unsigned IndexTypeQuals,
6218 SourceRange BracketsRange) {
6219 if (SizeExpr || !Size)
6220 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6221 IndexTypeQuals, BracketsRange,
6222 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006223
6224 QualType Types[] = {
6225 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6226 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6227 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006228 };
6229 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6230 QualType SizeType;
6231 for (unsigned I = 0; I != NumTypes; ++I)
6232 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6233 SizeType = Types[I];
6234 break;
6235 }
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregord6ff3322009-08-04 16:50:30 +00006237 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006238 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006239 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006240 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006241}
Mike Stump11289f42009-09-09 15:08:12 +00006242
Douglas Gregord6ff3322009-08-04 16:50:30 +00006243template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006244QualType
6245TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006246 ArrayType::ArraySizeModifier SizeMod,
6247 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006248 unsigned IndexTypeQuals,
6249 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006250 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006251 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006252}
6253
6254template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006255QualType
Mike Stump11289f42009-09-09 15:08:12 +00006256TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006257 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006258 unsigned IndexTypeQuals,
6259 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006260 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006261 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006262}
Mike Stump11289f42009-09-09 15:08:12 +00006263
Douglas Gregord6ff3322009-08-04 16:50:30 +00006264template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006265QualType
6266TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006267 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006268 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006269 unsigned IndexTypeQuals,
6270 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006271 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006272 SizeExpr.takeAs<Expr>(),
6273 IndexTypeQuals, BracketsRange);
6274}
6275
6276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006277QualType
6278TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006279 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006281 unsigned IndexTypeQuals,
6282 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006283 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006284 SizeExpr.takeAs<Expr>(),
6285 IndexTypeQuals, BracketsRange);
6286}
6287
6288template<typename Derived>
6289QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006290 unsigned NumElements,
6291 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006292 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006293 return SemaRef.Context.getVectorType(ElementType, NumElements,
6294 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006295}
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregord6ff3322009-08-04 16:50:30 +00006297template<typename Derived>
6298QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6299 unsigned NumElements,
6300 SourceLocation AttributeLoc) {
6301 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6302 NumElements, true);
6303 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006304 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006305 AttributeLoc);
6306 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6307 AttributeLoc);
6308}
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregord6ff3322009-08-04 16:50:30 +00006310template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006311QualType
6312TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006314 SourceLocation AttributeLoc) {
6315 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6316}
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregord6ff3322009-08-04 16:50:30 +00006318template<typename Derived>
6319QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006320 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006321 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006322 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006323 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006324 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006325 Quals,
6326 getDerived().getBaseLocation(),
6327 getDerived().getBaseEntity());
6328}
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregord6ff3322009-08-04 16:50:30 +00006330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006331QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6332 return SemaRef.Context.getFunctionNoProtoType(T);
6333}
6334
6335template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006336QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6337 assert(D && "no decl found");
6338 if (D->isInvalidDecl()) return QualType();
6339
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006340 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006341 TypeDecl *Ty;
6342 if (isa<UsingDecl>(D)) {
6343 UsingDecl *Using = cast<UsingDecl>(D);
6344 assert(Using->isTypeName() &&
6345 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6346
6347 // A valid resolved using typename decl points to exactly one type decl.
6348 assert(++Using->shadow_begin() == Using->shadow_end());
6349 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006350
John McCallb96ec562009-12-04 22:46:56 +00006351 } else {
6352 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6353 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6354 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6355 }
6356
6357 return SemaRef.Context.getTypeDeclType(Ty);
6358}
6359
6360template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006361QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006362 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6363}
6364
6365template<typename Derived>
6366QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6367 return SemaRef.Context.getTypeOfType(Underlying);
6368}
6369
6370template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006371QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006372 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6373}
6374
6375template<typename Derived>
6376QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006377 TemplateName Template,
6378 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006379 const TemplateArgumentListInfo &TemplateArgs) {
6380 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006381}
Mike Stump11289f42009-09-09 15:08:12 +00006382
Douglas Gregor1135c352009-08-06 05:28:30 +00006383template<typename Derived>
6384NestedNameSpecifier *
6385TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6386 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006387 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006388 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006389 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006390 CXXScopeSpec SS;
6391 // FIXME: The source location information is all wrong.
6392 SS.setRange(Range);
6393 SS.setScopeRep(Prefix);
6394 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006395 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006396 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006397 ObjectType,
6398 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006399 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006400}
6401
6402template<typename Derived>
6403NestedNameSpecifier *
6404TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6405 SourceRange Range,
6406 NamespaceDecl *NS) {
6407 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6408}
6409
6410template<typename Derived>
6411NestedNameSpecifier *
6412TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6413 SourceRange Range,
6414 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006415 QualType T) {
6416 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006417 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006418 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006419 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6420 T.getTypePtr());
6421 }
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregor1135c352009-08-06 05:28:30 +00006423 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6424 return 0;
6425}
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregor71dc5092009-08-06 06:41:21 +00006427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006428TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006429TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6430 bool TemplateKW,
6431 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006432 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006433 Template);
6434}
6435
6436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006437TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006438TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006439 const IdentifierInfo &II,
6440 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006441 CXXScopeSpec SS;
6442 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006443 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006444 UnqualifiedId Name;
6445 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006446 return getSema().ActOnDependentTemplateName(
6447 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006448 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006449 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006450 ObjectType.getAsOpaquePtr(),
6451 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006452 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006453}
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregora16548e2009-08-11 05:31:07 +00006455template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006456TemplateName
6457TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6458 OverloadedOperatorKind Operator,
6459 QualType ObjectType) {
6460 CXXScopeSpec SS;
6461 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6462 SS.setScopeRep(Qualifier);
6463 UnqualifiedId Name;
6464 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6465 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6466 Operator, SymbolLocations);
6467 return getSema().ActOnDependentTemplateName(
6468 /*FIXME:*/getDerived().getBaseLocation(),
6469 SS,
6470 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006471 ObjectType.getAsOpaquePtr(),
6472 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006473 .template getAsVal<TemplateName>();
6474}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006475
Douglas Gregor71395fa2009-11-04 00:56:37 +00006476template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006477Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006478TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6479 SourceLocation OpLoc,
6480 ExprArg Callee,
6481 ExprArg First,
6482 ExprArg Second) {
6483 Expr *FirstExpr = (Expr *)First.get();
6484 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006485 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006486 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006489 if (Op == OO_Subscript) {
6490 if (!FirstExpr->getType()->isOverloadableType() &&
6491 !SecondExpr->getType()->isOverloadableType())
6492 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006493 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006494 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006495 } else if (Op == OO_Arrow) {
6496 // -> is never a builtin operation.
6497 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006498 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006499 if (!FirstExpr->getType()->isOverloadableType()) {
6500 // The argument is not of overloadable type, so try to create a
6501 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006502 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006504
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6506 }
6507 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006508 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006509 !SecondExpr->getType()->isOverloadableType()) {
6510 // Neither of the arguments is an overloadable type, so try to
6511 // create a built-in binary operation.
6512 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006513 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6515 if (Result.isInvalid())
6516 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 First.release();
6519 Second.release();
6520 return move(Result);
6521 }
6522 }
Mike Stump11289f42009-09-09 15:08:12 +00006523
6524 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006526 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006527
John McCalld14a8642009-11-21 08:51:07 +00006528 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6529 assert(ULE->requiresADL());
6530
6531 // FIXME: Do we have to check
6532 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006533 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006534 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006535 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006536 }
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 // Add any functions found via argument-dependent lookup.
6539 Expr *Args[2] = { FirstExpr, SecondExpr };
6540 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006541
Douglas Gregora16548e2009-08-11 05:31:07 +00006542 // Create the overloaded operator invocation for unary operators.
6543 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006544 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006545 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6546 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6547 }
Mike Stump11289f42009-09-09 15:08:12 +00006548
Sebastian Redladba46e2009-10-29 20:17:01 +00006549 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006550 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6551 OpLoc,
6552 move(First),
6553 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006554
Douglas Gregora16548e2009-08-11 05:31:07 +00006555 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006556 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006557 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006558 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006559 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6560 if (Result.isInvalid())
6561 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563 First.release();
6564 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006565 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006566}
Mike Stump11289f42009-09-09 15:08:12 +00006567
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006568template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006569Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006570TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6571 SourceLocation OperatorLoc,
6572 bool isArrow,
6573 NestedNameSpecifier *Qualifier,
6574 SourceRange QualifierRange,
6575 TypeSourceInfo *ScopeType,
6576 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006577 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006578 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006579 CXXScopeSpec SS;
6580 if (Qualifier) {
6581 SS.setRange(QualifierRange);
6582 SS.setScopeRep(Qualifier);
6583 }
6584
6585 Expr *BaseE = (Expr *)Base.get();
6586 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006587 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006588 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006589 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006590 !BaseType->getAs<PointerType>()->getPointeeType()
6591 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006592 // This pseudo-destructor expression is still a pseudo-destructor.
6593 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6594 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006595 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006596 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006597 /*FIXME?*/true);
6598 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006599
Douglas Gregor678f90d2010-02-25 01:56:36 +00006600 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006601 DeclarationName Name
6602 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6603 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006604
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006605 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006606
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006607 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6608 OperatorLoc, isArrow,
6609 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006610 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006611 /*TemplateArgs*/ 0);
6612}
6613
Douglas Gregord6ff3322009-08-04 16:50:30 +00006614} // end namespace clang
6615
6616#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H