blob: 656c03d890b7341e1554b41e88e21d6860f355b4 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000016#include "clang/Sema/Sema.h"
17#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000027#include "clang/Sema/Ownership.h"
28#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000029#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Alexis Hunta8136cc2010-05-05 15:23:54 +000098
Douglas Gregord6ff3322009-08-04 16:50:30 +000099 /// \brief Initializes a new tree transformer.
100 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000101
Douglas Gregord6ff3322009-08-04 16:50:30 +0000102 /// \brief Retrieves a reference to the derived class.
103 Derived &getDerived() { return static_cast<Derived&>(*this); }
104
105 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000106 const Derived &getDerived() const {
107 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000108 }
109
110 /// \brief Retrieves a reference to the semantic analysis object used for
111 /// this tree transform.
112 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Whether the transformation should always rebuild AST nodes, even
115 /// if none of the children have changed.
116 ///
117 /// Subclasses may override this function to specify when the transformation
118 /// should rebuild all AST nodes.
119 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000120
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Returns the location of the entity being transformed, if that
122 /// information was not available elsewhere in the AST.
123 ///
Mike Stump11289f42009-09-09 15:08:12 +0000124 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// provide an alternative implementation that provides better location
126 /// information.
127 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Returns the name of the entity being transformed, if that
130 /// information was not available elsewhere in the AST.
131 ///
132 /// By default, returns an empty name. Subclasses can provide an alternative
133 /// implementation with a more precise name.
134 DeclarationName getBaseEntity() { return DeclarationName(); }
135
Douglas Gregora16548e2009-08-11 05:31:07 +0000136 /// \brief Sets the "base" location and entity when that
137 /// information is known based on another transformation.
138 ///
139 /// By default, the source location and entity are ignored. Subclasses can
140 /// override this function to provide a customized implementation.
141 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000142
Douglas Gregora16548e2009-08-11 05:31:07 +0000143 /// \brief RAII object that temporarily sets the base location and entity
144 /// used for reporting diagnostics in types.
145 class TemporaryBase {
146 TreeTransform &Self;
147 SourceLocation OldLocation;
148 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregora16548e2009-08-11 05:31:07 +0000150 public:
151 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000152 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 OldLocation = Self.getDerived().getBaseLocation();
154 OldEntity = Self.getDerived().getBaseEntity();
155 Self.getDerived().setBase(Location, Entity);
156 }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregora16548e2009-08-11 05:31:07 +0000158 ~TemporaryBase() {
159 Self.getDerived().setBase(OldLocation, OldEntity);
160 }
161 };
Mike Stump11289f42009-09-09 15:08:12 +0000162
163 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000164 /// transformed.
165 ///
166 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000167 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000168 /// not change. For example, template instantiation need not traverse
169 /// non-dependent types.
170 bool AlreadyTransformed(QualType T) {
171 return T.isNull();
172 }
173
Douglas Gregord196a582009-12-14 19:27:10 +0000174 /// \brief Determine whether the given call argument should be dropped, e.g.,
175 /// because it is a default argument.
176 ///
177 /// Subclasses can provide an alternative implementation of this routine to
178 /// determine which kinds of call arguments get dropped. By default,
179 /// CXXDefaultArgument nodes are dropped (prior to transformation).
180 bool DropCallArgument(Expr *E) {
181 return E->isDefaultArgument();
182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000183
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// \brief Transforms the given type into another type.
185 ///
John McCall550e0c22009-10-21 00:40:46 +0000186 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000187 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000188 /// function. This is expensive, but we don't mind, because
189 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000190 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000191 ///
192 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000193 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000194
John McCall550e0c22009-10-21 00:40:46 +0000195 /// \brief Transforms the given type-with-location into a new
196 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000197 ///
John McCall550e0c22009-10-21 00:40:46 +0000198 /// By default, this routine transforms a type by delegating to the
199 /// appropriate TransformXXXType to build a new type. Subclasses
200 /// may override this function (to take over all type
201 /// transformations) or some set of the TransformXXXType functions
202 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000212
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000213 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000214 ///
Mike Stump11289f42009-09-09 15:08:12 +0000215 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000216 /// appropriate TransformXXXStmt function to transform a specific kind of
217 /// statement or the TransformExpr() function to transform an expression.
218 /// Subclasses may override this function to transform statements using some
219 /// other mechanism.
220 ///
221 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000222 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000223
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000224 /// \brief Transform the given expression.
225 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000226 /// By default, this routine transforms an expression by delegating to the
227 /// appropriate TransformXXXExpr function to build a new expression.
228 /// Subclasses may override this function to transform expressions using some
229 /// other mechanism.
230 ///
231 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000232 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000233
Douglas Gregord6ff3322009-08-04 16:50:30 +0000234 /// \brief Transform the given declaration, which is referenced from a type
235 /// or expression.
236 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000237 /// By default, acts as the identity function on declarations. Subclasses
238 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000239 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000240
241 /// \brief Transform the definition of the given declaration.
242 ///
Mike Stump11289f42009-09-09 15:08:12 +0000243 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000244 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000245 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
246 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000247 }
Mike Stump11289f42009-09-09 15:08:12 +0000248
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000249 /// \brief Transform the given declaration, which was the first part of a
250 /// nested-name-specifier in a member access expression.
251 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000252 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000253 /// identifier in a nested-name-specifier of a member access expression, e.g.,
254 /// the \c T in \c x->T::member
255 ///
256 /// By default, invokes TransformDecl() to transform the declaration.
257 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000258 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
259 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000260 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000261
Douglas Gregord6ff3322009-08-04 16:50:30 +0000262 /// \brief Transform the given nested-name-specifier.
263 ///
Mike Stump11289f42009-09-09 15:08:12 +0000264 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000265 /// nested-name-specifier. Subclasses may override this function to provide
266 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000267 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000268 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000269 QualType ObjectType = QualType(),
270 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000271
Douglas Gregorf816bd72009-09-03 22:13:48 +0000272 /// \brief Transform the given declaration name.
273 ///
274 /// By default, transforms the types of conversion function, constructor,
275 /// and destructor names and then (if needed) rebuilds the declaration name.
276 /// Identifiers and selectors are returned unmodified. Sublcasses may
277 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000278 DeclarationNameInfo
279 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
280 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000283 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000284 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000285 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000286 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000287 TemplateName TransformTemplateName(TemplateName Name,
288 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000289
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 /// \brief Transform the given template argument.
291 ///
Mike Stump11289f42009-09-09 15:08:12 +0000292 /// By default, this operation transforms the type, expression, or
293 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000294 /// new template argument from the transformed result. Subclasses may
295 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000296 ///
297 /// Returns true if there was an error.
298 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
299 TemplateArgumentLoc &Output);
300
301 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
302 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
303 TemplateArgumentLoc &ArgLoc);
304
John McCallbcd03502009-12-07 02:54:59 +0000305 /// \brief Fakes up a TypeSourceInfo for a type.
306 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
307 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000308 getDerived().getBaseLocation());
309 }
Mike Stump11289f42009-09-09 15:08:12 +0000310
John McCall550e0c22009-10-21 00:40:46 +0000311#define ABSTRACT_TYPELOC(CLASS, PARENT)
312#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000313 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
314 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000315#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000316
John McCall58f10c32010-03-11 09:03:00 +0000317 /// \brief Transforms the parameters of a function type into the
318 /// given vectors.
319 ///
320 /// The result vectors should be kept in sync; null entries in the
321 /// variables vector are acceptable.
322 ///
323 /// Return true on error.
324 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
325 llvm::SmallVectorImpl<QualType> &PTypes,
326 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
327
328 /// \brief Transforms a single function-type parameter. Return null
329 /// on error.
330 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
331
Alexis Hunta8136cc2010-05-05 15:23:54 +0000332 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000334
Alexis Hunta8136cc2010-05-05 15:23:54 +0000335 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
337 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000338
Douglas Gregorebe10102009-08-20 07:17:43 +0000339 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000340 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000341
Douglas Gregorebe10102009-08-20 07:17:43 +0000342#define STMT(Node, Parent) \
343 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000344#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000345 OwningExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000346#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000347#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000348
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 /// \brief Build a new pointer type given its pointee type.
350 ///
351 /// By default, performs semantic analysis when building the pointer type.
352 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000353 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000354
355 /// \brief Build a new block pointer type given its pointee type.
356 ///
Mike Stump11289f42009-09-09 15:08:12 +0000357 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000358 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000359 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000360
John McCall70dd5f62009-10-30 00:06:24 +0000361 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000362 ///
John McCall70dd5f62009-10-30 00:06:24 +0000363 /// By default, performs semantic analysis when building the
364 /// reference type. Subclasses may override this routine to provide
365 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000366 ///
John McCall70dd5f62009-10-30 00:06:24 +0000367 /// \param LValue whether the type was written with an lvalue sigil
368 /// or an rvalue sigil.
369 QualType RebuildReferenceType(QualType ReferentType,
370 bool LValue,
371 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Douglas Gregord6ff3322009-08-04 16:50:30 +0000373 /// \brief Build a new member pointer type given the pointee type and the
374 /// class type it refers into.
375 ///
376 /// By default, performs semantic analysis when building the member pointer
377 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000378 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
379 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000380
Douglas Gregord6ff3322009-08-04 16:50:30 +0000381 /// \brief Build a new array type given the element type, size
382 /// modifier, size of the array (if known), size expression, and index type
383 /// qualifiers.
384 ///
385 /// By default, performs semantic analysis when building the array type.
386 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000387 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000388 QualType RebuildArrayType(QualType ElementType,
389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt *Size,
391 Expr *SizeExpr,
392 unsigned IndexTypeQuals,
393 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000394
Douglas Gregord6ff3322009-08-04 16:50:30 +0000395 /// \brief Build a new constant array type given the element type, size
396 /// modifier, (known) size of the array, and index type qualifiers.
397 ///
398 /// By default, performs semantic analysis when building the array type.
399 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000400 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000401 ArrayType::ArraySizeModifier SizeMod,
402 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000403 unsigned IndexTypeQuals,
404 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406 /// \brief Build a new incomplete array type given the element type, size
407 /// modifier, and index type qualifiers.
408 ///
409 /// By default, performs semantic analysis when building the array type.
410 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000411 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000413 unsigned IndexTypeQuals,
414 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000415
Mike Stump11289f42009-09-09 15:08:12 +0000416 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// size modifier, size expression, and index type qualifiers.
418 ///
419 /// By default, performs semantic analysis when building the array type.
420 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000421 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000423 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 unsigned IndexTypeQuals,
425 SourceRange BracketsRange);
426
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000428 /// size modifier, size expression, and index type qualifiers.
429 ///
430 /// By default, performs semantic analysis when building the array type.
431 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000432 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000434 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000435 unsigned IndexTypeQuals,
436 SourceRange BracketsRange);
437
438 /// \brief Build a new vector type given the element type and
439 /// number of elements.
440 ///
441 /// By default, performs semantic analysis when building the vector type.
442 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000443 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner37141f42010-06-23 06:00:24 +0000444 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000445
Douglas Gregord6ff3322009-08-04 16:50:30 +0000446 /// \brief Build a new extended vector type given the element type and
447 /// number of elements.
448 ///
449 /// By default, performs semantic analysis when building the vector type.
450 /// Subclasses may override this routine to provide different behavior.
451 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
452 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000453
454 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000455 /// given the element type and number of elements.
456 ///
457 /// By default, performs semantic analysis when building the vector type.
458 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000459 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000460 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000461 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000462
Douglas Gregord6ff3322009-08-04 16:50:30 +0000463 /// \brief Build a new function type.
464 ///
465 /// By default, performs semantic analysis when building the function type.
466 /// Subclasses may override this routine to provide different behavior.
467 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000468 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000469 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000470 bool Variadic, unsigned Quals,
471 const FunctionType::ExtInfo &Info);
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
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000547 if (InstName.isNull())
548 return QualType();
549
John McCallc392f372010-06-11 00:33:02 +0000550 // If it's still dependent, make a dependent specialization.
551 if (InstName.getAsDependentTemplateName())
552 return SemaRef.Context.getDependentTemplateSpecializationType(
553 Keyword, NNS, Name, Args);
554
555 // Otherwise, make an elaborated type wrapping a non-dependent
556 // specialization.
557 QualType T =
558 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
559 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000560
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000561 // NOTE: NNS is already recorded in template specialization type T.
562 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000563 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564
565 /// \brief Build a new typename type that refers to an identifier.
566 ///
567 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000568 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000569 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000570 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000571 NestedNameSpecifier *NNS,
572 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000573 SourceLocation KeywordLoc,
574 SourceRange NNSRange,
575 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000576 CXXScopeSpec SS;
577 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000578 SS.setRange(NNSRange);
579
Douglas Gregore677daf2010-03-31 22:19:08 +0000580 if (NNS->isDependent()) {
581 // If the name is still dependent, just build a new dependent name type.
582 if (!SemaRef.computeDeclContext(SS))
583 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
584 }
585
Abramo Bagnara6150c882010-05-11 21:36:43 +0000586 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000587 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
588 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000589
590 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
591
Abramo Bagnarad7548482010-05-19 21:37:53 +0000592 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000593 // into a non-dependent elaborated-type-specifier. Find the tag we're
594 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000595 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000596 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
597 if (!DC)
598 return QualType();
599
John McCallbf8c5192010-05-27 06:40:31 +0000600 if (SemaRef.RequireCompleteDeclContext(SS, DC))
601 return QualType();
602
Douglas Gregore677daf2010-03-31 22:19:08 +0000603 TagDecl *Tag = 0;
604 SemaRef.LookupQualifiedName(Result, DC);
605 switch (Result.getResultKind()) {
606 case LookupResult::NotFound:
607 case LookupResult::NotFoundInCurrentInstantiation:
608 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000609
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 case LookupResult::Found:
611 Tag = Result.getAsSingle<TagDecl>();
612 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000613
Douglas Gregore677daf2010-03-31 22:19:08 +0000614 case LookupResult::FoundOverloaded:
615 case LookupResult::FoundUnresolvedValue:
616 llvm_unreachable("Tag lookup cannot find non-tags");
617 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000618
Douglas Gregore677daf2010-03-31 22:19:08 +0000619 case LookupResult::Ambiguous:
620 // Let the LookupResult structure handle ambiguities.
621 return QualType();
622 }
623
624 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000625 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000626 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000627 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000628 return QualType();
629 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000630
Abramo Bagnarad7548482010-05-19 21:37:53 +0000631 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
632 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000633 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
634 return QualType();
635 }
636
637 // Build the elaborated-type-specifier type.
638 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000639 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000640 }
Mike Stump11289f42009-09-09 15:08:12 +0000641
Douglas Gregor1135c352009-08-06 05:28:30 +0000642 /// \brief Build a new nested-name-specifier given the prefix and an
643 /// identifier that names the next step in the nested-name-specifier.
644 ///
645 /// By default, performs semantic analysis when building the new
646 /// nested-name-specifier. Subclasses may override this routine to provide
647 /// different behavior.
648 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
649 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000650 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000651 QualType ObjectType,
652 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000653
654 /// \brief Build a new nested-name-specifier given the prefix and the
655 /// namespace named in the next step in the nested-name-specifier.
656 ///
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661 SourceRange Range,
662 NamespaceDecl *NS);
663
664 /// \brief Build a new nested-name-specifier given the prefix and the
665 /// type named in the next step in the nested-name-specifier.
666 ///
667 /// By default, performs semantic analysis when building the new
668 /// nested-name-specifier. Subclasses may override this routine to provide
669 /// different behavior.
670 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
671 SourceRange Range,
672 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000673 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000674
675 /// \brief Build a new template name given a nested name specifier, a flag
676 /// indicating whether the "template" keyword was provided, and the template
677 /// that the template name refers to.
678 ///
679 /// By default, builds the new template name directly. Subclasses may override
680 /// this routine to provide different behavior.
681 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
682 bool TemplateKW,
683 TemplateDecl *Template);
684
Douglas Gregor71dc5092009-08-06 06:41:21 +0000685 /// \brief Build a new template name given a nested name specifier and the
686 /// name that is referred to as a template.
687 ///
688 /// By default, performs semantic analysis to determine whether the name can
689 /// be resolved to a specific template, then builds the appropriate kind of
690 /// template name. Subclasses may override this routine to provide different
691 /// behavior.
692 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000693 const IdentifierInfo &II,
694 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000695
Douglas Gregor71395fa2009-11-04 00:56:37 +0000696 /// \brief Build a new template name given a nested name specifier and the
697 /// overloaded operator name that is referred to as a template.
698 ///
699 /// By default, performs semantic analysis to determine whether the name can
700 /// be resolved to a specific template, then builds the appropriate kind of
701 /// template name. Subclasses may override this routine to provide different
702 /// behavior.
703 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
704 OverloadedOperatorKind Operator,
705 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000706
Douglas Gregorebe10102009-08-20 07:17:43 +0000707 /// \brief Build a new compound statement.
708 ///
709 /// By default, performs semantic analysis to build the new statement.
710 /// Subclasses may override this routine to provide different behavior.
711 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
712 MultiStmtArg Statements,
713 SourceLocation RBraceLoc,
714 bool IsStmtExpr) {
715 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
716 IsStmtExpr);
717 }
718
719 /// \brief Build a new case statement.
720 ///
721 /// By default, performs semantic analysis to build the new statement.
722 /// Subclasses may override this routine to provide different behavior.
723 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
724 ExprArg LHS,
725 SourceLocation EllipsisLoc,
726 ExprArg RHS,
727 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000728 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 ColonLoc);
730 }
Mike Stump11289f42009-09-09 15:08:12 +0000731
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 /// \brief Attach the body to a new case statement.
733 ///
734 /// By default, performs semantic analysis to build the new statement.
735 /// Subclasses may override this routine to provide different behavior.
736 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
737 getSema().ActOnCaseStmtBody(S.get(), move(Body));
738 return move(S);
739 }
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 /// \brief Build a new default statement.
742 ///
743 /// By default, performs semantic analysis to build the new statement.
744 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000745 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 SourceLocation ColonLoc,
747 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000748 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000749 /*CurScope=*/0);
750 }
Mike Stump11289f42009-09-09 15:08:12 +0000751
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 /// \brief Build a new label statement.
753 ///
754 /// By default, performs semantic analysis to build the new statement.
755 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000756 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 IdentifierInfo *Id,
758 SourceLocation ColonLoc,
759 StmtArg SubStmt) {
760 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
761 }
Mike Stump11289f42009-09-09 15:08:12 +0000762
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 /// \brief Build a new "if" statement.
764 ///
765 /// By default, performs semantic analysis to build the new statement.
766 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000767 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000768 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000769 SourceLocation ElseLoc, StmtArg Else) {
John McCall48871652010-08-21 09:40:31 +0000770 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000771 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 }
Mike Stump11289f42009-09-09 15:08:12 +0000773
Douglas Gregorebe10102009-08-20 07:17:43 +0000774 /// \brief Start building a new switch statement.
775 ///
776 /// By default, performs semantic analysis to build the new statement.
777 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000778 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
779 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000780 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000781 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
John McCall48871652010-08-21 09:40:31 +0000782 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 }
Mike Stump11289f42009-09-09 15:08:12 +0000784
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 /// \brief Attach the body to the switch statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000789 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000790 StmtArg Switch, StmtArg Body) {
791 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
792 move(Body));
793 }
794
795 /// \brief Build a new while statement.
796 ///
797 /// By default, performs semantic analysis to build the new statement.
798 /// Subclasses may override this routine to provide different behavior.
799 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000800 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000801 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000803 return getSema().ActOnWhileStmt(WhileLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000804 CondVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 }
Mike Stump11289f42009-09-09 15:08:12 +0000806
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 /// \brief Build a new do-while statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
811 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
812 SourceLocation WhileLoc,
813 SourceLocation LParenLoc,
814 ExprArg Cond,
815 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000816 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 move(Cond), RParenLoc);
818 }
819
820 /// \brief Build a new for statement.
821 ///
822 /// By default, performs semantic analysis to build the new statement.
823 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000824 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000825 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000826 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000827 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000828 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000829 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
John McCall48871652010-08-21 09:40:31 +0000830 CondVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000831 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 /// \brief Build a new goto statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
838 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
839 SourceLocation LabelLoc,
840 LabelStmt *Label) {
841 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
842 }
843
844 /// \brief Build a new indirect goto statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
848 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
849 SourceLocation StarLoc,
850 ExprArg Target) {
851 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
852 }
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 /// \brief Build a new return statement.
855 ///
856 /// By default, performs semantic analysis to build the new statement.
857 /// Subclasses may override this routine to provide different behavior.
858 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
859 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000860
Douglas Gregorebe10102009-08-20 07:17:43 +0000861 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
862 }
Mike Stump11289f42009-09-09 15:08:12 +0000863
Douglas Gregorebe10102009-08-20 07:17:43 +0000864 /// \brief Build a new declaration statement.
865 ///
866 /// By default, performs semantic analysis to build the new statement.
867 /// Subclasses may override this routine to provide different behavior.
868 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000869 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000870 SourceLocation EndLoc) {
871 return getSema().Owned(
872 new (getSema().Context) DeclStmt(
873 DeclGroupRef::Create(getSema().Context,
874 Decls, NumDecls),
875 StartLoc, EndLoc));
876 }
Mike Stump11289f42009-09-09 15:08:12 +0000877
Anders Carlssonaaeef072010-01-24 05:50:09 +0000878 /// \brief Build a new inline asm statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
882 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
883 bool IsSimple,
884 bool IsVolatile,
885 unsigned NumOutputs,
886 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000887 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000888 MultiExprArg Constraints,
889 MultiExprArg Exprs,
890 ExprArg AsmString,
891 MultiExprArg Clobbers,
892 SourceLocation RParenLoc,
893 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000894 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000895 NumInputs, Names, move(Constraints),
896 move(Exprs), move(AsmString), move(Clobbers),
897 RParenLoc, MSAsm);
898 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000899
900 /// \brief Build a new Objective-C @try statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
904 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
905 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000906 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000907 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000908 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000909 move(Finally));
910 }
911
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000912 /// \brief Rebuild an Objective-C exception declaration.
913 ///
914 /// By default, performs semantic analysis to build the new declaration.
915 /// Subclasses may override this routine to provide different behavior.
916 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
917 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000918 return getSema().BuildObjCExceptionDecl(TInfo, T,
919 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000920 ExceptionDecl->getLocation());
921 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000922
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 /// \brief Build a new Objective-C @catch statement.
924 ///
925 /// By default, performs semantic analysis to build the new statement.
926 /// Subclasses may override this routine to provide different behavior.
927 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
928 SourceLocation RParenLoc,
929 VarDecl *Var,
930 StmtArg Body) {
931 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall48871652010-08-21 09:40:31 +0000932 Var, move(Body));
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000933 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000934
Douglas Gregor306de2f2010-04-22 23:59:56 +0000935 /// \brief Build a new Objective-C @finally statement.
936 ///
937 /// By default, performs semantic analysis to build the new statement.
938 /// Subclasses may override this routine to provide different behavior.
939 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
940 StmtArg Body) {
941 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
942 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000943
Douglas Gregor6148de72010-04-22 22:01:21 +0000944 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000945 ///
946 /// By default, performs semantic analysis to build the new statement.
947 /// Subclasses may override this routine to provide different behavior.
948 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
949 ExprArg Operand) {
950 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
951 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000952
Douglas Gregor6148de72010-04-22 22:01:21 +0000953 /// \brief Build a new Objective-C @synchronized statement.
954 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
957 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
958 ExprArg Object,
959 StmtArg Body) {
960 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
961 move(Body));
962 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000963
964 /// \brief Build a new Objective-C fast enumeration statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
968 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
969 SourceLocation LParenLoc,
970 StmtArg Element,
971 ExprArg Collection,
972 SourceLocation RParenLoc,
973 StmtArg Body) {
974 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000975 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000976 move(Collection),
977 RParenLoc,
978 move(Body));
979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000980
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 /// \brief Build a new C++ exception declaration.
982 ///
983 /// By default, performs semantic analysis to build the new decaration.
984 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000985 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000986 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 IdentifierInfo *Name,
988 SourceLocation Loc,
989 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000990 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 TypeRange);
992 }
993
994 /// \brief Build a new C++ catch statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
998 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
999 VarDecl *ExceptionDecl,
1000 StmtArg Handler) {
1001 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +00001002 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 Handler.takeAs<Stmt>()));
1004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
1010 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1011 StmtArg TryBlock,
1012 MultiStmtArg Handlers) {
1013 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001020 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1021 LookupResult &R,
1022 bool RequiresADL) {
1023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001031 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1032 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001033 ValueDecl *VD,
1034 const DeclarationNameInfo &NameInfo,
John McCallce546572009-12-08 09:08:17 +00001035 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001036 CXXScopeSpec SS;
1037 SS.setScopeRep(Qualifier);
1038 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001039
1040 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001041
1042 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 }
Mike Stump11289f42009-09-09 15:08:12 +00001044
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001046 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// By default, performs semantic analysis to build the new expression.
1048 /// Subclasses may override this routine to provide different behavior.
1049 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1050 SourceLocation RParen) {
1051 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1052 }
1053
Douglas Gregorad8a3362009-09-04 17:36:40 +00001054 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001055 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
1058 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1059 SourceLocation OperatorLoc,
1060 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001061 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001062 SourceRange QualifierRange,
1063 TypeSourceInfo *ScopeType,
1064 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001065 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001066 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
1072 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1073 UnaryOperator::Opcode Opc,
1074 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001075 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 }
Mike Stump11289f42009-09-09 15:08:12 +00001077
Douglas Gregor882211c2010-04-28 22:16:22 +00001078 /// \brief Build a new builtin offsetof expression.
1079 ///
1080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1083 TypeSourceInfo *Type,
1084 Action::OffsetOfComponent *Components,
1085 unsigned NumComponents,
1086 SourceLocation RParenLoc) {
1087 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1088 NumComponents, RParenLoc);
1089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001092 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 /// By default, performs semantic analysis to build the new expression.
1094 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001095 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001096 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001098 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 }
1100
Mike Stump11289f42009-09-09 15:08:12 +00001101 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
1106 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1107 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001108 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1110 OpLoc, isSizeOf, R);
1111 if (Result.isInvalid())
1112 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001113
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 SubExpr.release();
1115 return move(Result);
1116 }
Mike Stump11289f42009-09-09 15:08:12 +00001117
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001119 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 /// By default, performs semantic analysis to build the new expression.
1121 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001122 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 SourceLocation LBracketLoc,
1124 ExprArg RHS,
1125 SourceLocation RBracketLoc) {
1126 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001127 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 RBracketLoc);
1129 }
1130
1131 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001132 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 /// By default, performs semantic analysis to build the new expression.
1134 /// Subclasses may override this routine to provide different behavior.
1135 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1136 MultiExprArg Args,
1137 SourceLocation *CommaLocs,
1138 SourceLocation RParenLoc) {
1139 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1140 move(Args), CommaLocs, RParenLoc);
1141 }
1142
1143 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001144 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001145 /// By default, performs semantic analysis to build the new expression.
1146 /// Subclasses may override this routine to provide different behavior.
1147 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001148 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001149 NestedNameSpecifier *Qualifier,
1150 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001151 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001152 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001153 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001154 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001155 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001156 if (!Member->getDeclName()) {
1157 // We have a reference to an unnamed field.
1158 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001159
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001160 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001161 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1162 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001163 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001164
Mike Stump11289f42009-09-09 15:08:12 +00001165 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001166 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001167 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001168 cast<FieldDecl>(Member)->getType());
1169 return getSema().Owned(ME);
1170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001172 CXXScopeSpec SS;
1173 if (Qualifier) {
1174 SS.setRange(QualifierRange);
1175 SS.setScopeRep(Qualifier);
1176 }
1177
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001178 Expr *BaseExpr = Base.takeAs<Expr>();
1179 getSema().DefaultFunctionArrayConversion(BaseExpr);
1180 QualType BaseType = BaseExpr->getType();
John McCall2d74de92009-12-01 22:10:20 +00001181
John McCall16df1e52010-03-30 21:47:33 +00001182 // FIXME: this involves duplicating earlier analysis in a lot of
1183 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001184 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001185 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001186 R.resolveKind();
1187
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001188 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1189 BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
1198 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1199 BinaryOperator::Opcode Opc,
1200 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001202 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 }
1204
1205 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001206 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 /// By default, performs semantic analysis to build the new expression.
1208 /// Subclasses may override this routine to provide different behavior.
1209 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1210 SourceLocation QuestionLoc,
1211 ExprArg LHS,
1212 SourceLocation ColonLoc,
1213 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001214 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 move(LHS), move(RHS));
1216 }
1217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001219 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001222 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
1225 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001226 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1227 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
1234 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001235 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 SourceLocation RParenLoc,
1237 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001238 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1239 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001243 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001246 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 SourceLocation OpLoc,
1248 SourceLocation AccessorLoc,
1249 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001250
John McCall10eae182009-11-30 22:42:35 +00001251 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001252 QualType BaseType = ((Expr*) Base.get())->getType();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001253 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall2d74de92009-12-01 22:10:20 +00001254 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001255 OpLoc, /*IsArrow*/ false,
1256 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001257 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001258 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001262 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
1265 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1266 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001267 SourceLocation RBraceLoc,
1268 QualType ResultTy) {
1269 OwningExprResult Result
1270 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1271 if (Result.isInvalid() || ResultTy->isDependentType())
1272 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001273
Douglas Gregord3d93062009-11-09 17:16:50 +00001274 // Patch in the result type we were given, which may have been computed
1275 // when the initial InitListExpr was built.
1276 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1277 ILE->setType(ResultTy);
1278 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001282 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// By default, performs semantic analysis to build the new expression.
1284 /// Subclasses may override this routine to provide different behavior.
1285 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1286 MultiExprArg ArrayExprs,
1287 SourceLocation EqualOrColonLoc,
1288 bool GNUSyntax,
1289 ExprArg Init) {
1290 OwningExprResult Result
1291 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1292 move(Init));
1293 if (Result.isInvalid())
1294 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 ArrayExprs.release();
1297 return move(Result);
1298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, builds the implicit value initialization without performing
1303 /// any semantic analysis. Subclasses may override this routine to provide
1304 /// different behavior.
1305 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1306 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnara27db2392010-08-10 10:06:15 +00001313 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1314 ExprArg SubExpr, TypeSourceInfo *TInfo,
1315 SourceLocation RParenLoc) {
1316 return getSema().BuildVAArgExpr(BuiltinLoc,
1317 move(SubExpr), TInfo,
1318 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
1320
1321 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
1325 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1326 MultiExprArg SubExprs,
1327 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001328 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001329 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
1334 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// rather than attempting to map the label statement itself.
1336 /// Subclasses may override this routine to provide different behavior.
1337 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1338 SourceLocation LabelLoc,
1339 LabelStmt *Label) {
1340 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1341 }
Mike Stump11289f42009-09-09 15:08:12 +00001342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001344 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1348 StmtArg SubStmt,
1349 SourceLocation RParenLoc) {
1350 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new __builtin_types_compatible_p expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
1357 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001358 TypeSourceInfo *TInfo1,
1359 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001361 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1362 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 RParenLoc);
1364 }
Mike Stump11289f42009-09-09 15:08:12 +00001365
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 /// \brief Build a new __builtin_choose_expr expression.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// Subclasses may override this routine to provide different behavior.
1370 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1371 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1372 SourceLocation RParenLoc) {
1373 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1374 move(Cond), move(LHS), move(RHS),
1375 RParenLoc);
1376 }
Mike Stump11289f42009-09-09 15:08:12 +00001377
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 /// \brief Build a new overloaded operator call expression.
1379 ///
1380 /// By default, performs semantic analysis to build the new expression.
1381 /// The semantic analysis provides the behavior of template instantiation,
1382 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001383 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// argument-dependent lookup, etc. Subclasses may override this routine to
1385 /// provide different behavior.
1386 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1387 SourceLocation OpLoc,
1388 ExprArg Callee,
1389 ExprArg First,
1390 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001391
1392 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 /// reinterpret_cast.
1394 ///
1395 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001396 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 /// Subclasses may override this routine to provide different behavior.
1398 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1399 Stmt::StmtClass Class,
1400 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001401 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 SourceLocation RAngleLoc,
1403 SourceLocation LParenLoc,
1404 ExprArg SubExpr,
1405 SourceLocation RParenLoc) {
1406 switch (Class) {
1407 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001408 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001409 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 move(SubExpr), RParenLoc);
1411
1412 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001413 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001414 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001418 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001419 RAngleLoc, LParenLoc,
1420 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001424 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001425 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001427
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 default:
1429 assert(false && "Invalid C++ named cast");
1430 break;
1431 }
Mike Stump11289f42009-09-09 15:08:12 +00001432
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 return getSema().ExprError();
1434 }
Mike Stump11289f42009-09-09 15:08:12 +00001435
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// \brief Build a new C++ static_cast expression.
1437 ///
1438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
1440 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1441 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001442 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 SourceLocation RAngleLoc,
1444 SourceLocation LParenLoc,
1445 ExprArg SubExpr,
1446 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001447 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1448 TInfo, move(SubExpr),
1449 SourceRange(LAngleLoc, RAngleLoc),
1450 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 }
1452
1453 /// \brief Build a new C++ dynamic_cast expression.
1454 ///
1455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1458 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001459 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 SourceLocation RAngleLoc,
1461 SourceLocation LParenLoc,
1462 ExprArg SubExpr,
1463 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001464 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1465 TInfo, move(SubExpr),
1466 SourceRange(LAngleLoc, RAngleLoc),
1467 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 }
1469
1470 /// \brief Build a new C++ reinterpret_cast expression.
1471 ///
1472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
1474 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1475 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001476 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 SourceLocation RAngleLoc,
1478 SourceLocation LParenLoc,
1479 ExprArg SubExpr,
1480 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001481 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1482 TInfo, move(SubExpr),
1483 SourceRange(LAngleLoc, RAngleLoc),
1484 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 }
1486
1487 /// \brief Build a new C++ const_cast expression.
1488 ///
1489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
1491 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1492 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001493 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 SourceLocation RAngleLoc,
1495 SourceLocation LParenLoc,
1496 ExprArg SubExpr,
1497 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001498 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1499 TInfo, move(SubExpr),
1500 SourceRange(LAngleLoc, RAngleLoc),
1501 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// \brief Build a new C++ functional-style cast expression.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
1508 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001509 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 SourceLocation LParenLoc,
1511 ExprArg SubExpr,
1512 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001513 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001515 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001517 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001518 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 RParenLoc);
1520 }
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new C++ typeid(type) expression.
1523 ///
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001526 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1527 SourceLocation TypeidLoc,
1528 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001530 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001531 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 }
Mike Stump11289f42009-09-09 15:08:12 +00001533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// \brief Build a new C++ typeid(expr) expression.
1535 ///
1536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001538 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1539 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 ExprArg Operand,
1541 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001542 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1543 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001544 }
1545
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// \brief Build a new C++ "this" expression.
1547 ///
1548 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001549 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001551 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001552 QualType ThisType,
1553 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001555 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1556 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 }
1558
1559 /// \brief Build a new C++ throw expression.
1560 ///
1561 /// By default, performs semantic analysis to build the new expression.
1562 /// Subclasses may override this routine to provide different behavior.
1563 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1564 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1565 }
1566
1567 /// \brief Build a new C++ default-argument expression.
1568 ///
1569 /// By default, builds a new default-argument expression, which does not
1570 /// require any semantic analysis. Subclasses may override this routine to
1571 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001572 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001573 ParmVarDecl *Param) {
1574 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1575 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 }
1577
1578 /// \brief Build a new C++ zero-initialization expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor747eb782010-07-08 06:14:04 +00001582 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 SourceLocation LParenLoc,
1584 QualType T,
1585 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001586 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1587 T.getAsOpaquePtr(), LParenLoc,
1588 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 0, RParenLoc);
1590 }
Mike Stump11289f42009-09-09 15:08:12 +00001591
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 /// \brief Build a new C++ "new" expression.
1593 ///
1594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001596 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 bool UseGlobal,
1598 SourceLocation PlacementLParen,
1599 MultiExprArg PlacementArgs,
1600 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001601 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 QualType AllocType,
1603 SourceLocation TypeLoc,
1604 SourceRange TypeRange,
1605 ExprArg ArraySize,
1606 SourceLocation ConstructorLParen,
1607 MultiExprArg ConstructorArgs,
1608 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001609 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 PlacementLParen,
1611 move(PlacementArgs),
1612 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001613 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 AllocType,
1615 TypeLoc,
1616 TypeRange,
1617 move(ArraySize),
1618 ConstructorLParen,
1619 move(ConstructorArgs),
1620 ConstructorRParen);
1621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// \brief Build a new C++ "delete" expression.
1624 ///
1625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
1627 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1628 bool IsGlobalDelete,
1629 bool IsArrayForm,
1630 ExprArg Operand) {
1631 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1632 move(Operand));
1633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new unary type trait expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
1639 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1640 SourceLocation StartLoc,
1641 SourceLocation LParenLoc,
1642 QualType T,
1643 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001644 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 T.getAsOpaquePtr(), RParenLoc);
1646 }
1647
Mike Stump11289f42009-09-09 15:08:12 +00001648 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 /// expression.
1650 ///
1651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001653 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001655 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001656 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 CXXScopeSpec SS;
1658 SS.setRange(QualifierRange);
1659 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001660
1661 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001662 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001663 *TemplateArgs);
1664
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001665 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new template-id expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001672 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1673 LookupResult &R,
1674 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001675 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001676 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 }
1678
1679 /// \brief Build a new object-construction expression.
1680 ///
1681 /// By default, performs semantic analysis to build the new expression.
1682 /// Subclasses may override this routine to provide different behavior.
1683 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001684 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 CXXConstructorDecl *Constructor,
1686 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001687 MultiExprArg Args,
1688 bool RequiresZeroInit,
1689 CXXConstructExpr::ConstructionKind ConstructKind) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001690 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001691 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001692 ConvertedArgs))
1693 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001694
Douglas Gregordb121ba2009-12-14 16:27:04 +00001695 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001696 move_arg(ConvertedArgs),
1697 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 }
1699
1700 /// \brief Build a new object-construction expression.
1701 ///
1702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
1704 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1705 QualType T,
1706 SourceLocation LParenLoc,
1707 MultiExprArg Args,
1708 SourceLocation *Commas,
1709 SourceLocation RParenLoc) {
1710 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1711 T.getAsOpaquePtr(),
1712 LParenLoc,
1713 move(Args),
1714 Commas,
1715 RParenLoc);
1716 }
1717
1718 /// \brief Build a new object-construction expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
1722 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1723 QualType T,
1724 SourceLocation LParenLoc,
1725 MultiExprArg Args,
1726 SourceLocation *Commas,
1727 SourceLocation RParenLoc) {
1728 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1729 /*FIXME*/LParenLoc),
1730 T.getAsOpaquePtr(),
1731 LParenLoc,
1732 move(Args),
1733 Commas,
1734 RParenLoc);
1735 }
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 /// \brief Build a new member reference expression.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001741 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001742 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 bool IsArrow,
1744 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 NestedNameSpecifier *Qualifier,
1746 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001747 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001748 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001749 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001751 SS.setRange(QualifierRange);
1752 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001753
John McCall2d74de92009-12-01 22:10:20 +00001754 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1755 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001756 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001757 MemberNameInfo,
1758 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
1760
John McCall10eae182009-11-30 22:42:35 +00001761 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001765 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001766 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001767 SourceLocation OperatorLoc,
1768 bool IsArrow,
1769 NestedNameSpecifier *Qualifier,
1770 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001771 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001772 LookupResult &R,
1773 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001774 CXXScopeSpec SS;
1775 SS.setRange(QualifierRange);
1776 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001777
John McCall2d74de92009-12-01 22:10:20 +00001778 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1779 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001780 SS, FirstQualifierInScope,
1781 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001782 }
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 /// \brief Build a new Objective-C @encode expression.
1785 ///
1786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
1788 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001789 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001791 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001793 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001794
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001795 /// \brief Build a new Objective-C class message.
1796 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1797 Selector Sel,
1798 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001799 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 MultiExprArg Args,
1801 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001802 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1803 ReceiverTypeInfo->getType(),
1804 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001805 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 move(Args));
1807 }
1808
1809 /// \brief Build a new Objective-C instance message.
1810 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1811 Selector Sel,
1812 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001813 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001814 MultiExprArg Args,
1815 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001816 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1817 return SemaRef.BuildInstanceMessage(move(Receiver),
1818 ReceiverType,
1819 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001820 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001821 move(Args));
1822 }
1823
Douglas Gregord51d90d2010-04-26 20:11:03 +00001824 /// \brief Build a new Objective-C ivar reference expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
1828 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1829 SourceLocation IvarLoc,
1830 bool IsArrow, bool IsFreeIvar) {
1831 // FIXME: We lose track of the IsFreeIvar bit.
1832 CXXScopeSpec SS;
1833 Expr *Base = BaseArg.takeAs<Expr>();
1834 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1835 Sema::LookupMemberName);
1836 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1837 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001838 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001839 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 if (Result.isInvalid())
1841 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001842
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 if (Result.get())
1844 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001845
1846 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001847 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001849 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001850 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001851 /*TemplateArgs=*/0);
1852 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001853
1854 /// \brief Build a new Objective-C property reference expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001858 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001859 ObjCPropertyDecl *Property,
1860 SourceLocation PropertyLoc) {
1861 CXXScopeSpec SS;
1862 Expr *Base = BaseArg.takeAs<Expr>();
1863 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1864 Sema::LookupMemberName);
1865 bool IsArrow = false;
1866 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1867 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001868 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001869 if (Result.isInvalid())
1870 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871
Douglas Gregor9faee212010-04-26 20:47:02 +00001872 if (Result.get())
1873 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001874
1875 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001876 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001877 /*FIXME:*/PropertyLoc, IsArrow,
1878 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001879 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001881 /*TemplateArgs=*/0);
1882 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001883
1884 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001885 /// expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001888 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001889 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1890 ObjCMethodDecl *Getter,
1891 QualType T,
1892 ObjCMethodDecl *Setter,
1893 SourceLocation NameLoc,
1894 ExprArg Base) {
1895 // Since these expressions can only be value-dependent, we do not need to
1896 // perform semantic analysis again.
1897 return getSema().Owned(
1898 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1899 Setter,
1900 NameLoc,
1901 Base.takeAs<Expr>()));
1902 }
1903
Douglas Gregord51d90d2010-04-26 20:11:03 +00001904 /// \brief Build a new Objective-C "isa" expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
1908 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1909 bool IsArrow) {
1910 CXXScopeSpec SS;
1911 Expr *Base = BaseArg.takeAs<Expr>();
1912 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1913 Sema::LookupMemberName);
1914 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1915 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001916 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 if (Result.isInvalid())
1918 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001919
Douglas Gregord51d90d2010-04-26 20:11:03 +00001920 if (Result.get())
1921 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001922
1923 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001924 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001925 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001926 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001927 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001928 /*TemplateArgs=*/0);
1929 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001930
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 /// \brief Build a new shuffle vector expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
1935 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1936 MultiExprArg SubExprs,
1937 SourceLocation RParenLoc) {
1938 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001939 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1941 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1942 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1943 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 // Build a reference to the __builtin_shufflevector builtin
1946 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001947 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001949 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001951
1952 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 unsigned NumSubExprs = SubExprs.size();
1954 Expr **Subs = (Expr **)SubExprs.release();
1955 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1956 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001957 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 RParenLoc);
1959 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 // Type-check the __builtin_shufflevector expression.
1962 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1963 if (Result.isInvalid())
1964 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001967 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001969};
Douglas Gregora16548e2009-08-11 05:31:07 +00001970
Douglas Gregorebe10102009-08-20 07:17:43 +00001971template<typename Derived>
1972Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1973 if (!S)
1974 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregorebe10102009-08-20 07:17:43 +00001976 switch (S->getStmtClass()) {
1977 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001978
Douglas Gregorebe10102009-08-20 07:17:43 +00001979 // Transform individual statement nodes
1980#define STMT(Node, Parent) \
1981 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1982#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001983#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001984
Douglas Gregorebe10102009-08-20 07:17:43 +00001985 // Transform expressions by calling TransformExpr.
1986#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001987#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001988#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001989#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001990 {
1991 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1992 if (E.isInvalid())
1993 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001994
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001995 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001996 }
Mike Stump11289f42009-09-09 15:08:12 +00001997 }
1998
Douglas Gregorebe10102009-08-20 07:17:43 +00001999 return SemaRef.Owned(S->Retain());
2000}
Mike Stump11289f42009-09-09 15:08:12 +00002001
2002
Douglas Gregore922c772009-08-04 22:27:00 +00002003template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00002004Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 if (!E)
2006 return SemaRef.Owned(E);
2007
2008 switch (E->getStmtClass()) {
2009 case Stmt::NoStmtClass: break;
2010#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002011#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002012#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002013 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002014#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002015 }
2016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002018}
2019
2020template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002021NestedNameSpecifier *
2022TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002023 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002024 QualType ObjectType,
2025 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002026 if (!NNS)
2027 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002028
Douglas Gregorebe10102009-08-20 07:17:43 +00002029 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002030 NestedNameSpecifier *Prefix = NNS->getPrefix();
2031 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002032 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002033 ObjectType,
2034 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002035 if (!Prefix)
2036 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002037
2038 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002039 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002040 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002041 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 }
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregor1135c352009-08-06 05:28:30 +00002044 switch (NNS->getKind()) {
2045 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002046 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002047 "Identifier nested-name-specifier with no prefix or object type");
2048 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2049 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002050 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002051
2052 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002053 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002054 ObjectType,
2055 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002058 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002059 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002060 getDerived().TransformDecl(Range.getBegin(),
2061 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002063 Prefix == NNS->getPrefix() &&
2064 NS == NNS->getAsNamespace())
2065 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregor1135c352009-08-06 05:28:30 +00002067 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Douglas Gregor1135c352009-08-06 05:28:30 +00002070 case NestedNameSpecifier::Global:
2071 // There is no meaningful transformation that one could perform on the
2072 // global scope.
2073 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002074
Douglas Gregor1135c352009-08-06 05:28:30 +00002075 case NestedNameSpecifier::TypeSpecWithTemplate:
2076 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002077 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002078 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2079 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002080 if (T.isNull())
2081 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregor1135c352009-08-06 05:28:30 +00002083 if (!getDerived().AlwaysRebuild() &&
2084 Prefix == NNS->getPrefix() &&
2085 T == QualType(NNS->getAsType(), 0))
2086 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002087
2088 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2089 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002090 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002091 }
2092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Douglas Gregor1135c352009-08-06 05:28:30 +00002094 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002095 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002096}
2097
2098template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002099DeclarationNameInfo
2100TreeTransform<Derived>
2101::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2102 QualType ObjectType) {
2103 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002104 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002105 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002106
2107 switch (Name.getNameKind()) {
2108 case DeclarationName::Identifier:
2109 case DeclarationName::ObjCZeroArgSelector:
2110 case DeclarationName::ObjCOneArgSelector:
2111 case DeclarationName::ObjCMultiArgSelector:
2112 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002113 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002114 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002115 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002116
Douglas Gregorf816bd72009-09-03 22:13:48 +00002117 case DeclarationName::CXXConstructorName:
2118 case DeclarationName::CXXDestructorName:
2119 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002120 TypeSourceInfo *NewTInfo;
2121 CanQualType NewCanTy;
2122 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2123 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2124 if (!NewTInfo)
2125 return DeclarationNameInfo();
2126 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2127 }
2128 else {
2129 NewTInfo = 0;
2130 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2131 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2132 ObjectType);
2133 if (NewT.isNull())
2134 return DeclarationNameInfo();
2135 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2136 }
Mike Stump11289f42009-09-09 15:08:12 +00002137
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002138 DeclarationName NewName
2139 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2140 NewCanTy);
2141 DeclarationNameInfo NewNameInfo(NameInfo);
2142 NewNameInfo.setName(NewName);
2143 NewNameInfo.setNamedTypeInfo(NewTInfo);
2144 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002145 }
Mike Stump11289f42009-09-09 15:08:12 +00002146 }
2147
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002148 assert(0 && "Unknown name kind.");
2149 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002150}
2151
2152template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002153TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002154TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2155 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002156 SourceLocation Loc = getDerived().getBaseLocation();
2157
Douglas Gregor71dc5092009-08-06 06:41:21 +00002158 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002159 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002161 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2162 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002163 if (!NNS)
2164 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregor71dc5092009-08-06 06:41:21 +00002166 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002167 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002168 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 if (!TransTemplate)
2170 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregor71dc5092009-08-06 06:41:21 +00002172 if (!getDerived().AlwaysRebuild() &&
2173 NNS == QTN->getQualifier() &&
2174 TransTemplate == Template)
2175 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2178 TransTemplate);
2179 }
Mike Stump11289f42009-09-09 15:08:12 +00002180
John McCalle66edc12009-11-24 19:00:30 +00002181 // These should be getting filtered out before they make it into the AST.
2182 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002183 }
Mike Stump11289f42009-09-09 15:08:12 +00002184
Douglas Gregor71dc5092009-08-06 06:41:21 +00002185 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002186 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002188 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2189 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002190 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002191 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002192
Douglas Gregor71dc5092009-08-06 06:41:21 +00002193 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002194 NNS == DTN->getQualifier() &&
2195 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002196 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002197
Douglas Gregor71395fa2009-11-04 00:56:37 +00002198 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002199 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002200 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201
2202 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002203 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204 }
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002207 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002208 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002209 if (!TransTemplate)
2210 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002211
Douglas Gregor71dc5092009-08-06 06:41:21 +00002212 if (!getDerived().AlwaysRebuild() &&
2213 TransTemplate == Template)
2214 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregor71dc5092009-08-06 06:41:21 +00002216 return TemplateName(TransTemplate);
2217 }
Mike Stump11289f42009-09-09 15:08:12 +00002218
John McCalle66edc12009-11-24 19:00:30 +00002219 // These should be getting filtered out before they reach the AST.
2220 assert(false && "overloaded function decl survived to here");
2221 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002222}
2223
2224template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002225void TreeTransform<Derived>::InventTemplateArgumentLoc(
2226 const TemplateArgument &Arg,
2227 TemplateArgumentLoc &Output) {
2228 SourceLocation Loc = getDerived().getBaseLocation();
2229 switch (Arg.getKind()) {
2230 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002231 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002232 break;
2233
2234 case TemplateArgument::Type:
2235 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002236 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002237
John McCall0ad16662009-10-29 08:12:44 +00002238 break;
2239
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002240 case TemplateArgument::Template:
2241 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2242 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002243
John McCall0ad16662009-10-29 08:12:44 +00002244 case TemplateArgument::Expression:
2245 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2246 break;
2247
2248 case TemplateArgument::Declaration:
2249 case TemplateArgument::Integral:
2250 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002251 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002252 break;
2253 }
2254}
2255
2256template<typename Derived>
2257bool TreeTransform<Derived>::TransformTemplateArgument(
2258 const TemplateArgumentLoc &Input,
2259 TemplateArgumentLoc &Output) {
2260 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002261 switch (Arg.getKind()) {
2262 case TemplateArgument::Null:
2263 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002264 Output = Input;
2265 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002266
Douglas Gregore922c772009-08-04 22:27:00 +00002267 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002268 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002269 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002270 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002271
2272 DI = getDerived().TransformType(DI);
2273 if (!DI) return true;
2274
2275 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2276 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002277 }
Mike Stump11289f42009-09-09 15:08:12 +00002278
Douglas Gregore922c772009-08-04 22:27:00 +00002279 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002280 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002281 DeclarationName Name;
2282 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2283 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002284 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002285 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002286 if (!D) return true;
2287
John McCall0d07eb32009-10-29 18:45:58 +00002288 Expr *SourceExpr = Input.getSourceDeclExpression();
2289 if (SourceExpr) {
2290 EnterExpressionEvaluationContext Unevaluated(getSema(),
2291 Action::Unevaluated);
2292 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2293 if (E.isInvalid())
2294 SourceExpr = NULL;
2295 else {
2296 SourceExpr = E.takeAs<Expr>();
2297 SourceExpr->Retain();
2298 }
2299 }
2300
2301 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002302 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002303 }
Mike Stump11289f42009-09-09 15:08:12 +00002304
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002305 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002306 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002307 TemplateName Template
2308 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2309 if (Template.isNull())
2310 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002311
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002312 Output = TemplateArgumentLoc(TemplateArgument(Template),
2313 Input.getTemplateQualifierRange(),
2314 Input.getTemplateNameLoc());
2315 return false;
2316 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002317
Douglas Gregore922c772009-08-04 22:27:00 +00002318 case TemplateArgument::Expression: {
2319 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002320 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002321 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002322
John McCall0ad16662009-10-29 08:12:44 +00002323 Expr *InputExpr = Input.getSourceExpression();
2324 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2325
2326 Sema::OwningExprResult E
2327 = getDerived().TransformExpr(InputExpr);
2328 if (E.isInvalid()) return true;
2329
2330 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002331 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002332 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2333 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002334 }
Mike Stump11289f42009-09-09 15:08:12 +00002335
Douglas Gregore922c772009-08-04 22:27:00 +00002336 case TemplateArgument::Pack: {
2337 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2338 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002339 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002340 AEnd = Arg.pack_end();
2341 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002342
John McCall0ad16662009-10-29 08:12:44 +00002343 // FIXME: preserve source information here when we start
2344 // caring about parameter packs.
2345
John McCall0d07eb32009-10-29 18:45:58 +00002346 TemplateArgumentLoc InputArg;
2347 TemplateArgumentLoc OutputArg;
2348 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2349 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002350 return true;
2351
John McCall0d07eb32009-10-29 18:45:58 +00002352 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002353 }
2354 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002355 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002356 true);
John McCall0d07eb32009-10-29 18:45:58 +00002357 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002358 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002359 }
2360 }
Mike Stump11289f42009-09-09 15:08:12 +00002361
Douglas Gregore922c772009-08-04 22:27:00 +00002362 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002363 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002364}
2365
Douglas Gregord6ff3322009-08-04 16:50:30 +00002366//===----------------------------------------------------------------------===//
2367// Type transformation
2368//===----------------------------------------------------------------------===//
2369
2370template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002371QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002372 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002373 if (getDerived().AlreadyTransformed(T))
2374 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002375
John McCall550e0c22009-10-21 00:40:46 +00002376 // Temporary workaround. All of these transformations should
2377 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002378 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002379 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002380
Douglas Gregorfe17d252010-02-16 19:09:40 +00002381 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002382
John McCall550e0c22009-10-21 00:40:46 +00002383 if (!NewDI)
2384 return QualType();
2385
2386 return NewDI->getType();
2387}
2388
2389template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002390TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2391 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002392 if (getDerived().AlreadyTransformed(DI->getType()))
2393 return DI;
2394
2395 TypeLocBuilder TLB;
2396
2397 TypeLoc TL = DI->getTypeLoc();
2398 TLB.reserve(TL.getFullDataSize());
2399
Douglas Gregorfe17d252010-02-16 19:09:40 +00002400 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002401 if (Result.isNull())
2402 return 0;
2403
John McCallbcd03502009-12-07 02:54:59 +00002404 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002405}
2406
2407template<typename Derived>
2408QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002409TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2410 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002411 switch (T.getTypeLocClass()) {
2412#define ABSTRACT_TYPELOC(CLASS, PARENT)
2413#define TYPELOC(CLASS, PARENT) \
2414 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002415 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2416 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002417#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002418 }
Mike Stump11289f42009-09-09 15:08:12 +00002419
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002420 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002421 return QualType();
2422}
2423
2424/// FIXME: By default, this routine adds type qualifiers only to types
2425/// that can have qualifiers, and silently suppresses those qualifiers
2426/// that are not permitted (e.g., qualifiers on reference or function
2427/// types). This is the right thing for template instantiation, but
2428/// probably not for other clients.
2429template<typename Derived>
2430QualType
2431TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002432 QualifiedTypeLoc T,
2433 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002434 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002435
Douglas Gregorfe17d252010-02-16 19:09:40 +00002436 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2437 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002438 if (Result.isNull())
2439 return QualType();
2440
2441 // Silently suppress qualifiers if the result type can't be qualified.
2442 // FIXME: this is the right thing for template instantiation, but
2443 // probably not for other clients.
2444 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002445 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002446
John McCallcb0f89a2010-06-05 06:41:15 +00002447 if (!Quals.empty()) {
2448 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2449 TLB.push<QualifiedTypeLoc>(Result);
2450 // No location information to preserve.
2451 }
John McCall550e0c22009-10-21 00:40:46 +00002452
2453 return Result;
2454}
2455
2456template <class TyLoc> static inline
2457QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2458 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2459 NewT.setNameLoc(T.getNameLoc());
2460 return T.getType();
2461}
2462
John McCall550e0c22009-10-21 00:40:46 +00002463template<typename Derived>
2464QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002465 BuiltinTypeLoc T,
2466 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002467 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2468 NewT.setBuiltinLoc(T.getBuiltinLoc());
2469 if (T.needsExtraLocalData())
2470 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2471 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472}
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002475QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002476 ComplexTypeLoc T,
2477 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002478 // FIXME: recurse?
2479 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002480}
Mike Stump11289f42009-09-09 15:08:12 +00002481
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002483QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002484 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002485 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002486 QualType PointeeType
2487 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002488 if (PointeeType.isNull())
2489 return QualType();
2490
2491 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002492 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002493 // A dependent pointer type 'T *' has is being transformed such
2494 // that an Objective-C class type is being replaced for 'T'. The
2495 // resulting pointer type is an ObjCObjectPointerType, not a
2496 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002497 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002498
John McCall8b07ec22010-05-15 11:32:37 +00002499 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2500 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002501 return Result;
2502 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002503
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002504 if (getDerived().AlwaysRebuild() ||
2505 PointeeType != TL.getPointeeLoc().getType()) {
2506 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2507 if (Result.isNull())
2508 return QualType();
2509 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002510
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002511 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2512 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002513 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002514}
Mike Stump11289f42009-09-09 15:08:12 +00002515
2516template<typename Derived>
2517QualType
John McCall550e0c22009-10-21 00:40:46 +00002518TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002519 BlockPointerTypeLoc TL,
2520 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002521 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002522 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2523 if (PointeeType.isNull())
2524 return QualType();
2525
2526 QualType Result = TL.getType();
2527 if (getDerived().AlwaysRebuild() ||
2528 PointeeType != TL.getPointeeLoc().getType()) {
2529 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002530 TL.getSigilLoc());
2531 if (Result.isNull())
2532 return QualType();
2533 }
2534
Douglas Gregor049211a2010-04-22 16:50:51 +00002535 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002536 NewT.setSigilLoc(TL.getSigilLoc());
2537 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002538}
2539
John McCall70dd5f62009-10-30 00:06:24 +00002540/// Transforms a reference type. Note that somewhat paradoxically we
2541/// don't care whether the type itself is an l-value type or an r-value
2542/// type; we only care if the type was *written* as an l-value type
2543/// or an r-value type.
2544template<typename Derived>
2545QualType
2546TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002547 ReferenceTypeLoc TL,
2548 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002549 const ReferenceType *T = TL.getTypePtr();
2550
2551 // Note that this works with the pointee-as-written.
2552 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2553 if (PointeeType.isNull())
2554 return QualType();
2555
2556 QualType Result = TL.getType();
2557 if (getDerived().AlwaysRebuild() ||
2558 PointeeType != T->getPointeeTypeAsWritten()) {
2559 Result = getDerived().RebuildReferenceType(PointeeType,
2560 T->isSpelledAsLValue(),
2561 TL.getSigilLoc());
2562 if (Result.isNull())
2563 return QualType();
2564 }
2565
2566 // r-value references can be rebuilt as l-value references.
2567 ReferenceTypeLoc NewTL;
2568 if (isa<LValueReferenceType>(Result))
2569 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2570 else
2571 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2572 NewTL.setSigilLoc(TL.getSigilLoc());
2573
2574 return Result;
2575}
2576
Mike Stump11289f42009-09-09 15:08:12 +00002577template<typename Derived>
2578QualType
John McCall550e0c22009-10-21 00:40:46 +00002579TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002580 LValueReferenceTypeLoc TL,
2581 QualType ObjectType) {
2582 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583}
2584
Mike Stump11289f42009-09-09 15:08:12 +00002585template<typename Derived>
2586QualType
John McCall550e0c22009-10-21 00:40:46 +00002587TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002588 RValueReferenceTypeLoc TL,
2589 QualType ObjectType) {
2590 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002591}
Mike Stump11289f42009-09-09 15:08:12 +00002592
Douglas Gregord6ff3322009-08-04 16:50:30 +00002593template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002594QualType
John McCall550e0c22009-10-21 00:40:46 +00002595TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002596 MemberPointerTypeLoc TL,
2597 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002598 MemberPointerType *T = TL.getTypePtr();
2599
2600 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002601 if (PointeeType.isNull())
2602 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002603
John McCall550e0c22009-10-21 00:40:46 +00002604 // TODO: preserve source information for this.
2605 QualType ClassType
2606 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002607 if (ClassType.isNull())
2608 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002609
John McCall550e0c22009-10-21 00:40:46 +00002610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 PointeeType != T->getPointeeType() ||
2613 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002614 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2615 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002616 if (Result.isNull())
2617 return QualType();
2618 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002619
John McCall550e0c22009-10-21 00:40:46 +00002620 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2621 NewTL.setSigilLoc(TL.getSigilLoc());
2622
2623 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002624}
2625
Mike Stump11289f42009-09-09 15:08:12 +00002626template<typename Derived>
2627QualType
John McCall550e0c22009-10-21 00:40:46 +00002628TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002629 ConstantArrayTypeLoc TL,
2630 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002631 ConstantArrayType *T = TL.getTypePtr();
2632 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002633 if (ElementType.isNull())
2634 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002635
John McCall550e0c22009-10-21 00:40:46 +00002636 QualType Result = TL.getType();
2637 if (getDerived().AlwaysRebuild() ||
2638 ElementType != T->getElementType()) {
2639 Result = getDerived().RebuildConstantArrayType(ElementType,
2640 T->getSizeModifier(),
2641 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002642 T->getIndexTypeCVRQualifiers(),
2643 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002644 if (Result.isNull())
2645 return QualType();
2646 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002647
John McCall550e0c22009-10-21 00:40:46 +00002648 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2649 NewTL.setLBracketLoc(TL.getLBracketLoc());
2650 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002651
John McCall550e0c22009-10-21 00:40:46 +00002652 Expr *Size = TL.getSizeExpr();
2653 if (Size) {
2654 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2655 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2656 }
2657 NewTL.setSizeExpr(Size);
2658
2659 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002660}
Mike Stump11289f42009-09-09 15:08:12 +00002661
Douglas Gregord6ff3322009-08-04 16:50:30 +00002662template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002663QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002664 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002665 IncompleteArrayTypeLoc TL,
2666 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002667 IncompleteArrayType *T = TL.getTypePtr();
2668 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002669 if (ElementType.isNull())
2670 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002671
John McCall550e0c22009-10-21 00:40:46 +00002672 QualType Result = TL.getType();
2673 if (getDerived().AlwaysRebuild() ||
2674 ElementType != T->getElementType()) {
2675 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002676 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002677 T->getIndexTypeCVRQualifiers(),
2678 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002679 if (Result.isNull())
2680 return QualType();
2681 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002682
John McCall550e0c22009-10-21 00:40:46 +00002683 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2684 NewTL.setLBracketLoc(TL.getLBracketLoc());
2685 NewTL.setRBracketLoc(TL.getRBracketLoc());
2686 NewTL.setSizeExpr(0);
2687
2688 return Result;
2689}
2690
2691template<typename Derived>
2692QualType
2693TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002694 VariableArrayTypeLoc TL,
2695 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002696 VariableArrayType *T = TL.getTypePtr();
2697 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2698 if (ElementType.isNull())
2699 return QualType();
2700
2701 // Array bounds are not potentially evaluated contexts
2702 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2703
2704 Sema::OwningExprResult SizeResult
2705 = getDerived().TransformExpr(T->getSizeExpr());
2706 if (SizeResult.isInvalid())
2707 return QualType();
2708
2709 Expr *Size = static_cast<Expr*>(SizeResult.get());
2710
2711 QualType Result = TL.getType();
2712 if (getDerived().AlwaysRebuild() ||
2713 ElementType != T->getElementType() ||
2714 Size != T->getSizeExpr()) {
2715 Result = getDerived().RebuildVariableArrayType(ElementType,
2716 T->getSizeModifier(),
2717 move(SizeResult),
2718 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002719 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002720 if (Result.isNull())
2721 return QualType();
2722 }
2723 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002724
John McCall550e0c22009-10-21 00:40:46 +00002725 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2726 NewTL.setLBracketLoc(TL.getLBracketLoc());
2727 NewTL.setRBracketLoc(TL.getRBracketLoc());
2728 NewTL.setSizeExpr(Size);
2729
2730 return Result;
2731}
2732
2733template<typename Derived>
2734QualType
2735TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002736 DependentSizedArrayTypeLoc TL,
2737 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002738 DependentSizedArrayType *T = TL.getTypePtr();
2739 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2740 if (ElementType.isNull())
2741 return QualType();
2742
2743 // Array bounds are not potentially evaluated contexts
2744 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2745
2746 Sema::OwningExprResult SizeResult
2747 = getDerived().TransformExpr(T->getSizeExpr());
2748 if (SizeResult.isInvalid())
2749 return QualType();
2750
2751 Expr *Size = static_cast<Expr*>(SizeResult.get());
2752
2753 QualType Result = TL.getType();
2754 if (getDerived().AlwaysRebuild() ||
2755 ElementType != T->getElementType() ||
2756 Size != T->getSizeExpr()) {
2757 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2758 T->getSizeModifier(),
2759 move(SizeResult),
2760 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002761 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002762 if (Result.isNull())
2763 return QualType();
2764 }
2765 else SizeResult.take();
2766
2767 // We might have any sort of array type now, but fortunately they
2768 // all have the same location layout.
2769 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2770 NewTL.setLBracketLoc(TL.getLBracketLoc());
2771 NewTL.setRBracketLoc(TL.getRBracketLoc());
2772 NewTL.setSizeExpr(Size);
2773
2774 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775}
Mike Stump11289f42009-09-09 15:08:12 +00002776
2777template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002779 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002780 DependentSizedExtVectorTypeLoc TL,
2781 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002782 DependentSizedExtVectorType *T = TL.getTypePtr();
2783
2784 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002785 QualType ElementType = getDerived().TransformType(T->getElementType());
2786 if (ElementType.isNull())
2787 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002788
Douglas Gregore922c772009-08-04 22:27:00 +00002789 // Vector sizes are not potentially evaluated contexts
2790 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2791
Douglas Gregord6ff3322009-08-04 16:50:30 +00002792 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2793 if (Size.isInvalid())
2794 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002795
John McCall550e0c22009-10-21 00:40:46 +00002796 QualType Result = TL.getType();
2797 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002798 ElementType != T->getElementType() ||
2799 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002800 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002801 move(Size),
2802 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002803 if (Result.isNull())
2804 return QualType();
2805 }
2806 else Size.take();
2807
2808 // Result might be dependent or not.
2809 if (isa<DependentSizedExtVectorType>(Result)) {
2810 DependentSizedExtVectorTypeLoc NewTL
2811 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
2813 } else {
2814 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2815 NewTL.setNameLoc(TL.getNameLoc());
2816 }
2817
2818 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002819}
Mike Stump11289f42009-09-09 15:08:12 +00002820
2821template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002822QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002823 VectorTypeLoc TL,
2824 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002825 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002826 QualType ElementType = getDerived().TransformType(T->getElementType());
2827 if (ElementType.isNull())
2828 return QualType();
2829
John McCall550e0c22009-10-21 00:40:46 +00002830 QualType Result = TL.getType();
2831 if (getDerived().AlwaysRebuild() ||
2832 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002833 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002834 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002835 if (Result.isNull())
2836 return QualType();
2837 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002838
John McCall550e0c22009-10-21 00:40:46 +00002839 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2840 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002841
John McCall550e0c22009-10-21 00:40:46 +00002842 return Result;
2843}
2844
2845template<typename Derived>
2846QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002847 ExtVectorTypeLoc TL,
2848 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002849 VectorType *T = TL.getTypePtr();
2850 QualType ElementType = getDerived().TransformType(T->getElementType());
2851 if (ElementType.isNull())
2852 return QualType();
2853
2854 QualType Result = TL.getType();
2855 if (getDerived().AlwaysRebuild() ||
2856 ElementType != T->getElementType()) {
2857 Result = getDerived().RebuildExtVectorType(ElementType,
2858 T->getNumElements(),
2859 /*FIXME*/ SourceLocation());
2860 if (Result.isNull())
2861 return QualType();
2862 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002863
John McCall550e0c22009-10-21 00:40:46 +00002864 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2865 NewTL.setNameLoc(TL.getNameLoc());
2866
2867 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002868}
Mike Stump11289f42009-09-09 15:08:12 +00002869
2870template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002871ParmVarDecl *
2872TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2873 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2874 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2875 if (!NewDI)
2876 return 0;
2877
2878 if (NewDI == OldDI)
2879 return OldParm;
2880 else
2881 return ParmVarDecl::Create(SemaRef.Context,
2882 OldParm->getDeclContext(),
2883 OldParm->getLocation(),
2884 OldParm->getIdentifier(),
2885 NewDI->getType(),
2886 NewDI,
2887 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002888 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002889 /* DefArg */ NULL);
2890}
2891
2892template<typename Derived>
2893bool TreeTransform<Derived>::
2894 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2895 llvm::SmallVectorImpl<QualType> &PTypes,
2896 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2897 FunctionProtoType *T = TL.getTypePtr();
2898
2899 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2900 ParmVarDecl *OldParm = TL.getArg(i);
2901
2902 QualType NewType;
2903 ParmVarDecl *NewParm;
2904
2905 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002906 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2907 if (!NewParm)
2908 return true;
2909 NewType = NewParm->getType();
2910
2911 // Deal with the possibility that we don't have a parameter
2912 // declaration for this parameter.
2913 } else {
2914 NewParm = 0;
2915
2916 QualType OldType = T->getArgType(i);
2917 NewType = getDerived().TransformType(OldType);
2918 if (NewType.isNull())
2919 return true;
2920 }
2921
2922 PTypes.push_back(NewType);
2923 PVars.push_back(NewParm);
2924 }
2925
2926 return false;
2927}
2928
2929template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002930QualType
John McCall550e0c22009-10-21 00:40:46 +00002931TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002932 FunctionProtoTypeLoc TL,
2933 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002934 // Transform the parameters. We do this first for the benefit of template
2935 // instantiations, so that the ParmVarDecls get/ placed into the template
2936 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002937 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002938 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002939 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2940 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002941
Douglas Gregor14cf7522010-04-30 18:55:50 +00002942 FunctionProtoType *T = TL.getTypePtr();
2943 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2944 if (ResultType.isNull())
2945 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002946
John McCall550e0c22009-10-21 00:40:46 +00002947 QualType Result = TL.getType();
2948 if (getDerived().AlwaysRebuild() ||
2949 ResultType != T->getResultType() ||
2950 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2951 Result = getDerived().RebuildFunctionProtoType(ResultType,
2952 ParamTypes.data(),
2953 ParamTypes.size(),
2954 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002955 T->getTypeQuals(),
2956 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002957 if (Result.isNull())
2958 return QualType();
2959 }
Mike Stump11289f42009-09-09 15:08:12 +00002960
John McCall550e0c22009-10-21 00:40:46 +00002961 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2962 NewTL.setLParenLoc(TL.getLParenLoc());
2963 NewTL.setRParenLoc(TL.getRParenLoc());
2964 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2965 NewTL.setArg(i, ParamDecls[i]);
2966
2967 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002968}
Mike Stump11289f42009-09-09 15:08:12 +00002969
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970template<typename Derived>
2971QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002972 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002973 FunctionNoProtoTypeLoc TL,
2974 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002975 FunctionNoProtoType *T = TL.getTypePtr();
2976 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2977 if (ResultType.isNull())
2978 return QualType();
2979
2980 QualType Result = TL.getType();
2981 if (getDerived().AlwaysRebuild() ||
2982 ResultType != T->getResultType())
2983 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2984
2985 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2986 NewTL.setLParenLoc(TL.getLParenLoc());
2987 NewTL.setRParenLoc(TL.getRParenLoc());
2988
2989 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002990}
Mike Stump11289f42009-09-09 15:08:12 +00002991
John McCallb96ec562009-12-04 22:46:56 +00002992template<typename Derived> QualType
2993TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002994 UnresolvedUsingTypeLoc TL,
2995 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002996 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002997 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002998 if (!D)
2999 return QualType();
3000
3001 QualType Result = TL.getType();
3002 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3003 Result = getDerived().RebuildUnresolvedUsingType(D);
3004 if (Result.isNull())
3005 return QualType();
3006 }
3007
3008 // We might get an arbitrary type spec type back. We should at
3009 // least always get a type spec type, though.
3010 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3011 NewTL.setNameLoc(TL.getNameLoc());
3012
3013 return Result;
3014}
3015
Douglas Gregord6ff3322009-08-04 16:50:30 +00003016template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003017QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003018 TypedefTypeLoc TL,
3019 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003020 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003022 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3023 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024 if (!Typedef)
3025 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003026
John McCall550e0c22009-10-21 00:40:46 +00003027 QualType Result = TL.getType();
3028 if (getDerived().AlwaysRebuild() ||
3029 Typedef != T->getDecl()) {
3030 Result = getDerived().RebuildTypedefType(Typedef);
3031 if (Result.isNull())
3032 return QualType();
3033 }
Mike Stump11289f42009-09-09 15:08:12 +00003034
John McCall550e0c22009-10-21 00:40:46 +00003035 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3036 NewTL.setNameLoc(TL.getNameLoc());
3037
3038 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003039}
Mike Stump11289f42009-09-09 15:08:12 +00003040
Douglas Gregord6ff3322009-08-04 16:50:30 +00003041template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003042QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003043 TypeOfExprTypeLoc TL,
3044 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003045 // typeof expressions are not potentially evaluated contexts
3046 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003047
John McCalle8595032010-01-13 20:03:27 +00003048 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003049 if (E.isInvalid())
3050 return QualType();
3051
John McCall550e0c22009-10-21 00:40:46 +00003052 QualType Result = TL.getType();
3053 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003054 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003055 Result = getDerived().RebuildTypeOfExprType(move(E));
3056 if (Result.isNull())
3057 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003058 }
John McCall550e0c22009-10-21 00:40:46 +00003059 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003060
John McCall550e0c22009-10-21 00:40:46 +00003061 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003062 NewTL.setTypeofLoc(TL.getTypeofLoc());
3063 NewTL.setLParenLoc(TL.getLParenLoc());
3064 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003065
3066 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003067}
Mike Stump11289f42009-09-09 15:08:12 +00003068
3069template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003070QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003071 TypeOfTypeLoc TL,
3072 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003073 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3074 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3075 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003077
John McCall550e0c22009-10-21 00:40:46 +00003078 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003079 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3080 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003081 if (Result.isNull())
3082 return QualType();
3083 }
Mike Stump11289f42009-09-09 15:08:12 +00003084
John McCall550e0c22009-10-21 00:40:46 +00003085 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003086 NewTL.setTypeofLoc(TL.getTypeofLoc());
3087 NewTL.setLParenLoc(TL.getLParenLoc());
3088 NewTL.setRParenLoc(TL.getRParenLoc());
3089 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003090
3091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003092}
Mike Stump11289f42009-09-09 15:08:12 +00003093
3094template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003095QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003096 DecltypeTypeLoc TL,
3097 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003098 DecltypeType *T = TL.getTypePtr();
3099
Douglas Gregore922c772009-08-04 22:27:00 +00003100 // decltype expressions are not potentially evaluated contexts
3101 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003102
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3104 if (E.isInvalid())
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 E.get() != T->getUnderlyingExpr()) {
3110 Result = getDerived().RebuildDecltypeType(move(E));
3111 if (Result.isNull())
3112 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003113 }
John McCall550e0c22009-10-21 00:40:46 +00003114 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003115
John McCall550e0c22009-10-21 00:40:46 +00003116 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3117 NewTL.setNameLoc(TL.getNameLoc());
3118
3119 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003120}
3121
3122template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003123QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003124 RecordTypeLoc TL,
3125 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003126 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003128 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3129 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003130 if (!Record)
3131 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003132
John McCall550e0c22009-10-21 00:40:46 +00003133 QualType Result = TL.getType();
3134 if (getDerived().AlwaysRebuild() ||
3135 Record != T->getDecl()) {
3136 Result = getDerived().RebuildRecordType(Record);
3137 if (Result.isNull())
3138 return QualType();
3139 }
Mike Stump11289f42009-09-09 15:08:12 +00003140
John McCall550e0c22009-10-21 00:40:46 +00003141 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3142 NewTL.setNameLoc(TL.getNameLoc());
3143
3144 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145}
Mike Stump11289f42009-09-09 15:08:12 +00003146
3147template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003148QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003149 EnumTypeLoc TL,
3150 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003151 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003153 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3154 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003155 if (!Enum)
3156 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003157
John McCall550e0c22009-10-21 00:40:46 +00003158 QualType Result = TL.getType();
3159 if (getDerived().AlwaysRebuild() ||
3160 Enum != T->getDecl()) {
3161 Result = getDerived().RebuildEnumType(Enum);
3162 if (Result.isNull())
3163 return QualType();
3164 }
Mike Stump11289f42009-09-09 15:08:12 +00003165
John McCall550e0c22009-10-21 00:40:46 +00003166 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3167 NewTL.setNameLoc(TL.getNameLoc());
3168
3169 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003170}
John McCallfcc33b02009-09-05 00:15:47 +00003171
John McCalle78aac42010-03-10 03:28:59 +00003172template<typename Derived>
3173QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3174 TypeLocBuilder &TLB,
3175 InjectedClassNameTypeLoc TL,
3176 QualType ObjectType) {
3177 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3178 TL.getTypePtr()->getDecl());
3179 if (!D) return QualType();
3180
3181 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3182 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3183 return T;
3184}
3185
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregord6ff3322009-08-04 16:50:30 +00003187template<typename Derived>
3188QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003189 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003190 TemplateTypeParmTypeLoc TL,
3191 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003192 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003193}
3194
Mike Stump11289f42009-09-09 15:08:12 +00003195template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003196QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003197 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003198 SubstTemplateTypeParmTypeLoc TL,
3199 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003200 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003201}
3202
3203template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003204QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3205 const TemplateSpecializationType *TST,
3206 QualType ObjectType) {
3207 // FIXME: this entire method is a temporary workaround; callers
3208 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003209
John McCall0ad16662009-10-29 08:12:44 +00003210 // Fake up a TemplateSpecializationTypeLoc.
3211 TypeLocBuilder TLB;
3212 TemplateSpecializationTypeLoc TL
3213 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3214
John McCall0d07eb32009-10-29 18:45:58 +00003215 SourceLocation BaseLoc = getDerived().getBaseLocation();
3216
3217 TL.setTemplateNameLoc(BaseLoc);
3218 TL.setLAngleLoc(BaseLoc);
3219 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003220 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3221 const TemplateArgument &TA = TST->getArg(i);
3222 TemplateArgumentLoc TAL;
3223 getDerived().InventTemplateArgumentLoc(TA, TAL);
3224 TL.setArgLocInfo(i, TAL.getLocInfo());
3225 }
3226
3227 TypeLocBuilder IgnoredTLB;
3228 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003229}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003230
Douglas Gregorc59e5612009-10-19 22:04:39 +00003231template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003232QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003233 TypeLocBuilder &TLB,
3234 TemplateSpecializationTypeLoc TL,
3235 QualType ObjectType) {
3236 const TemplateSpecializationType *T = TL.getTypePtr();
3237
Mike Stump11289f42009-09-09 15:08:12 +00003238 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003239 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003240 if (Template.isNull())
3241 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall6b51f282009-11-23 01:53:49 +00003243 TemplateArgumentListInfo NewTemplateArgs;
3244 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3245 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3246
3247 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3248 TemplateArgumentLoc Loc;
3249 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003250 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003251 NewTemplateArgs.addArgument(Loc);
3252 }
Mike Stump11289f42009-09-09 15:08:12 +00003253
John McCall0ad16662009-10-29 08:12:44 +00003254 // FIXME: maybe don't rebuild if all the template arguments are the same.
3255
3256 QualType Result =
3257 getDerived().RebuildTemplateSpecializationType(Template,
3258 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003259 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003260
3261 if (!Result.isNull()) {
3262 TemplateSpecializationTypeLoc NewTL
3263 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3264 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3265 NewTL.setLAngleLoc(TL.getLAngleLoc());
3266 NewTL.setRAngleLoc(TL.getRAngleLoc());
3267 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3268 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269 }
Mike Stump11289f42009-09-09 15:08:12 +00003270
John McCall0ad16662009-10-29 08:12:44 +00003271 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272}
Mike Stump11289f42009-09-09 15:08:12 +00003273
3274template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003275QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003276TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3277 ElaboratedTypeLoc TL,
3278 QualType ObjectType) {
3279 ElaboratedType *T = TL.getTypePtr();
3280
3281 NestedNameSpecifier *NNS = 0;
3282 // NOTE: the qualifier in an ElaboratedType is optional.
3283 if (T->getQualifier() != 0) {
3284 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003285 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003286 ObjectType);
3287 if (!NNS)
3288 return QualType();
3289 }
Mike Stump11289f42009-09-09 15:08:12 +00003290
Abramo Bagnarad7548482010-05-19 21:37:53 +00003291 QualType NamedT;
3292 // FIXME: this test is meant to workaround a problem (failing assertion)
3293 // occurring if directly executing the code in the else branch.
3294 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3295 TemplateSpecializationTypeLoc OldNamedTL
3296 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3297 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003298 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003299 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3300 if (NamedT.isNull())
3301 return QualType();
3302 TemplateSpecializationTypeLoc NewNamedTL
3303 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3304 NewNamedTL.copy(OldNamedTL);
3305 }
3306 else {
3307 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3308 if (NamedT.isNull())
3309 return QualType();
3310 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 QualType Result = TL.getType();
3313 if (getDerived().AlwaysRebuild() ||
3314 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003315 NamedT != T->getNamedType()) {
3316 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003317 if (Result.isNull())
3318 return QualType();
3319 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320
Abramo Bagnara6150c882010-05-11 21:36:43 +00003321 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003322 NewTL.setKeywordLoc(TL.getKeywordLoc());
3323 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003324
3325 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326}
Mike Stump11289f42009-09-09 15:08:12 +00003327
3328template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003329QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3330 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003331 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003332 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003333
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003335 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3336 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003337 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338 if (!NNS)
3339 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003340
John McCallc392f372010-06-11 00:33:02 +00003341 QualType Result
3342 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3343 T->getIdentifier(),
3344 TL.getKeywordLoc(),
3345 TL.getQualifierRange(),
3346 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003347 if (Result.isNull())
3348 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349
Abramo Bagnarad7548482010-05-19 21:37:53 +00003350 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3351 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003352 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3353
Abramo Bagnarad7548482010-05-19 21:37:53 +00003354 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3355 NewTL.setKeywordLoc(TL.getKeywordLoc());
3356 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003357 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003358 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3359 NewTL.setKeywordLoc(TL.getKeywordLoc());
3360 NewTL.setQualifierRange(TL.getQualifierRange());
3361 NewTL.setNameLoc(TL.getNameLoc());
3362 }
John McCall550e0c22009-10-21 00:40:46 +00003363 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003364}
Mike Stump11289f42009-09-09 15:08:12 +00003365
Douglas Gregord6ff3322009-08-04 16:50:30 +00003366template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003367QualType TreeTransform<Derived>::
3368 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3369 DependentTemplateSpecializationTypeLoc TL,
3370 QualType ObjectType) {
3371 DependentTemplateSpecializationType *T = TL.getTypePtr();
3372
3373 NestedNameSpecifier *NNS
3374 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3375 TL.getQualifierRange(),
3376 ObjectType);
3377 if (!NNS)
3378 return QualType();
3379
3380 TemplateArgumentListInfo NewTemplateArgs;
3381 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3382 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3383
3384 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3385 TemplateArgumentLoc Loc;
3386 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3387 return QualType();
3388 NewTemplateArgs.addArgument(Loc);
3389 }
3390
3391 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3392 T->getKeyword(),
3393 NNS,
3394 T->getIdentifier(),
3395 TL.getNameLoc(),
3396 NewTemplateArgs);
3397 if (Result.isNull())
3398 return QualType();
3399
3400 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3401 QualType NamedT = ElabT->getNamedType();
3402
3403 // Copy information relevant to the template specialization.
3404 TemplateSpecializationTypeLoc NamedTL
3405 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3406 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3407 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3408 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3409 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3410
3411 // Copy information relevant to the elaborated type.
3412 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3413 NewTL.setKeywordLoc(TL.getKeywordLoc());
3414 NewTL.setQualifierRange(TL.getQualifierRange());
3415 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003416 TypeLoc NewTL(Result, TL.getOpaqueData());
3417 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003418 }
3419 return Result;
3420}
3421
3422template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003423QualType
3424TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003425 ObjCInterfaceTypeLoc TL,
3426 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003427 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003428 TLB.pushFullCopy(TL);
3429 return TL.getType();
3430}
3431
3432template<typename Derived>
3433QualType
3434TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3435 ObjCObjectTypeLoc TL,
3436 QualType ObjectType) {
3437 // ObjCObjectType is never dependent.
3438 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003439 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440}
Mike Stump11289f42009-09-09 15:08:12 +00003441
3442template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003443QualType
3444TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003445 ObjCObjectPointerTypeLoc TL,
3446 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003447 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003448 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003449 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003450}
3451
Douglas Gregord6ff3322009-08-04 16:50:30 +00003452//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003453// Statement transformation
3454//===----------------------------------------------------------------------===//
3455template<typename Derived>
3456Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003457TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3458 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003459}
3460
3461template<typename Derived>
3462Sema::OwningStmtResult
3463TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3464 return getDerived().TransformCompoundStmt(S, false);
3465}
3466
3467template<typename Derived>
3468Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003469TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003470 bool IsStmtExpr) {
3471 bool SubStmtChanged = false;
3472 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3473 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3474 B != BEnd; ++B) {
3475 OwningStmtResult Result = getDerived().TransformStmt(*B);
3476 if (Result.isInvalid())
3477 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003478
Douglas Gregorebe10102009-08-20 07:17:43 +00003479 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3480 Statements.push_back(Result.takeAs<Stmt>());
3481 }
Mike Stump11289f42009-09-09 15:08:12 +00003482
Douglas Gregorebe10102009-08-20 07:17:43 +00003483 if (!getDerived().AlwaysRebuild() &&
3484 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003485 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003486
3487 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3488 move_arg(Statements),
3489 S->getRBracLoc(),
3490 IsStmtExpr);
3491}
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregorebe10102009-08-20 07:17:43 +00003493template<typename Derived>
3494Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003495TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003496 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3497 {
3498 // The case value expressions are not potentially evaluated.
3499 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003500
Eli Friedman06577382009-11-19 03:14:00 +00003501 // Transform the left-hand case value.
3502 LHS = getDerived().TransformExpr(S->getLHS());
3503 if (LHS.isInvalid())
3504 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003505
Eli Friedman06577382009-11-19 03:14:00 +00003506 // Transform the right-hand case value (for the GNU case-range extension).
3507 RHS = getDerived().TransformExpr(S->getRHS());
3508 if (RHS.isInvalid())
3509 return SemaRef.StmtError();
3510 }
Mike Stump11289f42009-09-09 15:08:12 +00003511
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Build the case statement.
3513 // Case statements are always rebuilt so that they will attached to their
3514 // transformed switch statement.
3515 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3516 move(LHS),
3517 S->getEllipsisLoc(),
3518 move(RHS),
3519 S->getColonLoc());
3520 if (Case.isInvalid())
3521 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 // Transform the statement following the case
3524 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3525 if (SubStmt.isInvalid())
3526 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregorebe10102009-08-20 07:17:43 +00003528 // Attach the body to the case statement
3529 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3530}
3531
3532template<typename Derived>
3533Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003534TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003535 // Transform the statement following the default case
3536 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3537 if (SubStmt.isInvalid())
3538 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003539
Douglas Gregorebe10102009-08-20 07:17:43 +00003540 // Default statements are always rebuilt
3541 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3542 move(SubStmt));
3543}
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregorebe10102009-08-20 07:17:43 +00003545template<typename Derived>
3546Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003547TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003548 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3549 if (SubStmt.isInvalid())
3550 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 // FIXME: Pass the real colon location in.
3553 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3554 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3555 move(SubStmt));
3556}
Mike Stump11289f42009-09-09 15:08:12 +00003557
Douglas Gregorebe10102009-08-20 07:17:43 +00003558template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003559Sema::OwningStmtResult
3560TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003561 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003562 OwningExprResult Cond(SemaRef);
3563 VarDecl *ConditionVar = 0;
3564 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003565 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003566 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003567 getDerived().TransformDefinition(
3568 S->getConditionVariable()->getLocation(),
3569 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003570 if (!ConditionVar)
3571 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003572 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003573 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003574
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003575 if (Cond.isInvalid())
3576 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003577
3578 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003579 if (S->getCond()) {
3580 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3581 S->getIfLoc(),
3582 move(Cond));
3583 if (CondE.isInvalid())
3584 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003585
Douglas Gregor6d319c62010-05-08 23:34:38 +00003586 Cond = move(CondE);
3587 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003588 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003589
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003590 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3591 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3592 return SemaRef.StmtError();
3593
Douglas Gregorebe10102009-08-20 07:17:43 +00003594 // Transform the "then" branch.
3595 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3596 if (Then.isInvalid())
3597 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003598
Douglas Gregorebe10102009-08-20 07:17:43 +00003599 // Transform the "else" branch.
3600 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3601 if (Else.isInvalid())
3602 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003605 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003606 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003607 Then.get() == S->getThen() &&
3608 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003609 return SemaRef.Owned(S->Retain());
3610
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003611 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003612 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003613 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003614}
3615
3616template<typename Derived>
3617Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003618TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003619 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003620 OwningExprResult Cond(SemaRef);
3621 VarDecl *ConditionVar = 0;
3622 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003623 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003624 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003625 getDerived().TransformDefinition(
3626 S->getConditionVariable()->getLocation(),
3627 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003628 if (!ConditionVar)
3629 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003630 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003631 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003632
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003633 if (Cond.isInvalid())
3634 return SemaRef.StmtError();
3635 }
Mike Stump11289f42009-09-09 15:08:12 +00003636
Douglas Gregorebe10102009-08-20 07:17:43 +00003637 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003638 OwningStmtResult Switch
3639 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3640 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003641 if (Switch.isInvalid())
3642 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregorebe10102009-08-20 07:17:43 +00003644 // Transform the body of the switch statement.
3645 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3646 if (Body.isInvalid())
3647 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregorebe10102009-08-20 07:17:43 +00003649 // Complete the switch statement.
3650 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3651 move(Body));
3652}
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorebe10102009-08-20 07:17:43 +00003654template<typename Derived>
3655Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003656TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003657 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003658 OwningExprResult Cond(SemaRef);
3659 VarDecl *ConditionVar = 0;
3660 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003661 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003662 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003663 getDerived().TransformDefinition(
3664 S->getConditionVariable()->getLocation(),
3665 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003666 if (!ConditionVar)
3667 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003668 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003669 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003670
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003671 if (Cond.isInvalid())
3672 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003673
3674 if (S->getCond()) {
3675 // Convert the condition to a boolean value.
3676 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003677 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003678 move(Cond));
3679 if (CondE.isInvalid())
3680 return getSema().StmtError();
3681 Cond = move(CondE);
3682 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003683 }
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003685 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3686 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3687 return SemaRef.StmtError();
3688
Douglas Gregorebe10102009-08-20 07:17:43 +00003689 // Transform the body
3690 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3691 if (Body.isInvalid())
3692 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003693
Douglas Gregorebe10102009-08-20 07:17:43 +00003694 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003695 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003696 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003697 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003698 return SemaRef.Owned(S->Retain());
3699
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003700 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003701 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003702}
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregorebe10102009-08-20 07:17:43 +00003704template<typename Derived>
3705Sema::OwningStmtResult
3706TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003707 // Transform the body
3708 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3709 if (Body.isInvalid())
3710 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003711
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003712 // Transform the condition
3713 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3714 if (Cond.isInvalid())
3715 return SemaRef.StmtError();
3716
Douglas Gregorebe10102009-08-20 07:17:43 +00003717 if (!getDerived().AlwaysRebuild() &&
3718 Cond.get() == S->getCond() &&
3719 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003720 return SemaRef.Owned(S->Retain());
3721
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3723 /*FIXME:*/S->getWhileLoc(), move(Cond),
3724 S->getRParenLoc());
3725}
Mike Stump11289f42009-09-09 15:08:12 +00003726
Douglas Gregorebe10102009-08-20 07:17:43 +00003727template<typename Derived>
3728Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003729TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003730 // Transform the initialization statement
3731 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3732 if (Init.isInvalid())
3733 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregorebe10102009-08-20 07:17:43 +00003735 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003736 OwningExprResult Cond(SemaRef);
3737 VarDecl *ConditionVar = 0;
3738 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003739 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003740 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003741 getDerived().TransformDefinition(
3742 S->getConditionVariable()->getLocation(),
3743 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003744 if (!ConditionVar)
3745 return SemaRef.StmtError();
3746 } else {
3747 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003748
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003749 if (Cond.isInvalid())
3750 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003751
3752 if (S->getCond()) {
3753 // Convert the condition to a boolean value.
3754 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3755 S->getForLoc(),
3756 move(Cond));
3757 if (CondE.isInvalid())
3758 return getSema().StmtError();
3759
3760 Cond = move(CondE);
3761 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003762 }
Mike Stump11289f42009-09-09 15:08:12 +00003763
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003764 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3765 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3766 return SemaRef.StmtError();
3767
Douglas Gregorebe10102009-08-20 07:17:43 +00003768 // Transform the increment
3769 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3770 if (Inc.isInvalid())
3771 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003773 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3774 if (S->getInc() && !FullInc->get())
3775 return SemaRef.StmtError();
3776
Douglas Gregorebe10102009-08-20 07:17:43 +00003777 // Transform the body
3778 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3779 if (Body.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 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003784 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003785 Inc.get() == S->getInc() &&
3786 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003787 return SemaRef.Owned(S->Retain());
3788
Douglas Gregorebe10102009-08-20 07:17:43 +00003789 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003790 move(Init), FullCond, ConditionVar,
3791 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003792}
3793
3794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003795Sema::OwningStmtResult
3796TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003797 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003798 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003799 S->getLabel());
3800}
3801
3802template<typename Derived>
3803Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003804TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003805 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3806 if (Target.isInvalid())
3807 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003808
Douglas Gregorebe10102009-08-20 07:17:43 +00003809 if (!getDerived().AlwaysRebuild() &&
3810 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003811 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003812
3813 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3814 move(Target));
3815}
3816
3817template<typename Derived>
3818Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003819TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3820 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003821}
Mike Stump11289f42009-09-09 15:08:12 +00003822
Douglas Gregorebe10102009-08-20 07:17:43 +00003823template<typename Derived>
3824Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003825TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3826 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003827}
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregorebe10102009-08-20 07:17:43 +00003829template<typename Derived>
3830Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003831TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3833 if (Result.isInvalid())
3834 return SemaRef.StmtError();
3835
Mike Stump11289f42009-09-09 15:08:12 +00003836 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003837 // to tell whether the return type of the function has changed.
3838 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3839}
Mike Stump11289f42009-09-09 15:08:12 +00003840
Douglas Gregorebe10102009-08-20 07:17:43 +00003841template<typename Derived>
3842Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003843TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003844 bool DeclChanged = false;
3845 llvm::SmallVector<Decl *, 4> Decls;
3846 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3847 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003848 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3849 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003850 if (!Transformed)
3851 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregorebe10102009-08-20 07:17:43 +00003853 if (Transformed != *D)
3854 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003855
Douglas Gregorebe10102009-08-20 07:17:43 +00003856 Decls.push_back(Transformed);
3857 }
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregorebe10102009-08-20 07:17:43 +00003859 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003860 return SemaRef.Owned(S->Retain());
3861
3862 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003863 S->getStartLoc(), S->getEndLoc());
3864}
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregorebe10102009-08-20 07:17:43 +00003866template<typename Derived>
3867Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003868TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003869 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003870 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003871}
3872
3873template<typename Derived>
3874Sema::OwningStmtResult
3875TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003876
Anders Carlssonaaeef072010-01-24 05:50:09 +00003877 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3878 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003879 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003880
Anders Carlssonaaeef072010-01-24 05:50:09 +00003881 OwningExprResult AsmString(SemaRef);
3882 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3883
3884 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003885
Anders Carlssonaaeef072010-01-24 05:50:09 +00003886 // Go through the outputs.
3887 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003888 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003889
Anders Carlssonaaeef072010-01-24 05:50:09 +00003890 // No need to transform the constraint literal.
3891 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003892
Anders Carlssonaaeef072010-01-24 05:50:09 +00003893 // Transform the output expr.
3894 Expr *OutputExpr = S->getOutputExpr(I);
3895 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3896 if (Result.isInvalid())
3897 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003898
Anders Carlssonaaeef072010-01-24 05:50:09 +00003899 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003900
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 Exprs.push_back(Result.takeAs<Expr>());
3902 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003903
Anders Carlssonaaeef072010-01-24 05:50:09 +00003904 // Go through the inputs.
3905 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003906 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003907
Anders Carlssonaaeef072010-01-24 05:50:09 +00003908 // No need to transform the constraint literal.
3909 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003910
Anders Carlssonaaeef072010-01-24 05:50:09 +00003911 // Transform the input expr.
3912 Expr *InputExpr = S->getInputExpr(I);
3913 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3914 if (Result.isInvalid())
3915 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003916
Anders Carlssonaaeef072010-01-24 05:50:09 +00003917 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003918
Anders Carlssonaaeef072010-01-24 05:50:09 +00003919 Exprs.push_back(Result.takeAs<Expr>());
3920 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003921
Anders Carlssonaaeef072010-01-24 05:50:09 +00003922 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3923 return SemaRef.Owned(S->Retain());
3924
3925 // Go through the clobbers.
3926 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3927 Clobbers.push_back(S->getClobber(I)->Retain());
3928
3929 // No need to transform the asm string literal.
3930 AsmString = SemaRef.Owned(S->getAsmString());
3931
3932 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3933 S->isSimple(),
3934 S->isVolatile(),
3935 S->getNumOutputs(),
3936 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003937 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003938 move_arg(Constraints),
3939 move_arg(Exprs),
3940 move(AsmString),
3941 move_arg(Clobbers),
3942 S->getRParenLoc(),
3943 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003944}
3945
3946
3947template<typename Derived>
3948Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003949TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003950 // Transform the body of the @try.
3951 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3952 if (TryBody.isInvalid())
3953 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003954
Douglas Gregor96c79492010-04-23 22:50:49 +00003955 // Transform the @catch statements (if present).
3956 bool AnyCatchChanged = false;
3957 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3958 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3959 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003960 if (Catch.isInvalid())
3961 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003962 if (Catch.get() != S->getCatchStmt(I))
3963 AnyCatchChanged = true;
3964 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003965 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003966
Douglas Gregor306de2f2010-04-22 23:59:56 +00003967 // Transform the @finally statement (if present).
3968 OwningStmtResult Finally(SemaRef);
3969 if (S->getFinallyStmt()) {
3970 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3971 if (Finally.isInvalid())
3972 return SemaRef.StmtError();
3973 }
3974
3975 // If nothing changed, just retain this statement.
3976 if (!getDerived().AlwaysRebuild() &&
3977 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003978 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003979 Finally.get() == S->getFinallyStmt())
3980 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003981
Douglas Gregor306de2f2010-04-22 23:59:56 +00003982 // Build a new statement.
3983 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003984 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003985}
Mike Stump11289f42009-09-09 15:08:12 +00003986
Douglas Gregorebe10102009-08-20 07:17:43 +00003987template<typename Derived>
3988Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003989TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003990 // Transform the @catch parameter, if there is one.
3991 VarDecl *Var = 0;
3992 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3993 TypeSourceInfo *TSInfo = 0;
3994 if (FromVar->getTypeSourceInfo()) {
3995 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3996 if (!TSInfo)
3997 return SemaRef.StmtError();
3998 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003999
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004000 QualType T;
4001 if (TSInfo)
4002 T = TSInfo->getType();
4003 else {
4004 T = getDerived().TransformType(FromVar->getType());
4005 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00004006 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004007 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004008
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004009 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4010 if (!Var)
4011 return SemaRef.StmtError();
4012 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004013
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004014 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4015 if (Body.isInvalid())
4016 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004017
4018 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004019 S->getRParenLoc(),
4020 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004021}
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregorebe10102009-08-20 07:17:43 +00004023template<typename Derived>
4024Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004025TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004026 // Transform the body.
4027 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4028 if (Body.isInvalid())
4029 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004030
Douglas Gregor306de2f2010-04-22 23:59:56 +00004031 // If nothing changed, just retain this statement.
4032 if (!getDerived().AlwaysRebuild() &&
4033 Body.get() == S->getFinallyBody())
4034 return SemaRef.Owned(S->Retain());
4035
4036 // Build a new statement.
4037 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4038 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004039}
Mike Stump11289f42009-09-09 15:08:12 +00004040
Douglas Gregorebe10102009-08-20 07:17:43 +00004041template<typename Derived>
4042Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004043TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00004044 OwningExprResult Operand(SemaRef);
4045 if (S->getThrowExpr()) {
4046 Operand = getDerived().TransformExpr(S->getThrowExpr());
4047 if (Operand.isInvalid())
4048 return getSema().StmtError();
4049 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004050
Douglas Gregor2900c162010-04-22 21:44:01 +00004051 if (!getDerived().AlwaysRebuild() &&
4052 Operand.get() == S->getThrowExpr())
4053 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004054
Douglas Gregor2900c162010-04-22 21:44:01 +00004055 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00004056}
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregorebe10102009-08-20 07:17:43 +00004058template<typename Derived>
4059Sema::OwningStmtResult
4060TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004061 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004062 // Transform the object we are locking.
4063 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4064 if (Object.isInvalid())
4065 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004066
Douglas Gregor6148de72010-04-22 22:01:21 +00004067 // Transform the body.
4068 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4069 if (Body.isInvalid())
4070 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004071
Douglas Gregor6148de72010-04-22 22:01:21 +00004072 // If nothing change, just retain the current statement.
4073 if (!getDerived().AlwaysRebuild() &&
4074 Object.get() == S->getSynchExpr() &&
4075 Body.get() == S->getSynchBody())
4076 return SemaRef.Owned(S->Retain());
4077
4078 // Build a new statement.
4079 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4080 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004081}
4082
4083template<typename Derived>
4084Sema::OwningStmtResult
4085TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004086 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004087 // Transform the element statement.
4088 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4089 if (Element.isInvalid())
4090 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004091
Douglas Gregorf68a5082010-04-22 23:10:45 +00004092 // Transform the collection expression.
4093 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4094 if (Collection.isInvalid())
4095 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004096
Douglas Gregorf68a5082010-04-22 23:10:45 +00004097 // Transform the body.
4098 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4099 if (Body.isInvalid())
4100 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004101
Douglas Gregorf68a5082010-04-22 23:10:45 +00004102 // If nothing changed, just retain this statement.
4103 if (!getDerived().AlwaysRebuild() &&
4104 Element.get() == S->getElement() &&
4105 Collection.get() == S->getCollection() &&
4106 Body.get() == S->getBody())
4107 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004108
Douglas Gregorf68a5082010-04-22 23:10:45 +00004109 // Build a new statement.
4110 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4111 /*FIXME:*/S->getForLoc(),
4112 move(Element),
4113 move(Collection),
4114 S->getRParenLoc(),
4115 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004116}
4117
4118
4119template<typename Derived>
4120Sema::OwningStmtResult
4121TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4122 // Transform the exception declaration, if any.
4123 VarDecl *Var = 0;
4124 if (S->getExceptionDecl()) {
4125 VarDecl *ExceptionDecl = S->getExceptionDecl();
4126 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4127 ExceptionDecl->getDeclName());
4128
4129 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4130 if (T.isNull())
4131 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregorebe10102009-08-20 07:17:43 +00004133 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4134 T,
John McCallbcd03502009-12-07 02:54:59 +00004135 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004136 ExceptionDecl->getIdentifier(),
4137 ExceptionDecl->getLocation(),
4138 /*FIXME: Inaccurate*/
4139 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004140 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004141 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004142 }
Mike Stump11289f42009-09-09 15:08:12 +00004143
Douglas Gregorebe10102009-08-20 07:17:43 +00004144 // Transform the actual exception handler.
4145 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004146 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004147 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregorebe10102009-08-20 07:17:43 +00004149 if (!getDerived().AlwaysRebuild() &&
4150 !Var &&
4151 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004152 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004153
4154 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4155 Var,
4156 move(Handler));
4157}
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregorebe10102009-08-20 07:17:43 +00004159template<typename Derived>
4160Sema::OwningStmtResult
4161TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4162 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004163 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004164 = getDerived().TransformCompoundStmt(S->getTryBlock());
4165 if (TryBlock.isInvalid())
4166 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregorebe10102009-08-20 07:17:43 +00004168 // Transform the handlers.
4169 bool HandlerChanged = false;
4170 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4171 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004172 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004173 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4174 if (Handler.isInvalid())
4175 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004176
Douglas Gregorebe10102009-08-20 07:17:43 +00004177 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4178 Handlers.push_back(Handler.takeAs<Stmt>());
4179 }
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregorebe10102009-08-20 07:17:43 +00004181 if (!getDerived().AlwaysRebuild() &&
4182 TryBlock.get() == S->getTryBlock() &&
4183 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004184 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004185
4186 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004187 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004188}
Mike Stump11289f42009-09-09 15:08:12 +00004189
Douglas Gregorebe10102009-08-20 07:17:43 +00004190//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004191// Expression transformation
4192//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004193template<typename Derived>
4194Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004195TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004196 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
4199template<typename Derived>
4200Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004201TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004202 NestedNameSpecifier *Qualifier = 0;
4203 if (E->getQualifier()) {
4204 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004205 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004206 if (!Qualifier)
4207 return SemaRef.ExprError();
4208 }
John McCallce546572009-12-08 09:08:17 +00004209
4210 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004211 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4212 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004213 if (!ND)
4214 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004215
John McCall815039a2010-08-17 21:27:17 +00004216 DeclarationNameInfo NameInfo = E->getNameInfo();
4217 if (NameInfo.getName()) {
4218 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4219 if (!NameInfo.getName())
4220 return SemaRef.ExprError();
4221 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004222
4223 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004224 Qualifier == E->getQualifier() &&
4225 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004226 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004227 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004228
4229 // Mark it referenced in the new context regardless.
4230 // FIXME: this is a bit instantiation-specific.
4231 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4232
Mike Stump11289f42009-09-09 15:08:12 +00004233 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004234 }
John McCallce546572009-12-08 09:08:17 +00004235
4236 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004237 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004238 TemplateArgs = &TransArgs;
4239 TransArgs.setLAngleLoc(E->getLAngleLoc());
4240 TransArgs.setRAngleLoc(E->getRAngleLoc());
4241 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4242 TemplateArgumentLoc Loc;
4243 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4244 return SemaRef.ExprError();
4245 TransArgs.addArgument(Loc);
4246 }
4247 }
4248
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004249 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004250 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004251}
Mike Stump11289f42009-09-09 15:08:12 +00004252
Douglas Gregora16548e2009-08-11 05:31:07 +00004253template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004254Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004255TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004256 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004257}
Mike Stump11289f42009-09-09 15:08:12 +00004258
Douglas Gregora16548e2009-08-11 05:31:07 +00004259template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004260Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004261TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004262 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004263}
Mike Stump11289f42009-09-09 15:08:12 +00004264
Douglas Gregora16548e2009-08-11 05:31:07 +00004265template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004266Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004267TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004268 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004269}
Mike Stump11289f42009-09-09 15:08:12 +00004270
Douglas Gregora16548e2009-08-11 05:31:07 +00004271template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004272Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004273TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004274 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004275}
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004278Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004279TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004280 return SemaRef.Owned(E->Retain());
4281}
4282
4283template<typename Derived>
4284Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004285TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4287 if (SubExpr.isInvalid())
4288 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004289
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004291 return SemaRef.Owned(E->Retain());
4292
4293 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004294 E->getRParen());
4295}
4296
Mike Stump11289f42009-09-09 15:08:12 +00004297template<typename Derived>
4298Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004299TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4300 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 if (SubExpr.isInvalid())
4302 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004303
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004305 return SemaRef.Owned(E->Retain());
4306
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4308 E->getOpcode(),
4309 move(SubExpr));
4310}
Mike Stump11289f42009-09-09 15:08:12 +00004311
Douglas Gregora16548e2009-08-11 05:31:07 +00004312template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004313Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004314TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4315 // Transform the type.
4316 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4317 if (!Type)
4318 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004319
Douglas Gregor882211c2010-04-28 22:16:22 +00004320 // Transform all of the components into components similar to what the
4321 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004322 // FIXME: It would be slightly more efficient in the non-dependent case to
4323 // just map FieldDecls, rather than requiring the rebuilder to look for
4324 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004325 // template code that we don't care.
4326 bool ExprChanged = false;
4327 typedef Action::OffsetOfComponent Component;
4328 typedef OffsetOfExpr::OffsetOfNode Node;
4329 llvm::SmallVector<Component, 4> Components;
4330 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4331 const Node &ON = E->getComponent(I);
4332 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004333 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004334 Comp.LocStart = ON.getRange().getBegin();
4335 Comp.LocEnd = ON.getRange().getEnd();
4336 switch (ON.getKind()) {
4337 case Node::Array: {
4338 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4339 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4340 if (Index.isInvalid())
4341 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004342
Douglas Gregor882211c2010-04-28 22:16:22 +00004343 ExprChanged = ExprChanged || Index.get() != FromIndex;
4344 Comp.isBrackets = true;
4345 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4346 break;
4347 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004348
Douglas Gregor882211c2010-04-28 22:16:22 +00004349 case Node::Field:
4350 case Node::Identifier:
4351 Comp.isBrackets = false;
4352 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004353 if (!Comp.U.IdentInfo)
4354 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004355
Douglas Gregor882211c2010-04-28 22:16:22 +00004356 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004357
Douglas Gregord1702062010-04-29 00:18:15 +00004358 case Node::Base:
4359 // Will be recomputed during the rebuild.
4360 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004361 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004362
Douglas Gregor882211c2010-04-28 22:16:22 +00004363 Components.push_back(Comp);
4364 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004365
Douglas Gregor882211c2010-04-28 22:16:22 +00004366 // If nothing changed, retain the existing expression.
4367 if (!getDerived().AlwaysRebuild() &&
4368 Type == E->getTypeSourceInfo() &&
4369 !ExprChanged)
4370 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004371
Douglas Gregor882211c2010-04-28 22:16:22 +00004372 // Build a new offsetof expression.
4373 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4374 Components.data(), Components.size(),
4375 E->getRParenLoc());
4376}
4377
4378template<typename Derived>
4379Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004380TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004382 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004383
John McCallbcd03502009-12-07 02:54:59 +00004384 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004385 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004387
John McCall4c98fd82009-11-04 07:28:41 +00004388 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004389 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004390
John McCall4c98fd82009-11-04 07:28:41 +00004391 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004392 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 E->getSourceRange());
4394 }
Mike Stump11289f42009-09-09 15:08:12 +00004395
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004397 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 // C++0x [expr.sizeof]p1:
4399 // The operand is either an expression, which is an unevaluated operand
4400 // [...]
4401 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004402
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4404 if (SubExpr.isInvalid())
4405 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregora16548e2009-08-11 05:31:07 +00004407 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4408 return SemaRef.Owned(E->Retain());
4409 }
Mike Stump11289f42009-09-09 15:08:12 +00004410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4412 E->isSizeOf(),
4413 E->getSourceRange());
4414}
Mike Stump11289f42009-09-09 15:08:12 +00004415
Douglas Gregora16548e2009-08-11 05:31:07 +00004416template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004417Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004418TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4420 if (LHS.isInvalid())
4421 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4424 if (RHS.isInvalid())
4425 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004426
4427
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 if (!getDerived().AlwaysRebuild() &&
4429 LHS.get() == E->getLHS() &&
4430 RHS.get() == E->getRHS())
4431 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4434 /*FIXME:*/E->getLHS()->getLocStart(),
4435 move(RHS),
4436 E->getRBracketLoc());
4437}
Mike Stump11289f42009-09-09 15:08:12 +00004438
4439template<typename Derived>
4440Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004441TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 // Transform the callee.
4443 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4444 if (Callee.isInvalid())
4445 return SemaRef.ExprError();
4446
4447 // Transform arguments.
4448 bool ArgChanged = false;
4449 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4450 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4451 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4452 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4453 if (Arg.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 // FIXME: Wrong source location information for the ','.
4457 FakeCommaLocs.push_back(
4458 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004459
4460 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 Args.push_back(Arg.takeAs<Expr>());
4462 }
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 if (!getDerived().AlwaysRebuild() &&
4465 Callee.get() == E->getCallee() &&
4466 !ArgChanged)
4467 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregora16548e2009-08-11 05:31:07 +00004469 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004470 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4472 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4473 move_arg(Args),
4474 FakeCommaLocs.data(),
4475 E->getRParenLoc());
4476}
Mike Stump11289f42009-09-09 15:08:12 +00004477
4478template<typename Derived>
4479Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004480TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4482 if (Base.isInvalid())
4483 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004485 NestedNameSpecifier *Qualifier = 0;
4486 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004487 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004488 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004489 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004490 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004491 return SemaRef.ExprError();
4492 }
Mike Stump11289f42009-09-09 15:08:12 +00004493
Eli Friedman2cfcef62009-12-04 06:40:45 +00004494 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004495 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4496 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 if (!Member)
4498 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
John McCall16df1e52010-03-30 21:47:33 +00004500 NamedDecl *FoundDecl = E->getFoundDecl();
4501 if (FoundDecl == E->getMemberDecl()) {
4502 FoundDecl = Member;
4503 } else {
4504 FoundDecl = cast_or_null<NamedDecl>(
4505 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4506 if (!FoundDecl)
4507 return SemaRef.ExprError();
4508 }
4509
Douglas Gregora16548e2009-08-11 05:31:07 +00004510 if (!getDerived().AlwaysRebuild() &&
4511 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004512 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004513 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004514 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004515 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004516
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004517 // Mark it referenced in the new context regardless.
4518 // FIXME: this is a bit instantiation-specific.
4519 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004520 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004521 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004522
John McCall6b51f282009-11-23 01:53:49 +00004523 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004524 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004525 TransArgs.setLAngleLoc(E->getLAngleLoc());
4526 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004527 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004528 TemplateArgumentLoc Loc;
4529 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004530 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004531 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004532 }
4533 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004534
Douglas Gregora16548e2009-08-11 05:31:07 +00004535 // FIXME: Bogus source location for the operator
4536 SourceLocation FakeOperatorLoc
4537 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4538
John McCall38836f02010-01-15 08:34:02 +00004539 // FIXME: to do this check properly, we will need to preserve the
4540 // first-qualifier-in-scope here, just in case we had a dependent
4541 // base (and therefore couldn't do the check) and a
4542 // nested-name-qualifier (and therefore could do the lookup).
4543 NamedDecl *FirstQualifierInScope = 0;
4544
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4546 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004547 Qualifier,
4548 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004549 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004550 Member,
John McCall16df1e52010-03-30 21:47:33 +00004551 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004552 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004553 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004554 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004555}
Mike Stump11289f42009-09-09 15:08:12 +00004556
Douglas Gregora16548e2009-08-11 05:31:07 +00004557template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004558Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004559TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4561 if (LHS.isInvalid())
4562 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4565 if (RHS.isInvalid())
4566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 if (!getDerived().AlwaysRebuild() &&
4569 LHS.get() == E->getLHS() &&
4570 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004571 return SemaRef.Owned(E->Retain());
4572
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4574 move(LHS), move(RHS));
4575}
4576
Mike Stump11289f42009-09-09 15:08:12 +00004577template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004578Sema::OwningExprResult
4579TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004580 CompoundAssignOperator *E) {
4581 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004582}
Mike Stump11289f42009-09-09 15:08:12 +00004583
Douglas Gregora16548e2009-08-11 05:31:07 +00004584template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004585Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004586TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4588 if (Cond.isInvalid())
4589 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4592 if (LHS.isInvalid())
4593 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4596 if (RHS.isInvalid())
4597 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004598
Douglas Gregora16548e2009-08-11 05:31:07 +00004599 if (!getDerived().AlwaysRebuild() &&
4600 Cond.get() == E->getCond() &&
4601 LHS.get() == E->getLHS() &&
4602 RHS.get() == E->getRHS())
4603 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004604
4605 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004606 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004607 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004608 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 move(RHS));
4610}
Mike Stump11289f42009-09-09 15:08:12 +00004611
4612template<typename Derived>
4613Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004614TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004615 // Implicit casts are eliminated during transformation, since they
4616 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004617 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregora16548e2009-08-11 05:31:07 +00004620template<typename Derived>
4621Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004622TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004623 TypeSourceInfo *OldT;
4624 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 {
4626 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004627 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4629 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004630
John McCall97513962010-01-15 18:39:57 +00004631 OldT = E->getTypeInfoAsWritten();
4632 NewT = getDerived().TransformType(OldT);
4633 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 return SemaRef.ExprError();
4635 }
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregor6131b442009-12-12 18:16:41 +00004637 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004638 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 if (SubExpr.isInvalid())
4640 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004643 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004644 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004645 return SemaRef.Owned(E->Retain());
4646
John McCall97513962010-01-15 18:39:57 +00004647 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4648 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 E->getRParenLoc(),
4650 move(SubExpr));
4651}
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004654Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004655TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004656 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4657 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4658 if (!NewT)
4659 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregora16548e2009-08-11 05:31:07 +00004661 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4662 if (Init.isInvalid())
4663 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004666 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004668 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004669
John McCall5d7aa7f2010-01-19 22:33:45 +00004670 // Note: the expression type doesn't necessarily match the
4671 // type-as-written, but that's okay, because it should always be
4672 // derivable from the initializer.
4673
John McCalle15bbff2010-01-18 19:35:47 +00004674 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 /*FIXME:*/E->getInitializer()->getLocEnd(),
4676 move(Init));
4677}
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregora16548e2009-08-11 05:31:07 +00004679template<typename Derived>
4680Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004681TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4683 if (Base.isInvalid())
4684 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregora16548e2009-08-11 05:31:07 +00004686 if (!getDerived().AlwaysRebuild() &&
4687 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004688 return SemaRef.Owned(E->Retain());
4689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004691 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4693 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4694 E->getAccessorLoc(),
4695 E->getAccessor());
4696}
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregora16548e2009-08-11 05:31:07 +00004698template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004699Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004700TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4704 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4705 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4706 if (Init.isInvalid())
4707 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 InitChanged = InitChanged || Init.get() != E->getInit(I);
4710 Inits.push_back(Init.takeAs<Expr>());
4711 }
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004714 return SemaRef.Owned(E->Retain());
4715
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004717 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004718}
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregora16548e2009-08-11 05:31:07 +00004720template<typename Derived>
4721Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004722TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregorebe10102009-08-20 07:17:43 +00004725 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4727 if (Init.isInvalid())
4728 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregorebe10102009-08-20 07:17:43 +00004730 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4732 bool ExprChanged = false;
4733 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4734 DEnd = E->designators_end();
4735 D != DEnd; ++D) {
4736 if (D->isFieldDesignator()) {
4737 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4738 D->getDotLoc(),
4739 D->getFieldLoc()));
4740 continue;
4741 }
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 if (D->isArrayDesignator()) {
4744 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4745 if (Index.isInvalid())
4746 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004747
4748 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004749 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4752 ArrayExprs.push_back(Index.release());
4753 continue;
4754 }
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004757 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4759 if (Start.isInvalid())
4760 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4763 if (End.isInvalid())
4764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004765
4766 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 End.get(),
4768 D->getLBracketLoc(),
4769 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4772 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 ArrayExprs.push_back(Start.release());
4775 ArrayExprs.push_back(End.release());
4776 }
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 if (!getDerived().AlwaysRebuild() &&
4779 Init.get() == E->getInit() &&
4780 !ExprChanged)
4781 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4784 E->getEqualOrColonLoc(),
4785 E->usesGNUSyntax(), move(Init));
4786}
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004789Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004790TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004791 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004792 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004793
Douglas Gregor3da3c062009-10-28 00:29:27 +00004794 // FIXME: Will we ever have proper type location here? Will we actually
4795 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 QualType T = getDerived().TransformType(E->getType());
4797 if (T.isNull())
4798 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 if (!getDerived().AlwaysRebuild() &&
4801 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004802 return SemaRef.Owned(E->Retain());
4803
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 return getDerived().RebuildImplicitValueInitExpr(T);
4805}
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004808Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004809TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004810 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4811 if (!TInfo)
4812 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4815 if (SubExpr.isInvalid())
4816 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004819 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 SubExpr.get() == E->getSubExpr())
4821 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004824 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004825}
4826
4827template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004828Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004829TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 bool ArgumentChanged = false;
4831 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4832 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4833 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4834 if (Init.isInvalid())
4835 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4838 Inits.push_back(Init.takeAs<Expr>());
4839 }
Mike Stump11289f42009-09-09 15:08:12 +00004840
Douglas Gregora16548e2009-08-11 05:31:07 +00004841 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4842 move_arg(Inits),
4843 E->getRParenLoc());
4844}
Mike Stump11289f42009-09-09 15:08:12 +00004845
Douglas Gregora16548e2009-08-11 05:31:07 +00004846/// \brief Transform an address-of-label expression.
4847///
4848/// By default, the transformation of an address-of-label expression always
4849/// rebuilds the expression, so that the label identifier can be resolved to
4850/// the corresponding label statement by semantic analysis.
4851template<typename Derived>
4852Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004853TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4855 E->getLabel());
4856}
Mike Stump11289f42009-09-09 15:08:12 +00004857
4858template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004859Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004860TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004861 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4863 if (SubStmt.isInvalid())
4864 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 if (!getDerived().AlwaysRebuild() &&
4867 SubStmt.get() == E->getSubStmt())
4868 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004869
4870 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 move(SubStmt),
4872 E->getRParenLoc());
4873}
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875template<typename Derived>
4876Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004877TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004878 TypeSourceInfo *TInfo1;
4879 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004880
4881 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4882 if (!TInfo1)
4883 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004884
Douglas Gregor7058c262010-08-10 14:27:00 +00004885 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4886 if (!TInfo2)
4887 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004888
4889 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004890 TInfo1 == E->getArgTInfo1() &&
4891 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004892 return SemaRef.Owned(E->Retain());
4893
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004895 TInfo1, TInfo2,
4896 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004897}
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899template<typename Derived>
4900Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004901TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004902 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4903 if (Cond.isInvalid())
4904 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004905
Douglas Gregora16548e2009-08-11 05:31:07 +00004906 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4907 if (LHS.isInvalid())
4908 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004909
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4911 if (RHS.isInvalid())
4912 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004913
Douglas Gregora16548e2009-08-11 05:31:07 +00004914 if (!getDerived().AlwaysRebuild() &&
4915 Cond.get() == E->getCond() &&
4916 LHS.get() == E->getLHS() &&
4917 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004918 return SemaRef.Owned(E->Retain());
4919
Douglas Gregora16548e2009-08-11 05:31:07 +00004920 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4921 move(Cond), move(LHS), move(RHS),
4922 E->getRParenLoc());
4923}
Mike Stump11289f42009-09-09 15:08:12 +00004924
Douglas Gregora16548e2009-08-11 05:31:07 +00004925template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004926Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004927TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004928 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004929}
4930
4931template<typename Derived>
4932Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004933TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004934 switch (E->getOperator()) {
4935 case OO_New:
4936 case OO_Delete:
4937 case OO_Array_New:
4938 case OO_Array_Delete:
4939 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4940 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004941
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004942 case OO_Call: {
4943 // This is a call to an object's operator().
4944 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4945
4946 // Transform the object itself.
4947 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4948 if (Object.isInvalid())
4949 return SemaRef.ExprError();
4950
4951 // FIXME: Poor location information
4952 SourceLocation FakeLParenLoc
4953 = SemaRef.PP.getLocForEndOfToken(
4954 static_cast<Expr *>(Object.get())->getLocEnd());
4955
4956 // Transform the call arguments.
4957 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4958 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4959 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004960 if (getDerived().DropCallArgument(E->getArg(I)))
4961 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004962
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004963 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4964 if (Arg.isInvalid())
4965 return SemaRef.ExprError();
4966
4967 // FIXME: Poor source location information.
4968 SourceLocation FakeCommaLoc
4969 = SemaRef.PP.getLocForEndOfToken(
4970 static_cast<Expr *>(Arg.get())->getLocEnd());
4971 FakeCommaLocs.push_back(FakeCommaLoc);
4972 Args.push_back(Arg.release());
4973 }
4974
4975 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4976 move_arg(Args),
4977 FakeCommaLocs.data(),
4978 E->getLocEnd());
4979 }
4980
4981#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4982 case OO_##Name:
4983#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4984#include "clang/Basic/OperatorKinds.def"
4985 case OO_Subscript:
4986 // Handled below.
4987 break;
4988
4989 case OO_Conditional:
4990 llvm_unreachable("conditional operator is not actually overloadable");
4991 return SemaRef.ExprError();
4992
4993 case OO_None:
4994 case NUM_OVERLOADED_OPERATORS:
4995 llvm_unreachable("not an overloaded operator?");
4996 return SemaRef.ExprError();
4997 }
4998
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
5000 if (Callee.isInvalid())
5001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005002
John McCall47f29ea2009-12-08 09:21:05 +00005003 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 if (First.isInvalid())
5005 return SemaRef.ExprError();
5006
5007 OwningExprResult Second(SemaRef);
5008 if (E->getNumArgs() == 2) {
5009 Second = getDerived().TransformExpr(E->getArg(1));
5010 if (Second.isInvalid())
5011 return SemaRef.ExprError();
5012 }
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 if (!getDerived().AlwaysRebuild() &&
5015 Callee.get() == E->getCallee() &&
5016 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005017 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5018 return SemaRef.Owned(E->Retain());
5019
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5021 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005022 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 move(First),
5024 move(Second));
5025}
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregora16548e2009-08-11 05:31:07 +00005027template<typename Derived>
5028Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005029TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5030 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregora16548e2009-08-11 05:31:07 +00005033template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005034Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005035TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005036 TypeSourceInfo *OldT;
5037 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 {
5039 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005040 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5042 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005043
John McCall97513962010-01-15 18:39:57 +00005044 OldT = E->getTypeInfoAsWritten();
5045 NewT = getDerived().TransformType(OldT);
5046 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 return SemaRef.ExprError();
5048 }
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregor6131b442009-12-12 18:16:41 +00005050 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005051 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 if (SubExpr.isInvalid())
5053 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005054
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005056 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005057 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005058 return SemaRef.Owned(E->Retain());
5059
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005061 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5063 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5064 SourceLocation FakeRParenLoc
5065 = SemaRef.PP.getLocForEndOfToken(
5066 E->getSubExpr()->getSourceRange().getEnd());
5067 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005068 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005069 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005070 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 FakeRAngleLoc,
5072 FakeRAngleLoc,
5073 move(SubExpr),
5074 FakeRParenLoc);
5075}
Mike Stump11289f42009-09-09 15:08:12 +00005076
Douglas Gregora16548e2009-08-11 05:31:07 +00005077template<typename Derived>
5078Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005079TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5080 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005081}
Mike Stump11289f42009-09-09 15:08:12 +00005082
5083template<typename Derived>
5084Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005085TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5086 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005087}
5088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089template<typename Derived>
5090Sema::OwningExprResult
5091TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005092 CXXReinterpretCastExpr *E) {
5093 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096template<typename Derived>
5097Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005098TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5099 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005100}
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregora16548e2009-08-11 05:31:07 +00005102template<typename Derived>
5103Sema::OwningExprResult
5104TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005105 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005106 TypeSourceInfo *OldT;
5107 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 {
5109 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005110
John McCall97513962010-01-15 18:39:57 +00005111 OldT = E->getTypeInfoAsWritten();
5112 NewT = getDerived().TransformType(OldT);
5113 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 return SemaRef.ExprError();
5115 }
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregor6131b442009-12-12 18:16:41 +00005117 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005118 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 if (SubExpr.isInvalid())
5120 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregora16548e2009-08-11 05:31:07 +00005122 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005123 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005125 return SemaRef.Owned(E->Retain());
5126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 // FIXME: The end of the type's source range is wrong
5128 return getDerived().RebuildCXXFunctionalCastExpr(
5129 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005130 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 /*FIXME:*/E->getSubExpr()->getLocStart(),
5132 move(SubExpr),
5133 E->getRParenLoc());
5134}
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregora16548e2009-08-11 05:31:07 +00005136template<typename Derived>
5137Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005138TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005140 TypeSourceInfo *TInfo
5141 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5142 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005146 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005147 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005148
Douglas Gregor9da64192010-04-26 22:37:10 +00005149 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5150 E->getLocStart(),
5151 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005152 E->getLocEnd());
5153 }
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 // We don't know whether the expression is potentially evaluated until
5156 // after we perform semantic analysis, so the expression is potentially
5157 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005158 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005160
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5162 if (SubExpr.isInvalid())
5163 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 if (!getDerived().AlwaysRebuild() &&
5166 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005167 return SemaRef.Owned(E->Retain());
5168
Douglas Gregor9da64192010-04-26 22:37:10 +00005169 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5170 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005171 move(SubExpr),
5172 E->getLocEnd());
5173}
5174
5175template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005176Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005178 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005179}
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregora16548e2009-08-11 05:31:07 +00005181template<typename Derived>
5182Sema::OwningExprResult
5183TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005184 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005185 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregora16548e2009-08-11 05:31:07 +00005188template<typename Derived>
5189Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005191 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 QualType T = getDerived().TransformType(E->getType());
5194 if (T.isNull())
5195 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 if (!getDerived().AlwaysRebuild() &&
5198 T == E->getType())
5199 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregorb15af892010-01-07 23:12:05 +00005201 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005202}
Mike Stump11289f42009-09-09 15:08:12 +00005203
Douglas Gregora16548e2009-08-11 05:31:07 +00005204template<typename Derived>
5205Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005206TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005207 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5208 if (SubExpr.isInvalid())
5209 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005210
Douglas Gregora16548e2009-08-11 05:31:07 +00005211 if (!getDerived().AlwaysRebuild() &&
5212 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005213 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005214
5215 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5216}
Mike Stump11289f42009-09-09 15:08:12 +00005217
Douglas Gregora16548e2009-08-11 05:31:07 +00005218template<typename Derived>
5219Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005220TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005221 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005222 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5223 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005224 if (!Param)
5225 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005226
Chandler Carruth794da4c2010-02-08 06:42:49 +00005227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005228 Param == E->getParam())
5229 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregor033f6752009-12-23 23:03:06 +00005231 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005232}
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregora16548e2009-08-11 05:31:07 +00005234template<typename Derived>
5235Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005236TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5238
5239 QualType T = getDerived().TransformType(E->getType());
5240 if (T.isNull())
5241 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 if (!getDerived().AlwaysRebuild() &&
5244 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005245 return SemaRef.Owned(E->Retain());
5246
Douglas Gregor747eb782010-07-08 06:14:04 +00005247 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5248 /*FIXME:*/E->getTypeBeginLoc(),
5249 T,
5250 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005251}
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregora16548e2009-08-11 05:31:07 +00005253template<typename Derived>
5254Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005255TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 // Transform the type that we're allocating
5257 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5258 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5259 if (AllocType.isNull())
5260 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005261
Douglas Gregora16548e2009-08-11 05:31:07 +00005262 // Transform the size of the array we're allocating (if any).
5263 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5264 if (ArraySize.isInvalid())
5265 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregora16548e2009-08-11 05:31:07 +00005267 // Transform the placement arguments (if any).
5268 bool ArgumentChanged = false;
5269 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5270 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5271 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5272 if (Arg.isInvalid())
5273 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005274
Douglas Gregora16548e2009-08-11 05:31:07 +00005275 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5276 PlacementArgs.push_back(Arg.take());
5277 }
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregorebe10102009-08-20 07:17:43 +00005279 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005280 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5281 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005282 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5283 break;
5284
Douglas Gregora16548e2009-08-11 05:31:07 +00005285 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5286 if (Arg.isInvalid())
5287 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregora16548e2009-08-11 05:31:07 +00005289 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5290 ConstructorArgs.push_back(Arg.take());
5291 }
Mike Stump11289f42009-09-09 15:08:12 +00005292
Douglas Gregord2d9da02010-02-26 00:38:10 +00005293 // Transform constructor, new operator, and delete operator.
5294 CXXConstructorDecl *Constructor = 0;
5295 if (E->getConstructor()) {
5296 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005297 getDerived().TransformDecl(E->getLocStart(),
5298 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005299 if (!Constructor)
5300 return SemaRef.ExprError();
5301 }
5302
5303 FunctionDecl *OperatorNew = 0;
5304 if (E->getOperatorNew()) {
5305 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005306 getDerived().TransformDecl(E->getLocStart(),
5307 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005308 if (!OperatorNew)
5309 return SemaRef.ExprError();
5310 }
5311
5312 FunctionDecl *OperatorDelete = 0;
5313 if (E->getOperatorDelete()) {
5314 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005315 getDerived().TransformDecl(E->getLocStart(),
5316 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005317 if (!OperatorDelete)
5318 return SemaRef.ExprError();
5319 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005320
Douglas Gregora16548e2009-08-11 05:31:07 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 AllocType == E->getAllocatedType() &&
5323 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005324 Constructor == E->getConstructor() &&
5325 OperatorNew == E->getOperatorNew() &&
5326 OperatorDelete == E->getOperatorDelete() &&
5327 !ArgumentChanged) {
5328 // Mark any declarations we need as referenced.
5329 // FIXME: instantiation-specific.
5330 if (Constructor)
5331 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5332 if (OperatorNew)
5333 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5334 if (OperatorDelete)
5335 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005336 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005337 }
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005339 if (!ArraySize.get()) {
5340 // If no array size was specified, but the new expression was
5341 // instantiated with an array type (e.g., "new T" where T is
5342 // instantiated with "int[4]"), extract the outer bound from the
5343 // array type as our array size. We do this with constant and
5344 // dependently-sized array types.
5345 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5346 if (!ArrayT) {
5347 // Do nothing
5348 } else if (const ConstantArrayType *ConsArrayT
5349 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005350 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005351 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005352 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005353 SemaRef.Context.getSizeType(),
5354 /*FIXME:*/E->getLocStart()));
5355 AllocType = ConsArrayT->getElementType();
5356 } else if (const DependentSizedArrayType *DepArrayT
5357 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5358 if (DepArrayT->getSizeExpr()) {
5359 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5360 AllocType = DepArrayT->getElementType();
5361 }
5362 }
5363 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005364 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5365 E->isGlobalNew(),
5366 /*FIXME:*/E->getLocStart(),
5367 move_arg(PlacementArgs),
5368 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005369 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005370 AllocType,
5371 /*FIXME:*/E->getLocStart(),
5372 /*FIXME:*/SourceRange(),
5373 move(ArraySize),
5374 /*FIXME:*/E->getLocStart(),
5375 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005376 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005377}
Mike Stump11289f42009-09-09 15:08:12 +00005378
Douglas Gregora16548e2009-08-11 05:31:07 +00005379template<typename Derived>
5380Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005381TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5383 if (Operand.isInvalid())
5384 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregord2d9da02010-02-26 00:38:10 +00005386 // Transform the delete operator, if known.
5387 FunctionDecl *OperatorDelete = 0;
5388 if (E->getOperatorDelete()) {
5389 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005390 getDerived().TransformDecl(E->getLocStart(),
5391 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005392 if (!OperatorDelete)
5393 return SemaRef.ExprError();
5394 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005397 Operand.get() == E->getArgument() &&
5398 OperatorDelete == E->getOperatorDelete()) {
5399 // Mark any declarations we need as referenced.
5400 // FIXME: instantiation-specific.
5401 if (OperatorDelete)
5402 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005403 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005404 }
Mike Stump11289f42009-09-09 15:08:12 +00005405
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5407 E->isGlobalDelete(),
5408 E->isArrayForm(),
5409 move(Operand));
5410}
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregora16548e2009-08-11 05:31:07 +00005412template<typename Derived>
5413Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005414TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005415 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005416 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5417 if (Base.isInvalid())
5418 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregor678f90d2010-02-25 01:56:36 +00005420 Sema::TypeTy *ObjectTypePtr = 0;
5421 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005422 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005423 E->getOperatorLoc(),
5424 E->isArrow()? tok::arrow : tok::period,
5425 ObjectTypePtr,
5426 MayBePseudoDestructor);
5427 if (Base.isInvalid())
5428 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005429
Douglas Gregor678f90d2010-02-25 01:56:36 +00005430 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005431 NestedNameSpecifier *Qualifier
5432 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005433 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005434 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005435 if (E->getQualifier() && !Qualifier)
5436 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005437
Douglas Gregor678f90d2010-02-25 01:56:36 +00005438 PseudoDestructorTypeStorage Destroyed;
5439 if (E->getDestroyedTypeInfo()) {
5440 TypeSourceInfo *DestroyedTypeInfo
5441 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5442 if (!DestroyedTypeInfo)
5443 return SemaRef.ExprError();
5444 Destroyed = DestroyedTypeInfo;
5445 } else if (ObjectType->isDependentType()) {
5446 // We aren't likely to be able to resolve the identifier down to a type
5447 // now anyway, so just retain the identifier.
5448 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5449 E->getDestroyedTypeLoc());
5450 } else {
5451 // Look for a destructor known with the given name.
5452 CXXScopeSpec SS;
5453 if (Qualifier) {
5454 SS.setScopeRep(Qualifier);
5455 SS.setRange(E->getQualifierRange());
5456 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005457
Douglas Gregor678f90d2010-02-25 01:56:36 +00005458 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5459 *E->getDestroyedTypeIdentifier(),
5460 E->getDestroyedTypeLoc(),
5461 /*Scope=*/0,
5462 SS, ObjectTypePtr,
5463 false);
5464 if (!T)
5465 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005466
Douglas Gregor678f90d2010-02-25 01:56:36 +00005467 Destroyed
5468 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5469 E->getDestroyedTypeLoc());
5470 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005471
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005472 TypeSourceInfo *ScopeTypeInfo = 0;
5473 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005474 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005475 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005476 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005477 return SemaRef.ExprError();
5478 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005479
Douglas Gregorad8a3362009-09-04 17:36:40 +00005480 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5481 E->getOperatorLoc(),
5482 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005483 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005484 E->getQualifierRange(),
5485 ScopeTypeInfo,
5486 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005487 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005488 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005489}
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregorad8a3362009-09-04 17:36:40 +00005491template<typename Derived>
5492Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005493TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005494 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005495 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5496
5497 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5498 Sema::LookupOrdinaryName);
5499
5500 // Transform all the decls.
5501 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5502 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005503 NamedDecl *InstD = static_cast<NamedDecl*>(
5504 getDerived().TransformDecl(Old->getNameLoc(),
5505 *I));
John McCall84d87672009-12-10 09:41:52 +00005506 if (!InstD) {
5507 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5508 // This can happen because of dependent hiding.
5509 if (isa<UsingShadowDecl>(*I))
5510 continue;
5511 else
5512 return SemaRef.ExprError();
5513 }
John McCalle66edc12009-11-24 19:00:30 +00005514
5515 // Expand using declarations.
5516 if (isa<UsingDecl>(InstD)) {
5517 UsingDecl *UD = cast<UsingDecl>(InstD);
5518 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5519 E = UD->shadow_end(); I != E; ++I)
5520 R.addDecl(*I);
5521 continue;
5522 }
5523
5524 R.addDecl(InstD);
5525 }
5526
5527 // Resolve a kind, but don't do any further analysis. If it's
5528 // ambiguous, the callee needs to deal with it.
5529 R.resolveKind();
5530
5531 // Rebuild the nested-name qualifier, if present.
5532 CXXScopeSpec SS;
5533 NestedNameSpecifier *Qualifier = 0;
5534 if (Old->getQualifier()) {
5535 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005536 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005537 if (!Qualifier)
5538 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005539
John McCalle66edc12009-11-24 19:00:30 +00005540 SS.setScopeRep(Qualifier);
5541 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005542 }
5543
Douglas Gregor9262f472010-04-27 18:19:34 +00005544 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005545 CXXRecordDecl *NamingClass
5546 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5547 Old->getNameLoc(),
5548 Old->getNamingClass()));
5549 if (!NamingClass)
5550 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005551
Douglas Gregorda7be082010-04-27 16:10:10 +00005552 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005553 }
5554
5555 // If we have no template arguments, it's a normal declaration name.
5556 if (!Old->hasExplicitTemplateArgs())
5557 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5558
5559 // If we have template arguments, rebuild them, then rebuild the
5560 // templateid expression.
5561 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5562 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5563 TemplateArgumentLoc Loc;
5564 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5565 return SemaRef.ExprError();
5566 TransArgs.addArgument(Loc);
5567 }
5568
5569 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5570 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005571}
Mike Stump11289f42009-09-09 15:08:12 +00005572
Douglas Gregora16548e2009-08-11 05:31:07 +00005573template<typename Derived>
5574Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005575TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005577
Douglas Gregora16548e2009-08-11 05:31:07 +00005578 QualType T = getDerived().TransformType(E->getQueriedType());
5579 if (T.isNull())
5580 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 if (!getDerived().AlwaysRebuild() &&
5583 T == E->getQueriedType())
5584 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregora16548e2009-08-11 05:31:07 +00005586 // FIXME: Bad location information
5587 SourceLocation FakeLParenLoc
5588 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005589
5590 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005591 E->getLocStart(),
5592 /*FIXME:*/FakeLParenLoc,
5593 T,
5594 E->getLocEnd());
5595}
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregora16548e2009-08-11 05:31:07 +00005597template<typename Derived>
5598Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005599TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005600 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005602 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005603 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 if (!NNS)
5605 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005606
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005607 DeclarationNameInfo NameInfo
5608 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5609 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005610 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005611
John McCalle66edc12009-11-24 19:00:30 +00005612 if (!E->hasExplicitTemplateArgs()) {
5613 if (!getDerived().AlwaysRebuild() &&
5614 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005615 // Note: it is sufficient to compare the Name component of NameInfo:
5616 // if name has not changed, DNLoc has not changed either.
5617 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005618 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005619
John McCalle66edc12009-11-24 19:00:30 +00005620 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5621 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005622 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005623 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005624 }
John McCall6b51f282009-11-23 01:53:49 +00005625
5626 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005628 TemplateArgumentLoc Loc;
5629 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005630 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005631 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 }
5633
John McCalle66edc12009-11-24 19:00:30 +00005634 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5635 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005636 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005637 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005638}
5639
5640template<typename Derived>
5641Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005642TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005643 // CXXConstructExprs are always implicit, so when we have a
5644 // 1-argument construction we just transform that argument.
5645 if (E->getNumArgs() == 1 ||
5646 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5647 return getDerived().TransformExpr(E->getArg(0));
5648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5650
5651 QualType T = getDerived().TransformType(E->getType());
5652 if (T.isNull())
5653 return SemaRef.ExprError();
5654
5655 CXXConstructorDecl *Constructor
5656 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005657 getDerived().TransformDecl(E->getLocStart(),
5658 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 if (!Constructor)
5660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 bool ArgumentChanged = false;
5663 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005664 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 ArgEnd = E->arg_end();
5666 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005667 if (getDerived().DropCallArgument(*Arg)) {
5668 ArgumentChanged = true;
5669 break;
5670 }
5671
Douglas Gregora16548e2009-08-11 05:31:07 +00005672 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5673 if (TransArg.isInvalid())
5674 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5677 Args.push_back(TransArg.takeAs<Expr>());
5678 }
5679
5680 if (!getDerived().AlwaysRebuild() &&
5681 T == E->getType() &&
5682 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005683 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005684 // Mark the constructor as referenced.
5685 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005686 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005688 }
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregordb121ba2009-12-14 16:27:04 +00005690 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5691 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005692 move_arg(Args),
5693 E->requiresZeroInitialization(),
5694 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005695}
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697/// \brief Transform a C++ temporary-binding expression.
5698///
Douglas Gregor363b1512009-12-24 18:51:59 +00005699/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5700/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005701template<typename Derived>
5702Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005703TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005704 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Anders Carlssonba6c4372010-01-29 02:39:32 +00005707/// \brief Transform a C++ reference-binding expression.
5708///
5709/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5710/// transform the subexpression and return that.
5711template<typename Derived>
5712Sema::OwningExprResult
5713TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5714 return getDerived().TransformExpr(E->getSubExpr());
5715}
5716
Mike Stump11289f42009-09-09 15:08:12 +00005717/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005718/// be destroyed after the expression is evaluated.
5719///
Douglas Gregor363b1512009-12-24 18:51:59 +00005720/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5721/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005722template<typename Derived>
5723Sema::OwningExprResult
5724TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005725 CXXExprWithTemporaries *E) {
5726 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005727}
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregora16548e2009-08-11 05:31:07 +00005729template<typename Derived>
5730Sema::OwningExprResult
5731TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005732 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5734 QualType T = getDerived().TransformType(E->getType());
5735 if (T.isNull())
5736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 CXXConstructorDecl *Constructor
5739 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005740 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005741 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 if (!Constructor)
5743 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005744
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 bool ArgumentChanged = false;
5746 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5747 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005748 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 ArgEnd = E->arg_end();
5750 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005751 if (getDerived().DropCallArgument(*Arg)) {
5752 ArgumentChanged = true;
5753 break;
5754 }
5755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5757 if (TransArg.isInvalid())
5758 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5761 Args.push_back((Expr *)TransArg.release());
5762 }
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 if (!getDerived().AlwaysRebuild() &&
5765 T == E->getType() &&
5766 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005767 !ArgumentChanged) {
5768 // FIXME: Instantiation-specific
5769 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005770 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005771 }
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 // FIXME: Bogus location information
5774 SourceLocation CommaLoc;
5775 if (Args.size() > 1) {
5776 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005777 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5779 }
5780 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5781 T,
5782 /*FIXME:*/E->getTypeBeginLoc(),
5783 move_arg(Args),
5784 &CommaLoc,
5785 E->getLocEnd());
5786}
Mike Stump11289f42009-09-09 15:08:12 +00005787
Douglas Gregora16548e2009-08-11 05:31:07 +00005788template<typename Derived>
5789Sema::OwningExprResult
5790TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005791 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5793 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5794 if (T.isNull())
5795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 bool ArgumentChanged = false;
5798 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5799 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5800 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5801 ArgEnd = E->arg_end();
5802 Arg != ArgEnd; ++Arg) {
5803 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5804 if (TransArg.isInvalid())
5805 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005806
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5808 FakeCommaLocs.push_back(
5809 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5810 Args.push_back(TransArg.takeAs<Expr>());
5811 }
Mike Stump11289f42009-09-09 15:08:12 +00005812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 if (!getDerived().AlwaysRebuild() &&
5814 T == E->getTypeAsWritten() &&
5815 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005816 return SemaRef.Owned(E->Retain());
5817
Douglas Gregora16548e2009-08-11 05:31:07 +00005818 // FIXME: we're faking the locations of the commas
5819 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5820 T,
5821 E->getLParenLoc(),
5822 move_arg(Args),
5823 FakeCommaLocs.data(),
5824 E->getRParenLoc());
5825}
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827template<typename Derived>
5828Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005829TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005830 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005831 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005832 OwningExprResult Base(SemaRef, (Expr*) 0);
5833 Expr *OldBase;
5834 QualType BaseType;
5835 QualType ObjectType;
5836 if (!E->isImplicitAccess()) {
5837 OldBase = E->getBase();
5838 Base = getDerived().TransformExpr(OldBase);
5839 if (Base.isInvalid())
5840 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005841
John McCall2d74de92009-12-01 22:10:20 +00005842 // Start the member reference and compute the object's type.
5843 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005844 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005845 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5846 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005847 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005848 ObjectTy,
5849 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005850 if (Base.isInvalid())
5851 return SemaRef.ExprError();
5852
5853 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5854 BaseType = ((Expr*) Base.get())->getType();
5855 } else {
5856 OldBase = 0;
5857 BaseType = getDerived().TransformType(E->getBaseType());
5858 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5859 }
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005861 // Transform the first part of the nested-name-specifier that qualifies
5862 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005863 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005864 = getDerived().TransformFirstQualifierInScope(
5865 E->getFirstQualifierFoundInScope(),
5866 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005868 NestedNameSpecifier *Qualifier = 0;
5869 if (E->getQualifier()) {
5870 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5871 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005872 ObjectType,
5873 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005874 if (!Qualifier)
5875 return SemaRef.ExprError();
5876 }
Mike Stump11289f42009-09-09 15:08:12 +00005877
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005878 DeclarationNameInfo NameInfo
5879 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5880 ObjectType);
5881 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005882 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005883
John McCall2d74de92009-12-01 22:10:20 +00005884 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005885 // This is a reference to a member without an explicitly-specified
5886 // template argument list. Optimize for this common case.
5887 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005888 Base.get() == OldBase &&
5889 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005890 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005891 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005892 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005893 return SemaRef.Owned(E->Retain());
5894
John McCall8cd78132009-11-19 22:55:06 +00005895 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005896 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005897 E->isArrow(),
5898 E->getOperatorLoc(),
5899 Qualifier,
5900 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005901 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005902 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005903 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005904 }
5905
John McCall6b51f282009-11-23 01:53:49 +00005906 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005907 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005908 TemplateArgumentLoc Loc;
5909 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005910 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005911 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005912 }
Mike Stump11289f42009-09-09 15:08:12 +00005913
John McCall8cd78132009-11-19 22:55:06 +00005914 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005915 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 E->isArrow(),
5917 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005918 Qualifier,
5919 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005920 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005921 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005922 &TransArgs);
5923}
5924
5925template<typename Derived>
5926Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005927TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005928 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005929 OwningExprResult Base(SemaRef, (Expr*) 0);
5930 QualType BaseType;
5931 if (!Old->isImplicitAccess()) {
5932 Base = getDerived().TransformExpr(Old->getBase());
5933 if (Base.isInvalid())
5934 return SemaRef.ExprError();
5935 BaseType = ((Expr*) Base.get())->getType();
5936 } else {
5937 BaseType = getDerived().TransformType(Old->getBaseType());
5938 }
John McCall10eae182009-11-30 22:42:35 +00005939
5940 NestedNameSpecifier *Qualifier = 0;
5941 if (Old->getQualifier()) {
5942 Qualifier
5943 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005944 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005945 if (Qualifier == 0)
5946 return SemaRef.ExprError();
5947 }
5948
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005949 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005950 Sema::LookupOrdinaryName);
5951
5952 // Transform all the decls.
5953 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5954 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005955 NamedDecl *InstD = static_cast<NamedDecl*>(
5956 getDerived().TransformDecl(Old->getMemberLoc(),
5957 *I));
John McCall84d87672009-12-10 09:41:52 +00005958 if (!InstD) {
5959 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5960 // This can happen because of dependent hiding.
5961 if (isa<UsingShadowDecl>(*I))
5962 continue;
5963 else
5964 return SemaRef.ExprError();
5965 }
John McCall10eae182009-11-30 22:42:35 +00005966
5967 // Expand using declarations.
5968 if (isa<UsingDecl>(InstD)) {
5969 UsingDecl *UD = cast<UsingDecl>(InstD);
5970 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5971 E = UD->shadow_end(); I != E; ++I)
5972 R.addDecl(*I);
5973 continue;
5974 }
5975
5976 R.addDecl(InstD);
5977 }
5978
5979 R.resolveKind();
5980
Douglas Gregor9262f472010-04-27 18:19:34 +00005981 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005982 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005983 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005984 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005985 Old->getMemberLoc(),
5986 Old->getNamingClass()));
5987 if (!NamingClass)
5988 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005989
Douglas Gregorda7be082010-04-27 16:10:10 +00005990 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005991 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005992
John McCall10eae182009-11-30 22:42:35 +00005993 TemplateArgumentListInfo TransArgs;
5994 if (Old->hasExplicitTemplateArgs()) {
5995 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5996 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5997 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5998 TemplateArgumentLoc Loc;
5999 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6000 Loc))
6001 return SemaRef.ExprError();
6002 TransArgs.addArgument(Loc);
6003 }
6004 }
John McCall38836f02010-01-15 08:34:02 +00006005
6006 // FIXME: to do this check properly, we will need to preserve the
6007 // first-qualifier-in-scope here, just in case we had a dependent
6008 // base (and therefore couldn't do the check) and a
6009 // nested-name-qualifier (and therefore could do the lookup).
6010 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006011
John McCall10eae182009-11-30 22:42:35 +00006012 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00006013 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006014 Old->getOperatorLoc(),
6015 Old->isArrow(),
6016 Qualifier,
6017 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006018 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006019 R,
6020 (Old->hasExplicitTemplateArgs()
6021 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006022}
6023
6024template<typename Derived>
6025Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006026TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006027 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006028}
6029
Mike Stump11289f42009-09-09 15:08:12 +00006030template<typename Derived>
6031Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006032TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006033 TypeSourceInfo *EncodedTypeInfo
6034 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6035 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006036 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006039 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006040 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006041
6042 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006043 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 E->getRParenLoc());
6045}
Mike Stump11289f42009-09-09 15:08:12 +00006046
Douglas Gregora16548e2009-08-11 05:31:07 +00006047template<typename Derived>
6048Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006049TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006050 // Transform arguments.
6051 bool ArgChanged = false;
6052 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6053 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6054 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6055 if (Arg.isInvalid())
6056 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006057
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006058 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6059 Args.push_back(Arg.takeAs<Expr>());
6060 }
6061
6062 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6063 // Class message: transform the receiver type.
6064 TypeSourceInfo *ReceiverTypeInfo
6065 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6066 if (!ReceiverTypeInfo)
6067 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006068
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006069 // If nothing changed, just retain the existing message send.
6070 if (!getDerived().AlwaysRebuild() &&
6071 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6072 return SemaRef.Owned(E->Retain());
6073
6074 // Build a new class message send.
6075 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6076 E->getSelector(),
6077 E->getMethodDecl(),
6078 E->getLeftLoc(),
6079 move_arg(Args),
6080 E->getRightLoc());
6081 }
6082
6083 // Instance message: transform the receiver
6084 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6085 "Only class and instance messages may be instantiated");
6086 OwningExprResult Receiver
6087 = getDerived().TransformExpr(E->getInstanceReceiver());
6088 if (Receiver.isInvalid())
6089 return SemaRef.ExprError();
6090
6091 // If nothing changed, just retain the existing message send.
6092 if (!getDerived().AlwaysRebuild() &&
6093 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6094 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006095
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006096 // Build a new instance message send.
6097 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6098 E->getSelector(),
6099 E->getMethodDecl(),
6100 E->getLeftLoc(),
6101 move_arg(Args),
6102 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006103}
6104
Mike Stump11289f42009-09-09 15:08:12 +00006105template<typename Derived>
6106Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006107TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006108 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006109}
6110
Mike Stump11289f42009-09-09 15:08:12 +00006111template<typename Derived>
6112Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006114 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006115}
6116
Mike Stump11289f42009-09-09 15:08:12 +00006117template<typename Derived>
6118Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006120 // Transform the base expression.
6121 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6122 if (Base.isInvalid())
6123 return SemaRef.ExprError();
6124
6125 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006126
Douglas Gregord51d90d2010-04-26 20:11:03 +00006127 // If nothing changed, just retain the existing expression.
6128 if (!getDerived().AlwaysRebuild() &&
6129 Base.get() == E->getBase())
6130 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006131
Douglas Gregord51d90d2010-04-26 20:11:03 +00006132 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6133 E->getLocation(),
6134 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006135}
6136
Mike Stump11289f42009-09-09 15:08:12 +00006137template<typename Derived>
6138Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006139TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006140 // Transform the base expression.
6141 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6142 if (Base.isInvalid())
6143 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006144
Douglas Gregor9faee212010-04-26 20:47:02 +00006145 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006146
Douglas Gregor9faee212010-04-26 20:47:02 +00006147 // If nothing changed, just retain the existing expression.
6148 if (!getDerived().AlwaysRebuild() &&
6149 Base.get() == E->getBase())
6150 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006151
Douglas Gregor9faee212010-04-26 20:47:02 +00006152 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6153 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006154}
6155
Mike Stump11289f42009-09-09 15:08:12 +00006156template<typename Derived>
6157Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006158TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006159 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006160 // If this implicit setter/getter refers to class methods, it cannot have any
6161 // dependent parts. Just retain the existing declaration.
6162 if (E->getInterfaceDecl())
6163 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006164
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006165 // Transform the base expression.
6166 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6167 if (Base.isInvalid())
6168 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006169
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006170 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006171
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006172 // If nothing changed, just retain the existing expression.
6173 if (!getDerived().AlwaysRebuild() &&
6174 Base.get() == E->getBase())
6175 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006176
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006177 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6178 E->getGetterMethod(),
6179 E->getType(),
6180 E->getSetterMethod(),
6181 E->getLocation(),
6182 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006183
Douglas Gregora16548e2009-08-11 05:31:07 +00006184}
6185
Mike Stump11289f42009-09-09 15:08:12 +00006186template<typename Derived>
6187Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006189 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006190 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006191}
6192
Mike Stump11289f42009-09-09 15:08:12 +00006193template<typename Derived>
6194Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006196 // Transform the base expression.
6197 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6198 if (Base.isInvalid())
6199 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006200
Douglas Gregord51d90d2010-04-26 20:11:03 +00006201 // If nothing changed, just retain the existing expression.
6202 if (!getDerived().AlwaysRebuild() &&
6203 Base.get() == E->getBase())
6204 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006205
Douglas Gregord51d90d2010-04-26 20:11:03 +00006206 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6207 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006208}
6209
Mike Stump11289f42009-09-09 15:08:12 +00006210template<typename Derived>
6211Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006212TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 bool ArgumentChanged = false;
6214 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6215 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6216 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6217 if (SubExpr.isInvalid())
6218 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006219
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6221 SubExprs.push_back(SubExpr.takeAs<Expr>());
6222 }
Mike Stump11289f42009-09-09 15:08:12 +00006223
Douglas Gregora16548e2009-08-11 05:31:07 +00006224 if (!getDerived().AlwaysRebuild() &&
6225 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006226 return SemaRef.Owned(E->Retain());
6227
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6229 move_arg(SubExprs),
6230 E->getRParenLoc());
6231}
6232
Mike Stump11289f42009-09-09 15:08:12 +00006233template<typename Derived>
6234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006235TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006236 SourceLocation CaretLoc(E->getExprLoc());
6237
6238 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6239 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6240 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6241 llvm::SmallVector<ParmVarDecl*, 4> Params;
6242 llvm::SmallVector<QualType, 4> ParamTypes;
6243
6244 // Parameter substitution.
6245 const BlockDecl *BD = E->getBlockDecl();
6246 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6247 EN = BD->param_end(); P != EN; ++P) {
6248 ParmVarDecl *OldParm = (*P);
6249 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6250 QualType NewType = NewParm->getType();
6251 Params.push_back(NewParm);
6252 ParamTypes.push_back(NewParm->getType());
6253 }
6254
6255 const FunctionType *BExprFunctionType = E->getFunctionType();
6256 QualType BExprResultType = BExprFunctionType->getResultType();
6257 if (!BExprResultType.isNull()) {
6258 if (!BExprResultType->isDependentType())
6259 CurBlock->ReturnType = BExprResultType;
6260 else if (BExprResultType != SemaRef.Context.DependentTy)
6261 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6262 }
6263
6264 // Transform the body
6265 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6266 if (Body.isInvalid())
6267 return SemaRef.ExprError();
6268 // Set the parameters on the block decl.
6269 if (!Params.empty())
6270 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6271
6272 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6273 CurBlock->ReturnType,
6274 ParamTypes.data(),
6275 ParamTypes.size(),
6276 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006277 0,
6278 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006279
6280 CurBlock->FunctionType = FunctionType;
6281 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006282}
6283
Mike Stump11289f42009-09-09 15:08:12 +00006284template<typename Derived>
6285Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006286TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006287 NestedNameSpecifier *Qualifier = 0;
6288
6289 ValueDecl *ND
6290 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6291 E->getDecl()));
6292 if (!ND)
6293 return SemaRef.ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006294
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006295 if (!getDerived().AlwaysRebuild() &&
6296 ND == E->getDecl()) {
6297 // Mark it referenced in the new context regardless.
6298 // FIXME: this is a bit instantiation-specific.
6299 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6300
6301 return SemaRef.Owned(E->Retain());
6302 }
6303
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006304 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006305 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006306 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006307}
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregora16548e2009-08-11 05:31:07 +00006309//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006310// Type reconstruction
6311//===----------------------------------------------------------------------===//
6312
Mike Stump11289f42009-09-09 15:08:12 +00006313template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006314QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6315 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006316 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006317 getDerived().getBaseEntity());
6318}
6319
Mike Stump11289f42009-09-09 15:08:12 +00006320template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006321QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6322 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006323 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006324 getDerived().getBaseEntity());
6325}
6326
Mike Stump11289f42009-09-09 15:08:12 +00006327template<typename Derived>
6328QualType
John McCall70dd5f62009-10-30 00:06:24 +00006329TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6330 bool WrittenAsLValue,
6331 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006332 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006333 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006334}
6335
6336template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006337QualType
John McCall70dd5f62009-10-30 00:06:24 +00006338TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6339 QualType ClassType,
6340 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006341 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006342 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006343}
6344
6345template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006346QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6348 ArrayType::ArraySizeModifier SizeMod,
6349 const llvm::APInt *Size,
6350 Expr *SizeExpr,
6351 unsigned IndexTypeQuals,
6352 SourceRange BracketsRange) {
6353 if (SizeExpr || !Size)
6354 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6355 IndexTypeQuals, BracketsRange,
6356 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006357
6358 QualType Types[] = {
6359 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6360 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6361 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006362 };
6363 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6364 QualType SizeType;
6365 for (unsigned I = 0; I != NumTypes; ++I)
6366 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6367 SizeType = Types[I];
6368 break;
6369 }
Mike Stump11289f42009-09-09 15:08:12 +00006370
Douglas Gregord6ff3322009-08-04 16:50:30 +00006371 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006372 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006373 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006374 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375}
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006378QualType
6379TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006380 ArrayType::ArraySizeModifier SizeMod,
6381 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006382 unsigned IndexTypeQuals,
6383 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006384 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006385 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006386}
6387
6388template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006389QualType
Mike Stump11289f42009-09-09 15:08:12 +00006390TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006392 unsigned IndexTypeQuals,
6393 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006394 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006395 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006396}
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006399QualType
6400TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006402 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006403 unsigned IndexTypeQuals,
6404 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006405 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006406 SizeExpr.takeAs<Expr>(),
6407 IndexTypeQuals, BracketsRange);
6408}
6409
6410template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006411QualType
6412TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006413 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006415 unsigned IndexTypeQuals,
6416 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006417 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006418 SizeExpr.takeAs<Expr>(),
6419 IndexTypeQuals, BracketsRange);
6420}
6421
6422template<typename Derived>
6423QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006424 unsigned NumElements,
6425 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006427 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006428}
Mike Stump11289f42009-09-09 15:08:12 +00006429
Douglas Gregord6ff3322009-08-04 16:50:30 +00006430template<typename Derived>
6431QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6432 unsigned NumElements,
6433 SourceLocation AttributeLoc) {
6434 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6435 NumElements, true);
6436 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006437 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438 AttributeLoc);
6439 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6440 AttributeLoc);
6441}
Mike Stump11289f42009-09-09 15:08:12 +00006442
Douglas Gregord6ff3322009-08-04 16:50:30 +00006443template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006444QualType
6445TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006447 SourceLocation AttributeLoc) {
6448 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6449}
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregord6ff3322009-08-04 16:50:30 +00006451template<typename Derived>
6452QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006453 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006454 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006455 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006456 unsigned Quals,
6457 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006458 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006459 Quals,
6460 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006461 getDerived().getBaseEntity(),
6462 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006463}
Mike Stump11289f42009-09-09 15:08:12 +00006464
Douglas Gregord6ff3322009-08-04 16:50:30 +00006465template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006466QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6467 return SemaRef.Context.getFunctionNoProtoType(T);
6468}
6469
6470template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006471QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6472 assert(D && "no decl found");
6473 if (D->isInvalidDecl()) return QualType();
6474
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006475 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006476 TypeDecl *Ty;
6477 if (isa<UsingDecl>(D)) {
6478 UsingDecl *Using = cast<UsingDecl>(D);
6479 assert(Using->isTypeName() &&
6480 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6481
6482 // A valid resolved using typename decl points to exactly one type decl.
6483 assert(++Using->shadow_begin() == Using->shadow_end());
6484 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006485
John McCallb96ec562009-12-04 22:46:56 +00006486 } else {
6487 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6488 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6489 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6490 }
6491
6492 return SemaRef.Context.getTypeDeclType(Ty);
6493}
6494
6495template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006496QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006497 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6498}
6499
6500template<typename Derived>
6501QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6502 return SemaRef.Context.getTypeOfType(Underlying);
6503}
6504
6505template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006506QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006507 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6508}
6509
6510template<typename Derived>
6511QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006512 TemplateName Template,
6513 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006514 const TemplateArgumentListInfo &TemplateArgs) {
6515 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006516}
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregor1135c352009-08-06 05:28:30 +00006518template<typename Derived>
6519NestedNameSpecifier *
6520TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6521 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006522 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006523 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006524 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006525 CXXScopeSpec SS;
6526 // FIXME: The source location information is all wrong.
6527 SS.setRange(Range);
6528 SS.setScopeRep(Prefix);
6529 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006530 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006531 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006532 ObjectType,
6533 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006534 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006535}
6536
6537template<typename Derived>
6538NestedNameSpecifier *
6539TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6540 SourceRange Range,
6541 NamespaceDecl *NS) {
6542 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6543}
6544
6545template<typename Derived>
6546NestedNameSpecifier *
6547TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6548 SourceRange Range,
6549 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006550 QualType T) {
6551 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006552 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006553 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006554 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6555 T.getTypePtr());
6556 }
Mike Stump11289f42009-09-09 15:08:12 +00006557
Douglas Gregor1135c352009-08-06 05:28:30 +00006558 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6559 return 0;
6560}
Mike Stump11289f42009-09-09 15:08:12 +00006561
Douglas Gregor71dc5092009-08-06 06:41:21 +00006562template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006563TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006564TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6565 bool TemplateKW,
6566 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006567 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006568 Template);
6569}
6570
6571template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006572TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006573TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006574 const IdentifierInfo &II,
6575 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006576 CXXScopeSpec SS;
6577 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006578 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006579 UnqualifiedId Name;
6580 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006581 Sema::TemplateTy Template;
6582 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6583 /*FIXME:*/getDerived().getBaseLocation(),
6584 SS,
6585 Name,
6586 ObjectType.getAsOpaquePtr(),
6587 /*EnteringContext=*/false,
6588 Template);
6589 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006590}
Mike Stump11289f42009-09-09 15:08:12 +00006591
Douglas Gregora16548e2009-08-11 05:31:07 +00006592template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006593TemplateName
6594TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6595 OverloadedOperatorKind Operator,
6596 QualType ObjectType) {
6597 CXXScopeSpec SS;
6598 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6599 SS.setScopeRep(Qualifier);
6600 UnqualifiedId Name;
6601 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6602 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6603 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006604 Sema::TemplateTy Template;
6605 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006606 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006607 SS,
6608 Name,
6609 ObjectType.getAsOpaquePtr(),
6610 /*EnteringContext=*/false,
6611 Template);
6612 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006613}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006614
Douglas Gregor71395fa2009-11-04 00:56:37 +00006615template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006616Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006617TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6618 SourceLocation OpLoc,
6619 ExprArg Callee,
6620 ExprArg First,
6621 ExprArg Second) {
6622 Expr *FirstExpr = (Expr *)First.get();
6623 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006624 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006625 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregora16548e2009-08-11 05:31:07 +00006627 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006628 if (Op == OO_Subscript) {
6629 if (!FirstExpr->getType()->isOverloadableType() &&
6630 !SecondExpr->getType()->isOverloadableType())
6631 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006632 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006633 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006634 } else if (Op == OO_Arrow) {
6635 // -> is never a builtin operation.
6636 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006637 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006638 if (!FirstExpr->getType()->isOverloadableType()) {
6639 // The argument is not of overloadable type, so try to create a
6640 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006641 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006642 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006643
Douglas Gregora16548e2009-08-11 05:31:07 +00006644 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6645 }
6646 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006647 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 !SecondExpr->getType()->isOverloadableType()) {
6649 // Neither of the arguments is an overloadable type, so try to
6650 // create a built-in binary operation.
6651 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006652 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6654 if (Result.isInvalid())
6655 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006656
Douglas Gregora16548e2009-08-11 05:31:07 +00006657 First.release();
6658 Second.release();
6659 return move(Result);
6660 }
6661 }
Mike Stump11289f42009-09-09 15:08:12 +00006662
6663 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006665 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006666
John McCalld14a8642009-11-21 08:51:07 +00006667 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6668 assert(ULE->requiresADL());
6669
6670 // FIXME: Do we have to check
6671 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006672 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006673 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006674 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006675 }
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 // Add any functions found via argument-dependent lookup.
6678 Expr *Args[2] = { FirstExpr, SecondExpr };
6679 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006680
Douglas Gregora16548e2009-08-11 05:31:07 +00006681 // Create the overloaded operator invocation for unary operators.
6682 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006683 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6685 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6686 }
Mike Stump11289f42009-09-09 15:08:12 +00006687
Sebastian Redladba46e2009-10-29 20:17:01 +00006688 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006689 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6690 OpLoc,
6691 move(First),
6692 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006693
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006695 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006697 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6699 if (Result.isInvalid())
6700 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006701
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 First.release();
6703 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006704 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006705}
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006707template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006708Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006709TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6710 SourceLocation OperatorLoc,
6711 bool isArrow,
6712 NestedNameSpecifier *Qualifier,
6713 SourceRange QualifierRange,
6714 TypeSourceInfo *ScopeType,
6715 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006716 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006717 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006718 CXXScopeSpec SS;
6719 if (Qualifier) {
6720 SS.setRange(QualifierRange);
6721 SS.setScopeRep(Qualifier);
6722 }
6723
6724 Expr *BaseE = (Expr *)Base.get();
6725 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006726 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006727 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006728 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006729 !BaseType->getAs<PointerType>()->getPointeeType()
6730 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006731 // This pseudo-destructor expression is still a pseudo-destructor.
6732 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6733 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006734 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006735 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006736 /*FIXME?*/true);
6737 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006738
Douglas Gregor678f90d2010-02-25 01:56:36 +00006739 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006740 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6741 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6742 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6743 NameInfo.setNamedTypeInfo(DestroyedType);
6744
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006745 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006746
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006747 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6748 OperatorLoc, isArrow,
6749 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006750 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006751 /*TemplateArgs*/ 0);
6752}
6753
Douglas Gregord6ff3322009-08-04 16:50:30 +00006754} // end namespace clang
6755
6756#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H