blob: d2995778fc643b0afefe5f4e6b08dfa5856e0aab [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.
John McCallc392f372010-06-11 00:33:02 +0000536 QualType RebuildDependentTemplateSpecializationType(
537 ElaboratedTypeKeyword Keyword,
538 NestedNameSpecifier *NNS,
539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
545 getDerived().RebuildTemplateName(NNS, *Name, QualType());
546
547 // If it's still dependent, make a dependent specialization.
548 if (InstName.getAsDependentTemplateName())
549 return SemaRef.Context.getDependentTemplateSpecializationType(
550 Keyword, NNS, Name, Args);
551
552 // Otherwise, make an elaborated type wrapping a non-dependent
553 // specialization.
554 QualType T =
555 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
556 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000557
558 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000559 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560
561 /// \brief Build a new typename type that refers to an identifier.
562 ///
563 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000564 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000566 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000567 NestedNameSpecifier *NNS,
568 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 SourceLocation KeywordLoc,
570 SourceRange NNSRange,
571 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000572 CXXScopeSpec SS;
573 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 SS.setRange(NNSRange);
575
Douglas Gregore677daf2010-03-31 22:19:08 +0000576 if (NNS->isDependent()) {
577 // If the name is still dependent, just build a new dependent name type.
578 if (!SemaRef.computeDeclContext(SS))
579 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
580 }
581
Abramo Bagnara6150c882010-05-11 21:36:43 +0000582 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000583 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
584 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000585
586 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
587
Abramo Bagnarad7548482010-05-19 21:37:53 +0000588 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000589 // into a non-dependent elaborated-type-specifier. Find the tag we're
590 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
593 if (!DC)
594 return QualType();
595
John McCallbf8c5192010-05-27 06:40:31 +0000596 if (SemaRef.RequireCompleteDeclContext(SS, DC))
597 return QualType();
598
Douglas Gregore677daf2010-03-31 22:19:08 +0000599 TagDecl *Tag = 0;
600 SemaRef.LookupQualifiedName(Result, DC);
601 switch (Result.getResultKind()) {
602 case LookupResult::NotFound:
603 case LookupResult::NotFoundInCurrentInstantiation:
604 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000605
Douglas Gregore677daf2010-03-31 22:19:08 +0000606 case LookupResult::Found:
607 Tag = Result.getAsSingle<TagDecl>();
608 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000609
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 case LookupResult::FoundOverloaded:
611 case LookupResult::FoundUnresolvedValue:
612 llvm_unreachable("Tag lookup cannot find non-tags");
613 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 case LookupResult::Ambiguous:
616 // Let the LookupResult structure handle ambiguities.
617 return QualType();
618 }
619
620 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000621 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000622 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000623 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000624 return QualType();
625 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000626
Abramo Bagnarad7548482010-05-19 21:37:53 +0000627 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
628 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000629 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
630 return QualType();
631 }
632
633 // Build the elaborated-type-specifier type.
634 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000635 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000636 }
Mike Stump11289f42009-09-09 15:08:12 +0000637
Douglas Gregor1135c352009-08-06 05:28:30 +0000638 /// \brief Build a new nested-name-specifier given the prefix and an
639 /// identifier that names the next step in the nested-name-specifier.
640 ///
641 /// By default, performs semantic analysis when building the new
642 /// nested-name-specifier. Subclasses may override this routine to provide
643 /// different behavior.
644 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
645 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000646 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000647 QualType ObjectType,
648 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000649
650 /// \brief Build a new nested-name-specifier given the prefix and the
651 /// namespace named in the next step in the nested-name-specifier.
652 ///
653 /// By default, performs semantic analysis when building the new
654 /// nested-name-specifier. Subclasses may override this routine to provide
655 /// different behavior.
656 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
657 SourceRange Range,
658 NamespaceDecl *NS);
659
660 /// \brief Build a new nested-name-specifier given the prefix and the
661 /// type named in the next step in the nested-name-specifier.
662 ///
663 /// By default, performs semantic analysis when building the new
664 /// nested-name-specifier. Subclasses may override this routine to provide
665 /// different behavior.
666 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
667 SourceRange Range,
668 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000669 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000670
671 /// \brief Build a new template name given a nested name specifier, a flag
672 /// indicating whether the "template" keyword was provided, and the template
673 /// that the template name refers to.
674 ///
675 /// By default, builds the new template name directly. Subclasses may override
676 /// this routine to provide different behavior.
677 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
678 bool TemplateKW,
679 TemplateDecl *Template);
680
Douglas Gregor71dc5092009-08-06 06:41:21 +0000681 /// \brief Build a new template name given a nested name specifier and the
682 /// name that is referred to as a template.
683 ///
684 /// By default, performs semantic analysis to determine whether the name can
685 /// be resolved to a specific template, then builds the appropriate kind of
686 /// template name. Subclasses may override this routine to provide different
687 /// behavior.
688 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000689 const IdentifierInfo &II,
690 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000691
Douglas Gregor71395fa2009-11-04 00:56:37 +0000692 /// \brief Build a new template name given a nested name specifier and the
693 /// overloaded operator name that is referred to as a template.
694 ///
695 /// By default, performs semantic analysis to determine whether the name can
696 /// be resolved to a specific template, then builds the appropriate kind of
697 /// template name. Subclasses may override this routine to provide different
698 /// behavior.
699 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
700 OverloadedOperatorKind Operator,
701 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000702
Douglas Gregorebe10102009-08-20 07:17:43 +0000703 /// \brief Build a new compound statement.
704 ///
705 /// By default, performs semantic analysis to build the new statement.
706 /// Subclasses may override this routine to provide different behavior.
707 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
708 MultiStmtArg Statements,
709 SourceLocation RBraceLoc,
710 bool IsStmtExpr) {
711 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
712 IsStmtExpr);
713 }
714
715 /// \brief Build a new case statement.
716 ///
717 /// By default, performs semantic analysis to build the new statement.
718 /// Subclasses may override this routine to provide different behavior.
719 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
720 ExprArg LHS,
721 SourceLocation EllipsisLoc,
722 ExprArg RHS,
723 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000724 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000725 ColonLoc);
726 }
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 /// \brief Attach the body to a new case statement.
729 ///
730 /// By default, performs semantic analysis to build the new statement.
731 /// Subclasses may override this routine to provide different behavior.
732 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
733 getSema().ActOnCaseStmtBody(S.get(), move(Body));
734 return move(S);
735 }
Mike Stump11289f42009-09-09 15:08:12 +0000736
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 /// \brief Build a new default statement.
738 ///
739 /// By default, performs semantic analysis to build the new statement.
740 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000741 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 SourceLocation ColonLoc,
743 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000744 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 /*CurScope=*/0);
746 }
Mike Stump11289f42009-09-09 15:08:12 +0000747
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 /// \brief Build a new label statement.
749 ///
750 /// By default, performs semantic analysis to build the new statement.
751 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000752 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 IdentifierInfo *Id,
754 SourceLocation ColonLoc,
755 StmtArg SubStmt) {
756 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
757 }
Mike Stump11289f42009-09-09 15:08:12 +0000758
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 /// \brief Build a new "if" statement.
760 ///
761 /// By default, performs semantic analysis to build the new statement.
762 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000763 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000764 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000765 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000766 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000767 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 }
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 /// \brief Start building a new switch statement.
771 ///
772 /// By default, performs semantic analysis to build the new statement.
773 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000774 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
775 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000776 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000777 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
778 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 }
Mike Stump11289f42009-09-09 15:08:12 +0000780
Douglas Gregorebe10102009-08-20 07:17:43 +0000781 /// \brief Attach the body to the switch statement.
782 ///
783 /// By default, performs semantic analysis to build the new statement.
784 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000785 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000786 StmtArg Switch, StmtArg Body) {
787 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
788 move(Body));
789 }
790
791 /// \brief Build a new while statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
795 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000796 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000797 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000798 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000799 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000800 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 }
Mike Stump11289f42009-09-09 15:08:12 +0000802
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 /// \brief Build a new do-while statement.
804 ///
805 /// By default, performs semantic analysis to build the new statement.
806 /// Subclasses may override this routine to provide different behavior.
807 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
808 SourceLocation WhileLoc,
809 SourceLocation LParenLoc,
810 ExprArg Cond,
811 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000812 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 move(Cond), RParenLoc);
814 }
815
816 /// \brief Build a new for statement.
817 ///
818 /// By default, performs semantic analysis to build the new statement.
819 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000820 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000822 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000823 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000825 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000826 DeclPtrTy::make(CondVar),
827 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 }
Mike Stump11289f42009-09-09 15:08:12 +0000829
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 /// \brief Build a new goto statement.
831 ///
832 /// By default, performs semantic analysis to build the new statement.
833 /// Subclasses may override this routine to provide different behavior.
834 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
835 SourceLocation LabelLoc,
836 LabelStmt *Label) {
837 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
838 }
839
840 /// \brief Build a new indirect goto statement.
841 ///
842 /// By default, performs semantic analysis to build the new statement.
843 /// Subclasses may override this routine to provide different behavior.
844 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
845 SourceLocation StarLoc,
846 ExprArg Target) {
847 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
848 }
Mike Stump11289f42009-09-09 15:08:12 +0000849
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 /// \brief Build a new return statement.
851 ///
852 /// By default, performs semantic analysis to build the new statement.
853 /// Subclasses may override this routine to provide different behavior.
854 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
855 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
858 }
Mike Stump11289f42009-09-09 15:08:12 +0000859
Douglas Gregorebe10102009-08-20 07:17:43 +0000860 /// \brief Build a new declaration 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 RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000865 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000866 SourceLocation EndLoc) {
867 return getSema().Owned(
868 new (getSema().Context) DeclStmt(
869 DeclGroupRef::Create(getSema().Context,
870 Decls, NumDecls),
871 StartLoc, EndLoc));
872 }
Mike Stump11289f42009-09-09 15:08:12 +0000873
Anders Carlssonaaeef072010-01-24 05:50:09 +0000874 /// \brief Build a new inline asm statement.
875 ///
876 /// By default, performs semantic analysis to build the new statement.
877 /// Subclasses may override this routine to provide different behavior.
878 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
879 bool IsSimple,
880 bool IsVolatile,
881 unsigned NumOutputs,
882 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000883 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000884 MultiExprArg Constraints,
885 MultiExprArg Exprs,
886 ExprArg AsmString,
887 MultiExprArg Clobbers,
888 SourceLocation RParenLoc,
889 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000890 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000891 NumInputs, Names, move(Constraints),
892 move(Exprs), move(AsmString), move(Clobbers),
893 RParenLoc, MSAsm);
894 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000895
896 /// \brief Build a new Objective-C @try statement.
897 ///
898 /// By default, performs semantic analysis to build the new statement.
899 /// Subclasses may override this routine to provide different behavior.
900 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
901 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000902 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000903 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000904 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000905 move(Finally));
906 }
907
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000908 /// \brief Rebuild an Objective-C exception declaration.
909 ///
910 /// By default, performs semantic analysis to build the new declaration.
911 /// Subclasses may override this routine to provide different behavior.
912 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
913 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000914 return getSema().BuildObjCExceptionDecl(TInfo, T,
915 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000916 ExceptionDecl->getLocation());
917 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000918
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000919 /// \brief Build a new Objective-C @catch statement.
920 ///
921 /// By default, performs semantic analysis to build the new statement.
922 /// Subclasses may override this routine to provide different behavior.
923 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
924 SourceLocation RParenLoc,
925 VarDecl *Var,
926 StmtArg Body) {
927 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
928 Sema::DeclPtrTy::make(Var),
929 move(Body));
930 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000931
Douglas Gregor306de2f2010-04-22 23:59:56 +0000932 /// \brief Build a new Objective-C @finally statement.
933 ///
934 /// By default, performs semantic analysis to build the new statement.
935 /// Subclasses may override this routine to provide different behavior.
936 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
937 StmtArg Body) {
938 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
939 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000940
Douglas Gregor6148de72010-04-22 22:01:21 +0000941 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
945 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
946 ExprArg Operand) {
947 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
948 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000949
Douglas Gregor6148de72010-04-22 22:01:21 +0000950 /// \brief Build a new Objective-C @synchronized statement.
951 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000952 /// By default, performs semantic analysis to build the new statement.
953 /// Subclasses may override this routine to provide different behavior.
954 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
955 ExprArg Object,
956 StmtArg Body) {
957 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
958 move(Body));
959 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000960
961 /// \brief Build a new Objective-C fast enumeration statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
965 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
966 SourceLocation LParenLoc,
967 StmtArg Element,
968 ExprArg Collection,
969 SourceLocation RParenLoc,
970 StmtArg Body) {
971 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000972 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000973 move(Collection),
974 RParenLoc,
975 move(Body));
976 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000977
Douglas Gregorebe10102009-08-20 07:17:43 +0000978 /// \brief Build a new C++ exception declaration.
979 ///
980 /// By default, performs semantic analysis to build the new decaration.
981 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000982 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000983 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 IdentifierInfo *Name,
985 SourceLocation Loc,
986 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000987 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000988 TypeRange);
989 }
990
991 /// \brief Build a new C++ catch statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
995 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
996 VarDecl *ExceptionDecl,
997 StmtArg Handler) {
998 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000999 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 Handler.takeAs<Stmt>()));
1001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /// \brief Build a new C++ try statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
1007 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1008 StmtArg TryBlock,
1009 MultiStmtArg Handlers) {
1010 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1011 }
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001017 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1018 LookupResult &R,
1019 bool RequiresADL) {
1020 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 }
1022
1023
1024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001028 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1029 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001030 ValueDecl *VD, SourceLocation Loc,
1031 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001032 CXXScopeSpec SS;
1033 SS.setScopeRep(Qualifier);
1034 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001035
1036 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001037
John McCallce546572009-12-08 09:08:17 +00001038 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001042 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 /// By default, performs semantic analysis to build the new expression.
1044 /// Subclasses may override this routine to provide different behavior.
1045 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1046 SourceLocation RParen) {
1047 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1048 }
1049
Douglas Gregorad8a3362009-09-04 17:36:40 +00001050 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001051 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
1054 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1055 SourceLocation OperatorLoc,
1056 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001057 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001058 SourceRange QualifierRange,
1059 TypeSourceInfo *ScopeType,
1060 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001061 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001062 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001065 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 /// By default, performs semantic analysis to build the new expression.
1067 /// Subclasses may override this routine to provide different behavior.
1068 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1069 UnaryOperator::Opcode Opc,
1070 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001071 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001072 }
Mike Stump11289f42009-09-09 15:08:12 +00001073
Douglas Gregor882211c2010-04-28 22:16:22 +00001074 /// \brief Build a new builtin offsetof expression.
1075 ///
1076 /// By default, performs semantic analysis to build the new expression.
1077 /// Subclasses may override this routine to provide different behavior.
1078 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1079 TypeSourceInfo *Type,
1080 Action::OffsetOfComponent *Components,
1081 unsigned NumComponents,
1082 SourceLocation RParenLoc) {
1083 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1084 NumComponents, RParenLoc);
1085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001086
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 /// By default, performs semantic analysis to build the new expression.
1090 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001091 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001092 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001094 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 }
1096
Mike Stump11289f42009-09-09 15:08:12 +00001097 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
1102 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1103 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001104 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1106 OpLoc, isSizeOf, R);
1107 if (Result.isInvalid())
1108 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 SubExpr.release();
1111 return move(Result);
1112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001115 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// By default, performs semantic analysis to build the new expression.
1117 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001118 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 SourceLocation LBracketLoc,
1120 ExprArg RHS,
1121 SourceLocation RBracketLoc) {
1122 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001123 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 RBracketLoc);
1125 }
1126
1127 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001128 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001129 /// By default, performs semantic analysis to build the new expression.
1130 /// Subclasses may override this routine to provide different behavior.
1131 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1132 MultiExprArg Args,
1133 SourceLocation *CommaLocs,
1134 SourceLocation RParenLoc) {
1135 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1136 move(Args), CommaLocs, RParenLoc);
1137 }
1138
1139 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001140 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 /// By default, performs semantic analysis to build the new expression.
1142 /// Subclasses may override this routine to provide different behavior.
1143 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001144 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001145 NestedNameSpecifier *Qualifier,
1146 SourceRange QualifierRange,
1147 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001148 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001149 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001150 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001151 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001152 if (!Member->getDeclName()) {
1153 // We have a reference to an unnamed field.
1154 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001155
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001156 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001157 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1158 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001159 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001160
Mike Stump11289f42009-09-09 15:08:12 +00001161 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001162 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001163 Member, MemberLoc,
1164 cast<FieldDecl>(Member)->getType());
1165 return getSema().Owned(ME);
1166 }
Mike Stump11289f42009-09-09 15:08:12 +00001167
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001168 CXXScopeSpec SS;
1169 if (Qualifier) {
1170 SS.setRange(QualifierRange);
1171 SS.setScopeRep(Qualifier);
1172 }
1173
John McCall2d74de92009-12-01 22:10:20 +00001174 QualType BaseType = ((Expr*) Base.get())->getType();
1175
John McCall16df1e52010-03-30 21:47:33 +00001176 // FIXME: this involves duplicating earlier analysis in a lot of
1177 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001178 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1179 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001180 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001181 R.resolveKind();
1182
John McCall2d74de92009-12-01 22:10:20 +00001183 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1184 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001185 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001186 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 }
Mike Stump11289f42009-09-09 15:08:12 +00001188
Douglas Gregora16548e2009-08-11 05:31:07 +00001189 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001190 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 /// By default, performs semantic analysis to build the new expression.
1192 /// Subclasses may override this routine to provide different behavior.
1193 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1194 BinaryOperator::Opcode Opc,
1195 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001196 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001197 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 }
1199
1200 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001201 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 /// By default, performs semantic analysis to build the new expression.
1203 /// Subclasses may override this routine to provide different behavior.
1204 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1205 SourceLocation QuestionLoc,
1206 ExprArg LHS,
1207 SourceLocation ColonLoc,
1208 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001209 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 move(LHS), move(RHS));
1211 }
1212
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001214 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 /// By default, performs semantic analysis to build the new expression.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001217 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1218 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 SourceLocation RParenLoc,
1220 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001221 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1222 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
1229 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001230 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 SourceLocation RParenLoc,
1232 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001233 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1234 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 }
Mike Stump11289f42009-09-09 15:08:12 +00001236
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001238 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001241 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 SourceLocation OpLoc,
1243 SourceLocation AccessorLoc,
1244 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001245
John McCall10eae182009-11-30 22:42:35 +00001246 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001247 QualType BaseType = ((Expr*) Base.get())->getType();
1248 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001249 OpLoc, /*IsArrow*/ false,
1250 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001251 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001252 AccessorLoc,
1253 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 }
Mike Stump11289f42009-09-09 15:08:12 +00001255
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001257 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
1260 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1261 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001262 SourceLocation RBraceLoc,
1263 QualType ResultTy) {
1264 OwningExprResult Result
1265 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1266 if (Result.isInvalid() || ResultTy->isDependentType())
1267 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001268
Douglas Gregord3d93062009-11-09 17:16:50 +00001269 // Patch in the result type we were given, which may have been computed
1270 // when the initial InitListExpr was built.
1271 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1272 ILE->setType(ResultTy);
1273 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 }
Mike Stump11289f42009-09-09 15:08:12 +00001275
Douglas Gregora16548e2009-08-11 05:31:07 +00001276 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001277 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 /// By default, performs semantic analysis to build the new expression.
1279 /// Subclasses may override this routine to provide different behavior.
1280 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1281 MultiExprArg ArrayExprs,
1282 SourceLocation EqualOrColonLoc,
1283 bool GNUSyntax,
1284 ExprArg Init) {
1285 OwningExprResult Result
1286 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1287 move(Init));
1288 if (Result.isInvalid())
1289 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001290
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 ArrayExprs.release();
1292 return move(Result);
1293 }
Mike Stump11289f42009-09-09 15:08:12 +00001294
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001296 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// By default, builds the implicit value initialization without performing
1298 /// any semantic analysis. Subclasses may override this routine to provide
1299 /// different behavior.
1300 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1301 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1302 }
Mike Stump11289f42009-09-09 15:08:12 +00001303
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001305 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
1308 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1309 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001310 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 RParenLoc);
1312 }
1313
1314 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1319 MultiExprArg SubExprs,
1320 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001321 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001322 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 }
Mike Stump11289f42009-09-09 15:08:12 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001326 ///
1327 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// rather than attempting to map the label statement itself.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1331 SourceLocation LabelLoc,
1332 LabelStmt *Label) {
1333 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1334 }
Mike Stump11289f42009-09-09 15:08:12 +00001335
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001337 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 /// By default, performs semantic analysis to build the new expression.
1339 /// Subclasses may override this routine to provide different behavior.
1340 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1341 StmtArg SubStmt,
1342 SourceLocation RParenLoc) {
1343 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1344 }
Mike Stump11289f42009-09-09 15:08:12 +00001345
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// \brief Build a new __builtin_types_compatible_p expression.
1347 ///
1348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
1350 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1351 QualType T1, QualType T2,
1352 SourceLocation RParenLoc) {
1353 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1354 T1.getAsOpaquePtr(),
1355 T2.getAsOpaquePtr(),
1356 RParenLoc);
1357 }
Mike Stump11289f42009-09-09 15:08:12 +00001358
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// \brief Build a new __builtin_choose_expr expression.
1360 ///
1361 /// By default, performs semantic analysis to build the new expression.
1362 /// Subclasses may override this routine to provide different behavior.
1363 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1364 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1365 SourceLocation RParenLoc) {
1366 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1367 move(Cond), move(LHS), move(RHS),
1368 RParenLoc);
1369 }
Mike Stump11289f42009-09-09 15:08:12 +00001370
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// \brief Build a new overloaded operator call expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// The semantic analysis provides the behavior of template instantiation,
1375 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001376 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// argument-dependent lookup, etc. Subclasses may override this routine to
1378 /// provide different behavior.
1379 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1380 SourceLocation OpLoc,
1381 ExprArg Callee,
1382 ExprArg First,
1383 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001384
1385 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// reinterpret_cast.
1387 ///
1388 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001389 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// Subclasses may override this routine to provide different behavior.
1391 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1392 Stmt::StmtClass Class,
1393 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001394 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 SourceLocation RAngleLoc,
1396 SourceLocation LParenLoc,
1397 ExprArg SubExpr,
1398 SourceLocation RParenLoc) {
1399 switch (Class) {
1400 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 move(SubExpr), RParenLoc);
1404
1405 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
1413 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001415
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001417 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001418 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 default:
1422 assert(false && "Invalid C++ named cast");
1423 break;
1424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 return getSema().ExprError();
1427 }
Mike Stump11289f42009-09-09 15:08:12 +00001428
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// \brief Build a new C++ static_cast expression.
1430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1434 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RAngleLoc,
1437 SourceLocation LParenLoc,
1438 ExprArg SubExpr,
1439 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001440 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1441 TInfo, move(SubExpr),
1442 SourceRange(LAngleLoc, RAngleLoc),
1443 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new C++ dynamic_cast expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1451 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001452 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RAngleLoc,
1454 SourceLocation LParenLoc,
1455 ExprArg SubExpr,
1456 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001457 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1458 TInfo, move(SubExpr),
1459 SourceRange(LAngleLoc, RAngleLoc),
1460 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
1462
1463 /// \brief Build a new C++ reinterpret_cast expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1468 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001469 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation RAngleLoc,
1471 SourceLocation LParenLoc,
1472 ExprArg SubExpr,
1473 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001474 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1475 TInfo, move(SubExpr),
1476 SourceRange(LAngleLoc, RAngleLoc),
1477 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new C++ const_cast expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
1484 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1485 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 SourceLocation RAngleLoc,
1488 SourceLocation LParenLoc,
1489 ExprArg SubExpr,
1490 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001491 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1492 TInfo, move(SubExpr),
1493 SourceRange(LAngleLoc, RAngleLoc),
1494 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 }
Mike Stump11289f42009-09-09 15:08:12 +00001496
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 /// \brief Build a new C++ functional-style cast expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001502 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 SourceLocation LParenLoc,
1504 ExprArg SubExpr,
1505 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001506 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001508 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001510 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001511 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 RParenLoc);
1513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new C++ typeid(type) expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1520 SourceLocation TypeidLoc,
1521 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001523 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001524 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 }
Mike Stump11289f42009-09-09 15:08:12 +00001526
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// \brief Build a new C++ typeid(expr) expression.
1528 ///
1529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001531 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1532 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 ExprArg Operand,
1534 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001535 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1536 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001537 }
1538
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// \brief Build a new C++ "this" expression.
1540 ///
1541 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001542 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001544 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001545 QualType ThisType,
1546 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001548 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1549 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 }
1551
1552 /// \brief Build a new C++ throw expression.
1553 ///
1554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
1556 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1557 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1558 }
1559
1560 /// \brief Build a new C++ default-argument expression.
1561 ///
1562 /// By default, builds a new default-argument expression, which does not
1563 /// require any semantic analysis. Subclasses may override this routine to
1564 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001565 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001566 ParmVarDecl *Param) {
1567 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1568 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 }
1570
1571 /// \brief Build a new C++ zero-initialization 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 RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 SourceLocation LParenLoc,
1577 QualType T,
1578 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001579 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1580 T.getAsOpaquePtr(), LParenLoc,
1581 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 0, RParenLoc);
1583 }
Mike Stump11289f42009-09-09 15:08:12 +00001584
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// \brief Build a new C++ "new" expression.
1586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001589 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 bool UseGlobal,
1591 SourceLocation PlacementLParen,
1592 MultiExprArg PlacementArgs,
1593 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001594 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 QualType AllocType,
1596 SourceLocation TypeLoc,
1597 SourceRange TypeRange,
1598 ExprArg ArraySize,
1599 SourceLocation ConstructorLParen,
1600 MultiExprArg ConstructorArgs,
1601 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001602 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 PlacementLParen,
1604 move(PlacementArgs),
1605 PlacementRParen,
1606 ParenTypeId,
1607 AllocType,
1608 TypeLoc,
1609 TypeRange,
1610 move(ArraySize),
1611 ConstructorLParen,
1612 move(ConstructorArgs),
1613 ConstructorRParen);
1614 }
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 /// \brief Build a new C++ "delete" expression.
1617 ///
1618 /// By default, performs semantic analysis to build the new expression.
1619 /// Subclasses may override this routine to provide different behavior.
1620 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1621 bool IsGlobalDelete,
1622 bool IsArrayForm,
1623 ExprArg Operand) {
1624 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1625 move(Operand));
1626 }
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// \brief Build a new unary type trait expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
1632 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1633 SourceLocation StartLoc,
1634 SourceLocation LParenLoc,
1635 QualType T,
1636 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001637 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 T.getAsOpaquePtr(), RParenLoc);
1639 }
1640
Mike Stump11289f42009-09-09 15:08:12 +00001641 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 /// expression.
1643 ///
1644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001646 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 SourceRange QualifierRange,
1648 DeclarationName Name,
1649 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001650 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 CXXScopeSpec SS;
1652 SS.setRange(QualifierRange);
1653 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001654
1655 if (TemplateArgs)
1656 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1657 *TemplateArgs);
1658
1659 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 }
1661
1662 /// \brief Build a new template-id expression.
1663 ///
1664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001666 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1667 LookupResult &R,
1668 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001669 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001670 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 }
1672
1673 /// \brief Build a new object-construction expression.
1674 ///
1675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
1677 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001678 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 CXXConstructorDecl *Constructor,
1680 bool IsElidable,
1681 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001682 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001683 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001684 ConvertedArgs))
1685 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001686
Douglas Gregordb121ba2009-12-14 16:27:04 +00001687 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1688 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 }
1690
1691 /// \brief Build a new object-construction expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
1695 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1696 QualType T,
1697 SourceLocation LParenLoc,
1698 MultiExprArg Args,
1699 SourceLocation *Commas,
1700 SourceLocation RParenLoc) {
1701 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1702 T.getAsOpaquePtr(),
1703 LParenLoc,
1704 move(Args),
1705 Commas,
1706 RParenLoc);
1707 }
1708
1709 /// \brief Build a new object-construction expression.
1710 ///
1711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
1713 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1714 QualType T,
1715 SourceLocation LParenLoc,
1716 MultiExprArg Args,
1717 SourceLocation *Commas,
1718 SourceLocation RParenLoc) {
1719 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1720 /*FIXME*/LParenLoc),
1721 T.getAsOpaquePtr(),
1722 LParenLoc,
1723 move(Args),
1724 Commas,
1725 RParenLoc);
1726 }
Mike Stump11289f42009-09-09 15:08:12 +00001727
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 /// \brief Build a new member reference expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001732 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001733 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 bool IsArrow,
1735 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001736 NestedNameSpecifier *Qualifier,
1737 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001738 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001740 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001741 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001743 SS.setRange(QualifierRange);
1744 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001745
John McCall2d74de92009-12-01 22:10:20 +00001746 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1747 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001748 SS, FirstQualifierInScope,
1749 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 }
1751
John McCall10eae182009-11-30 22:42:35 +00001752 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001753 ///
1754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001756 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001757 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001758 SourceLocation OperatorLoc,
1759 bool IsArrow,
1760 NestedNameSpecifier *Qualifier,
1761 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001762 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001763 LookupResult &R,
1764 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001765 CXXScopeSpec SS;
1766 SS.setRange(QualifierRange);
1767 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001768
John McCall2d74de92009-12-01 22:10:20 +00001769 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1770 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001771 SS, FirstQualifierInScope,
1772 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001773 }
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 /// \brief Build a new Objective-C @encode expression.
1776 ///
1777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
1779 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001780 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001782 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001784 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001785
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001786 /// \brief Build a new Objective-C class message.
1787 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
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 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1794 ReceiverTypeInfo->getType(),
1795 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001796 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001797 move(Args));
1798 }
1799
1800 /// \brief Build a new Objective-C instance message.
1801 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1802 Selector Sel,
1803 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001804 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001805 MultiExprArg Args,
1806 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001807 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1808 return SemaRef.BuildInstanceMessage(move(Receiver),
1809 ReceiverType,
1810 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001811 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001812 move(Args));
1813 }
1814
Douglas Gregord51d90d2010-04-26 20:11:03 +00001815 /// \brief Build a new Objective-C ivar reference expression.
1816 ///
1817 /// By default, performs semantic analysis to build the new expression.
1818 /// Subclasses may override this routine to provide different behavior.
1819 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1820 SourceLocation IvarLoc,
1821 bool IsArrow, bool IsFreeIvar) {
1822 // FIXME: We lose track of the IsFreeIvar bit.
1823 CXXScopeSpec SS;
1824 Expr *Base = BaseArg.takeAs<Expr>();
1825 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1826 Sema::LookupMemberName);
1827 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1828 /*FIME:*/IvarLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001829 SS, DeclPtrTy(),
1830 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001831 if (Result.isInvalid())
1832 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001833
Douglas Gregord51d90d2010-04-26 20:11:03 +00001834 if (Result.get())
1835 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001836
1837 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001838 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001839 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001841 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001842 /*TemplateArgs=*/0);
1843 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001844
1845 /// \brief Build a new Objective-C property reference expression.
1846 ///
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001849 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001850 ObjCPropertyDecl *Property,
1851 SourceLocation PropertyLoc) {
1852 CXXScopeSpec SS;
1853 Expr *Base = BaseArg.takeAs<Expr>();
1854 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1855 Sema::LookupMemberName);
1856 bool IsArrow = false;
1857 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1858 /*FIME:*/PropertyLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001859 SS, DeclPtrTy(),
1860 false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001861 if (Result.isInvalid())
1862 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001863
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 if (Result.get())
1865 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001866
1867 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001868 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001869 /*FIXME:*/PropertyLoc, IsArrow,
1870 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001871 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001872 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 /*TemplateArgs=*/0);
1874 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001875
1876 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001877 /// expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001881 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1882 ObjCMethodDecl *Getter,
1883 QualType T,
1884 ObjCMethodDecl *Setter,
1885 SourceLocation NameLoc,
1886 ExprArg Base) {
1887 // Since these expressions can only be value-dependent, we do not need to
1888 // perform semantic analysis again.
1889 return getSema().Owned(
1890 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1891 Setter,
1892 NameLoc,
1893 Base.takeAs<Expr>()));
1894 }
1895
Douglas Gregord51d90d2010-04-26 20:11:03 +00001896 /// \brief Build a new Objective-C "isa" expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
1900 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1901 bool IsArrow) {
1902 CXXScopeSpec SS;
1903 Expr *Base = BaseArg.takeAs<Expr>();
1904 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1905 Sema::LookupMemberName);
1906 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1907 /*FIME:*/IsaLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001908 SS, DeclPtrTy(),
1909 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001910 if (Result.isInvalid())
1911 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001912
Douglas Gregord51d90d2010-04-26 20:11:03 +00001913 if (Result.get())
1914 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001915
1916 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001918 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001919 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001920 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001921 /*TemplateArgs=*/0);
1922 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001923
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 /// \brief Build a new shuffle vector expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
1928 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1929 MultiExprArg SubExprs,
1930 SourceLocation RParenLoc) {
1931 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001932 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1934 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1935 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1936 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001937
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 // Build a reference to the __builtin_shufflevector builtin
1939 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001940 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001942 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001944
1945 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 unsigned NumSubExprs = SubExprs.size();
1947 Expr **Subs = (Expr **)SubExprs.release();
1948 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1949 Subs, NumSubExprs,
1950 Builtin->getResultType(),
1951 RParenLoc);
1952 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001953
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 // Type-check the __builtin_shufflevector expression.
1955 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1956 if (Result.isInvalid())
1957 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001960 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001962};
Douglas Gregora16548e2009-08-11 05:31:07 +00001963
Douglas Gregorebe10102009-08-20 07:17:43 +00001964template<typename Derived>
1965Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1966 if (!S)
1967 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregorebe10102009-08-20 07:17:43 +00001969 switch (S->getStmtClass()) {
1970 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 // Transform individual statement nodes
1973#define STMT(Node, Parent) \
1974 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1975#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001976#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregorebe10102009-08-20 07:17:43 +00001978 // Transform expressions by calling TransformExpr.
1979#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001980#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001981#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001982#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001983 {
1984 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1985 if (E.isInvalid())
1986 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001987
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001988 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001989 }
Mike Stump11289f42009-09-09 15:08:12 +00001990 }
1991
Douglas Gregorebe10102009-08-20 07:17:43 +00001992 return SemaRef.Owned(S->Retain());
1993}
Mike Stump11289f42009-09-09 15:08:12 +00001994
1995
Douglas Gregore922c772009-08-04 22:27:00 +00001996template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001997Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 if (!E)
1999 return SemaRef.Owned(E);
2000
2001 switch (E->getStmtClass()) {
2002 case Stmt::NoStmtClass: break;
2003#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002004#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002005#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002006 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002007#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002008 }
2009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002011}
2012
2013template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002014NestedNameSpecifier *
2015TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002016 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002017 QualType ObjectType,
2018 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002019 if (!NNS)
2020 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002021
Douglas Gregorebe10102009-08-20 07:17:43 +00002022 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002023 NestedNameSpecifier *Prefix = NNS->getPrefix();
2024 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002025 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002026 ObjectType,
2027 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002028 if (!Prefix)
2029 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002030
2031 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002032 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002033 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002034 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregor1135c352009-08-06 05:28:30 +00002037 switch (NNS->getKind()) {
2038 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002039 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002040 "Identifier nested-name-specifier with no prefix or object type");
2041 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2042 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002043 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002044
2045 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002046 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002047 ObjectType,
2048 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002049
Douglas Gregor1135c352009-08-06 05:28:30 +00002050 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002051 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002052 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002053 getDerived().TransformDecl(Range.getBegin(),
2054 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002055 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 Prefix == NNS->getPrefix() &&
2057 NS == NNS->getAsNamespace())
2058 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002059
Douglas Gregor1135c352009-08-06 05:28:30 +00002060 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2061 }
Mike Stump11289f42009-09-09 15:08:12 +00002062
Douglas Gregor1135c352009-08-06 05:28:30 +00002063 case NestedNameSpecifier::Global:
2064 // There is no meaningful transformation that one could perform on the
2065 // global scope.
2066 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregor1135c352009-08-06 05:28:30 +00002068 case NestedNameSpecifier::TypeSpecWithTemplate:
2069 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002070 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002071 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2072 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002073 if (T.isNull())
2074 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregor1135c352009-08-06 05:28:30 +00002076 if (!getDerived().AlwaysRebuild() &&
2077 Prefix == NNS->getPrefix() &&
2078 T == QualType(NNS->getAsType(), 0))
2079 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002080
2081 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2082 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002083 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002084 }
2085 }
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregor1135c352009-08-06 05:28:30 +00002087 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002088 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002089}
2090
2091template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002092DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002093TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002094 SourceLocation Loc,
2095 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002096 if (!Name)
2097 return Name;
2098
2099 switch (Name.getNameKind()) {
2100 case DeclarationName::Identifier:
2101 case DeclarationName::ObjCZeroArgSelector:
2102 case DeclarationName::ObjCOneArgSelector:
2103 case DeclarationName::ObjCMultiArgSelector:
2104 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002105 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002106 case DeclarationName::CXXUsingDirective:
2107 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002108
Douglas Gregorf816bd72009-09-03 22:13:48 +00002109 case DeclarationName::CXXConstructorName:
2110 case DeclarationName::CXXDestructorName:
2111 case DeclarationName::CXXConversionFunctionName: {
2112 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002114 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002115 if (T.isNull())
2116 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregorf816bd72009-09-03 22:13:48 +00002118 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002119 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002120 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002121 }
Mike Stump11289f42009-09-09 15:08:12 +00002122 }
2123
Douglas Gregorf816bd72009-09-03 22:13:48 +00002124 return DeclarationName();
2125}
2126
2127template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002128TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002129TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2130 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002131 SourceLocation Loc = getDerived().getBaseLocation();
2132
Douglas Gregor71dc5092009-08-06 06:41:21 +00002133 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002134 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002135 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002136 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2137 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002138 if (!NNS)
2139 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregor71dc5092009-08-06 06:41:21 +00002141 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002142 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002143 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002144 if (!TransTemplate)
2145 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002146
Douglas Gregor71dc5092009-08-06 06:41:21 +00002147 if (!getDerived().AlwaysRebuild() &&
2148 NNS == QTN->getQualifier() &&
2149 TransTemplate == Template)
2150 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002151
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2153 TransTemplate);
2154 }
Mike Stump11289f42009-09-09 15:08:12 +00002155
John McCalle66edc12009-11-24 19:00:30 +00002156 // These should be getting filtered out before they make it into the AST.
2157 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002158 }
Mike Stump11289f42009-09-09 15:08:12 +00002159
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002161 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002162 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002163 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2164 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002165 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002166 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor71dc5092009-08-06 06:41:21 +00002168 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002169 NNS == DTN->getQualifier() &&
2170 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregor71395fa2009-11-04 00:56:37 +00002173 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002174 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002175 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002176
2177 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002178 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002179 }
Mike Stump11289f42009-09-09 15:08:12 +00002180
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002182 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002183 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 if (!TransTemplate)
2185 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 if (!getDerived().AlwaysRebuild() &&
2188 TransTemplate == Template)
2189 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002190
Douglas Gregor71dc5092009-08-06 06:41:21 +00002191 return TemplateName(TransTemplate);
2192 }
Mike Stump11289f42009-09-09 15:08:12 +00002193
John McCalle66edc12009-11-24 19:00:30 +00002194 // These should be getting filtered out before they reach the AST.
2195 assert(false && "overloaded function decl survived to here");
2196 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002197}
2198
2199template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002200void TreeTransform<Derived>::InventTemplateArgumentLoc(
2201 const TemplateArgument &Arg,
2202 TemplateArgumentLoc &Output) {
2203 SourceLocation Loc = getDerived().getBaseLocation();
2204 switch (Arg.getKind()) {
2205 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002206 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002207 break;
2208
2209 case TemplateArgument::Type:
2210 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002211 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002212
John McCall0ad16662009-10-29 08:12:44 +00002213 break;
2214
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002215 case TemplateArgument::Template:
2216 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2217 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002218
John McCall0ad16662009-10-29 08:12:44 +00002219 case TemplateArgument::Expression:
2220 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2221 break;
2222
2223 case TemplateArgument::Declaration:
2224 case TemplateArgument::Integral:
2225 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002226 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002227 break;
2228 }
2229}
2230
2231template<typename Derived>
2232bool TreeTransform<Derived>::TransformTemplateArgument(
2233 const TemplateArgumentLoc &Input,
2234 TemplateArgumentLoc &Output) {
2235 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002236 switch (Arg.getKind()) {
2237 case TemplateArgument::Null:
2238 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002239 Output = Input;
2240 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregore922c772009-08-04 22:27:00 +00002242 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002243 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002244 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002245 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002246
2247 DI = getDerived().TransformType(DI);
2248 if (!DI) return true;
2249
2250 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2251 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002252 }
Mike Stump11289f42009-09-09 15:08:12 +00002253
Douglas Gregore922c772009-08-04 22:27:00 +00002254 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002255 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002256 DeclarationName Name;
2257 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2258 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002259 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002260 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002261 if (!D) return true;
2262
John McCall0d07eb32009-10-29 18:45:58 +00002263 Expr *SourceExpr = Input.getSourceDeclExpression();
2264 if (SourceExpr) {
2265 EnterExpressionEvaluationContext Unevaluated(getSema(),
2266 Action::Unevaluated);
2267 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2268 if (E.isInvalid())
2269 SourceExpr = NULL;
2270 else {
2271 SourceExpr = E.takeAs<Expr>();
2272 SourceExpr->Retain();
2273 }
2274 }
2275
2276 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002277 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002278 }
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002280 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002281 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002282 TemplateName Template
2283 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2284 if (Template.isNull())
2285 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002286
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002287 Output = TemplateArgumentLoc(TemplateArgument(Template),
2288 Input.getTemplateQualifierRange(),
2289 Input.getTemplateNameLoc());
2290 return false;
2291 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002292
Douglas Gregore922c772009-08-04 22:27:00 +00002293 case TemplateArgument::Expression: {
2294 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002295 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002296 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002297
John McCall0ad16662009-10-29 08:12:44 +00002298 Expr *InputExpr = Input.getSourceExpression();
2299 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2300
2301 Sema::OwningExprResult E
2302 = getDerived().TransformExpr(InputExpr);
2303 if (E.isInvalid()) return true;
2304
2305 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002306 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002307 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2308 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002309 }
Mike Stump11289f42009-09-09 15:08:12 +00002310
Douglas Gregore922c772009-08-04 22:27:00 +00002311 case TemplateArgument::Pack: {
2312 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2313 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002314 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002315 AEnd = Arg.pack_end();
2316 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002317
John McCall0ad16662009-10-29 08:12:44 +00002318 // FIXME: preserve source information here when we start
2319 // caring about parameter packs.
2320
John McCall0d07eb32009-10-29 18:45:58 +00002321 TemplateArgumentLoc InputArg;
2322 TemplateArgumentLoc OutputArg;
2323 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2324 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002325 return true;
2326
John McCall0d07eb32009-10-29 18:45:58 +00002327 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002328 }
2329 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002330 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002331 true);
John McCall0d07eb32009-10-29 18:45:58 +00002332 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002333 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002334 }
2335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregore922c772009-08-04 22:27:00 +00002337 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002338 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002339}
2340
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341//===----------------------------------------------------------------------===//
2342// Type transformation
2343//===----------------------------------------------------------------------===//
2344
2345template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002346QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002347 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002348 if (getDerived().AlreadyTransformed(T))
2349 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002350
John McCall550e0c22009-10-21 00:40:46 +00002351 // Temporary workaround. All of these transformations should
2352 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002353 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002354 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002355
Douglas Gregorfe17d252010-02-16 19:09:40 +00002356 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002357
John McCall550e0c22009-10-21 00:40:46 +00002358 if (!NewDI)
2359 return QualType();
2360
2361 return NewDI->getType();
2362}
2363
2364template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002365TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2366 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002367 if (getDerived().AlreadyTransformed(DI->getType()))
2368 return DI;
2369
2370 TypeLocBuilder TLB;
2371
2372 TypeLoc TL = DI->getTypeLoc();
2373 TLB.reserve(TL.getFullDataSize());
2374
Douglas Gregorfe17d252010-02-16 19:09:40 +00002375 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002376 if (Result.isNull())
2377 return 0;
2378
John McCallbcd03502009-12-07 02:54:59 +00002379 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002380}
2381
2382template<typename Derived>
2383QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002384TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2385 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002386 switch (T.getTypeLocClass()) {
2387#define ABSTRACT_TYPELOC(CLASS, PARENT)
2388#define TYPELOC(CLASS, PARENT) \
2389 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002390 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2391 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002392#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002393 }
Mike Stump11289f42009-09-09 15:08:12 +00002394
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002395 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002396 return QualType();
2397}
2398
2399/// FIXME: By default, this routine adds type qualifiers only to types
2400/// that can have qualifiers, and silently suppresses those qualifiers
2401/// that are not permitted (e.g., qualifiers on reference or function
2402/// types). This is the right thing for template instantiation, but
2403/// probably not for other clients.
2404template<typename Derived>
2405QualType
2406TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002407 QualifiedTypeLoc T,
2408 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002409 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002410
Douglas Gregorfe17d252010-02-16 19:09:40 +00002411 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2412 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002413 if (Result.isNull())
2414 return QualType();
2415
2416 // Silently suppress qualifiers if the result type can't be qualified.
2417 // FIXME: this is the right thing for template instantiation, but
2418 // probably not for other clients.
2419 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002420 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002421
John McCallcb0f89a2010-06-05 06:41:15 +00002422 if (!Quals.empty()) {
2423 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2424 TLB.push<QualifiedTypeLoc>(Result);
2425 // No location information to preserve.
2426 }
John McCall550e0c22009-10-21 00:40:46 +00002427
2428 return Result;
2429}
2430
2431template <class TyLoc> static inline
2432QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2433 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2434 NewT.setNameLoc(T.getNameLoc());
2435 return T.getType();
2436}
2437
John McCall550e0c22009-10-21 00:40:46 +00002438template<typename Derived>
2439QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002440 BuiltinTypeLoc T,
2441 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002442 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2443 NewT.setBuiltinLoc(T.getBuiltinLoc());
2444 if (T.needsExtraLocalData())
2445 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2446 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002447}
Mike Stump11289f42009-09-09 15:08:12 +00002448
Douglas Gregord6ff3322009-08-04 16:50:30 +00002449template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002450QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002451 ComplexTypeLoc T,
2452 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002453 // FIXME: recurse?
2454 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002455}
Mike Stump11289f42009-09-09 15:08:12 +00002456
Douglas Gregord6ff3322009-08-04 16:50:30 +00002457template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002458QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002459 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002460 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002461 QualType PointeeType
2462 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002463 if (PointeeType.isNull())
2464 return QualType();
2465
2466 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002467 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002468 // A dependent pointer type 'T *' has is being transformed such
2469 // that an Objective-C class type is being replaced for 'T'. The
2470 // resulting pointer type is an ObjCObjectPointerType, not a
2471 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002472 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002473
John McCall8b07ec22010-05-15 11:32:37 +00002474 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2475 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002476 return Result;
2477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002478
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002479 if (getDerived().AlwaysRebuild() ||
2480 PointeeType != TL.getPointeeLoc().getType()) {
2481 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2482 if (Result.isNull())
2483 return QualType();
2484 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002486 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2487 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002488 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002489}
Mike Stump11289f42009-09-09 15:08:12 +00002490
2491template<typename Derived>
2492QualType
John McCall550e0c22009-10-21 00:40:46 +00002493TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002494 BlockPointerTypeLoc TL,
2495 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002496 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002497 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2498 if (PointeeType.isNull())
2499 return QualType();
2500
2501 QualType Result = TL.getType();
2502 if (getDerived().AlwaysRebuild() ||
2503 PointeeType != TL.getPointeeLoc().getType()) {
2504 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002505 TL.getSigilLoc());
2506 if (Result.isNull())
2507 return QualType();
2508 }
2509
Douglas Gregor049211a2010-04-22 16:50:51 +00002510 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002511 NewT.setSigilLoc(TL.getSigilLoc());
2512 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002513}
2514
John McCall70dd5f62009-10-30 00:06:24 +00002515/// Transforms a reference type. Note that somewhat paradoxically we
2516/// don't care whether the type itself is an l-value type or an r-value
2517/// type; we only care if the type was *written* as an l-value type
2518/// or an r-value type.
2519template<typename Derived>
2520QualType
2521TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002522 ReferenceTypeLoc TL,
2523 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002524 const ReferenceType *T = TL.getTypePtr();
2525
2526 // Note that this works with the pointee-as-written.
2527 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2528 if (PointeeType.isNull())
2529 return QualType();
2530
2531 QualType Result = TL.getType();
2532 if (getDerived().AlwaysRebuild() ||
2533 PointeeType != T->getPointeeTypeAsWritten()) {
2534 Result = getDerived().RebuildReferenceType(PointeeType,
2535 T->isSpelledAsLValue(),
2536 TL.getSigilLoc());
2537 if (Result.isNull())
2538 return QualType();
2539 }
2540
2541 // r-value references can be rebuilt as l-value references.
2542 ReferenceTypeLoc NewTL;
2543 if (isa<LValueReferenceType>(Result))
2544 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2545 else
2546 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2547 NewTL.setSigilLoc(TL.getSigilLoc());
2548
2549 return Result;
2550}
2551
Mike Stump11289f42009-09-09 15:08:12 +00002552template<typename Derived>
2553QualType
John McCall550e0c22009-10-21 00:40:46 +00002554TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002555 LValueReferenceTypeLoc TL,
2556 QualType ObjectType) {
2557 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002558}
2559
Mike Stump11289f42009-09-09 15:08:12 +00002560template<typename Derived>
2561QualType
John McCall550e0c22009-10-21 00:40:46 +00002562TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002563 RValueReferenceTypeLoc TL,
2564 QualType ObjectType) {
2565 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002566}
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregord6ff3322009-08-04 16:50:30 +00002568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002569QualType
John McCall550e0c22009-10-21 00:40:46 +00002570TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002571 MemberPointerTypeLoc TL,
2572 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002573 MemberPointerType *T = TL.getTypePtr();
2574
2575 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002576 if (PointeeType.isNull())
2577 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002578
John McCall550e0c22009-10-21 00:40:46 +00002579 // TODO: preserve source information for this.
2580 QualType ClassType
2581 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582 if (ClassType.isNull())
2583 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002584
John McCall550e0c22009-10-21 00:40:46 +00002585 QualType Result = TL.getType();
2586 if (getDerived().AlwaysRebuild() ||
2587 PointeeType != T->getPointeeType() ||
2588 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002589 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2590 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002591 if (Result.isNull())
2592 return QualType();
2593 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594
John McCall550e0c22009-10-21 00:40:46 +00002595 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2596 NewTL.setSigilLoc(TL.getSigilLoc());
2597
2598 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599}
2600
Mike Stump11289f42009-09-09 15:08:12 +00002601template<typename Derived>
2602QualType
John McCall550e0c22009-10-21 00:40:46 +00002603TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002604 ConstantArrayTypeLoc TL,
2605 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002606 ConstantArrayType *T = TL.getTypePtr();
2607 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608 if (ElementType.isNull())
2609 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002610
John McCall550e0c22009-10-21 00:40:46 +00002611 QualType Result = TL.getType();
2612 if (getDerived().AlwaysRebuild() ||
2613 ElementType != T->getElementType()) {
2614 Result = getDerived().RebuildConstantArrayType(ElementType,
2615 T->getSizeModifier(),
2616 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002617 T->getIndexTypeCVRQualifiers(),
2618 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002619 if (Result.isNull())
2620 return QualType();
2621 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002622
John McCall550e0c22009-10-21 00:40:46 +00002623 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2624 NewTL.setLBracketLoc(TL.getLBracketLoc());
2625 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002626
John McCall550e0c22009-10-21 00:40:46 +00002627 Expr *Size = TL.getSizeExpr();
2628 if (Size) {
2629 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2630 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2631 }
2632 NewTL.setSizeExpr(Size);
2633
2634 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635}
Mike Stump11289f42009-09-09 15:08:12 +00002636
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002639 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002640 IncompleteArrayTypeLoc TL,
2641 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002642 IncompleteArrayType *T = TL.getTypePtr();
2643 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002644 if (ElementType.isNull())
2645 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002646
John McCall550e0c22009-10-21 00:40:46 +00002647 QualType Result = TL.getType();
2648 if (getDerived().AlwaysRebuild() ||
2649 ElementType != T->getElementType()) {
2650 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002652 T->getIndexTypeCVRQualifiers(),
2653 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002654 if (Result.isNull())
2655 return QualType();
2656 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002657
John McCall550e0c22009-10-21 00:40:46 +00002658 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2659 NewTL.setLBracketLoc(TL.getLBracketLoc());
2660 NewTL.setRBracketLoc(TL.getRBracketLoc());
2661 NewTL.setSizeExpr(0);
2662
2663 return Result;
2664}
2665
2666template<typename Derived>
2667QualType
2668TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002669 VariableArrayTypeLoc TL,
2670 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002671 VariableArrayType *T = TL.getTypePtr();
2672 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2673 if (ElementType.isNull())
2674 return QualType();
2675
2676 // Array bounds are not potentially evaluated contexts
2677 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2678
2679 Sema::OwningExprResult SizeResult
2680 = getDerived().TransformExpr(T->getSizeExpr());
2681 if (SizeResult.isInvalid())
2682 return QualType();
2683
2684 Expr *Size = static_cast<Expr*>(SizeResult.get());
2685
2686 QualType Result = TL.getType();
2687 if (getDerived().AlwaysRebuild() ||
2688 ElementType != T->getElementType() ||
2689 Size != T->getSizeExpr()) {
2690 Result = getDerived().RebuildVariableArrayType(ElementType,
2691 T->getSizeModifier(),
2692 move(SizeResult),
2693 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002694 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002695 if (Result.isNull())
2696 return QualType();
2697 }
2698 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002699
John McCall550e0c22009-10-21 00:40:46 +00002700 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2701 NewTL.setLBracketLoc(TL.getLBracketLoc());
2702 NewTL.setRBracketLoc(TL.getRBracketLoc());
2703 NewTL.setSizeExpr(Size);
2704
2705 return Result;
2706}
2707
2708template<typename Derived>
2709QualType
2710TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002711 DependentSizedArrayTypeLoc TL,
2712 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002713 DependentSizedArrayType *T = TL.getTypePtr();
2714 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2715 if (ElementType.isNull())
2716 return QualType();
2717
2718 // Array bounds are not potentially evaluated contexts
2719 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2720
2721 Sema::OwningExprResult SizeResult
2722 = getDerived().TransformExpr(T->getSizeExpr());
2723 if (SizeResult.isInvalid())
2724 return QualType();
2725
2726 Expr *Size = static_cast<Expr*>(SizeResult.get());
2727
2728 QualType Result = TL.getType();
2729 if (getDerived().AlwaysRebuild() ||
2730 ElementType != T->getElementType() ||
2731 Size != T->getSizeExpr()) {
2732 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2733 T->getSizeModifier(),
2734 move(SizeResult),
2735 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002736 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002737 if (Result.isNull())
2738 return QualType();
2739 }
2740 else SizeResult.take();
2741
2742 // We might have any sort of array type now, but fortunately they
2743 // all have the same location layout.
2744 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2745 NewTL.setLBracketLoc(TL.getLBracketLoc());
2746 NewTL.setRBracketLoc(TL.getRBracketLoc());
2747 NewTL.setSizeExpr(Size);
2748
2749 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750}
Mike Stump11289f42009-09-09 15:08:12 +00002751
2752template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002753QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002754 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002755 DependentSizedExtVectorTypeLoc TL,
2756 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002757 DependentSizedExtVectorType *T = TL.getTypePtr();
2758
2759 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002760 QualType ElementType = getDerived().TransformType(T->getElementType());
2761 if (ElementType.isNull())
2762 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002763
Douglas Gregore922c772009-08-04 22:27:00 +00002764 // Vector sizes are not potentially evaluated contexts
2765 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2766
Douglas Gregord6ff3322009-08-04 16:50:30 +00002767 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2768 if (Size.isInvalid())
2769 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 QualType Result = TL.getType();
2772 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002773 ElementType != T->getElementType() ||
2774 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002775 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776 move(Size),
2777 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002778 if (Result.isNull())
2779 return QualType();
2780 }
2781 else Size.take();
2782
2783 // Result might be dependent or not.
2784 if (isa<DependentSizedExtVectorType>(Result)) {
2785 DependentSizedExtVectorTypeLoc NewTL
2786 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 } else {
2789 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2790 NewTL.setNameLoc(TL.getNameLoc());
2791 }
2792
2793 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002794}
Mike Stump11289f42009-09-09 15:08:12 +00002795
2796template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002797QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002798 VectorTypeLoc TL,
2799 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002800 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002801 QualType ElementType = getDerived().TransformType(T->getElementType());
2802 if (ElementType.isNull())
2803 return QualType();
2804
John McCall550e0c22009-10-21 00:40:46 +00002805 QualType Result = TL.getType();
2806 if (getDerived().AlwaysRebuild() ||
2807 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002808 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2809 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002810 if (Result.isNull())
2811 return QualType();
2812 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002813
John McCall550e0c22009-10-21 00:40:46 +00002814 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2815 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002816
John McCall550e0c22009-10-21 00:40:46 +00002817 return Result;
2818}
2819
2820template<typename Derived>
2821QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002822 ExtVectorTypeLoc TL,
2823 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002824 VectorType *T = TL.getTypePtr();
2825 QualType ElementType = getDerived().TransformType(T->getElementType());
2826 if (ElementType.isNull())
2827 return QualType();
2828
2829 QualType Result = TL.getType();
2830 if (getDerived().AlwaysRebuild() ||
2831 ElementType != T->getElementType()) {
2832 Result = getDerived().RebuildExtVectorType(ElementType,
2833 T->getNumElements(),
2834 /*FIXME*/ SourceLocation());
2835 if (Result.isNull())
2836 return QualType();
2837 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002838
John McCall550e0c22009-10-21 00:40:46 +00002839 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2840 NewTL.setNameLoc(TL.getNameLoc());
2841
2842 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002843}
Mike Stump11289f42009-09-09 15:08:12 +00002844
2845template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002846ParmVarDecl *
2847TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2848 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2849 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2850 if (!NewDI)
2851 return 0;
2852
2853 if (NewDI == OldDI)
2854 return OldParm;
2855 else
2856 return ParmVarDecl::Create(SemaRef.Context,
2857 OldParm->getDeclContext(),
2858 OldParm->getLocation(),
2859 OldParm->getIdentifier(),
2860 NewDI->getType(),
2861 NewDI,
2862 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002863 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002864 /* DefArg */ NULL);
2865}
2866
2867template<typename Derived>
2868bool TreeTransform<Derived>::
2869 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2870 llvm::SmallVectorImpl<QualType> &PTypes,
2871 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2872 FunctionProtoType *T = TL.getTypePtr();
2873
2874 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2875 ParmVarDecl *OldParm = TL.getArg(i);
2876
2877 QualType NewType;
2878 ParmVarDecl *NewParm;
2879
2880 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002881 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2882 if (!NewParm)
2883 return true;
2884 NewType = NewParm->getType();
2885
2886 // Deal with the possibility that we don't have a parameter
2887 // declaration for this parameter.
2888 } else {
2889 NewParm = 0;
2890
2891 QualType OldType = T->getArgType(i);
2892 NewType = getDerived().TransformType(OldType);
2893 if (NewType.isNull())
2894 return true;
2895 }
2896
2897 PTypes.push_back(NewType);
2898 PVars.push_back(NewParm);
2899 }
2900
2901 return false;
2902}
2903
2904template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002905QualType
John McCall550e0c22009-10-21 00:40:46 +00002906TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002907 FunctionProtoTypeLoc TL,
2908 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002909 // Transform the parameters. We do this first for the benefit of template
2910 // instantiations, so that the ParmVarDecls get/ placed into the template
2911 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002912 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002913 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002914 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2915 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002916
Douglas Gregor14cf7522010-04-30 18:55:50 +00002917 FunctionProtoType *T = TL.getTypePtr();
2918 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2919 if (ResultType.isNull())
2920 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002921
John McCall550e0c22009-10-21 00:40:46 +00002922 QualType Result = TL.getType();
2923 if (getDerived().AlwaysRebuild() ||
2924 ResultType != T->getResultType() ||
2925 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2926 Result = getDerived().RebuildFunctionProtoType(ResultType,
2927 ParamTypes.data(),
2928 ParamTypes.size(),
2929 T->isVariadic(),
2930 T->getTypeQuals());
2931 if (Result.isNull())
2932 return QualType();
2933 }
Mike Stump11289f42009-09-09 15:08:12 +00002934
John McCall550e0c22009-10-21 00:40:46 +00002935 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2936 NewTL.setLParenLoc(TL.getLParenLoc());
2937 NewTL.setRParenLoc(TL.getRParenLoc());
2938 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2939 NewTL.setArg(i, ParamDecls[i]);
2940
2941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942}
Mike Stump11289f42009-09-09 15:08:12 +00002943
Douglas Gregord6ff3322009-08-04 16:50:30 +00002944template<typename Derived>
2945QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002946 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002947 FunctionNoProtoTypeLoc TL,
2948 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002949 FunctionNoProtoType *T = TL.getTypePtr();
2950 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2951 if (ResultType.isNull())
2952 return QualType();
2953
2954 QualType Result = TL.getType();
2955 if (getDerived().AlwaysRebuild() ||
2956 ResultType != T->getResultType())
2957 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2958
2959 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2960 NewTL.setLParenLoc(TL.getLParenLoc());
2961 NewTL.setRParenLoc(TL.getRParenLoc());
2962
2963 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002964}
Mike Stump11289f42009-09-09 15:08:12 +00002965
John McCallb96ec562009-12-04 22:46:56 +00002966template<typename Derived> QualType
2967TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002968 UnresolvedUsingTypeLoc TL,
2969 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002970 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002971 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002972 if (!D)
2973 return QualType();
2974
2975 QualType Result = TL.getType();
2976 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2977 Result = getDerived().RebuildUnresolvedUsingType(D);
2978 if (Result.isNull())
2979 return QualType();
2980 }
2981
2982 // We might get an arbitrary type spec type back. We should at
2983 // least always get a type spec type, though.
2984 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2985 NewTL.setNameLoc(TL.getNameLoc());
2986
2987 return Result;
2988}
2989
Douglas Gregord6ff3322009-08-04 16:50:30 +00002990template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002991QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002992 TypedefTypeLoc TL,
2993 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002994 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002996 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2997 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002998 if (!Typedef)
2999 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003000
John McCall550e0c22009-10-21 00:40:46 +00003001 QualType Result = TL.getType();
3002 if (getDerived().AlwaysRebuild() ||
3003 Typedef != T->getDecl()) {
3004 Result = getDerived().RebuildTypedefType(Typedef);
3005 if (Result.isNull())
3006 return QualType();
3007 }
Mike Stump11289f42009-09-09 15:08:12 +00003008
John McCall550e0c22009-10-21 00:40:46 +00003009 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3010 NewTL.setNameLoc(TL.getNameLoc());
3011
3012 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013}
Mike Stump11289f42009-09-09 15:08:12 +00003014
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003016QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003017 TypeOfExprTypeLoc TL,
3018 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003019 // typeof expressions are not potentially evaluated contexts
3020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003021
John McCalle8595032010-01-13 20:03:27 +00003022 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003023 if (E.isInvalid())
3024 return QualType();
3025
John McCall550e0c22009-10-21 00:40:46 +00003026 QualType Result = TL.getType();
3027 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003028 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003029 Result = getDerived().RebuildTypeOfExprType(move(E));
3030 if (Result.isNull())
3031 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003032 }
John McCall550e0c22009-10-21 00:40:46 +00003033 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003034
John McCall550e0c22009-10-21 00:40:46 +00003035 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003036 NewTL.setTypeofLoc(TL.getTypeofLoc());
3037 NewTL.setLParenLoc(TL.getLParenLoc());
3038 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003039
3040 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003041}
Mike Stump11289f42009-09-09 15:08:12 +00003042
3043template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003044QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003045 TypeOfTypeLoc TL,
3046 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003047 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3048 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3049 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003050 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003051
John McCall550e0c22009-10-21 00:40:46 +00003052 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003053 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3054 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003055 if (Result.isNull())
3056 return QualType();
3057 }
Mike Stump11289f42009-09-09 15:08:12 +00003058
John McCall550e0c22009-10-21 00:40:46 +00003059 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003060 NewTL.setTypeofLoc(TL.getTypeofLoc());
3061 NewTL.setLParenLoc(TL.getLParenLoc());
3062 NewTL.setRParenLoc(TL.getRParenLoc());
3063 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003064
3065 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003066}
Mike Stump11289f42009-09-09 15:08:12 +00003067
3068template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003069QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003070 DecltypeTypeLoc TL,
3071 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003072 DecltypeType *T = TL.getTypePtr();
3073
Douglas Gregore922c772009-08-04 22:27:00 +00003074 // decltype expressions are not potentially evaluated contexts
3075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003076
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3078 if (E.isInvalid())
3079 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003080
John McCall550e0c22009-10-21 00:40:46 +00003081 QualType Result = TL.getType();
3082 if (getDerived().AlwaysRebuild() ||
3083 E.get() != T->getUnderlyingExpr()) {
3084 Result = getDerived().RebuildDecltypeType(move(E));
3085 if (Result.isNull())
3086 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003087 }
John McCall550e0c22009-10-21 00:40:46 +00003088 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003089
John McCall550e0c22009-10-21 00:40:46 +00003090 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3091 NewTL.setNameLoc(TL.getNameLoc());
3092
3093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003094}
3095
3096template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003097QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003098 RecordTypeLoc TL,
3099 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003100 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003102 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3103 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104 if (!Record)
3105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003106
John McCall550e0c22009-10-21 00:40:46 +00003107 QualType Result = TL.getType();
3108 if (getDerived().AlwaysRebuild() ||
3109 Record != T->getDecl()) {
3110 Result = getDerived().RebuildRecordType(Record);
3111 if (Result.isNull())
3112 return QualType();
3113 }
Mike Stump11289f42009-09-09 15:08:12 +00003114
John McCall550e0c22009-10-21 00:40:46 +00003115 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3116 NewTL.setNameLoc(TL.getNameLoc());
3117
3118 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003119}
Mike Stump11289f42009-09-09 15:08:12 +00003120
3121template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003122QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003123 EnumTypeLoc TL,
3124 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003125 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003126 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003127 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3128 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129 if (!Enum)
3130 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 QualType Result = TL.getType();
3133 if (getDerived().AlwaysRebuild() ||
3134 Enum != T->getDecl()) {
3135 Result = getDerived().RebuildEnumType(Enum);
3136 if (Result.isNull())
3137 return QualType();
3138 }
Mike Stump11289f42009-09-09 15:08:12 +00003139
John McCall550e0c22009-10-21 00:40:46 +00003140 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3141 NewTL.setNameLoc(TL.getNameLoc());
3142
3143 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144}
John McCallfcc33b02009-09-05 00:15:47 +00003145
John McCalle78aac42010-03-10 03:28:59 +00003146template<typename Derived>
3147QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3148 TypeLocBuilder &TLB,
3149 InjectedClassNameTypeLoc TL,
3150 QualType ObjectType) {
3151 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3152 TL.getTypePtr()->getDecl());
3153 if (!D) return QualType();
3154
3155 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3156 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3157 return T;
3158}
3159
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregord6ff3322009-08-04 16:50:30 +00003161template<typename Derived>
3162QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003163 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003164 TemplateTypeParmTypeLoc TL,
3165 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003166 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167}
3168
Mike Stump11289f42009-09-09 15:08:12 +00003169template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003170QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003171 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003172 SubstTemplateTypeParmTypeLoc TL,
3173 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003174 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003175}
3176
3177template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003178QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3179 const TemplateSpecializationType *TST,
3180 QualType ObjectType) {
3181 // FIXME: this entire method is a temporary workaround; callers
3182 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003183
John McCall0ad16662009-10-29 08:12:44 +00003184 // Fake up a TemplateSpecializationTypeLoc.
3185 TypeLocBuilder TLB;
3186 TemplateSpecializationTypeLoc TL
3187 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3188
John McCall0d07eb32009-10-29 18:45:58 +00003189 SourceLocation BaseLoc = getDerived().getBaseLocation();
3190
3191 TL.setTemplateNameLoc(BaseLoc);
3192 TL.setLAngleLoc(BaseLoc);
3193 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003194 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3195 const TemplateArgument &TA = TST->getArg(i);
3196 TemplateArgumentLoc TAL;
3197 getDerived().InventTemplateArgumentLoc(TA, TAL);
3198 TL.setArgLocInfo(i, TAL.getLocInfo());
3199 }
3200
3201 TypeLocBuilder IgnoredTLB;
3202 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003203}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003204
Douglas Gregorc59e5612009-10-19 22:04:39 +00003205template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003206QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003207 TypeLocBuilder &TLB,
3208 TemplateSpecializationTypeLoc TL,
3209 QualType ObjectType) {
3210 const TemplateSpecializationType *T = TL.getTypePtr();
3211
Mike Stump11289f42009-09-09 15:08:12 +00003212 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003213 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003214 if (Template.isNull())
3215 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003216
John McCall6b51f282009-11-23 01:53:49 +00003217 TemplateArgumentListInfo NewTemplateArgs;
3218 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3219 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3220
3221 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3222 TemplateArgumentLoc Loc;
3223 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003224 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003225 NewTemplateArgs.addArgument(Loc);
3226 }
Mike Stump11289f42009-09-09 15:08:12 +00003227
John McCall0ad16662009-10-29 08:12:44 +00003228 // FIXME: maybe don't rebuild if all the template arguments are the same.
3229
3230 QualType Result =
3231 getDerived().RebuildTemplateSpecializationType(Template,
3232 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003233 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003234
3235 if (!Result.isNull()) {
3236 TemplateSpecializationTypeLoc NewTL
3237 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3238 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3239 NewTL.setLAngleLoc(TL.getLAngleLoc());
3240 NewTL.setRAngleLoc(TL.getRAngleLoc());
3241 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3242 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003243 }
Mike Stump11289f42009-09-09 15:08:12 +00003244
John McCall0ad16662009-10-29 08:12:44 +00003245 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246}
Mike Stump11289f42009-09-09 15:08:12 +00003247
3248template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003249QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003250TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3251 ElaboratedTypeLoc TL,
3252 QualType ObjectType) {
3253 ElaboratedType *T = TL.getTypePtr();
3254
3255 NestedNameSpecifier *NNS = 0;
3256 // NOTE: the qualifier in an ElaboratedType is optional.
3257 if (T->getQualifier() != 0) {
3258 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003259 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003260 ObjectType);
3261 if (!NNS)
3262 return QualType();
3263 }
Mike Stump11289f42009-09-09 15:08:12 +00003264
Abramo Bagnarad7548482010-05-19 21:37:53 +00003265 QualType NamedT;
3266 // FIXME: this test is meant to workaround a problem (failing assertion)
3267 // occurring if directly executing the code in the else branch.
3268 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3269 TemplateSpecializationTypeLoc OldNamedTL
3270 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3271 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003272 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003273 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3274 if (NamedT.isNull())
3275 return QualType();
3276 TemplateSpecializationTypeLoc NewNamedTL
3277 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3278 NewNamedTL.copy(OldNamedTL);
3279 }
3280 else {
3281 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3282 if (NamedT.isNull())
3283 return QualType();
3284 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003285
John McCall550e0c22009-10-21 00:40:46 +00003286 QualType Result = TL.getType();
3287 if (getDerived().AlwaysRebuild() ||
3288 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003289 NamedT != T->getNamedType()) {
3290 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003291 if (Result.isNull())
3292 return QualType();
3293 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003294
Abramo Bagnara6150c882010-05-11 21:36:43 +00003295 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003296 NewTL.setKeywordLoc(TL.getKeywordLoc());
3297 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003298
3299 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300}
Mike Stump11289f42009-09-09 15:08:12 +00003301
3302template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003303QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3304 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003305 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003306 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003307
Douglas Gregord6ff3322009-08-04 16:50:30 +00003308 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003309 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3310 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003311 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003312 if (!NNS)
3313 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003314
John McCallc392f372010-06-11 00:33:02 +00003315 QualType Result
3316 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3317 T->getIdentifier(),
3318 TL.getKeywordLoc(),
3319 TL.getQualifierRange(),
3320 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003321 if (Result.isNull())
3322 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323
Abramo Bagnarad7548482010-05-19 21:37:53 +00003324 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3325 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003326 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3327
Abramo Bagnarad7548482010-05-19 21:37:53 +00003328 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3329 NewTL.setKeywordLoc(TL.getKeywordLoc());
3330 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003331 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003332 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3333 NewTL.setKeywordLoc(TL.getKeywordLoc());
3334 NewTL.setQualifierRange(TL.getQualifierRange());
3335 NewTL.setNameLoc(TL.getNameLoc());
3336 }
John McCall550e0c22009-10-21 00:40:46 +00003337 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338}
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003341QualType TreeTransform<Derived>::
3342 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3343 DependentTemplateSpecializationTypeLoc TL,
3344 QualType ObjectType) {
3345 DependentTemplateSpecializationType *T = TL.getTypePtr();
3346
3347 NestedNameSpecifier *NNS
3348 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3349 TL.getQualifierRange(),
3350 ObjectType);
3351 if (!NNS)
3352 return QualType();
3353
3354 TemplateArgumentListInfo NewTemplateArgs;
3355 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3356 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3357
3358 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3359 TemplateArgumentLoc Loc;
3360 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3361 return QualType();
3362 NewTemplateArgs.addArgument(Loc);
3363 }
3364
3365 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3366 T->getKeyword(),
3367 NNS,
3368 T->getIdentifier(),
3369 TL.getNameLoc(),
3370 NewTemplateArgs);
3371 if (Result.isNull())
3372 return QualType();
3373
3374 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3375 QualType NamedT = ElabT->getNamedType();
3376
3377 // Copy information relevant to the template specialization.
3378 TemplateSpecializationTypeLoc NamedTL
3379 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3380 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3381 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3382 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3383 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3384
3385 // Copy information relevant to the elaborated type.
3386 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3387 NewTL.setKeywordLoc(TL.getKeywordLoc());
3388 NewTL.setQualifierRange(TL.getQualifierRange());
3389 } else {
3390 TLB.pushFullCopy(TL);
3391 }
3392 return Result;
3393}
3394
3395template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003396QualType
3397TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003398 ObjCInterfaceTypeLoc TL,
3399 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003400 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003401 TLB.pushFullCopy(TL);
3402 return TL.getType();
3403}
3404
3405template<typename Derived>
3406QualType
3407TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3408 ObjCObjectTypeLoc TL,
3409 QualType ObjectType) {
3410 // ObjCObjectType is never dependent.
3411 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003412 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003413}
Mike Stump11289f42009-09-09 15:08:12 +00003414
3415template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003416QualType
3417TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003418 ObjCObjectPointerTypeLoc TL,
3419 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003420 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003421 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003422 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003423}
3424
Douglas Gregord6ff3322009-08-04 16:50:30 +00003425//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003426// Statement transformation
3427//===----------------------------------------------------------------------===//
3428template<typename Derived>
3429Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003430TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3431 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003432}
3433
3434template<typename Derived>
3435Sema::OwningStmtResult
3436TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3437 return getDerived().TransformCompoundStmt(S, false);
3438}
3439
3440template<typename Derived>
3441Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003442TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003443 bool IsStmtExpr) {
3444 bool SubStmtChanged = false;
3445 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3446 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3447 B != BEnd; ++B) {
3448 OwningStmtResult Result = getDerived().TransformStmt(*B);
3449 if (Result.isInvalid())
3450 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003451
Douglas Gregorebe10102009-08-20 07:17:43 +00003452 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3453 Statements.push_back(Result.takeAs<Stmt>());
3454 }
Mike Stump11289f42009-09-09 15:08:12 +00003455
Douglas Gregorebe10102009-08-20 07:17:43 +00003456 if (!getDerived().AlwaysRebuild() &&
3457 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003458 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003459
3460 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3461 move_arg(Statements),
3462 S->getRBracLoc(),
3463 IsStmtExpr);
3464}
Mike Stump11289f42009-09-09 15:08:12 +00003465
Douglas Gregorebe10102009-08-20 07:17:43 +00003466template<typename Derived>
3467Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003468TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003469 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3470 {
3471 // The case value expressions are not potentially evaluated.
3472 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003473
Eli Friedman06577382009-11-19 03:14:00 +00003474 // Transform the left-hand case value.
3475 LHS = getDerived().TransformExpr(S->getLHS());
3476 if (LHS.isInvalid())
3477 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003478
Eli Friedman06577382009-11-19 03:14:00 +00003479 // Transform the right-hand case value (for the GNU case-range extension).
3480 RHS = getDerived().TransformExpr(S->getRHS());
3481 if (RHS.isInvalid())
3482 return SemaRef.StmtError();
3483 }
Mike Stump11289f42009-09-09 15:08:12 +00003484
Douglas Gregorebe10102009-08-20 07:17:43 +00003485 // Build the case statement.
3486 // Case statements are always rebuilt so that they will attached to their
3487 // transformed switch statement.
3488 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3489 move(LHS),
3490 S->getEllipsisLoc(),
3491 move(RHS),
3492 S->getColonLoc());
3493 if (Case.isInvalid())
3494 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // Transform the statement following the case
3497 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3498 if (SubStmt.isInvalid())
3499 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003500
Douglas Gregorebe10102009-08-20 07:17:43 +00003501 // Attach the body to the case statement
3502 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3503}
3504
3505template<typename Derived>
3506Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003507TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003508 // Transform the statement following the default case
3509 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3510 if (SubStmt.isInvalid())
3511 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregorebe10102009-08-20 07:17:43 +00003513 // Default statements are always rebuilt
3514 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3515 move(SubStmt));
3516}
Mike Stump11289f42009-09-09 15:08:12 +00003517
Douglas Gregorebe10102009-08-20 07:17:43 +00003518template<typename Derived>
3519Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003520TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3522 if (SubStmt.isInvalid())
3523 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregorebe10102009-08-20 07:17:43 +00003525 // FIXME: Pass the real colon location in.
3526 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3527 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3528 move(SubStmt));
3529}
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorebe10102009-08-20 07:17:43 +00003531template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003532Sema::OwningStmtResult
3533TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003535 OwningExprResult Cond(SemaRef);
3536 VarDecl *ConditionVar = 0;
3537 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003538 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003539 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003540 getDerived().TransformDefinition(
3541 S->getConditionVariable()->getLocation(),
3542 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003543 if (!ConditionVar)
3544 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003545 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003546 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003547
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003548 if (Cond.isInvalid())
3549 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003550
3551 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003552 if (S->getCond()) {
3553 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3554 S->getIfLoc(),
3555 move(Cond));
3556 if (CondE.isInvalid())
3557 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003558
Douglas Gregor6d319c62010-05-08 23:34:38 +00003559 Cond = move(CondE);
3560 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003561 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003562
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003563 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3564 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3565 return SemaRef.StmtError();
3566
Douglas Gregorebe10102009-08-20 07:17:43 +00003567 // Transform the "then" branch.
3568 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3569 if (Then.isInvalid())
3570 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003571
Douglas Gregorebe10102009-08-20 07:17:43 +00003572 // Transform the "else" branch.
3573 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3574 if (Else.isInvalid())
3575 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003576
Douglas Gregorebe10102009-08-20 07:17:43 +00003577 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003578 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003579 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003580 Then.get() == S->getThen() &&
3581 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003582 return SemaRef.Owned(S->Retain());
3583
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003584 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003586 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003587}
3588
3589template<typename Derived>
3590Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003591TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003592 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003593 OwningExprResult Cond(SemaRef);
3594 VarDecl *ConditionVar = 0;
3595 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003596 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003597 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003598 getDerived().TransformDefinition(
3599 S->getConditionVariable()->getLocation(),
3600 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003601 if (!ConditionVar)
3602 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003603 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003604 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003605
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003606 if (Cond.isInvalid())
3607 return SemaRef.StmtError();
3608 }
Mike Stump11289f42009-09-09 15:08:12 +00003609
Douglas Gregorebe10102009-08-20 07:17:43 +00003610 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003611 OwningStmtResult Switch
3612 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3613 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003614 if (Switch.isInvalid())
3615 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregorebe10102009-08-20 07:17:43 +00003617 // Transform the body of the switch statement.
3618 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3619 if (Body.isInvalid())
3620 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003621
Douglas Gregorebe10102009-08-20 07:17:43 +00003622 // Complete the switch statement.
3623 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3624 move(Body));
3625}
Mike Stump11289f42009-09-09 15:08:12 +00003626
Douglas Gregorebe10102009-08-20 07:17:43 +00003627template<typename Derived>
3628Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003629TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003630 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003631 OwningExprResult Cond(SemaRef);
3632 VarDecl *ConditionVar = 0;
3633 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003634 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003635 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003636 getDerived().TransformDefinition(
3637 S->getConditionVariable()->getLocation(),
3638 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003639 if (!ConditionVar)
3640 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003641 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003642 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003643
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003644 if (Cond.isInvalid())
3645 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003646
3647 if (S->getCond()) {
3648 // Convert the condition to a boolean value.
3649 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003650 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003651 move(Cond));
3652 if (CondE.isInvalid())
3653 return getSema().StmtError();
3654 Cond = move(CondE);
3655 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003656 }
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003658 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3659 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3660 return SemaRef.StmtError();
3661
Douglas Gregorebe10102009-08-20 07:17:43 +00003662 // Transform the body
3663 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3664 if (Body.isInvalid())
3665 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003666
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003668 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003669 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003671 return SemaRef.Owned(S->Retain());
3672
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003673 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003674 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003675}
Mike Stump11289f42009-09-09 15:08:12 +00003676
Douglas Gregorebe10102009-08-20 07:17:43 +00003677template<typename Derived>
3678Sema::OwningStmtResult
3679TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003680 // Transform the body
3681 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3682 if (Body.isInvalid())
3683 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003685 // Transform the condition
3686 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3687 if (Cond.isInvalid())
3688 return SemaRef.StmtError();
3689
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 if (!getDerived().AlwaysRebuild() &&
3691 Cond.get() == S->getCond() &&
3692 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003693 return SemaRef.Owned(S->Retain());
3694
Douglas Gregorebe10102009-08-20 07:17:43 +00003695 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3696 /*FIXME:*/S->getWhileLoc(), move(Cond),
3697 S->getRParenLoc());
3698}
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregorebe10102009-08-20 07:17:43 +00003700template<typename Derived>
3701Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003702TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003703 // Transform the initialization statement
3704 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3705 if (Init.isInvalid())
3706 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003709 OwningExprResult Cond(SemaRef);
3710 VarDecl *ConditionVar = 0;
3711 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003712 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003713 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003714 getDerived().TransformDefinition(
3715 S->getConditionVariable()->getLocation(),
3716 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003717 if (!ConditionVar)
3718 return SemaRef.StmtError();
3719 } else {
3720 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003721
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003722 if (Cond.isInvalid())
3723 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003724
3725 if (S->getCond()) {
3726 // Convert the condition to a boolean value.
3727 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3728 S->getForLoc(),
3729 move(Cond));
3730 if (CondE.isInvalid())
3731 return getSema().StmtError();
3732
3733 Cond = move(CondE);
3734 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003735 }
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003737 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3738 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3739 return SemaRef.StmtError();
3740
Douglas Gregorebe10102009-08-20 07:17:43 +00003741 // Transform the increment
3742 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3743 if (Inc.isInvalid())
3744 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003745
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003746 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3747 if (S->getInc() && !FullInc->get())
3748 return SemaRef.StmtError();
3749
Douglas Gregorebe10102009-08-20 07:17:43 +00003750 // Transform the body
3751 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3752 if (Body.isInvalid())
3753 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregorebe10102009-08-20 07:17:43 +00003755 if (!getDerived().AlwaysRebuild() &&
3756 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003757 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003758 Inc.get() == S->getInc() &&
3759 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003760 return SemaRef.Owned(S->Retain());
3761
Douglas Gregorebe10102009-08-20 07:17:43 +00003762 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003763 move(Init), FullCond, ConditionVar,
3764 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003765}
3766
3767template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003768Sema::OwningStmtResult
3769TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003770 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003771 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003772 S->getLabel());
3773}
3774
3775template<typename Derived>
3776Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003777TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3779 if (Target.isInvalid())
3780 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003781
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 if (!getDerived().AlwaysRebuild() &&
3783 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003784 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003785
3786 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3787 move(Target));
3788}
3789
3790template<typename Derived>
3791Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003792TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3793 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003794}
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregorebe10102009-08-20 07:17:43 +00003796template<typename Derived>
3797Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003798TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3799 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003800}
Mike Stump11289f42009-09-09 15:08:12 +00003801
Douglas Gregorebe10102009-08-20 07:17:43 +00003802template<typename Derived>
3803Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003804TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003805 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3806 if (Result.isInvalid())
3807 return SemaRef.StmtError();
3808
Mike Stump11289f42009-09-09 15:08:12 +00003809 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003810 // to tell whether the return type of the function has changed.
3811 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregorebe10102009-08-20 07:17:43 +00003814template<typename Derived>
3815Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003816TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003817 bool DeclChanged = false;
3818 llvm::SmallVector<Decl *, 4> Decls;
3819 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3820 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003821 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3822 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003823 if (!Transformed)
3824 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregorebe10102009-08-20 07:17:43 +00003826 if (Transformed != *D)
3827 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregorebe10102009-08-20 07:17:43 +00003829 Decls.push_back(Transformed);
3830 }
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003833 return SemaRef.Owned(S->Retain());
3834
3835 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003836 S->getStartLoc(), S->getEndLoc());
3837}
Mike Stump11289f42009-09-09 15:08:12 +00003838
Douglas Gregorebe10102009-08-20 07:17:43 +00003839template<typename Derived>
3840Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003841TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003842 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003843 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003844}
3845
3846template<typename Derived>
3847Sema::OwningStmtResult
3848TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003849
Anders Carlssonaaeef072010-01-24 05:50:09 +00003850 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3851 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003852 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003853
Anders Carlssonaaeef072010-01-24 05:50:09 +00003854 OwningExprResult AsmString(SemaRef);
3855 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3856
3857 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003858
Anders Carlssonaaeef072010-01-24 05:50:09 +00003859 // Go through the outputs.
3860 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003861 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003862
Anders Carlssonaaeef072010-01-24 05:50:09 +00003863 // No need to transform the constraint literal.
3864 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003865
Anders Carlssonaaeef072010-01-24 05:50:09 +00003866 // Transform the output expr.
3867 Expr *OutputExpr = S->getOutputExpr(I);
3868 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3869 if (Result.isInvalid())
3870 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003871
Anders Carlssonaaeef072010-01-24 05:50:09 +00003872 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003873
Anders Carlssonaaeef072010-01-24 05:50:09 +00003874 Exprs.push_back(Result.takeAs<Expr>());
3875 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003876
Anders Carlssonaaeef072010-01-24 05:50:09 +00003877 // Go through the inputs.
3878 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003879 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003880
Anders Carlssonaaeef072010-01-24 05:50:09 +00003881 // No need to transform the constraint literal.
3882 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003883
Anders Carlssonaaeef072010-01-24 05:50:09 +00003884 // Transform the input expr.
3885 Expr *InputExpr = S->getInputExpr(I);
3886 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3887 if (Result.isInvalid())
3888 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003889
Anders Carlssonaaeef072010-01-24 05:50:09 +00003890 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003891
Anders Carlssonaaeef072010-01-24 05:50:09 +00003892 Exprs.push_back(Result.takeAs<Expr>());
3893 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003894
Anders Carlssonaaeef072010-01-24 05:50:09 +00003895 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3896 return SemaRef.Owned(S->Retain());
3897
3898 // Go through the clobbers.
3899 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3900 Clobbers.push_back(S->getClobber(I)->Retain());
3901
3902 // No need to transform the asm string literal.
3903 AsmString = SemaRef.Owned(S->getAsmString());
3904
3905 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3906 S->isSimple(),
3907 S->isVolatile(),
3908 S->getNumOutputs(),
3909 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003910 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003911 move_arg(Constraints),
3912 move_arg(Exprs),
3913 move(AsmString),
3914 move_arg(Clobbers),
3915 S->getRParenLoc(),
3916 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003917}
3918
3919
3920template<typename Derived>
3921Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003922TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003923 // Transform the body of the @try.
3924 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3925 if (TryBody.isInvalid())
3926 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003927
Douglas Gregor96c79492010-04-23 22:50:49 +00003928 // Transform the @catch statements (if present).
3929 bool AnyCatchChanged = false;
3930 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3931 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3932 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003933 if (Catch.isInvalid())
3934 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003935 if (Catch.get() != S->getCatchStmt(I))
3936 AnyCatchChanged = true;
3937 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003938 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003939
Douglas Gregor306de2f2010-04-22 23:59:56 +00003940 // Transform the @finally statement (if present).
3941 OwningStmtResult Finally(SemaRef);
3942 if (S->getFinallyStmt()) {
3943 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3944 if (Finally.isInvalid())
3945 return SemaRef.StmtError();
3946 }
3947
3948 // If nothing changed, just retain this statement.
3949 if (!getDerived().AlwaysRebuild() &&
3950 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003951 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003952 Finally.get() == S->getFinallyStmt())
3953 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003954
Douglas Gregor306de2f2010-04-22 23:59:56 +00003955 // Build a new statement.
3956 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003957 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003958}
Mike Stump11289f42009-09-09 15:08:12 +00003959
Douglas Gregorebe10102009-08-20 07:17:43 +00003960template<typename Derived>
3961Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003962TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003963 // Transform the @catch parameter, if there is one.
3964 VarDecl *Var = 0;
3965 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3966 TypeSourceInfo *TSInfo = 0;
3967 if (FromVar->getTypeSourceInfo()) {
3968 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3969 if (!TSInfo)
3970 return SemaRef.StmtError();
3971 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003972
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003973 QualType T;
3974 if (TSInfo)
3975 T = TSInfo->getType();
3976 else {
3977 T = getDerived().TransformType(FromVar->getType());
3978 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003979 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003980 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003981
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003982 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3983 if (!Var)
3984 return SemaRef.StmtError();
3985 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003986
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003987 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3988 if (Body.isInvalid())
3989 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990
3991 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003992 S->getRParenLoc(),
3993 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003994}
Mike Stump11289f42009-09-09 15:08:12 +00003995
Douglas Gregorebe10102009-08-20 07:17:43 +00003996template<typename Derived>
3997Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003998TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003999 // Transform the body.
4000 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4001 if (Body.isInvalid())
4002 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004003
Douglas Gregor306de2f2010-04-22 23:59:56 +00004004 // If nothing changed, just retain this statement.
4005 if (!getDerived().AlwaysRebuild() &&
4006 Body.get() == S->getFinallyBody())
4007 return SemaRef.Owned(S->Retain());
4008
4009 // Build a new statement.
4010 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4011 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregorebe10102009-08-20 07:17:43 +00004014template<typename Derived>
4015Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004016TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00004017 OwningExprResult Operand(SemaRef);
4018 if (S->getThrowExpr()) {
4019 Operand = getDerived().TransformExpr(S->getThrowExpr());
4020 if (Operand.isInvalid())
4021 return getSema().StmtError();
4022 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004023
Douglas Gregor2900c162010-04-22 21:44:01 +00004024 if (!getDerived().AlwaysRebuild() &&
4025 Operand.get() == S->getThrowExpr())
4026 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
Douglas Gregor2900c162010-04-22 21:44:01 +00004028 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00004029}
Mike Stump11289f42009-09-09 15:08:12 +00004030
Douglas Gregorebe10102009-08-20 07:17:43 +00004031template<typename Derived>
4032Sema::OwningStmtResult
4033TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004034 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004035 // Transform the object we are locking.
4036 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4037 if (Object.isInvalid())
4038 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004039
Douglas Gregor6148de72010-04-22 22:01:21 +00004040 // Transform the body.
4041 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4042 if (Body.isInvalid())
4043 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004044
Douglas Gregor6148de72010-04-22 22:01:21 +00004045 // If nothing change, just retain the current statement.
4046 if (!getDerived().AlwaysRebuild() &&
4047 Object.get() == S->getSynchExpr() &&
4048 Body.get() == S->getSynchBody())
4049 return SemaRef.Owned(S->Retain());
4050
4051 // Build a new statement.
4052 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4053 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004054}
4055
4056template<typename Derived>
4057Sema::OwningStmtResult
4058TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004059 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004060 // Transform the element statement.
4061 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4062 if (Element.isInvalid())
4063 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004064
Douglas Gregorf68a5082010-04-22 23:10:45 +00004065 // Transform the collection expression.
4066 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4067 if (Collection.isInvalid())
4068 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004069
Douglas Gregorf68a5082010-04-22 23:10:45 +00004070 // Transform the body.
4071 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4072 if (Body.isInvalid())
4073 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004074
Douglas Gregorf68a5082010-04-22 23:10:45 +00004075 // If nothing changed, just retain this statement.
4076 if (!getDerived().AlwaysRebuild() &&
4077 Element.get() == S->getElement() &&
4078 Collection.get() == S->getCollection() &&
4079 Body.get() == S->getBody())
4080 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004081
Douglas Gregorf68a5082010-04-22 23:10:45 +00004082 // Build a new statement.
4083 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4084 /*FIXME:*/S->getForLoc(),
4085 move(Element),
4086 move(Collection),
4087 S->getRParenLoc(),
4088 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004089}
4090
4091
4092template<typename Derived>
4093Sema::OwningStmtResult
4094TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4095 // Transform the exception declaration, if any.
4096 VarDecl *Var = 0;
4097 if (S->getExceptionDecl()) {
4098 VarDecl *ExceptionDecl = S->getExceptionDecl();
4099 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4100 ExceptionDecl->getDeclName());
4101
4102 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4103 if (T.isNull())
4104 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregorebe10102009-08-20 07:17:43 +00004106 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4107 T,
John McCallbcd03502009-12-07 02:54:59 +00004108 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004109 ExceptionDecl->getIdentifier(),
4110 ExceptionDecl->getLocation(),
4111 /*FIXME: Inaccurate*/
4112 SourceRange(ExceptionDecl->getLocation()));
4113 if (!Var || Var->isInvalidDecl()) {
4114 if (Var)
4115 Var->Destroy(SemaRef.Context);
4116 return SemaRef.StmtError();
4117 }
4118 }
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregorebe10102009-08-20 07:17:43 +00004120 // Transform the actual exception handler.
4121 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4122 if (Handler.isInvalid()) {
4123 if (Var)
4124 Var->Destroy(SemaRef.Context);
4125 return SemaRef.StmtError();
4126 }
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregorebe10102009-08-20 07:17:43 +00004128 if (!getDerived().AlwaysRebuild() &&
4129 !Var &&
4130 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004131 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004132
4133 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4134 Var,
4135 move(Handler));
4136}
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregorebe10102009-08-20 07:17:43 +00004138template<typename Derived>
4139Sema::OwningStmtResult
4140TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4141 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004142 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004143 = getDerived().TransformCompoundStmt(S->getTryBlock());
4144 if (TryBlock.isInvalid())
4145 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregorebe10102009-08-20 07:17:43 +00004147 // Transform the handlers.
4148 bool HandlerChanged = false;
4149 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4150 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004151 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004152 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4153 if (Handler.isInvalid())
4154 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004155
Douglas Gregorebe10102009-08-20 07:17:43 +00004156 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4157 Handlers.push_back(Handler.takeAs<Stmt>());
4158 }
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregorebe10102009-08-20 07:17:43 +00004160 if (!getDerived().AlwaysRebuild() &&
4161 TryBlock.get() == S->getTryBlock() &&
4162 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004163 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004164
4165 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004166 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregorebe10102009-08-20 07:17:43 +00004169//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004170// Expression transformation
4171//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004172template<typename Derived>
4173Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004174TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004175 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004176}
Mike Stump11289f42009-09-09 15:08:12 +00004177
4178template<typename Derived>
4179Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004180TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004181 NestedNameSpecifier *Qualifier = 0;
4182 if (E->getQualifier()) {
4183 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004184 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004185 if (!Qualifier)
4186 return SemaRef.ExprError();
4187 }
John McCallce546572009-12-08 09:08:17 +00004188
4189 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004190 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4191 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 if (!ND)
4193 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004194
Alexis Hunta8136cc2010-05-05 15:23:54 +00004195 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004196 Qualifier == E->getQualifier() &&
4197 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004198 !E->hasExplicitTemplateArgumentList()) {
4199
4200 // Mark it referenced in the new context regardless.
4201 // FIXME: this is a bit instantiation-specific.
4202 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4203
Mike Stump11289f42009-09-09 15:08:12 +00004204 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004205 }
John McCallce546572009-12-08 09:08:17 +00004206
4207 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4208 if (E->hasExplicitTemplateArgumentList()) {
4209 TemplateArgs = &TransArgs;
4210 TransArgs.setLAngleLoc(E->getLAngleLoc());
4211 TransArgs.setRAngleLoc(E->getRAngleLoc());
4212 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4213 TemplateArgumentLoc Loc;
4214 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4215 return SemaRef.ExprError();
4216 TransArgs.addArgument(Loc);
4217 }
4218 }
4219
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004220 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004221 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004222}
Mike Stump11289f42009-09-09 15:08:12 +00004223
Douglas Gregora16548e2009-08-11 05:31:07 +00004224template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004225Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004226TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004227 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregora16548e2009-08-11 05:31:07 +00004230template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004231Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004232TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004233 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004234}
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregora16548e2009-08-11 05:31:07 +00004236template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004237Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004238TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004239 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004240}
Mike Stump11289f42009-09-09 15:08:12 +00004241
Douglas Gregora16548e2009-08-11 05:31:07 +00004242template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004243Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004244TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004245 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004246}
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004249Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004250TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004251 return SemaRef.Owned(E->Retain());
4252}
4253
4254template<typename Derived>
4255Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004256TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004257 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4258 if (SubExpr.isInvalid())
4259 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004262 return SemaRef.Owned(E->Retain());
4263
4264 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 E->getRParen());
4266}
4267
Mike Stump11289f42009-09-09 15:08:12 +00004268template<typename Derived>
4269Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004270TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4271 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 if (SubExpr.isInvalid())
4273 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004274
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004276 return SemaRef.Owned(E->Retain());
4277
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4279 E->getOpcode(),
4280 move(SubExpr));
4281}
Mike Stump11289f42009-09-09 15:08:12 +00004282
Douglas Gregora16548e2009-08-11 05:31:07 +00004283template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004284Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004285TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4286 // Transform the type.
4287 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4288 if (!Type)
4289 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004290
Douglas Gregor882211c2010-04-28 22:16:22 +00004291 // Transform all of the components into components similar to what the
4292 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004293 // FIXME: It would be slightly more efficient in the non-dependent case to
4294 // just map FieldDecls, rather than requiring the rebuilder to look for
4295 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004296 // template code that we don't care.
4297 bool ExprChanged = false;
4298 typedef Action::OffsetOfComponent Component;
4299 typedef OffsetOfExpr::OffsetOfNode Node;
4300 llvm::SmallVector<Component, 4> Components;
4301 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4302 const Node &ON = E->getComponent(I);
4303 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004304 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004305 Comp.LocStart = ON.getRange().getBegin();
4306 Comp.LocEnd = ON.getRange().getEnd();
4307 switch (ON.getKind()) {
4308 case Node::Array: {
4309 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4310 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4311 if (Index.isInvalid())
4312 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004313
Douglas Gregor882211c2010-04-28 22:16:22 +00004314 ExprChanged = ExprChanged || Index.get() != FromIndex;
4315 Comp.isBrackets = true;
4316 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4317 break;
4318 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004319
Douglas Gregor882211c2010-04-28 22:16:22 +00004320 case Node::Field:
4321 case Node::Identifier:
4322 Comp.isBrackets = false;
4323 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004324 if (!Comp.U.IdentInfo)
4325 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004326
Douglas Gregor882211c2010-04-28 22:16:22 +00004327 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004328
Douglas Gregord1702062010-04-29 00:18:15 +00004329 case Node::Base:
4330 // Will be recomputed during the rebuild.
4331 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004332 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004333
Douglas Gregor882211c2010-04-28 22:16:22 +00004334 Components.push_back(Comp);
4335 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004336
Douglas Gregor882211c2010-04-28 22:16:22 +00004337 // If nothing changed, retain the existing expression.
4338 if (!getDerived().AlwaysRebuild() &&
4339 Type == E->getTypeSourceInfo() &&
4340 !ExprChanged)
4341 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004342
Douglas Gregor882211c2010-04-28 22:16:22 +00004343 // Build a new offsetof expression.
4344 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4345 Components.data(), Components.size(),
4346 E->getRParenLoc());
4347}
4348
4349template<typename Derived>
4350Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004351TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004352 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004353 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004354
John McCallbcd03502009-12-07 02:54:59 +00004355 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004356 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004358
John McCall4c98fd82009-11-04 07:28:41 +00004359 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004361
John McCall4c98fd82009-11-04 07:28:41 +00004362 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004363 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 E->getSourceRange());
4365 }
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004368 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 // C++0x [expr.sizeof]p1:
4370 // The operand is either an expression, which is an unevaluated operand
4371 // [...]
4372 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4375 if (SubExpr.isInvalid())
4376 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004377
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4379 return SemaRef.Owned(E->Retain());
4380 }
Mike Stump11289f42009-09-09 15:08:12 +00004381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4383 E->isSizeOf(),
4384 E->getSourceRange());
4385}
Mike Stump11289f42009-09-09 15:08:12 +00004386
Douglas Gregora16548e2009-08-11 05:31:07 +00004387template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004388Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004389TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4391 if (LHS.isInvalid())
4392 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4395 if (RHS.isInvalid())
4396 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004397
4398
Douglas Gregora16548e2009-08-11 05:31:07 +00004399 if (!getDerived().AlwaysRebuild() &&
4400 LHS.get() == E->getLHS() &&
4401 RHS.get() == E->getRHS())
4402 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4405 /*FIXME:*/E->getLHS()->getLocStart(),
4406 move(RHS),
4407 E->getRBracketLoc());
4408}
Mike Stump11289f42009-09-09 15:08:12 +00004409
4410template<typename Derived>
4411Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004412TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 // Transform the callee.
4414 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4415 if (Callee.isInvalid())
4416 return SemaRef.ExprError();
4417
4418 // Transform arguments.
4419 bool ArgChanged = false;
4420 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4421 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4422 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4423 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4424 if (Arg.isInvalid())
4425 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004426
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 // FIXME: Wrong source location information for the ','.
4428 FakeCommaLocs.push_back(
4429 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004430
4431 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 Args.push_back(Arg.takeAs<Expr>());
4433 }
Mike Stump11289f42009-09-09 15:08:12 +00004434
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 if (!getDerived().AlwaysRebuild() &&
4436 Callee.get() == E->getCallee() &&
4437 !ArgChanged)
4438 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004441 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4443 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4444 move_arg(Args),
4445 FakeCommaLocs.data(),
4446 E->getRParenLoc());
4447}
Mike Stump11289f42009-09-09 15:08:12 +00004448
4449template<typename Derived>
4450Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004451TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4453 if (Base.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004456 NestedNameSpecifier *Qualifier = 0;
4457 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004458 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004459 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004460 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004461 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004462 return SemaRef.ExprError();
4463 }
Mike Stump11289f42009-09-09 15:08:12 +00004464
Eli Friedman2cfcef62009-12-04 06:40:45 +00004465 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004466 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4467 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 if (!Member)
4469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
John McCall16df1e52010-03-30 21:47:33 +00004471 NamedDecl *FoundDecl = E->getFoundDecl();
4472 if (FoundDecl == E->getMemberDecl()) {
4473 FoundDecl = Member;
4474 } else {
4475 FoundDecl = cast_or_null<NamedDecl>(
4476 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4477 if (!FoundDecl)
4478 return SemaRef.ExprError();
4479 }
4480
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 if (!getDerived().AlwaysRebuild() &&
4482 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004483 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004484 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004485 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004486 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004487
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004488 // Mark it referenced in the new context regardless.
4489 // FIXME: this is a bit instantiation-specific.
4490 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004491 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004492 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004493
John McCall6b51f282009-11-23 01:53:49 +00004494 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004495 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004496 TransArgs.setLAngleLoc(E->getLAngleLoc());
4497 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004498 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004499 TemplateArgumentLoc Loc;
4500 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004501 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004502 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004503 }
4504 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 // FIXME: Bogus source location for the operator
4507 SourceLocation FakeOperatorLoc
4508 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4509
John McCall38836f02010-01-15 08:34:02 +00004510 // FIXME: to do this check properly, we will need to preserve the
4511 // first-qualifier-in-scope here, just in case we had a dependent
4512 // base (and therefore couldn't do the check) and a
4513 // nested-name-qualifier (and therefore could do the lookup).
4514 NamedDecl *FirstQualifierInScope = 0;
4515
Douglas Gregora16548e2009-08-11 05:31:07 +00004516 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4517 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004518 Qualifier,
4519 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004521 Member,
John McCall16df1e52010-03-30 21:47:33 +00004522 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004523 (E->hasExplicitTemplateArgumentList()
4524 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004525 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004526}
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregora16548e2009-08-11 05:31:07 +00004528template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004529Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004530TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4532 if (LHS.isInvalid())
4533 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004534
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4536 if (RHS.isInvalid())
4537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 if (!getDerived().AlwaysRebuild() &&
4540 LHS.get() == E->getLHS() &&
4541 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004542 return SemaRef.Owned(E->Retain());
4543
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4545 move(LHS), move(RHS));
4546}
4547
Mike Stump11289f42009-09-09 15:08:12 +00004548template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004549Sema::OwningExprResult
4550TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004551 CompoundAssignOperator *E) {
4552 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004556Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004557TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4559 if (Cond.isInvalid())
4560 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004561
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4563 if (LHS.isInvalid())
4564 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4567 if (RHS.isInvalid())
4568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 if (!getDerived().AlwaysRebuild() &&
4571 Cond.get() == E->getCond() &&
4572 LHS.get() == E->getLHS() &&
4573 RHS.get() == E->getRHS())
4574 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004575
4576 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004577 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004578 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004579 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 move(RHS));
4581}
Mike Stump11289f42009-09-09 15:08:12 +00004582
4583template<typename Derived>
4584Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004585TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004586 // Implicit casts are eliminated during transformation, since they
4587 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004588 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004589}
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591template<typename Derived>
4592Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004593TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004594 TypeSourceInfo *OldT;
4595 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 {
4597 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004598 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4600 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004601
John McCall97513962010-01-15 18:39:57 +00004602 OldT = E->getTypeInfoAsWritten();
4603 NewT = getDerived().TransformType(OldT);
4604 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004605 return SemaRef.ExprError();
4606 }
Mike Stump11289f42009-09-09 15:08:12 +00004607
Douglas Gregor6131b442009-12-12 18:16:41 +00004608 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004609 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004610 if (SubExpr.isInvalid())
4611 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregora16548e2009-08-11 05:31:07 +00004613 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004614 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004616 return SemaRef.Owned(E->Retain());
4617
John McCall97513962010-01-15 18:39:57 +00004618 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4619 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 E->getRParenLoc(),
4621 move(SubExpr));
4622}
Mike Stump11289f42009-09-09 15:08:12 +00004623
Douglas Gregora16548e2009-08-11 05:31:07 +00004624template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004625Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004626TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004627 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4628 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4629 if (!NewT)
4630 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004631
Douglas Gregora16548e2009-08-11 05:31:07 +00004632 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4633 if (Init.isInvalid())
4634 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004635
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004637 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004639 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004640
John McCall5d7aa7f2010-01-19 22:33:45 +00004641 // Note: the expression type doesn't necessarily match the
4642 // type-as-written, but that's okay, because it should always be
4643 // derivable from the initializer.
4644
John McCalle15bbff2010-01-18 19:35:47 +00004645 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 /*FIXME:*/E->getInitializer()->getLocEnd(),
4647 move(Init));
4648}
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregora16548e2009-08-11 05:31:07 +00004650template<typename Derived>
4651Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004652TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4654 if (Base.isInvalid())
4655 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 if (!getDerived().AlwaysRebuild() &&
4658 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004659 return SemaRef.Owned(E->Retain());
4660
Douglas Gregora16548e2009-08-11 05:31:07 +00004661 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004662 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4664 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4665 E->getAccessorLoc(),
4666 E->getAccessor());
4667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregora16548e2009-08-11 05:31:07 +00004669template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004670Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004671TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4675 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4676 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4677 if (Init.isInvalid())
4678 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 InitChanged = InitChanged || Init.get() != E->getInit(I);
4681 Inits.push_back(Init.takeAs<Expr>());
4682 }
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004685 return SemaRef.Owned(E->Retain());
4686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004688 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004689}
Mike Stump11289f42009-09-09 15:08:12 +00004690
Douglas Gregora16548e2009-08-11 05:31:07 +00004691template<typename Derived>
4692Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004693TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregorebe10102009-08-20 07:17:43 +00004696 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4698 if (Init.isInvalid())
4699 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregorebe10102009-08-20 07:17:43 +00004701 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4703 bool ExprChanged = false;
4704 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4705 DEnd = E->designators_end();
4706 D != DEnd; ++D) {
4707 if (D->isFieldDesignator()) {
4708 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4709 D->getDotLoc(),
4710 D->getFieldLoc()));
4711 continue;
4712 }
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 if (D->isArrayDesignator()) {
4715 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4716 if (Index.isInvalid())
4717 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004718
4719 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4723 ArrayExprs.push_back(Index.release());
4724 continue;
4725 }
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004728 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4730 if (Start.isInvalid())
4731 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4734 if (End.isInvalid())
4735 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004736
4737 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 End.get(),
4739 D->getLBracketLoc(),
4740 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4743 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004744
Douglas Gregora16548e2009-08-11 05:31:07 +00004745 ArrayExprs.push_back(Start.release());
4746 ArrayExprs.push_back(End.release());
4747 }
Mike Stump11289f42009-09-09 15:08:12 +00004748
Douglas Gregora16548e2009-08-11 05:31:07 +00004749 if (!getDerived().AlwaysRebuild() &&
4750 Init.get() == E->getInit() &&
4751 !ExprChanged)
4752 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4755 E->getEqualOrColonLoc(),
4756 E->usesGNUSyntax(), move(Init));
4757}
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004760Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004761TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004762 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004763 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004764
Douglas Gregor3da3c062009-10-28 00:29:27 +00004765 // FIXME: Will we ever have proper type location here? Will we actually
4766 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 QualType T = getDerived().TransformType(E->getType());
4768 if (T.isNull())
4769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 if (!getDerived().AlwaysRebuild() &&
4772 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004773 return SemaRef.Owned(E->Retain());
4774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 return getDerived().RebuildImplicitValueInitExpr(T);
4776}
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004779Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004780TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004781 // FIXME: Do we want the type as written?
4782 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 {
4785 // FIXME: Source location isn't quite accurate.
4786 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4787 T = getDerived().TransformType(E->getType());
4788 if (T.isNull())
4789 return SemaRef.ExprError();
4790 }
Mike Stump11289f42009-09-09 15:08:12 +00004791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4793 if (SubExpr.isInvalid())
4794 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 if (!getDerived().AlwaysRebuild() &&
4797 T == E->getType() &&
4798 SubExpr.get() == E->getSubExpr())
4799 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004800
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4802 T, E->getRParenLoc());
4803}
4804
4805template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004806Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004807TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004808 bool ArgumentChanged = false;
4809 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4810 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4811 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4812 if (Init.isInvalid())
4813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4816 Inits.push_back(Init.takeAs<Expr>());
4817 }
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4820 move_arg(Inits),
4821 E->getRParenLoc());
4822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824/// \brief Transform an address-of-label expression.
4825///
4826/// By default, the transformation of an address-of-label expression always
4827/// rebuilds the expression, so that the label identifier can be resolved to
4828/// the corresponding label statement by semantic analysis.
4829template<typename Derived>
4830Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004831TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004832 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4833 E->getLabel());
4834}
Mike Stump11289f42009-09-09 15:08:12 +00004835
4836template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004837Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004838TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004839 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4841 if (SubStmt.isInvalid())
4842 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004843
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 if (!getDerived().AlwaysRebuild() &&
4845 SubStmt.get() == E->getSubStmt())
4846 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004847
4848 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 move(SubStmt),
4850 E->getRParenLoc());
4851}
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregora16548e2009-08-11 05:31:07 +00004853template<typename Derived>
4854Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004855TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 QualType T1, T2;
4857 {
4858 // FIXME: Source location isn't quite accurate.
4859 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 T1 = getDerived().TransformType(E->getArgType1());
4862 if (T1.isNull())
4863 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004864
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 T2 = getDerived().TransformType(E->getArgType2());
4866 if (T2.isNull())
4867 return SemaRef.ExprError();
4868 }
4869
4870 if (!getDerived().AlwaysRebuild() &&
4871 T1 == E->getArgType1() &&
4872 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004873 return SemaRef.Owned(E->Retain());
4874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4876 T1, T2, E->getRParenLoc());
4877}
Mike Stump11289f42009-09-09 15:08:12 +00004878
Douglas Gregora16548e2009-08-11 05:31:07 +00004879template<typename Derived>
4880Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004881TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4883 if (Cond.isInvalid())
4884 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregora16548e2009-08-11 05:31:07 +00004886 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4887 if (LHS.isInvalid())
4888 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregora16548e2009-08-11 05:31:07 +00004890 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4891 if (RHS.isInvalid())
4892 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 if (!getDerived().AlwaysRebuild() &&
4895 Cond.get() == E->getCond() &&
4896 LHS.get() == E->getLHS() &&
4897 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004898 return SemaRef.Owned(E->Retain());
4899
Douglas Gregora16548e2009-08-11 05:31:07 +00004900 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4901 move(Cond), move(LHS), move(RHS),
4902 E->getRParenLoc());
4903}
Mike Stump11289f42009-09-09 15:08:12 +00004904
Douglas Gregora16548e2009-08-11 05:31:07 +00004905template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004906Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004907TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004908 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004909}
4910
4911template<typename Derived>
4912Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004913TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004914 switch (E->getOperator()) {
4915 case OO_New:
4916 case OO_Delete:
4917 case OO_Array_New:
4918 case OO_Array_Delete:
4919 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4920 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004921
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004922 case OO_Call: {
4923 // This is a call to an object's operator().
4924 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4925
4926 // Transform the object itself.
4927 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4928 if (Object.isInvalid())
4929 return SemaRef.ExprError();
4930
4931 // FIXME: Poor location information
4932 SourceLocation FakeLParenLoc
4933 = SemaRef.PP.getLocForEndOfToken(
4934 static_cast<Expr *>(Object.get())->getLocEnd());
4935
4936 // Transform the call arguments.
4937 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4938 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4939 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004940 if (getDerived().DropCallArgument(E->getArg(I)))
4941 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004942
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004943 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4944 if (Arg.isInvalid())
4945 return SemaRef.ExprError();
4946
4947 // FIXME: Poor source location information.
4948 SourceLocation FakeCommaLoc
4949 = SemaRef.PP.getLocForEndOfToken(
4950 static_cast<Expr *>(Arg.get())->getLocEnd());
4951 FakeCommaLocs.push_back(FakeCommaLoc);
4952 Args.push_back(Arg.release());
4953 }
4954
4955 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4956 move_arg(Args),
4957 FakeCommaLocs.data(),
4958 E->getLocEnd());
4959 }
4960
4961#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4962 case OO_##Name:
4963#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4964#include "clang/Basic/OperatorKinds.def"
4965 case OO_Subscript:
4966 // Handled below.
4967 break;
4968
4969 case OO_Conditional:
4970 llvm_unreachable("conditional operator is not actually overloadable");
4971 return SemaRef.ExprError();
4972
4973 case OO_None:
4974 case NUM_OVERLOADED_OPERATORS:
4975 llvm_unreachable("not an overloaded operator?");
4976 return SemaRef.ExprError();
4977 }
4978
Douglas Gregora16548e2009-08-11 05:31:07 +00004979 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4980 if (Callee.isInvalid())
4981 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004982
John McCall47f29ea2009-12-08 09:21:05 +00004983 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 if (First.isInvalid())
4985 return SemaRef.ExprError();
4986
4987 OwningExprResult Second(SemaRef);
4988 if (E->getNumArgs() == 2) {
4989 Second = getDerived().TransformExpr(E->getArg(1));
4990 if (Second.isInvalid())
4991 return SemaRef.ExprError();
4992 }
Mike Stump11289f42009-09-09 15:08:12 +00004993
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 if (!getDerived().AlwaysRebuild() &&
4995 Callee.get() == E->getCallee() &&
4996 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004997 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4998 return SemaRef.Owned(E->Retain());
4999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5001 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005002 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 move(First),
5004 move(Second));
5005}
Mike Stump11289f42009-09-09 15:08:12 +00005006
Douglas Gregora16548e2009-08-11 05:31:07 +00005007template<typename Derived>
5008Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005009TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5010 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005011}
Mike Stump11289f42009-09-09 15:08:12 +00005012
Douglas Gregora16548e2009-08-11 05:31:07 +00005013template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005014Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005015TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005016 TypeSourceInfo *OldT;
5017 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 {
5019 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005020 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5022 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005023
John McCall97513962010-01-15 18:39:57 +00005024 OldT = E->getTypeInfoAsWritten();
5025 NewT = getDerived().TransformType(OldT);
5026 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005027 return SemaRef.ExprError();
5028 }
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregor6131b442009-12-12 18:16:41 +00005030 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005031 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 if (SubExpr.isInvalid())
5033 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005034
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005036 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005038 return SemaRef.Owned(E->Retain());
5039
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005041 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5043 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5044 SourceLocation FakeRParenLoc
5045 = SemaRef.PP.getLocForEndOfToken(
5046 E->getSubExpr()->getSourceRange().getEnd());
5047 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005048 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005049 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005050 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005051 FakeRAngleLoc,
5052 FakeRAngleLoc,
5053 move(SubExpr),
5054 FakeRParenLoc);
5055}
Mike Stump11289f42009-09-09 15:08:12 +00005056
Douglas Gregora16548e2009-08-11 05:31:07 +00005057template<typename Derived>
5058Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005059TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5060 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005061}
Mike Stump11289f42009-09-09 15:08:12 +00005062
5063template<typename Derived>
5064Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005065TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5066 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005067}
5068
Douglas Gregora16548e2009-08-11 05:31:07 +00005069template<typename Derived>
5070Sema::OwningExprResult
5071TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005072 CXXReinterpretCastExpr *E) {
5073 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005074}
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregora16548e2009-08-11 05:31:07 +00005076template<typename Derived>
5077Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5079 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
5084TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005085 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005086 TypeSourceInfo *OldT;
5087 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 {
5089 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005090
John McCall97513962010-01-15 18:39:57 +00005091 OldT = E->getTypeInfoAsWritten();
5092 NewT = getDerived().TransformType(OldT);
5093 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 return SemaRef.ExprError();
5095 }
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregor6131b442009-12-12 18:16:41 +00005097 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005098 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005099 if (SubExpr.isInvalid())
5100 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregora16548e2009-08-11 05:31:07 +00005102 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005103 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005105 return SemaRef.Owned(E->Retain());
5106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 // FIXME: The end of the type's source range is wrong
5108 return getDerived().RebuildCXXFunctionalCastExpr(
5109 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005110 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 /*FIXME:*/E->getSubExpr()->getLocStart(),
5112 move(SubExpr),
5113 E->getRParenLoc());
5114}
Mike Stump11289f42009-09-09 15:08:12 +00005115
Douglas Gregora16548e2009-08-11 05:31:07 +00005116template<typename Derived>
5117Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005118TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005120 TypeSourceInfo *TInfo
5121 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5122 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005124
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005126 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005128
Douglas Gregor9da64192010-04-26 22:37:10 +00005129 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5130 E->getLocStart(),
5131 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 E->getLocEnd());
5133 }
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 // We don't know whether the expression is potentially evaluated until
5136 // after we perform semantic analysis, so the expression is potentially
5137 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005138 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5142 if (SubExpr.isInvalid())
5143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 if (!getDerived().AlwaysRebuild() &&
5146 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005147 return SemaRef.Owned(E->Retain());
5148
Douglas Gregor9da64192010-04-26 22:37:10 +00005149 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5150 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 move(SubExpr),
5152 E->getLocEnd());
5153}
5154
5155template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005156Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005157TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005158 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005159}
Mike Stump11289f42009-09-09 15:08:12 +00005160
Douglas Gregora16548e2009-08-11 05:31:07 +00005161template<typename Derived>
5162Sema::OwningExprResult
5163TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005164 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005165 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005166}
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregora16548e2009-08-11 05:31:07 +00005168template<typename Derived>
5169Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005170TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005171 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregora16548e2009-08-11 05:31:07 +00005173 QualType T = getDerived().TransformType(E->getType());
5174 if (T.isNull())
5175 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 if (!getDerived().AlwaysRebuild() &&
5178 T == E->getType())
5179 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregorb15af892010-01-07 23:12:05 +00005181 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005182}
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>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5188 if (SubExpr.isInvalid())
5189 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregora16548e2009-08-11 05:31:07 +00005191 if (!getDerived().AlwaysRebuild() &&
5192 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005193 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005194
5195 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5196}
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregora16548e2009-08-11 05:31:07 +00005198template<typename Derived>
5199Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005200TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005201 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005202 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5203 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 if (!Param)
5205 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005206
Chandler Carruth794da4c2010-02-08 06:42:49 +00005207 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005208 Param == E->getParam())
5209 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005210
Douglas Gregor033f6752009-12-23 23:03:06 +00005211 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005212}
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora16548e2009-08-11 05:31:07 +00005214template<typename Derived>
5215Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005216TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005217 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5218
5219 QualType T = getDerived().TransformType(E->getType());
5220 if (T.isNull())
5221 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregora16548e2009-08-11 05:31:07 +00005223 if (!getDerived().AlwaysRebuild() &&
5224 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005225 return SemaRef.Owned(E->Retain());
5226
5227 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005228 /*FIXME:*/E->getTypeBeginLoc(),
5229 T,
5230 E->getRParenLoc());
5231}
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregora16548e2009-08-11 05:31:07 +00005233template<typename Derived>
5234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005235TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 // Transform the type that we're allocating
5237 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5238 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5239 if (AllocType.isNull())
5240 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 // Transform the size of the array we're allocating (if any).
5243 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5244 if (ArraySize.isInvalid())
5245 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 // Transform the placement arguments (if any).
5248 bool ArgumentChanged = false;
5249 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5250 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5251 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5252 if (Arg.isInvalid())
5253 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5256 PlacementArgs.push_back(Arg.take());
5257 }
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregorebe10102009-08-20 07:17:43 +00005259 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5261 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005262 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5263 break;
5264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5266 if (Arg.isInvalid())
5267 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregora16548e2009-08-11 05:31:07 +00005269 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5270 ConstructorArgs.push_back(Arg.take());
5271 }
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregord2d9da02010-02-26 00:38:10 +00005273 // Transform constructor, new operator, and delete operator.
5274 CXXConstructorDecl *Constructor = 0;
5275 if (E->getConstructor()) {
5276 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005277 getDerived().TransformDecl(E->getLocStart(),
5278 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005279 if (!Constructor)
5280 return SemaRef.ExprError();
5281 }
5282
5283 FunctionDecl *OperatorNew = 0;
5284 if (E->getOperatorNew()) {
5285 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005286 getDerived().TransformDecl(E->getLocStart(),
5287 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005288 if (!OperatorNew)
5289 return SemaRef.ExprError();
5290 }
5291
5292 FunctionDecl *OperatorDelete = 0;
5293 if (E->getOperatorDelete()) {
5294 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005295 getDerived().TransformDecl(E->getLocStart(),
5296 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005297 if (!OperatorDelete)
5298 return SemaRef.ExprError();
5299 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005300
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (!getDerived().AlwaysRebuild() &&
5302 AllocType == E->getAllocatedType() &&
5303 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005304 Constructor == E->getConstructor() &&
5305 OperatorNew == E->getOperatorNew() &&
5306 OperatorDelete == E->getOperatorDelete() &&
5307 !ArgumentChanged) {
5308 // Mark any declarations we need as referenced.
5309 // FIXME: instantiation-specific.
5310 if (Constructor)
5311 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5312 if (OperatorNew)
5313 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5314 if (OperatorDelete)
5315 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005316 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005317 }
Mike Stump11289f42009-09-09 15:08:12 +00005318
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005319 if (!ArraySize.get()) {
5320 // If no array size was specified, but the new expression was
5321 // instantiated with an array type (e.g., "new T" where T is
5322 // instantiated with "int[4]"), extract the outer bound from the
5323 // array type as our array size. We do this with constant and
5324 // dependently-sized array types.
5325 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5326 if (!ArrayT) {
5327 // Do nothing
5328 } else if (const ConstantArrayType *ConsArrayT
5329 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005330 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005331 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005332 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005333 SemaRef.Context.getSizeType(),
5334 /*FIXME:*/E->getLocStart()));
5335 AllocType = ConsArrayT->getElementType();
5336 } else if (const DependentSizedArrayType *DepArrayT
5337 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5338 if (DepArrayT->getSizeExpr()) {
5339 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5340 AllocType = DepArrayT->getElementType();
5341 }
5342 }
5343 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005344 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5345 E->isGlobalNew(),
5346 /*FIXME:*/E->getLocStart(),
5347 move_arg(PlacementArgs),
5348 /*FIXME:*/E->getLocStart(),
5349 E->isParenTypeId(),
5350 AllocType,
5351 /*FIXME:*/E->getLocStart(),
5352 /*FIXME:*/SourceRange(),
5353 move(ArraySize),
5354 /*FIXME:*/E->getLocStart(),
5355 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005356 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359template<typename Derived>
5360Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005361TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005362 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5363 if (Operand.isInvalid())
5364 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregord2d9da02010-02-26 00:38:10 +00005366 // Transform the delete operator, if known.
5367 FunctionDecl *OperatorDelete = 0;
5368 if (E->getOperatorDelete()) {
5369 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005370 getDerived().TransformDecl(E->getLocStart(),
5371 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005372 if (!OperatorDelete)
5373 return SemaRef.ExprError();
5374 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005375
Douglas Gregora16548e2009-08-11 05:31:07 +00005376 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005377 Operand.get() == E->getArgument() &&
5378 OperatorDelete == E->getOperatorDelete()) {
5379 // Mark any declarations we need as referenced.
5380 // FIXME: instantiation-specific.
5381 if (OperatorDelete)
5382 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005383 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005384 }
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregora16548e2009-08-11 05:31:07 +00005386 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5387 E->isGlobalDelete(),
5388 E->isArrayForm(),
5389 move(Operand));
5390}
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregora16548e2009-08-11 05:31:07 +00005392template<typename Derived>
5393Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005394TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005395 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005396 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5397 if (Base.isInvalid())
5398 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005399
Douglas Gregor678f90d2010-02-25 01:56:36 +00005400 Sema::TypeTy *ObjectTypePtr = 0;
5401 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005402 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005403 E->getOperatorLoc(),
5404 E->isArrow()? tok::arrow : tok::period,
5405 ObjectTypePtr,
5406 MayBePseudoDestructor);
5407 if (Base.isInvalid())
5408 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005409
Douglas Gregor678f90d2010-02-25 01:56:36 +00005410 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005411 NestedNameSpecifier *Qualifier
5412 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005413 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005414 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005415 if (E->getQualifier() && !Qualifier)
5416 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregor678f90d2010-02-25 01:56:36 +00005418 PseudoDestructorTypeStorage Destroyed;
5419 if (E->getDestroyedTypeInfo()) {
5420 TypeSourceInfo *DestroyedTypeInfo
5421 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5422 if (!DestroyedTypeInfo)
5423 return SemaRef.ExprError();
5424 Destroyed = DestroyedTypeInfo;
5425 } else if (ObjectType->isDependentType()) {
5426 // We aren't likely to be able to resolve the identifier down to a type
5427 // now anyway, so just retain the identifier.
5428 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5429 E->getDestroyedTypeLoc());
5430 } else {
5431 // Look for a destructor known with the given name.
5432 CXXScopeSpec SS;
5433 if (Qualifier) {
5434 SS.setScopeRep(Qualifier);
5435 SS.setRange(E->getQualifierRange());
5436 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005437
Douglas Gregor678f90d2010-02-25 01:56:36 +00005438 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5439 *E->getDestroyedTypeIdentifier(),
5440 E->getDestroyedTypeLoc(),
5441 /*Scope=*/0,
5442 SS, ObjectTypePtr,
5443 false);
5444 if (!T)
5445 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005446
Douglas Gregor678f90d2010-02-25 01:56:36 +00005447 Destroyed
5448 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5449 E->getDestroyedTypeLoc());
5450 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005451
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005452 TypeSourceInfo *ScopeTypeInfo = 0;
5453 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005454 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005455 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005456 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005457 return SemaRef.ExprError();
5458 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005459
Douglas Gregorad8a3362009-09-04 17:36:40 +00005460 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5461 E->getOperatorLoc(),
5462 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005463 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005464 E->getQualifierRange(),
5465 ScopeTypeInfo,
5466 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005467 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005468 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005469}
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregorad8a3362009-09-04 17:36:40 +00005471template<typename Derived>
5472Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005473TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005474 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005475 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5476
5477 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5478 Sema::LookupOrdinaryName);
5479
5480 // Transform all the decls.
5481 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5482 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005483 NamedDecl *InstD = static_cast<NamedDecl*>(
5484 getDerived().TransformDecl(Old->getNameLoc(),
5485 *I));
John McCall84d87672009-12-10 09:41:52 +00005486 if (!InstD) {
5487 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5488 // This can happen because of dependent hiding.
5489 if (isa<UsingShadowDecl>(*I))
5490 continue;
5491 else
5492 return SemaRef.ExprError();
5493 }
John McCalle66edc12009-11-24 19:00:30 +00005494
5495 // Expand using declarations.
5496 if (isa<UsingDecl>(InstD)) {
5497 UsingDecl *UD = cast<UsingDecl>(InstD);
5498 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5499 E = UD->shadow_end(); I != E; ++I)
5500 R.addDecl(*I);
5501 continue;
5502 }
5503
5504 R.addDecl(InstD);
5505 }
5506
5507 // Resolve a kind, but don't do any further analysis. If it's
5508 // ambiguous, the callee needs to deal with it.
5509 R.resolveKind();
5510
5511 // Rebuild the nested-name qualifier, if present.
5512 CXXScopeSpec SS;
5513 NestedNameSpecifier *Qualifier = 0;
5514 if (Old->getQualifier()) {
5515 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005516 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005517 if (!Qualifier)
5518 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005519
John McCalle66edc12009-11-24 19:00:30 +00005520 SS.setScopeRep(Qualifier);
5521 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005522 }
5523
Douglas Gregor9262f472010-04-27 18:19:34 +00005524 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005525 CXXRecordDecl *NamingClass
5526 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5527 Old->getNameLoc(),
5528 Old->getNamingClass()));
5529 if (!NamingClass)
5530 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005531
Douglas Gregorda7be082010-04-27 16:10:10 +00005532 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005533 }
5534
5535 // If we have no template arguments, it's a normal declaration name.
5536 if (!Old->hasExplicitTemplateArgs())
5537 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5538
5539 // If we have template arguments, rebuild them, then rebuild the
5540 // templateid expression.
5541 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5542 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5543 TemplateArgumentLoc Loc;
5544 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5545 return SemaRef.ExprError();
5546 TransArgs.addArgument(Loc);
5547 }
5548
5549 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5550 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005551}
Mike Stump11289f42009-09-09 15:08:12 +00005552
Douglas Gregora16548e2009-08-11 05:31:07 +00005553template<typename Derived>
5554Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005555TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 QualType T = getDerived().TransformType(E->getQueriedType());
5559 if (T.isNull())
5560 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 if (!getDerived().AlwaysRebuild() &&
5563 T == E->getQueriedType())
5564 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005565
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 // FIXME: Bad location information
5567 SourceLocation FakeLParenLoc
5568 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005569
5570 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 E->getLocStart(),
5572 /*FIXME:*/FakeLParenLoc,
5573 T,
5574 E->getLocEnd());
5575}
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregora16548e2009-08-11 05:31:07 +00005577template<typename Derived>
5578Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005579TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005580 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005582 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005583 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 if (!NNS)
5585 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005586
5587 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005588 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5589 if (!Name)
5590 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005591
John McCalle66edc12009-11-24 19:00:30 +00005592 if (!E->hasExplicitTemplateArgs()) {
5593 if (!getDerived().AlwaysRebuild() &&
5594 NNS == E->getQualifier() &&
5595 Name == E->getDeclName())
5596 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005597
John McCalle66edc12009-11-24 19:00:30 +00005598 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5599 E->getQualifierRange(),
5600 Name, E->getLocation(),
5601 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005602 }
John McCall6b51f282009-11-23 01:53:49 +00005603
5604 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005606 TemplateArgumentLoc Loc;
5607 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005609 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005610 }
5611
John McCalle66edc12009-11-24 19:00:30 +00005612 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5613 E->getQualifierRange(),
5614 Name, E->getLocation(),
5615 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005616}
5617
5618template<typename Derived>
5619Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005621 // CXXConstructExprs are always implicit, so when we have a
5622 // 1-argument construction we just transform that argument.
5623 if (E->getNumArgs() == 1 ||
5624 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5625 return getDerived().TransformExpr(E->getArg(0));
5626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5628
5629 QualType T = getDerived().TransformType(E->getType());
5630 if (T.isNull())
5631 return SemaRef.ExprError();
5632
5633 CXXConstructorDecl *Constructor
5634 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005635 getDerived().TransformDecl(E->getLocStart(),
5636 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 if (!Constructor)
5638 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 bool ArgumentChanged = false;
5641 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005642 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 ArgEnd = E->arg_end();
5644 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005645 if (getDerived().DropCallArgument(*Arg)) {
5646 ArgumentChanged = true;
5647 break;
5648 }
5649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5651 if (TransArg.isInvalid())
5652 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005653
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5655 Args.push_back(TransArg.takeAs<Expr>());
5656 }
5657
5658 if (!getDerived().AlwaysRebuild() &&
5659 T == E->getType() &&
5660 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005661 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005662 // Mark the constructor as referenced.
5663 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005664 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005666 }
Mike Stump11289f42009-09-09 15:08:12 +00005667
Douglas Gregordb121ba2009-12-14 16:27:04 +00005668 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5669 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 move_arg(Args));
5671}
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregora16548e2009-08-11 05:31:07 +00005673/// \brief Transform a C++ temporary-binding expression.
5674///
Douglas Gregor363b1512009-12-24 18:51:59 +00005675/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5676/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005677template<typename Derived>
5678Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005679TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005680 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005681}
Mike Stump11289f42009-09-09 15:08:12 +00005682
Anders Carlssonba6c4372010-01-29 02:39:32 +00005683/// \brief Transform a C++ reference-binding expression.
5684///
5685/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5686/// transform the subexpression and return that.
5687template<typename Derived>
5688Sema::OwningExprResult
5689TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5690 return getDerived().TransformExpr(E->getSubExpr());
5691}
5692
Mike Stump11289f42009-09-09 15:08:12 +00005693/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005694/// be destroyed after the expression is evaluated.
5695///
Douglas Gregor363b1512009-12-24 18:51:59 +00005696/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5697/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005698template<typename Derived>
5699Sema::OwningExprResult
5700TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005701 CXXExprWithTemporaries *E) {
5702 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005703}
Mike Stump11289f42009-09-09 15:08:12 +00005704
Douglas Gregora16548e2009-08-11 05:31:07 +00005705template<typename Derived>
5706Sema::OwningExprResult
5707TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005708 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5710 QualType T = getDerived().TransformType(E->getType());
5711 if (T.isNull())
5712 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 CXXConstructorDecl *Constructor
5715 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005716 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005717 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005718 if (!Constructor)
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 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005724 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 ArgEnd = E->arg_end();
5726 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005727 if (getDerived().DropCallArgument(*Arg)) {
5728 ArgumentChanged = true;
5729 break;
5730 }
5731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5733 if (TransArg.isInvalid())
5734 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5737 Args.push_back((Expr *)TransArg.release());
5738 }
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 if (!getDerived().AlwaysRebuild() &&
5741 T == E->getType() &&
5742 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005743 !ArgumentChanged) {
5744 // FIXME: Instantiation-specific
5745 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005746 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005747 }
Mike Stump11289f42009-09-09 15:08:12 +00005748
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 // FIXME: Bogus location information
5750 SourceLocation CommaLoc;
5751 if (Args.size() > 1) {
5752 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005753 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5755 }
5756 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5757 T,
5758 /*FIXME:*/E->getTypeBeginLoc(),
5759 move_arg(Args),
5760 &CommaLoc,
5761 E->getLocEnd());
5762}
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764template<typename Derived>
5765Sema::OwningExprResult
5766TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005767 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5769 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5770 if (T.isNull())
5771 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 bool ArgumentChanged = false;
5774 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5775 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5776 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5777 ArgEnd = E->arg_end();
5778 Arg != ArgEnd; ++Arg) {
5779 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5780 if (TransArg.isInvalid())
5781 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5784 FakeCommaLocs.push_back(
5785 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5786 Args.push_back(TransArg.takeAs<Expr>());
5787 }
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (!getDerived().AlwaysRebuild() &&
5790 T == E->getTypeAsWritten() &&
5791 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005792 return SemaRef.Owned(E->Retain());
5793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 // FIXME: we're faking the locations of the commas
5795 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5796 T,
5797 E->getLParenLoc(),
5798 move_arg(Args),
5799 FakeCommaLocs.data(),
5800 E->getRParenLoc());
5801}
Mike Stump11289f42009-09-09 15:08:12 +00005802
Douglas Gregora16548e2009-08-11 05:31:07 +00005803template<typename Derived>
5804Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005805TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005806 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005808 OwningExprResult Base(SemaRef, (Expr*) 0);
5809 Expr *OldBase;
5810 QualType BaseType;
5811 QualType ObjectType;
5812 if (!E->isImplicitAccess()) {
5813 OldBase = E->getBase();
5814 Base = getDerived().TransformExpr(OldBase);
5815 if (Base.isInvalid())
5816 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005817
John McCall2d74de92009-12-01 22:10:20 +00005818 // Start the member reference and compute the object's type.
5819 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005820 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005821 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5822 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005823 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005824 ObjectTy,
5825 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005826 if (Base.isInvalid())
5827 return SemaRef.ExprError();
5828
5829 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5830 BaseType = ((Expr*) Base.get())->getType();
5831 } else {
5832 OldBase = 0;
5833 BaseType = getDerived().TransformType(E->getBaseType());
5834 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5835 }
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005837 // Transform the first part of the nested-name-specifier that qualifies
5838 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005839 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005840 = getDerived().TransformFirstQualifierInScope(
5841 E->getFirstQualifierFoundInScope(),
5842 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005844 NestedNameSpecifier *Qualifier = 0;
5845 if (E->getQualifier()) {
5846 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5847 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005848 ObjectType,
5849 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005850 if (!Qualifier)
5851 return SemaRef.ExprError();
5852 }
Mike Stump11289f42009-09-09 15:08:12 +00005853
5854 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005855 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005856 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005857 if (!Name)
5858 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005859
John McCall2d74de92009-12-01 22:10:20 +00005860 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005861 // This is a reference to a member without an explicitly-specified
5862 // template argument list. Optimize for this common case.
5863 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005864 Base.get() == OldBase &&
5865 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005866 Qualifier == E->getQualifier() &&
5867 Name == E->getMember() &&
5868 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005869 return SemaRef.Owned(E->Retain());
5870
John McCall8cd78132009-11-19 22:55:06 +00005871 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005872 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005873 E->isArrow(),
5874 E->getOperatorLoc(),
5875 Qualifier,
5876 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005877 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005878 Name,
5879 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005880 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005881 }
5882
John McCall6b51f282009-11-23 01:53:49 +00005883 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005884 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005885 TemplateArgumentLoc Loc;
5886 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005887 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005888 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005889 }
Mike Stump11289f42009-09-09 15:08:12 +00005890
John McCall8cd78132009-11-19 22:55:06 +00005891 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005892 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 E->isArrow(),
5894 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005895 Qualifier,
5896 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005897 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005898 Name,
5899 E->getMemberLoc(),
5900 &TransArgs);
5901}
5902
5903template<typename Derived>
5904Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005905TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005906 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005907 OwningExprResult Base(SemaRef, (Expr*) 0);
5908 QualType BaseType;
5909 if (!Old->isImplicitAccess()) {
5910 Base = getDerived().TransformExpr(Old->getBase());
5911 if (Base.isInvalid())
5912 return SemaRef.ExprError();
5913 BaseType = ((Expr*) Base.get())->getType();
5914 } else {
5915 BaseType = getDerived().TransformType(Old->getBaseType());
5916 }
John McCall10eae182009-11-30 22:42:35 +00005917
5918 NestedNameSpecifier *Qualifier = 0;
5919 if (Old->getQualifier()) {
5920 Qualifier
5921 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005922 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005923 if (Qualifier == 0)
5924 return SemaRef.ExprError();
5925 }
5926
5927 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5928 Sema::LookupOrdinaryName);
5929
5930 // Transform all the decls.
5931 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5932 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005933 NamedDecl *InstD = static_cast<NamedDecl*>(
5934 getDerived().TransformDecl(Old->getMemberLoc(),
5935 *I));
John McCall84d87672009-12-10 09:41:52 +00005936 if (!InstD) {
5937 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5938 // This can happen because of dependent hiding.
5939 if (isa<UsingShadowDecl>(*I))
5940 continue;
5941 else
5942 return SemaRef.ExprError();
5943 }
John McCall10eae182009-11-30 22:42:35 +00005944
5945 // Expand using declarations.
5946 if (isa<UsingDecl>(InstD)) {
5947 UsingDecl *UD = cast<UsingDecl>(InstD);
5948 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5949 E = UD->shadow_end(); I != E; ++I)
5950 R.addDecl(*I);
5951 continue;
5952 }
5953
5954 R.addDecl(InstD);
5955 }
5956
5957 R.resolveKind();
5958
Douglas Gregor9262f472010-04-27 18:19:34 +00005959 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005960 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005961 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005962 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005963 Old->getMemberLoc(),
5964 Old->getNamingClass()));
5965 if (!NamingClass)
5966 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005967
Douglas Gregorda7be082010-04-27 16:10:10 +00005968 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005969 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005970
John McCall10eae182009-11-30 22:42:35 +00005971 TemplateArgumentListInfo TransArgs;
5972 if (Old->hasExplicitTemplateArgs()) {
5973 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5974 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5975 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5976 TemplateArgumentLoc Loc;
5977 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5978 Loc))
5979 return SemaRef.ExprError();
5980 TransArgs.addArgument(Loc);
5981 }
5982 }
John McCall38836f02010-01-15 08:34:02 +00005983
5984 // FIXME: to do this check properly, we will need to preserve the
5985 // first-qualifier-in-scope here, just in case we had a dependent
5986 // base (and therefore couldn't do the check) and a
5987 // nested-name-qualifier (and therefore could do the lookup).
5988 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005989
John McCall10eae182009-11-30 22:42:35 +00005990 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005991 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005992 Old->getOperatorLoc(),
5993 Old->isArrow(),
5994 Qualifier,
5995 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005996 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005997 R,
5998 (Old->hasExplicitTemplateArgs()
5999 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006000}
6001
6002template<typename Derived>
6003Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006004TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006005 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006006}
6007
Mike Stump11289f42009-09-09 15:08:12 +00006008template<typename Derived>
6009Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006011 TypeSourceInfo *EncodedTypeInfo
6012 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6013 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006015
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006017 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006018 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006019
6020 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006021 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006022 E->getRParenLoc());
6023}
Mike Stump11289f42009-09-09 15:08:12 +00006024
Douglas Gregora16548e2009-08-11 05:31:07 +00006025template<typename Derived>
6026Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006027TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006028 // Transform arguments.
6029 bool ArgChanged = false;
6030 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6031 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6032 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6033 if (Arg.isInvalid())
6034 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006035
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006036 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6037 Args.push_back(Arg.takeAs<Expr>());
6038 }
6039
6040 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6041 // Class message: transform the receiver type.
6042 TypeSourceInfo *ReceiverTypeInfo
6043 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6044 if (!ReceiverTypeInfo)
6045 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006046
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006047 // If nothing changed, just retain the existing message send.
6048 if (!getDerived().AlwaysRebuild() &&
6049 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6050 return SemaRef.Owned(E->Retain());
6051
6052 // Build a new class message send.
6053 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6054 E->getSelector(),
6055 E->getMethodDecl(),
6056 E->getLeftLoc(),
6057 move_arg(Args),
6058 E->getRightLoc());
6059 }
6060
6061 // Instance message: transform the receiver
6062 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6063 "Only class and instance messages may be instantiated");
6064 OwningExprResult Receiver
6065 = getDerived().TransformExpr(E->getInstanceReceiver());
6066 if (Receiver.isInvalid())
6067 return SemaRef.ExprError();
6068
6069 // If nothing changed, just retain the existing message send.
6070 if (!getDerived().AlwaysRebuild() &&
6071 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6072 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006073
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006074 // Build a new instance message send.
6075 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6076 E->getSelector(),
6077 E->getMethodDecl(),
6078 E->getLeftLoc(),
6079 move_arg(Args),
6080 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006081}
6082
Mike Stump11289f42009-09-09 15:08:12 +00006083template<typename Derived>
6084Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006085TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006086 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006087}
6088
Mike Stump11289f42009-09-09 15:08:12 +00006089template<typename Derived>
6090Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006092 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006093}
6094
Mike Stump11289f42009-09-09 15:08:12 +00006095template<typename Derived>
6096Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006098 // Transform the base expression.
6099 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6100 if (Base.isInvalid())
6101 return SemaRef.ExprError();
6102
6103 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006104
Douglas Gregord51d90d2010-04-26 20:11:03 +00006105 // If nothing changed, just retain the existing expression.
6106 if (!getDerived().AlwaysRebuild() &&
6107 Base.get() == E->getBase())
6108 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006109
Douglas Gregord51d90d2010-04-26 20:11:03 +00006110 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6111 E->getLocation(),
6112 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006113}
6114
Mike Stump11289f42009-09-09 15:08:12 +00006115template<typename Derived>
6116Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006118 // Transform the base expression.
6119 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6120 if (Base.isInvalid())
6121 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006122
Douglas Gregor9faee212010-04-26 20:47:02 +00006123 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006124
Douglas Gregor9faee212010-04-26 20:47:02 +00006125 // If nothing changed, just retain the existing expression.
6126 if (!getDerived().AlwaysRebuild() &&
6127 Base.get() == E->getBase())
6128 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006129
Douglas Gregor9faee212010-04-26 20:47:02 +00006130 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6131 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006132}
6133
Mike Stump11289f42009-09-09 15:08:12 +00006134template<typename Derived>
6135Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006136TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006137 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006138 // If this implicit setter/getter refers to class methods, it cannot have any
6139 // dependent parts. Just retain the existing declaration.
6140 if (E->getInterfaceDecl())
6141 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006142
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006143 // Transform the base expression.
6144 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6145 if (Base.isInvalid())
6146 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006147
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006148 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006149
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006150 // If nothing changed, just retain the existing expression.
6151 if (!getDerived().AlwaysRebuild() &&
6152 Base.get() == E->getBase())
6153 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006154
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006155 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6156 E->getGetterMethod(),
6157 E->getType(),
6158 E->getSetterMethod(),
6159 E->getLocation(),
6160 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006161
Douglas Gregora16548e2009-08-11 05:31:07 +00006162}
6163
Mike Stump11289f42009-09-09 15:08:12 +00006164template<typename Derived>
6165Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006166TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006167 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006168 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006169}
6170
Mike Stump11289f42009-09-09 15:08:12 +00006171template<typename Derived>
6172Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006173TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006174 // Transform the base expression.
6175 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6176 if (Base.isInvalid())
6177 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006178
Douglas Gregord51d90d2010-04-26 20:11:03 +00006179 // If nothing changed, just retain the existing expression.
6180 if (!getDerived().AlwaysRebuild() &&
6181 Base.get() == E->getBase())
6182 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006183
Douglas Gregord51d90d2010-04-26 20:11:03 +00006184 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6185 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006186}
6187
Mike Stump11289f42009-09-09 15:08:12 +00006188template<typename Derived>
6189Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006191 bool ArgumentChanged = false;
6192 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6193 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6194 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6195 if (SubExpr.isInvalid())
6196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6199 SubExprs.push_back(SubExpr.takeAs<Expr>());
6200 }
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregora16548e2009-08-11 05:31:07 +00006202 if (!getDerived().AlwaysRebuild() &&
6203 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006204 return SemaRef.Owned(E->Retain());
6205
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6207 move_arg(SubExprs),
6208 E->getRParenLoc());
6209}
6210
Mike Stump11289f42009-09-09 15:08:12 +00006211template<typename Derived>
6212Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006213TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006214 // FIXME: Implement this!
6215 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006216 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006217}
6218
Mike Stump11289f42009-09-09 15:08:12 +00006219template<typename Derived>
6220Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006221TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 // FIXME: Implement this!
6223 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006224 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006225}
Mike Stump11289f42009-09-09 15:08:12 +00006226
Douglas Gregora16548e2009-08-11 05:31:07 +00006227//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006228// Type reconstruction
6229//===----------------------------------------------------------------------===//
6230
Mike Stump11289f42009-09-09 15:08:12 +00006231template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006232QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6233 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006234 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006235 getDerived().getBaseEntity());
6236}
6237
Mike Stump11289f42009-09-09 15:08:12 +00006238template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006239QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6240 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006241 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006242 getDerived().getBaseEntity());
6243}
6244
Mike Stump11289f42009-09-09 15:08:12 +00006245template<typename Derived>
6246QualType
John McCall70dd5f62009-10-30 00:06:24 +00006247TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6248 bool WrittenAsLValue,
6249 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006250 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006251 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006252}
6253
6254template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006255QualType
John McCall70dd5f62009-10-30 00:06:24 +00006256TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6257 QualType ClassType,
6258 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006259 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006260 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006261}
6262
6263template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006264QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006265TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6266 ArrayType::ArraySizeModifier SizeMod,
6267 const llvm::APInt *Size,
6268 Expr *SizeExpr,
6269 unsigned IndexTypeQuals,
6270 SourceRange BracketsRange) {
6271 if (SizeExpr || !Size)
6272 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6273 IndexTypeQuals, BracketsRange,
6274 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006275
6276 QualType Types[] = {
6277 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6278 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6279 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006280 };
6281 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6282 QualType SizeType;
6283 for (unsigned I = 0; I != NumTypes; ++I)
6284 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6285 SizeType = Types[I];
6286 break;
6287 }
Mike Stump11289f42009-09-09 15:08:12 +00006288
Douglas Gregord6ff3322009-08-04 16:50:30 +00006289 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006290 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006291 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006292 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006293}
Mike Stump11289f42009-09-09 15:08:12 +00006294
Douglas Gregord6ff3322009-08-04 16:50:30 +00006295template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006296QualType
6297TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006298 ArrayType::ArraySizeModifier SizeMod,
6299 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006300 unsigned IndexTypeQuals,
6301 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006302 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006303 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006304}
6305
6306template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006307QualType
Mike Stump11289f42009-09-09 15:08:12 +00006308TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006309 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006310 unsigned IndexTypeQuals,
6311 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006312 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006313 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006314}
Mike Stump11289f42009-09-09 15:08:12 +00006315
Douglas Gregord6ff3322009-08-04 16:50:30 +00006316template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006317QualType
6318TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006319 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006321 unsigned IndexTypeQuals,
6322 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006323 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006324 SizeExpr.takeAs<Expr>(),
6325 IndexTypeQuals, BracketsRange);
6326}
6327
6328template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006329QualType
6330TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006331 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006333 unsigned IndexTypeQuals,
6334 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006335 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006336 SizeExpr.takeAs<Expr>(),
6337 IndexTypeQuals, BracketsRange);
6338}
6339
6340template<typename Derived>
6341QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006342 unsigned NumElements,
6343 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006344 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006345 return SemaRef.Context.getVectorType(ElementType, NumElements,
6346 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347}
Mike Stump11289f42009-09-09 15:08:12 +00006348
Douglas Gregord6ff3322009-08-04 16:50:30 +00006349template<typename Derived>
6350QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6351 unsigned NumElements,
6352 SourceLocation AttributeLoc) {
6353 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6354 NumElements, true);
6355 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006356 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006357 AttributeLoc);
6358 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6359 AttributeLoc);
6360}
Mike Stump11289f42009-09-09 15:08:12 +00006361
Douglas Gregord6ff3322009-08-04 16:50:30 +00006362template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006363QualType
6364TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006365 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006366 SourceLocation AttributeLoc) {
6367 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6368}
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370template<typename Derived>
6371QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006372 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006373 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006374 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006376 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377 Quals,
6378 getDerived().getBaseLocation(),
6379 getDerived().getBaseEntity());
6380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregord6ff3322009-08-04 16:50:30 +00006382template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006383QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6384 return SemaRef.Context.getFunctionNoProtoType(T);
6385}
6386
6387template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006388QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6389 assert(D && "no decl found");
6390 if (D->isInvalidDecl()) return QualType();
6391
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006392 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006393 TypeDecl *Ty;
6394 if (isa<UsingDecl>(D)) {
6395 UsingDecl *Using = cast<UsingDecl>(D);
6396 assert(Using->isTypeName() &&
6397 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6398
6399 // A valid resolved using typename decl points to exactly one type decl.
6400 assert(++Using->shadow_begin() == Using->shadow_end());
6401 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006402
John McCallb96ec562009-12-04 22:46:56 +00006403 } else {
6404 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6405 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6406 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6407 }
6408
6409 return SemaRef.Context.getTypeDeclType(Ty);
6410}
6411
6412template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006413QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6415}
6416
6417template<typename Derived>
6418QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6419 return SemaRef.Context.getTypeOfType(Underlying);
6420}
6421
6422template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006423QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6425}
6426
6427template<typename Derived>
6428QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006429 TemplateName Template,
6430 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006431 const TemplateArgumentListInfo &TemplateArgs) {
6432 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006433}
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregor1135c352009-08-06 05:28:30 +00006435template<typename Derived>
6436NestedNameSpecifier *
6437TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6438 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006439 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006440 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006441 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006442 CXXScopeSpec SS;
6443 // FIXME: The source location information is all wrong.
6444 SS.setRange(Range);
6445 SS.setScopeRep(Prefix);
6446 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006447 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006448 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006449 ObjectType,
6450 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006451 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006452}
6453
6454template<typename Derived>
6455NestedNameSpecifier *
6456TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6457 SourceRange Range,
6458 NamespaceDecl *NS) {
6459 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6460}
6461
6462template<typename Derived>
6463NestedNameSpecifier *
6464TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6465 SourceRange Range,
6466 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006467 QualType T) {
6468 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006469 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006470 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006471 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6472 T.getTypePtr());
6473 }
Mike Stump11289f42009-09-09 15:08:12 +00006474
Douglas Gregor1135c352009-08-06 05:28:30 +00006475 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6476 return 0;
6477}
Mike Stump11289f42009-09-09 15:08:12 +00006478
Douglas Gregor71dc5092009-08-06 06:41:21 +00006479template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006480TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006481TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6482 bool TemplateKW,
6483 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006484 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006485 Template);
6486}
6487
6488template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006489TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006490TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006491 const IdentifierInfo &II,
6492 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006493 CXXScopeSpec SS;
6494 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006495 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006496 UnqualifiedId Name;
6497 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006498 Sema::TemplateTy Template;
6499 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6500 /*FIXME:*/getDerived().getBaseLocation(),
6501 SS,
6502 Name,
6503 ObjectType.getAsOpaquePtr(),
6504 /*EnteringContext=*/false,
6505 Template);
6506 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006507}
Mike Stump11289f42009-09-09 15:08:12 +00006508
Douglas Gregora16548e2009-08-11 05:31:07 +00006509template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006510TemplateName
6511TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6512 OverloadedOperatorKind Operator,
6513 QualType ObjectType) {
6514 CXXScopeSpec SS;
6515 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6516 SS.setScopeRep(Qualifier);
6517 UnqualifiedId Name;
6518 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6519 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6520 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006521 Sema::TemplateTy Template;
6522 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006523 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006524 SS,
6525 Name,
6526 ObjectType.getAsOpaquePtr(),
6527 /*EnteringContext=*/false,
6528 Template);
6529 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006530}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006531
Douglas Gregor71395fa2009-11-04 00:56:37 +00006532template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006533Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006534TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6535 SourceLocation OpLoc,
6536 ExprArg Callee,
6537 ExprArg First,
6538 ExprArg Second) {
6539 Expr *FirstExpr = (Expr *)First.get();
6540 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006541 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006542 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006545 if (Op == OO_Subscript) {
6546 if (!FirstExpr->getType()->isOverloadableType() &&
6547 !SecondExpr->getType()->isOverloadableType())
6548 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006549 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006550 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006551 } else if (Op == OO_Arrow) {
6552 // -> is never a builtin operation.
6553 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006554 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006555 if (!FirstExpr->getType()->isOverloadableType()) {
6556 // The argument is not of overloadable type, so try to create a
6557 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006558 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006559 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006560
Douglas Gregora16548e2009-08-11 05:31:07 +00006561 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6562 }
6563 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006564 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006565 !SecondExpr->getType()->isOverloadableType()) {
6566 // Neither of the arguments is an overloadable type, so try to
6567 // create a built-in binary operation.
6568 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006569 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006570 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6571 if (Result.isInvalid())
6572 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006573
Douglas Gregora16548e2009-08-11 05:31:07 +00006574 First.release();
6575 Second.release();
6576 return move(Result);
6577 }
6578 }
Mike Stump11289f42009-09-09 15:08:12 +00006579
6580 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006581 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006582 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006583
John McCalld14a8642009-11-21 08:51:07 +00006584 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6585 assert(ULE->requiresADL());
6586
6587 // FIXME: Do we have to check
6588 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006589 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006590 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006591 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006592 }
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregora16548e2009-08-11 05:31:07 +00006594 // Add any functions found via argument-dependent lookup.
6595 Expr *Args[2] = { FirstExpr, SecondExpr };
6596 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006597
Douglas Gregora16548e2009-08-11 05:31:07 +00006598 // Create the overloaded operator invocation for unary operators.
6599 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006600 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006601 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6602 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6603 }
Mike Stump11289f42009-09-09 15:08:12 +00006604
Sebastian Redladba46e2009-10-29 20:17:01 +00006605 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006606 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6607 OpLoc,
6608 move(First),
6609 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006610
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006612 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006613 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006614 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6616 if (Result.isInvalid())
6617 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006618
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 First.release();
6620 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006621 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006622}
Mike Stump11289f42009-09-09 15:08:12 +00006623
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006624template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006625Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006626TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6627 SourceLocation OperatorLoc,
6628 bool isArrow,
6629 NestedNameSpecifier *Qualifier,
6630 SourceRange QualifierRange,
6631 TypeSourceInfo *ScopeType,
6632 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006633 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006634 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006635 CXXScopeSpec SS;
6636 if (Qualifier) {
6637 SS.setRange(QualifierRange);
6638 SS.setScopeRep(Qualifier);
6639 }
6640
6641 Expr *BaseE = (Expr *)Base.get();
6642 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006643 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006644 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006645 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006646 !BaseType->getAs<PointerType>()->getPointeeType()
6647 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006648 // This pseudo-destructor expression is still a pseudo-destructor.
6649 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6650 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006651 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006652 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006653 /*FIXME?*/true);
6654 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006655
Douglas Gregor678f90d2010-02-25 01:56:36 +00006656 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006657 DeclarationName Name
6658 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6659 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006660
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006661 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006662
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006663 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6664 OperatorLoc, isArrow,
6665 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006666 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006667 /*TemplateArgs*/ 0);
6668}
6669
Douglas Gregord6ff3322009-08-04 16:50:30 +00006670} // end namespace clang
6671
6672#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H