blob: 90ec1bd96a95578f2806e6a39119d543b446ae89 [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,
1687 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001688 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001689 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001690 ConvertedArgs))
1691 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001692
Douglas Gregordb121ba2009-12-14 16:27:04 +00001693 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1694 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 }
1696
1697 /// \brief Build a new object-construction expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
1701 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1702 QualType T,
1703 SourceLocation LParenLoc,
1704 MultiExprArg Args,
1705 SourceLocation *Commas,
1706 SourceLocation RParenLoc) {
1707 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1708 T.getAsOpaquePtr(),
1709 LParenLoc,
1710 move(Args),
1711 Commas,
1712 RParenLoc);
1713 }
1714
1715 /// \brief Build a new object-construction expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
1719 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1720 QualType T,
1721 SourceLocation LParenLoc,
1722 MultiExprArg Args,
1723 SourceLocation *Commas,
1724 SourceLocation RParenLoc) {
1725 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1726 /*FIXME*/LParenLoc),
1727 T.getAsOpaquePtr(),
1728 LParenLoc,
1729 move(Args),
1730 Commas,
1731 RParenLoc);
1732 }
Mike Stump11289f42009-09-09 15:08:12 +00001733
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 /// \brief Build a new member reference expression.
1735 ///
1736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001738 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001739 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 bool IsArrow,
1741 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001742 NestedNameSpecifier *Qualifier,
1743 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001744 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001745 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001746 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001748 SS.setRange(QualifierRange);
1749 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001750
John McCall2d74de92009-12-01 22:10:20 +00001751 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1752 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001753 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001754 MemberNameInfo,
1755 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 }
1757
John McCall10eae182009-11-30 22:42:35 +00001758 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001762 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001763 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001764 SourceLocation OperatorLoc,
1765 bool IsArrow,
1766 NestedNameSpecifier *Qualifier,
1767 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001768 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001769 LookupResult &R,
1770 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001771 CXXScopeSpec SS;
1772 SS.setRange(QualifierRange);
1773 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001774
John McCall2d74de92009-12-01 22:10:20 +00001775 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1776 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001777 SS, FirstQualifierInScope,
1778 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001779 }
Mike Stump11289f42009-09-09 15:08:12 +00001780
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 /// \brief Build a new Objective-C @encode expression.
1782 ///
1783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001786 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001788 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001790 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001791
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001792 /// \brief Build a new Objective-C class message.
1793 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1794 Selector Sel,
1795 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001796 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001797 MultiExprArg Args,
1798 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001799 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1800 ReceiverTypeInfo->getType(),
1801 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001802 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001803 move(Args));
1804 }
1805
1806 /// \brief Build a new Objective-C instance message.
1807 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1808 Selector Sel,
1809 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001810 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001811 MultiExprArg Args,
1812 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001813 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1814 return SemaRef.BuildInstanceMessage(move(Receiver),
1815 ReceiverType,
1816 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001817 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001818 move(Args));
1819 }
1820
Douglas Gregord51d90d2010-04-26 20:11:03 +00001821 /// \brief Build a new Objective-C ivar reference expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
1825 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1826 SourceLocation IvarLoc,
1827 bool IsArrow, bool IsFreeIvar) {
1828 // FIXME: We lose track of the IsFreeIvar bit.
1829 CXXScopeSpec SS;
1830 Expr *Base = BaseArg.takeAs<Expr>();
1831 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1832 Sema::LookupMemberName);
1833 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1834 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001835 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001836 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001837 if (Result.isInvalid())
1838 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001839
Douglas Gregord51d90d2010-04-26 20:11:03 +00001840 if (Result.get())
1841 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001842
1843 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001844 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001845 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001846 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001847 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001848 /*TemplateArgs=*/0);
1849 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001850
1851 /// \brief Build a new Objective-C property reference expression.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001855 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001856 ObjCPropertyDecl *Property,
1857 SourceLocation PropertyLoc) {
1858 CXXScopeSpec SS;
1859 Expr *Base = BaseArg.takeAs<Expr>();
1860 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1861 Sema::LookupMemberName);
1862 bool IsArrow = false;
1863 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1864 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001865 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001866 if (Result.isInvalid())
1867 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001868
Douglas Gregor9faee212010-04-26 20:47:02 +00001869 if (Result.get())
1870 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871
1872 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001874 /*FIXME:*/PropertyLoc, IsArrow,
1875 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001876 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001877 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001878 /*TemplateArgs=*/0);
1879 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880
1881 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001882 /// expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001885 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001886 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1887 ObjCMethodDecl *Getter,
1888 QualType T,
1889 ObjCMethodDecl *Setter,
1890 SourceLocation NameLoc,
1891 ExprArg Base) {
1892 // Since these expressions can only be value-dependent, we do not need to
1893 // perform semantic analysis again.
1894 return getSema().Owned(
1895 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1896 Setter,
1897 NameLoc,
1898 Base.takeAs<Expr>()));
1899 }
1900
Douglas Gregord51d90d2010-04-26 20:11:03 +00001901 /// \brief Build a new Objective-C "isa" expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1906 bool IsArrow) {
1907 CXXScopeSpec SS;
1908 Expr *Base = BaseArg.takeAs<Expr>();
1909 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1910 Sema::LookupMemberName);
1911 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1912 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001913 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001914 if (Result.isInvalid())
1915 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001916
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 if (Result.get())
1918 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001919
1920 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001921 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001922 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001923 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001924 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001925 /*TemplateArgs=*/0);
1926 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001927
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// \brief Build a new shuffle vector expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
1932 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1933 MultiExprArg SubExprs,
1934 SourceLocation RParenLoc) {
1935 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001936 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1938 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1939 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1940 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 // Build a reference to the __builtin_shufflevector builtin
1943 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001944 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001946 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001948
1949 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 unsigned NumSubExprs = SubExprs.size();
1951 Expr **Subs = (Expr **)SubExprs.release();
1952 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1953 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001954 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 RParenLoc);
1956 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 // Type-check the __builtin_shufflevector expression.
1959 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1960 if (Result.isInvalid())
1961 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001964 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001966};
Douglas Gregora16548e2009-08-11 05:31:07 +00001967
Douglas Gregorebe10102009-08-20 07:17:43 +00001968template<typename Derived>
1969Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1970 if (!S)
1971 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregorebe10102009-08-20 07:17:43 +00001973 switch (S->getStmtClass()) {
1974 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregorebe10102009-08-20 07:17:43 +00001976 // Transform individual statement nodes
1977#define STMT(Node, Parent) \
1978 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1979#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001980#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001981
Douglas Gregorebe10102009-08-20 07:17:43 +00001982 // Transform expressions by calling TransformExpr.
1983#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001984#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001985#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001986#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001987 {
1988 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1989 if (E.isInvalid())
1990 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001991
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001992 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994 }
1995
Douglas Gregorebe10102009-08-20 07:17:43 +00001996 return SemaRef.Owned(S->Retain());
1997}
Mike Stump11289f42009-09-09 15:08:12 +00001998
1999
Douglas Gregore922c772009-08-04 22:27:00 +00002000template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00002001Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 if (!E)
2003 return SemaRef.Owned(E);
2004
2005 switch (E->getStmtClass()) {
2006 case Stmt::NoStmtClass: break;
2007#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002008#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002009#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002010 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002011#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002012 }
2013
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002015}
2016
2017template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002018NestedNameSpecifier *
2019TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002020 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002021 QualType ObjectType,
2022 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002023 if (!NNS)
2024 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregorebe10102009-08-20 07:17:43 +00002026 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002027 NestedNameSpecifier *Prefix = NNS->getPrefix();
2028 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002029 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002030 ObjectType,
2031 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 if (!Prefix)
2033 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002034
2035 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002036 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002037 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002038 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002039 }
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 switch (NNS->getKind()) {
2042 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002043 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002044 "Identifier nested-name-specifier with no prefix or object type");
2045 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2046 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002047 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002048
2049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002050 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002051 ObjectType,
2052 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregor1135c352009-08-06 05:28:30 +00002054 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002055 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002057 getDerived().TransformDecl(Range.getBegin(),
2058 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002060 Prefix == NNS->getPrefix() &&
2061 NS == NNS->getAsNamespace())
2062 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002063
Douglas Gregor1135c352009-08-06 05:28:30 +00002064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2065 }
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregor1135c352009-08-06 05:28:30 +00002067 case NestedNameSpecifier::Global:
2068 // There is no meaningful transformation that one could perform on the
2069 // global scope.
2070 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002071
Douglas Gregor1135c352009-08-06 05:28:30 +00002072 case NestedNameSpecifier::TypeSpecWithTemplate:
2073 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002074 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002075 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2076 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002077 if (T.isNull())
2078 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002079
Douglas Gregor1135c352009-08-06 05:28:30 +00002080 if (!getDerived().AlwaysRebuild() &&
2081 Prefix == NNS->getPrefix() &&
2082 T == QualType(NNS->getAsType(), 0))
2083 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002084
2085 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2086 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002087 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002088 }
2089 }
Mike Stump11289f42009-09-09 15:08:12 +00002090
Douglas Gregor1135c352009-08-06 05:28:30 +00002091 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002092 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002093}
2094
2095template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002096DeclarationNameInfo
2097TreeTransform<Derived>
2098::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2099 QualType ObjectType) {
2100 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002102 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002103
2104 switch (Name.getNameKind()) {
2105 case DeclarationName::Identifier:
2106 case DeclarationName::ObjCZeroArgSelector:
2107 case DeclarationName::ObjCOneArgSelector:
2108 case DeclarationName::ObjCMultiArgSelector:
2109 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002110 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002111 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002112 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregorf816bd72009-09-03 22:13:48 +00002114 case DeclarationName::CXXConstructorName:
2115 case DeclarationName::CXXDestructorName:
2116 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002117 TypeSourceInfo *NewTInfo;
2118 CanQualType NewCanTy;
2119 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2120 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2121 if (!NewTInfo)
2122 return DeclarationNameInfo();
2123 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2124 }
2125 else {
2126 NewTInfo = 0;
2127 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2128 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2129 ObjectType);
2130 if (NewT.isNull())
2131 return DeclarationNameInfo();
2132 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2133 }
Mike Stump11289f42009-09-09 15:08:12 +00002134
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002135 DeclarationName NewName
2136 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2137 NewCanTy);
2138 DeclarationNameInfo NewNameInfo(NameInfo);
2139 NewNameInfo.setName(NewName);
2140 NewNameInfo.setNamedTypeInfo(NewTInfo);
2141 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002142 }
Mike Stump11289f42009-09-09 15:08:12 +00002143 }
2144
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002145 assert(0 && "Unknown name kind.");
2146 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002147}
2148
2149template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002150TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002151TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2152 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002153 SourceLocation Loc = getDerived().getBaseLocation();
2154
Douglas Gregor71dc5092009-08-06 06:41:21 +00002155 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002156 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002157 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002158 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2159 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 if (!NNS)
2161 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregor71dc5092009-08-06 06:41:21 +00002163 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002164 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002165 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002166 if (!TransTemplate)
2167 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 if (!getDerived().AlwaysRebuild() &&
2170 NNS == QTN->getQualifier() &&
2171 TransTemplate == Template)
2172 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2175 TransTemplate);
2176 }
Mike Stump11289f42009-09-09 15:08:12 +00002177
John McCalle66edc12009-11-24 19:00:30 +00002178 // These should be getting filtered out before they make it into the AST.
2179 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002180 }
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregor71dc5092009-08-06 06:41:21 +00002182 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002183 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002185 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2186 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002187 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002191 NNS == DTN->getQualifier() &&
2192 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002193 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002194
Douglas Gregor71395fa2009-11-04 00:56:37 +00002195 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002196 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002197 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002198
2199 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002200 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002204 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002205 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206 if (!TransTemplate)
2207 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregor71dc5092009-08-06 06:41:21 +00002209 if (!getDerived().AlwaysRebuild() &&
2210 TransTemplate == Template)
2211 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002212
Douglas Gregor71dc5092009-08-06 06:41:21 +00002213 return TemplateName(TransTemplate);
2214 }
Mike Stump11289f42009-09-09 15:08:12 +00002215
John McCalle66edc12009-11-24 19:00:30 +00002216 // These should be getting filtered out before they reach the AST.
2217 assert(false && "overloaded function decl survived to here");
2218 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002219}
2220
2221template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002222void TreeTransform<Derived>::InventTemplateArgumentLoc(
2223 const TemplateArgument &Arg,
2224 TemplateArgumentLoc &Output) {
2225 SourceLocation Loc = getDerived().getBaseLocation();
2226 switch (Arg.getKind()) {
2227 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002228 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002229 break;
2230
2231 case TemplateArgument::Type:
2232 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002233 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002234
John McCall0ad16662009-10-29 08:12:44 +00002235 break;
2236
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002237 case TemplateArgument::Template:
2238 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2239 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002240
John McCall0ad16662009-10-29 08:12:44 +00002241 case TemplateArgument::Expression:
2242 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2243 break;
2244
2245 case TemplateArgument::Declaration:
2246 case TemplateArgument::Integral:
2247 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002248 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002249 break;
2250 }
2251}
2252
2253template<typename Derived>
2254bool TreeTransform<Derived>::TransformTemplateArgument(
2255 const TemplateArgumentLoc &Input,
2256 TemplateArgumentLoc &Output) {
2257 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002258 switch (Arg.getKind()) {
2259 case TemplateArgument::Null:
2260 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002261 Output = Input;
2262 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregore922c772009-08-04 22:27:00 +00002264 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002265 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002266 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002267 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002268
2269 DI = getDerived().TransformType(DI);
2270 if (!DI) return true;
2271
2272 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2273 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002274 }
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregore922c772009-08-04 22:27:00 +00002276 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002277 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002278 DeclarationName Name;
2279 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2280 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002281 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002282 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002283 if (!D) return true;
2284
John McCall0d07eb32009-10-29 18:45:58 +00002285 Expr *SourceExpr = Input.getSourceDeclExpression();
2286 if (SourceExpr) {
2287 EnterExpressionEvaluationContext Unevaluated(getSema(),
2288 Action::Unevaluated);
2289 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2290 if (E.isInvalid())
2291 SourceExpr = NULL;
2292 else {
2293 SourceExpr = E.takeAs<Expr>();
2294 SourceExpr->Retain();
2295 }
2296 }
2297
2298 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002299 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002300 }
Mike Stump11289f42009-09-09 15:08:12 +00002301
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002302 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002303 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002304 TemplateName Template
2305 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2306 if (Template.isNull())
2307 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002308
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002309 Output = TemplateArgumentLoc(TemplateArgument(Template),
2310 Input.getTemplateQualifierRange(),
2311 Input.getTemplateNameLoc());
2312 return false;
2313 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002314
Douglas Gregore922c772009-08-04 22:27:00 +00002315 case TemplateArgument::Expression: {
2316 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002317 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002318 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002319
John McCall0ad16662009-10-29 08:12:44 +00002320 Expr *InputExpr = Input.getSourceExpression();
2321 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2322
2323 Sema::OwningExprResult E
2324 = getDerived().TransformExpr(InputExpr);
2325 if (E.isInvalid()) return true;
2326
2327 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002328 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002329 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2330 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002331 }
Mike Stump11289f42009-09-09 15:08:12 +00002332
Douglas Gregore922c772009-08-04 22:27:00 +00002333 case TemplateArgument::Pack: {
2334 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2335 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002336 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002337 AEnd = Arg.pack_end();
2338 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002339
John McCall0ad16662009-10-29 08:12:44 +00002340 // FIXME: preserve source information here when we start
2341 // caring about parameter packs.
2342
John McCall0d07eb32009-10-29 18:45:58 +00002343 TemplateArgumentLoc InputArg;
2344 TemplateArgumentLoc OutputArg;
2345 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2346 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002347 return true;
2348
John McCall0d07eb32009-10-29 18:45:58 +00002349 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002350 }
2351 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002352 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002353 true);
John McCall0d07eb32009-10-29 18:45:58 +00002354 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002355 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002356 }
2357 }
Mike Stump11289f42009-09-09 15:08:12 +00002358
Douglas Gregore922c772009-08-04 22:27:00 +00002359 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002360 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002361}
2362
Douglas Gregord6ff3322009-08-04 16:50:30 +00002363//===----------------------------------------------------------------------===//
2364// Type transformation
2365//===----------------------------------------------------------------------===//
2366
2367template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002368QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002369 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002370 if (getDerived().AlreadyTransformed(T))
2371 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002372
John McCall550e0c22009-10-21 00:40:46 +00002373 // Temporary workaround. All of these transformations should
2374 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002375 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002376 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002377
Douglas Gregorfe17d252010-02-16 19:09:40 +00002378 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002379
John McCall550e0c22009-10-21 00:40:46 +00002380 if (!NewDI)
2381 return QualType();
2382
2383 return NewDI->getType();
2384}
2385
2386template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002387TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2388 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002389 if (getDerived().AlreadyTransformed(DI->getType()))
2390 return DI;
2391
2392 TypeLocBuilder TLB;
2393
2394 TypeLoc TL = DI->getTypeLoc();
2395 TLB.reserve(TL.getFullDataSize());
2396
Douglas Gregorfe17d252010-02-16 19:09:40 +00002397 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002398 if (Result.isNull())
2399 return 0;
2400
John McCallbcd03502009-12-07 02:54:59 +00002401 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002402}
2403
2404template<typename Derived>
2405QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002406TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2407 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002408 switch (T.getTypeLocClass()) {
2409#define ABSTRACT_TYPELOC(CLASS, PARENT)
2410#define TYPELOC(CLASS, PARENT) \
2411 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002412 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2413 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002414#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002415 }
Mike Stump11289f42009-09-09 15:08:12 +00002416
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002417 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002418 return QualType();
2419}
2420
2421/// FIXME: By default, this routine adds type qualifiers only to types
2422/// that can have qualifiers, and silently suppresses those qualifiers
2423/// that are not permitted (e.g., qualifiers on reference or function
2424/// types). This is the right thing for template instantiation, but
2425/// probably not for other clients.
2426template<typename Derived>
2427QualType
2428TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002429 QualifiedTypeLoc T,
2430 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002431 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002432
Douglas Gregorfe17d252010-02-16 19:09:40 +00002433 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2434 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002435 if (Result.isNull())
2436 return QualType();
2437
2438 // Silently suppress qualifiers if the result type can't be qualified.
2439 // FIXME: this is the right thing for template instantiation, but
2440 // probably not for other clients.
2441 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002443
John McCallcb0f89a2010-06-05 06:41:15 +00002444 if (!Quals.empty()) {
2445 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2446 TLB.push<QualifiedTypeLoc>(Result);
2447 // No location information to preserve.
2448 }
John McCall550e0c22009-10-21 00:40:46 +00002449
2450 return Result;
2451}
2452
2453template <class TyLoc> static inline
2454QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2455 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2456 NewT.setNameLoc(T.getNameLoc());
2457 return T.getType();
2458}
2459
John McCall550e0c22009-10-21 00:40:46 +00002460template<typename Derived>
2461QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002462 BuiltinTypeLoc T,
2463 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002464 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2465 NewT.setBuiltinLoc(T.getBuiltinLoc());
2466 if (T.needsExtraLocalData())
2467 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2468 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002469}
Mike Stump11289f42009-09-09 15:08:12 +00002470
Douglas Gregord6ff3322009-08-04 16:50:30 +00002471template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002472QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002473 ComplexTypeLoc T,
2474 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002475 // FIXME: recurse?
2476 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002477}
Mike Stump11289f42009-09-09 15:08:12 +00002478
Douglas Gregord6ff3322009-08-04 16:50:30 +00002479template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002480QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002481 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002482 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002483 QualType PointeeType
2484 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002485 if (PointeeType.isNull())
2486 return QualType();
2487
2488 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002489 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002490 // A dependent pointer type 'T *' has is being transformed such
2491 // that an Objective-C class type is being replaced for 'T'. The
2492 // resulting pointer type is an ObjCObjectPointerType, not a
2493 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002494 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002495
John McCall8b07ec22010-05-15 11:32:37 +00002496 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2497 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002498 return Result;
2499 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002500
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002501 if (getDerived().AlwaysRebuild() ||
2502 PointeeType != TL.getPointeeLoc().getType()) {
2503 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2504 if (Result.isNull())
2505 return QualType();
2506 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002507
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002508 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2509 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002510 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002511}
Mike Stump11289f42009-09-09 15:08:12 +00002512
2513template<typename Derived>
2514QualType
John McCall550e0c22009-10-21 00:40:46 +00002515TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002516 BlockPointerTypeLoc TL,
2517 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002518 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002519 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2520 if (PointeeType.isNull())
2521 return QualType();
2522
2523 QualType Result = TL.getType();
2524 if (getDerived().AlwaysRebuild() ||
2525 PointeeType != TL.getPointeeLoc().getType()) {
2526 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002527 TL.getSigilLoc());
2528 if (Result.isNull())
2529 return QualType();
2530 }
2531
Douglas Gregor049211a2010-04-22 16:50:51 +00002532 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002533 NewT.setSigilLoc(TL.getSigilLoc());
2534 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002535}
2536
John McCall70dd5f62009-10-30 00:06:24 +00002537/// Transforms a reference type. Note that somewhat paradoxically we
2538/// don't care whether the type itself is an l-value type or an r-value
2539/// type; we only care if the type was *written* as an l-value type
2540/// or an r-value type.
2541template<typename Derived>
2542QualType
2543TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002544 ReferenceTypeLoc TL,
2545 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002546 const ReferenceType *T = TL.getTypePtr();
2547
2548 // Note that this works with the pointee-as-written.
2549 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2550 if (PointeeType.isNull())
2551 return QualType();
2552
2553 QualType Result = TL.getType();
2554 if (getDerived().AlwaysRebuild() ||
2555 PointeeType != T->getPointeeTypeAsWritten()) {
2556 Result = getDerived().RebuildReferenceType(PointeeType,
2557 T->isSpelledAsLValue(),
2558 TL.getSigilLoc());
2559 if (Result.isNull())
2560 return QualType();
2561 }
2562
2563 // r-value references can be rebuilt as l-value references.
2564 ReferenceTypeLoc NewTL;
2565 if (isa<LValueReferenceType>(Result))
2566 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2567 else
2568 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2569 NewTL.setSigilLoc(TL.getSigilLoc());
2570
2571 return Result;
2572}
2573
Mike Stump11289f42009-09-09 15:08:12 +00002574template<typename Derived>
2575QualType
John McCall550e0c22009-10-21 00:40:46 +00002576TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002577 LValueReferenceTypeLoc TL,
2578 QualType ObjectType) {
2579 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002580}
2581
Mike Stump11289f42009-09-09 15:08:12 +00002582template<typename Derived>
2583QualType
John McCall550e0c22009-10-21 00:40:46 +00002584TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002585 RValueReferenceTypeLoc TL,
2586 QualType ObjectType) {
2587 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002588}
Mike Stump11289f42009-09-09 15:08:12 +00002589
Douglas Gregord6ff3322009-08-04 16:50:30 +00002590template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002591QualType
John McCall550e0c22009-10-21 00:40:46 +00002592TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002593 MemberPointerTypeLoc TL,
2594 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002595 MemberPointerType *T = TL.getTypePtr();
2596
2597 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002598 if (PointeeType.isNull())
2599 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002600
John McCall550e0c22009-10-21 00:40:46 +00002601 // TODO: preserve source information for this.
2602 QualType ClassType
2603 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604 if (ClassType.isNull())
2605 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002606
John McCall550e0c22009-10-21 00:40:46 +00002607 QualType Result = TL.getType();
2608 if (getDerived().AlwaysRebuild() ||
2609 PointeeType != T->getPointeeType() ||
2610 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002611 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2612 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002613 if (Result.isNull())
2614 return QualType();
2615 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002616
John McCall550e0c22009-10-21 00:40:46 +00002617 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2618 NewTL.setSigilLoc(TL.getSigilLoc());
2619
2620 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002621}
2622
Mike Stump11289f42009-09-09 15:08:12 +00002623template<typename Derived>
2624QualType
John McCall550e0c22009-10-21 00:40:46 +00002625TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002626 ConstantArrayTypeLoc TL,
2627 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002628 ConstantArrayType *T = TL.getTypePtr();
2629 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002630 if (ElementType.isNull())
2631 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002632
John McCall550e0c22009-10-21 00:40:46 +00002633 QualType Result = TL.getType();
2634 if (getDerived().AlwaysRebuild() ||
2635 ElementType != T->getElementType()) {
2636 Result = getDerived().RebuildConstantArrayType(ElementType,
2637 T->getSizeModifier(),
2638 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002639 T->getIndexTypeCVRQualifiers(),
2640 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002641 if (Result.isNull())
2642 return QualType();
2643 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002644
John McCall550e0c22009-10-21 00:40:46 +00002645 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2646 NewTL.setLBracketLoc(TL.getLBracketLoc());
2647 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002648
John McCall550e0c22009-10-21 00:40:46 +00002649 Expr *Size = TL.getSizeExpr();
2650 if (Size) {
2651 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2652 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2653 }
2654 NewTL.setSizeExpr(Size);
2655
2656 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002657}
Mike Stump11289f42009-09-09 15:08:12 +00002658
Douglas Gregord6ff3322009-08-04 16:50:30 +00002659template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002660QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002661 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002662 IncompleteArrayTypeLoc TL,
2663 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002664 IncompleteArrayType *T = TL.getTypePtr();
2665 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002666 if (ElementType.isNull())
2667 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002668
John McCall550e0c22009-10-21 00:40:46 +00002669 QualType Result = TL.getType();
2670 if (getDerived().AlwaysRebuild() ||
2671 ElementType != T->getElementType()) {
2672 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002673 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002674 T->getIndexTypeCVRQualifiers(),
2675 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002676 if (Result.isNull())
2677 return QualType();
2678 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002679
John McCall550e0c22009-10-21 00:40:46 +00002680 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2681 NewTL.setLBracketLoc(TL.getLBracketLoc());
2682 NewTL.setRBracketLoc(TL.getRBracketLoc());
2683 NewTL.setSizeExpr(0);
2684
2685 return Result;
2686}
2687
2688template<typename Derived>
2689QualType
2690TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002691 VariableArrayTypeLoc TL,
2692 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002693 VariableArrayType *T = TL.getTypePtr();
2694 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2695 if (ElementType.isNull())
2696 return QualType();
2697
2698 // Array bounds are not potentially evaluated contexts
2699 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2700
2701 Sema::OwningExprResult SizeResult
2702 = getDerived().TransformExpr(T->getSizeExpr());
2703 if (SizeResult.isInvalid())
2704 return QualType();
2705
2706 Expr *Size = static_cast<Expr*>(SizeResult.get());
2707
2708 QualType Result = TL.getType();
2709 if (getDerived().AlwaysRebuild() ||
2710 ElementType != T->getElementType() ||
2711 Size != T->getSizeExpr()) {
2712 Result = getDerived().RebuildVariableArrayType(ElementType,
2713 T->getSizeModifier(),
2714 move(SizeResult),
2715 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002716 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002717 if (Result.isNull())
2718 return QualType();
2719 }
2720 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002721
John McCall550e0c22009-10-21 00:40:46 +00002722 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2723 NewTL.setLBracketLoc(TL.getLBracketLoc());
2724 NewTL.setRBracketLoc(TL.getRBracketLoc());
2725 NewTL.setSizeExpr(Size);
2726
2727 return Result;
2728}
2729
2730template<typename Derived>
2731QualType
2732TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002733 DependentSizedArrayTypeLoc TL,
2734 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002735 DependentSizedArrayType *T = TL.getTypePtr();
2736 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2737 if (ElementType.isNull())
2738 return QualType();
2739
2740 // Array bounds are not potentially evaluated contexts
2741 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2742
2743 Sema::OwningExprResult SizeResult
2744 = getDerived().TransformExpr(T->getSizeExpr());
2745 if (SizeResult.isInvalid())
2746 return QualType();
2747
2748 Expr *Size = static_cast<Expr*>(SizeResult.get());
2749
2750 QualType Result = TL.getType();
2751 if (getDerived().AlwaysRebuild() ||
2752 ElementType != T->getElementType() ||
2753 Size != T->getSizeExpr()) {
2754 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2755 T->getSizeModifier(),
2756 move(SizeResult),
2757 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002758 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002759 if (Result.isNull())
2760 return QualType();
2761 }
2762 else SizeResult.take();
2763
2764 // We might have any sort of array type now, but fortunately they
2765 // all have the same location layout.
2766 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2767 NewTL.setLBracketLoc(TL.getLBracketLoc());
2768 NewTL.setRBracketLoc(TL.getRBracketLoc());
2769 NewTL.setSizeExpr(Size);
2770
2771 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002772}
Mike Stump11289f42009-09-09 15:08:12 +00002773
2774template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002776 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002777 DependentSizedExtVectorTypeLoc TL,
2778 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002779 DependentSizedExtVectorType *T = TL.getTypePtr();
2780
2781 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002782 QualType ElementType = getDerived().TransformType(T->getElementType());
2783 if (ElementType.isNull())
2784 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregore922c772009-08-04 22:27:00 +00002786 // Vector sizes are not potentially evaluated contexts
2787 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2788
Douglas Gregord6ff3322009-08-04 16:50:30 +00002789 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2790 if (Size.isInvalid())
2791 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002792
John McCall550e0c22009-10-21 00:40:46 +00002793 QualType Result = TL.getType();
2794 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002795 ElementType != T->getElementType() ||
2796 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002797 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002798 move(Size),
2799 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002800 if (Result.isNull())
2801 return QualType();
2802 }
2803 else Size.take();
2804
2805 // Result might be dependent or not.
2806 if (isa<DependentSizedExtVectorType>(Result)) {
2807 DependentSizedExtVectorTypeLoc NewTL
2808 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2809 NewTL.setNameLoc(TL.getNameLoc());
2810 } else {
2811 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
2813 }
2814
2815 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002816}
Mike Stump11289f42009-09-09 15:08:12 +00002817
2818template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002819QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002820 VectorTypeLoc TL,
2821 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002822 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002823 QualType ElementType = getDerived().TransformType(T->getElementType());
2824 if (ElementType.isNull())
2825 return QualType();
2826
John McCall550e0c22009-10-21 00:40:46 +00002827 QualType Result = TL.getType();
2828 if (getDerived().AlwaysRebuild() ||
2829 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002830 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002831 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002832 if (Result.isNull())
2833 return QualType();
2834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002835
John McCall550e0c22009-10-21 00:40:46 +00002836 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002838
John McCall550e0c22009-10-21 00:40:46 +00002839 return Result;
2840}
2841
2842template<typename Derived>
2843QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002844 ExtVectorTypeLoc TL,
2845 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002846 VectorType *T = TL.getTypePtr();
2847 QualType ElementType = getDerived().TransformType(T->getElementType());
2848 if (ElementType.isNull())
2849 return QualType();
2850
2851 QualType Result = TL.getType();
2852 if (getDerived().AlwaysRebuild() ||
2853 ElementType != T->getElementType()) {
2854 Result = getDerived().RebuildExtVectorType(ElementType,
2855 T->getNumElements(),
2856 /*FIXME*/ SourceLocation());
2857 if (Result.isNull())
2858 return QualType();
2859 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002860
John McCall550e0c22009-10-21 00:40:46 +00002861 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2862 NewTL.setNameLoc(TL.getNameLoc());
2863
2864 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002865}
Mike Stump11289f42009-09-09 15:08:12 +00002866
2867template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002868ParmVarDecl *
2869TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2870 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2871 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2872 if (!NewDI)
2873 return 0;
2874
2875 if (NewDI == OldDI)
2876 return OldParm;
2877 else
2878 return ParmVarDecl::Create(SemaRef.Context,
2879 OldParm->getDeclContext(),
2880 OldParm->getLocation(),
2881 OldParm->getIdentifier(),
2882 NewDI->getType(),
2883 NewDI,
2884 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002885 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002886 /* DefArg */ NULL);
2887}
2888
2889template<typename Derived>
2890bool TreeTransform<Derived>::
2891 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2892 llvm::SmallVectorImpl<QualType> &PTypes,
2893 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2894 FunctionProtoType *T = TL.getTypePtr();
2895
2896 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2897 ParmVarDecl *OldParm = TL.getArg(i);
2898
2899 QualType NewType;
2900 ParmVarDecl *NewParm;
2901
2902 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002903 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2904 if (!NewParm)
2905 return true;
2906 NewType = NewParm->getType();
2907
2908 // Deal with the possibility that we don't have a parameter
2909 // declaration for this parameter.
2910 } else {
2911 NewParm = 0;
2912
2913 QualType OldType = T->getArgType(i);
2914 NewType = getDerived().TransformType(OldType);
2915 if (NewType.isNull())
2916 return true;
2917 }
2918
2919 PTypes.push_back(NewType);
2920 PVars.push_back(NewParm);
2921 }
2922
2923 return false;
2924}
2925
2926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002927QualType
John McCall550e0c22009-10-21 00:40:46 +00002928TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002929 FunctionProtoTypeLoc TL,
2930 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002931 // Transform the parameters. We do this first for the benefit of template
2932 // instantiations, so that the ParmVarDecls get/ placed into the template
2933 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002935 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002936 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2937 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002938
Douglas Gregor14cf7522010-04-30 18:55:50 +00002939 FunctionProtoType *T = TL.getTypePtr();
2940 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2941 if (ResultType.isNull())
2942 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002943
John McCall550e0c22009-10-21 00:40:46 +00002944 QualType Result = TL.getType();
2945 if (getDerived().AlwaysRebuild() ||
2946 ResultType != T->getResultType() ||
2947 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2948 Result = getDerived().RebuildFunctionProtoType(ResultType,
2949 ParamTypes.data(),
2950 ParamTypes.size(),
2951 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002952 T->getTypeQuals(),
2953 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002954 if (Result.isNull())
2955 return QualType();
2956 }
Mike Stump11289f42009-09-09 15:08:12 +00002957
John McCall550e0c22009-10-21 00:40:46 +00002958 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2959 NewTL.setLParenLoc(TL.getLParenLoc());
2960 NewTL.setRParenLoc(TL.getRParenLoc());
2961 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2962 NewTL.setArg(i, ParamDecls[i]);
2963
2964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002965}
Mike Stump11289f42009-09-09 15:08:12 +00002966
Douglas Gregord6ff3322009-08-04 16:50:30 +00002967template<typename Derived>
2968QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002969 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002970 FunctionNoProtoTypeLoc TL,
2971 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002972 FunctionNoProtoType *T = TL.getTypePtr();
2973 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2974 if (ResultType.isNull())
2975 return QualType();
2976
2977 QualType Result = TL.getType();
2978 if (getDerived().AlwaysRebuild() ||
2979 ResultType != T->getResultType())
2980 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2981
2982 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2983 NewTL.setLParenLoc(TL.getLParenLoc());
2984 NewTL.setRParenLoc(TL.getRParenLoc());
2985
2986 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987}
Mike Stump11289f42009-09-09 15:08:12 +00002988
John McCallb96ec562009-12-04 22:46:56 +00002989template<typename Derived> QualType
2990TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 UnresolvedUsingTypeLoc TL,
2992 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002993 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002994 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002995 if (!D)
2996 return QualType();
2997
2998 QualType Result = TL.getType();
2999 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3000 Result = getDerived().RebuildUnresolvedUsingType(D);
3001 if (Result.isNull())
3002 return QualType();
3003 }
3004
3005 // We might get an arbitrary type spec type back. We should at
3006 // least always get a type spec type, though.
3007 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3008 NewTL.setNameLoc(TL.getNameLoc());
3009
3010 return Result;
3011}
3012
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003014QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003015 TypedefTypeLoc TL,
3016 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003017 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003019 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3020 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 if (!Typedef)
3022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003023
John McCall550e0c22009-10-21 00:40:46 +00003024 QualType Result = TL.getType();
3025 if (getDerived().AlwaysRebuild() ||
3026 Typedef != T->getDecl()) {
3027 Result = getDerived().RebuildTypedefType(Typedef);
3028 if (Result.isNull())
3029 return QualType();
3030 }
Mike Stump11289f42009-09-09 15:08:12 +00003031
John McCall550e0c22009-10-21 00:40:46 +00003032 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3033 NewTL.setNameLoc(TL.getNameLoc());
3034
3035 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036}
Mike Stump11289f42009-09-09 15:08:12 +00003037
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003039QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003040 TypeOfExprTypeLoc TL,
3041 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003042 // typeof expressions are not potentially evaluated contexts
3043 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003044
John McCalle8595032010-01-13 20:03:27 +00003045 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003046 if (E.isInvalid())
3047 return QualType();
3048
John McCall550e0c22009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
3050 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003051 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003052 Result = getDerived().RebuildTypeOfExprType(move(E));
3053 if (Result.isNull())
3054 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003055 }
John McCall550e0c22009-10-21 00:40:46 +00003056 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003057
John McCall550e0c22009-10-21 00:40:46 +00003058 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003059 NewTL.setTypeofLoc(TL.getTypeofLoc());
3060 NewTL.setLParenLoc(TL.getLParenLoc());
3061 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003062
3063 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003064}
Mike Stump11289f42009-09-09 15:08:12 +00003065
3066template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003067QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003068 TypeOfTypeLoc TL,
3069 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003070 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3071 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3072 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCall550e0c22009-10-21 00:40:46 +00003075 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003076 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3077 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003078 if (Result.isNull())
3079 return QualType();
3080 }
Mike Stump11289f42009-09-09 15:08:12 +00003081
John McCall550e0c22009-10-21 00:40:46 +00003082 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003083 NewTL.setTypeofLoc(TL.getTypeofLoc());
3084 NewTL.setLParenLoc(TL.getLParenLoc());
3085 NewTL.setRParenLoc(TL.getRParenLoc());
3086 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003087
3088 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003089}
Mike Stump11289f42009-09-09 15:08:12 +00003090
3091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003092QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003093 DecltypeTypeLoc TL,
3094 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003095 DecltypeType *T = TL.getTypePtr();
3096
Douglas Gregore922c772009-08-04 22:27:00 +00003097 // decltype expressions are not potentially evaluated contexts
3098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003099
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3101 if (E.isInvalid())
3102 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 QualType Result = TL.getType();
3105 if (getDerived().AlwaysRebuild() ||
3106 E.get() != T->getUnderlyingExpr()) {
3107 Result = getDerived().RebuildDecltypeType(move(E));
3108 if (Result.isNull())
3109 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003110 }
John McCall550e0c22009-10-21 00:40:46 +00003111 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003112
John McCall550e0c22009-10-21 00:40:46 +00003113 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3114 NewTL.setNameLoc(TL.getNameLoc());
3115
3116 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117}
3118
3119template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003120QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003121 RecordTypeLoc TL,
3122 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003123 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003125 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3126 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 if (!Record)
3128 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003129
John McCall550e0c22009-10-21 00:40:46 +00003130 QualType Result = TL.getType();
3131 if (getDerived().AlwaysRebuild() ||
3132 Record != T->getDecl()) {
3133 Result = getDerived().RebuildRecordType(Record);
3134 if (Result.isNull())
3135 return QualType();
3136 }
Mike Stump11289f42009-09-09 15:08:12 +00003137
John McCall550e0c22009-10-21 00:40:46 +00003138 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3139 NewTL.setNameLoc(TL.getNameLoc());
3140
3141 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142}
Mike Stump11289f42009-09-09 15:08:12 +00003143
3144template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003145QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003146 EnumTypeLoc TL,
3147 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003148 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003150 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3151 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 if (!Enum)
3153 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003154
John McCall550e0c22009-10-21 00:40:46 +00003155 QualType Result = TL.getType();
3156 if (getDerived().AlwaysRebuild() ||
3157 Enum != T->getDecl()) {
3158 Result = getDerived().RebuildEnumType(Enum);
3159 if (Result.isNull())
3160 return QualType();
3161 }
Mike Stump11289f42009-09-09 15:08:12 +00003162
John McCall550e0c22009-10-21 00:40:46 +00003163 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3164 NewTL.setNameLoc(TL.getNameLoc());
3165
3166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167}
John McCallfcc33b02009-09-05 00:15:47 +00003168
John McCalle78aac42010-03-10 03:28:59 +00003169template<typename Derived>
3170QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3171 TypeLocBuilder &TLB,
3172 InjectedClassNameTypeLoc TL,
3173 QualType ObjectType) {
3174 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3175 TL.getTypePtr()->getDecl());
3176 if (!D) return QualType();
3177
3178 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3179 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3180 return T;
3181}
3182
Mike Stump11289f42009-09-09 15:08:12 +00003183
Douglas Gregord6ff3322009-08-04 16:50:30 +00003184template<typename Derived>
3185QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003186 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003187 TemplateTypeParmTypeLoc TL,
3188 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003189 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003190}
3191
Mike Stump11289f42009-09-09 15:08:12 +00003192template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003193QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003194 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003195 SubstTemplateTypeParmTypeLoc TL,
3196 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003197 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003198}
3199
3200template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003201QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3202 const TemplateSpecializationType *TST,
3203 QualType ObjectType) {
3204 // FIXME: this entire method is a temporary workaround; callers
3205 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003206
John McCall0ad16662009-10-29 08:12:44 +00003207 // Fake up a TemplateSpecializationTypeLoc.
3208 TypeLocBuilder TLB;
3209 TemplateSpecializationTypeLoc TL
3210 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3211
John McCall0d07eb32009-10-29 18:45:58 +00003212 SourceLocation BaseLoc = getDerived().getBaseLocation();
3213
3214 TL.setTemplateNameLoc(BaseLoc);
3215 TL.setLAngleLoc(BaseLoc);
3216 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003217 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3218 const TemplateArgument &TA = TST->getArg(i);
3219 TemplateArgumentLoc TAL;
3220 getDerived().InventTemplateArgumentLoc(TA, TAL);
3221 TL.setArgLocInfo(i, TAL.getLocInfo());
3222 }
3223
3224 TypeLocBuilder IgnoredTLB;
3225 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003226}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003227
Douglas Gregorc59e5612009-10-19 22:04:39 +00003228template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003229QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003230 TypeLocBuilder &TLB,
3231 TemplateSpecializationTypeLoc TL,
3232 QualType ObjectType) {
3233 const TemplateSpecializationType *T = TL.getTypePtr();
3234
Mike Stump11289f42009-09-09 15:08:12 +00003235 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003236 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003237 if (Template.isNull())
3238 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003239
John McCall6b51f282009-11-23 01:53:49 +00003240 TemplateArgumentListInfo NewTemplateArgs;
3241 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3242 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3243
3244 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3245 TemplateArgumentLoc Loc;
3246 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003247 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003248 NewTemplateArgs.addArgument(Loc);
3249 }
Mike Stump11289f42009-09-09 15:08:12 +00003250
John McCall0ad16662009-10-29 08:12:44 +00003251 // FIXME: maybe don't rebuild if all the template arguments are the same.
3252
3253 QualType Result =
3254 getDerived().RebuildTemplateSpecializationType(Template,
3255 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003256 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003257
3258 if (!Result.isNull()) {
3259 TemplateSpecializationTypeLoc NewTL
3260 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3261 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3262 NewTL.setLAngleLoc(TL.getLAngleLoc());
3263 NewTL.setRAngleLoc(TL.getRAngleLoc());
3264 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3265 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266 }
Mike Stump11289f42009-09-09 15:08:12 +00003267
John McCall0ad16662009-10-29 08:12:44 +00003268 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269}
Mike Stump11289f42009-09-09 15:08:12 +00003270
3271template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003272QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003273TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3274 ElaboratedTypeLoc TL,
3275 QualType ObjectType) {
3276 ElaboratedType *T = TL.getTypePtr();
3277
3278 NestedNameSpecifier *NNS = 0;
3279 // NOTE: the qualifier in an ElaboratedType is optional.
3280 if (T->getQualifier() != 0) {
3281 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003282 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003283 ObjectType);
3284 if (!NNS)
3285 return QualType();
3286 }
Mike Stump11289f42009-09-09 15:08:12 +00003287
Abramo Bagnarad7548482010-05-19 21:37:53 +00003288 QualType NamedT;
3289 // FIXME: this test is meant to workaround a problem (failing assertion)
3290 // occurring if directly executing the code in the else branch.
3291 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3292 TemplateSpecializationTypeLoc OldNamedTL
3293 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3294 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003295 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003296 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3297 if (NamedT.isNull())
3298 return QualType();
3299 TemplateSpecializationTypeLoc NewNamedTL
3300 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3301 NewNamedTL.copy(OldNamedTL);
3302 }
3303 else {
3304 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3305 if (NamedT.isNull())
3306 return QualType();
3307 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003308
John McCall550e0c22009-10-21 00:40:46 +00003309 QualType Result = TL.getType();
3310 if (getDerived().AlwaysRebuild() ||
3311 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003312 NamedT != T->getNamedType()) {
3313 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003314 if (Result.isNull())
3315 return QualType();
3316 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317
Abramo Bagnara6150c882010-05-11 21:36:43 +00003318 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003319 NewTL.setKeywordLoc(TL.getKeywordLoc());
3320 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003321
3322 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323}
Mike Stump11289f42009-09-09 15:08:12 +00003324
3325template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003326QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3327 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003328 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003329 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003330
Douglas Gregord6ff3322009-08-04 16:50:30 +00003331 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003332 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3333 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003334 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003335 if (!NNS)
3336 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003337
John McCallc392f372010-06-11 00:33:02 +00003338 QualType Result
3339 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3340 T->getIdentifier(),
3341 TL.getKeywordLoc(),
3342 TL.getQualifierRange(),
3343 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003344 if (Result.isNull())
3345 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346
Abramo Bagnarad7548482010-05-19 21:37:53 +00003347 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3348 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003349 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3350
Abramo Bagnarad7548482010-05-19 21:37:53 +00003351 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3352 NewTL.setKeywordLoc(TL.getKeywordLoc());
3353 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003354 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003355 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3356 NewTL.setKeywordLoc(TL.getKeywordLoc());
3357 NewTL.setQualifierRange(TL.getQualifierRange());
3358 NewTL.setNameLoc(TL.getNameLoc());
3359 }
John McCall550e0c22009-10-21 00:40:46 +00003360 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003361}
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregord6ff3322009-08-04 16:50:30 +00003363template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003364QualType TreeTransform<Derived>::
3365 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3366 DependentTemplateSpecializationTypeLoc TL,
3367 QualType ObjectType) {
3368 DependentTemplateSpecializationType *T = TL.getTypePtr();
3369
3370 NestedNameSpecifier *NNS
3371 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3372 TL.getQualifierRange(),
3373 ObjectType);
3374 if (!NNS)
3375 return QualType();
3376
3377 TemplateArgumentListInfo NewTemplateArgs;
3378 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3379 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3380
3381 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3382 TemplateArgumentLoc Loc;
3383 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3384 return QualType();
3385 NewTemplateArgs.addArgument(Loc);
3386 }
3387
3388 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3389 T->getKeyword(),
3390 NNS,
3391 T->getIdentifier(),
3392 TL.getNameLoc(),
3393 NewTemplateArgs);
3394 if (Result.isNull())
3395 return QualType();
3396
3397 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3398 QualType NamedT = ElabT->getNamedType();
3399
3400 // Copy information relevant to the template specialization.
3401 TemplateSpecializationTypeLoc NamedTL
3402 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3403 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3404 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3405 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3406 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3407
3408 // Copy information relevant to the elaborated type.
3409 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3410 NewTL.setKeywordLoc(TL.getKeywordLoc());
3411 NewTL.setQualifierRange(TL.getQualifierRange());
3412 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003413 TypeLoc NewTL(Result, TL.getOpaqueData());
3414 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003415 }
3416 return Result;
3417}
3418
3419template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003420QualType
3421TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003422 ObjCInterfaceTypeLoc TL,
3423 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003424 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003425 TLB.pushFullCopy(TL);
3426 return TL.getType();
3427}
3428
3429template<typename Derived>
3430QualType
3431TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3432 ObjCObjectTypeLoc TL,
3433 QualType ObjectType) {
3434 // ObjCObjectType is never dependent.
3435 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003436 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437}
Mike Stump11289f42009-09-09 15:08:12 +00003438
3439template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003440QualType
3441TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003442 ObjCObjectPointerTypeLoc TL,
3443 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003444 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003445 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003446 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003447}
3448
Douglas Gregord6ff3322009-08-04 16:50:30 +00003449//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003450// Statement transformation
3451//===----------------------------------------------------------------------===//
3452template<typename Derived>
3453Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003454TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3455 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003456}
3457
3458template<typename Derived>
3459Sema::OwningStmtResult
3460TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3461 return getDerived().TransformCompoundStmt(S, false);
3462}
3463
3464template<typename Derived>
3465Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003466TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 bool IsStmtExpr) {
3468 bool SubStmtChanged = false;
3469 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3470 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3471 B != BEnd; ++B) {
3472 OwningStmtResult Result = getDerived().TransformStmt(*B);
3473 if (Result.isInvalid())
3474 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003475
Douglas Gregorebe10102009-08-20 07:17:43 +00003476 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3477 Statements.push_back(Result.takeAs<Stmt>());
3478 }
Mike Stump11289f42009-09-09 15:08:12 +00003479
Douglas Gregorebe10102009-08-20 07:17:43 +00003480 if (!getDerived().AlwaysRebuild() &&
3481 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003482 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003483
3484 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3485 move_arg(Statements),
3486 S->getRBracLoc(),
3487 IsStmtExpr);
3488}
Mike Stump11289f42009-09-09 15:08:12 +00003489
Douglas Gregorebe10102009-08-20 07:17:43 +00003490template<typename Derived>
3491Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003492TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003493 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3494 {
3495 // The case value expressions are not potentially evaluated.
3496 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003497
Eli Friedman06577382009-11-19 03:14:00 +00003498 // Transform the left-hand case value.
3499 LHS = getDerived().TransformExpr(S->getLHS());
3500 if (LHS.isInvalid())
3501 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003502
Eli Friedman06577382009-11-19 03:14:00 +00003503 // Transform the right-hand case value (for the GNU case-range extension).
3504 RHS = getDerived().TransformExpr(S->getRHS());
3505 if (RHS.isInvalid())
3506 return SemaRef.StmtError();
3507 }
Mike Stump11289f42009-09-09 15:08:12 +00003508
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 // Build the case statement.
3510 // Case statements are always rebuilt so that they will attached to their
3511 // transformed switch statement.
3512 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3513 move(LHS),
3514 S->getEllipsisLoc(),
3515 move(RHS),
3516 S->getColonLoc());
3517 if (Case.isInvalid())
3518 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003519
Douglas Gregorebe10102009-08-20 07:17:43 +00003520 // Transform the statement following the case
3521 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3522 if (SubStmt.isInvalid())
3523 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregorebe10102009-08-20 07:17:43 +00003525 // Attach the body to the case statement
3526 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3527}
3528
3529template<typename Derived>
3530Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003531TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003532 // Transform the statement following the default case
3533 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3534 if (SubStmt.isInvalid())
3535 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003536
Douglas Gregorebe10102009-08-20 07:17:43 +00003537 // Default statements are always rebuilt
3538 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3539 move(SubStmt));
3540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregorebe10102009-08-20 07:17:43 +00003542template<typename Derived>
3543Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003544TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3546 if (SubStmt.isInvalid())
3547 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003548
Douglas Gregorebe10102009-08-20 07:17:43 +00003549 // FIXME: Pass the real colon location in.
3550 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3551 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3552 move(SubStmt));
3553}
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003556Sema::OwningStmtResult
3557TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003558 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003559 OwningExprResult Cond(SemaRef);
3560 VarDecl *ConditionVar = 0;
3561 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003562 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003563 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003564 getDerived().TransformDefinition(
3565 S->getConditionVariable()->getLocation(),
3566 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003567 if (!ConditionVar)
3568 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003569 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003570 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003571
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003572 if (Cond.isInvalid())
3573 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003574
3575 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003576 if (S->getCond()) {
3577 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3578 S->getIfLoc(),
3579 move(Cond));
3580 if (CondE.isInvalid())
3581 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003582
Douglas Gregor6d319c62010-05-08 23:34:38 +00003583 Cond = move(CondE);
3584 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003586
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003587 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3588 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3589 return SemaRef.StmtError();
3590
Douglas Gregorebe10102009-08-20 07:17:43 +00003591 // Transform the "then" branch.
3592 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3593 if (Then.isInvalid())
3594 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregorebe10102009-08-20 07:17:43 +00003596 // Transform the "else" branch.
3597 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3598 if (Else.isInvalid())
3599 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003602 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003603 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 Then.get() == S->getThen() &&
3605 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003606 return SemaRef.Owned(S->Retain());
3607
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003608 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003609 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003610 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003611}
3612
3613template<typename Derived>
3614Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003615TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003616 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003617 OwningExprResult Cond(SemaRef);
3618 VarDecl *ConditionVar = 0;
3619 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003620 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003621 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003622 getDerived().TransformDefinition(
3623 S->getConditionVariable()->getLocation(),
3624 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003625 if (!ConditionVar)
3626 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003627 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003628 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003629
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003630 if (Cond.isInvalid())
3631 return SemaRef.StmtError();
3632 }
Mike Stump11289f42009-09-09 15:08:12 +00003633
Douglas Gregorebe10102009-08-20 07:17:43 +00003634 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003635 OwningStmtResult Switch
3636 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3637 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003638 if (Switch.isInvalid())
3639 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregorebe10102009-08-20 07:17:43 +00003641 // Transform the body of the switch statement.
3642 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3643 if (Body.isInvalid())
3644 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003645
Douglas Gregorebe10102009-08-20 07:17:43 +00003646 // Complete the switch statement.
3647 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3648 move(Body));
3649}
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregorebe10102009-08-20 07:17:43 +00003651template<typename Derived>
3652Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003653TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003655 OwningExprResult Cond(SemaRef);
3656 VarDecl *ConditionVar = 0;
3657 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003658 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003659 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003660 getDerived().TransformDefinition(
3661 S->getConditionVariable()->getLocation(),
3662 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003663 if (!ConditionVar)
3664 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003665 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003666 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003667
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003668 if (Cond.isInvalid())
3669 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003670
3671 if (S->getCond()) {
3672 // Convert the condition to a boolean value.
3673 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003674 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003675 move(Cond));
3676 if (CondE.isInvalid())
3677 return getSema().StmtError();
3678 Cond = move(CondE);
3679 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003680 }
Mike Stump11289f42009-09-09 15:08:12 +00003681
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003682 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3683 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3684 return SemaRef.StmtError();
3685
Douglas Gregorebe10102009-08-20 07:17:43 +00003686 // Transform the body
3687 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3688 if (Body.isInvalid())
3689 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003692 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003693 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003694 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003695 return SemaRef.Owned(S->Retain());
3696
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003697 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003698 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003699}
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701template<typename Derived>
3702Sema::OwningStmtResult
3703TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 // Transform the body
3705 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3706 if (Body.isInvalid())
3707 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003708
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003709 // Transform the condition
3710 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3711 if (Cond.isInvalid())
3712 return SemaRef.StmtError();
3713
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 if (!getDerived().AlwaysRebuild() &&
3715 Cond.get() == S->getCond() &&
3716 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003717 return SemaRef.Owned(S->Retain());
3718
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3720 /*FIXME:*/S->getWhileLoc(), move(Cond),
3721 S->getRParenLoc());
3722}
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregorebe10102009-08-20 07:17:43 +00003724template<typename Derived>
3725Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003726TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003727 // Transform the initialization statement
3728 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3729 if (Init.isInvalid())
3730 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003731
Douglas Gregorebe10102009-08-20 07:17:43 +00003732 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003733 OwningExprResult Cond(SemaRef);
3734 VarDecl *ConditionVar = 0;
3735 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003736 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003737 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003738 getDerived().TransformDefinition(
3739 S->getConditionVariable()->getLocation(),
3740 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003741 if (!ConditionVar)
3742 return SemaRef.StmtError();
3743 } else {
3744 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003745
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003746 if (Cond.isInvalid())
3747 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003748
3749 if (S->getCond()) {
3750 // Convert the condition to a boolean value.
3751 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3752 S->getForLoc(),
3753 move(Cond));
3754 if (CondE.isInvalid())
3755 return getSema().StmtError();
3756
3757 Cond = move(CondE);
3758 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003759 }
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003761 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3762 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3763 return SemaRef.StmtError();
3764
Douglas Gregorebe10102009-08-20 07:17:43 +00003765 // Transform the increment
3766 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3767 if (Inc.isInvalid())
3768 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003770 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3771 if (S->getInc() && !FullInc->get())
3772 return SemaRef.StmtError();
3773
Douglas Gregorebe10102009-08-20 07:17:43 +00003774 // Transform the body
3775 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3776 if (Body.isInvalid())
3777 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003778
Douglas Gregorebe10102009-08-20 07:17:43 +00003779 if (!getDerived().AlwaysRebuild() &&
3780 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003781 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 Inc.get() == S->getInc() &&
3783 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003784 return SemaRef.Owned(S->Retain());
3785
Douglas Gregorebe10102009-08-20 07:17:43 +00003786 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003787 move(Init), FullCond, ConditionVar,
3788 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003789}
3790
3791template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003792Sema::OwningStmtResult
3793TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003794 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003795 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003796 S->getLabel());
3797}
3798
3799template<typename Derived>
3800Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003801TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003802 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3803 if (Target.isInvalid())
3804 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003805
Douglas Gregorebe10102009-08-20 07:17:43 +00003806 if (!getDerived().AlwaysRebuild() &&
3807 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003808 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003809
3810 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3811 move(Target));
3812}
3813
3814template<typename Derived>
3815Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003816TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3817 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003818}
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregorebe10102009-08-20 07:17:43 +00003820template<typename Derived>
3821Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003822TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3823 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003824}
Mike Stump11289f42009-09-09 15:08:12 +00003825
Douglas Gregorebe10102009-08-20 07:17:43 +00003826template<typename Derived>
3827Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003828TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003829 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3830 if (Result.isInvalid())
3831 return SemaRef.StmtError();
3832
Mike Stump11289f42009-09-09 15:08:12 +00003833 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003834 // to tell whether the return type of the function has changed.
3835 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3836}
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregorebe10102009-08-20 07:17:43 +00003838template<typename Derived>
3839Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003840TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003841 bool DeclChanged = false;
3842 llvm::SmallVector<Decl *, 4> Decls;
3843 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3844 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003845 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3846 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003847 if (!Transformed)
3848 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregorebe10102009-08-20 07:17:43 +00003850 if (Transformed != *D)
3851 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregorebe10102009-08-20 07:17:43 +00003853 Decls.push_back(Transformed);
3854 }
Mike Stump11289f42009-09-09 15:08:12 +00003855
Douglas Gregorebe10102009-08-20 07:17:43 +00003856 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003857 return SemaRef.Owned(S->Retain());
3858
3859 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003860 S->getStartLoc(), S->getEndLoc());
3861}
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregorebe10102009-08-20 07:17:43 +00003863template<typename Derived>
3864Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003865TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003866 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003867 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003868}
3869
3870template<typename Derived>
3871Sema::OwningStmtResult
3872TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003873
Anders Carlssonaaeef072010-01-24 05:50:09 +00003874 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3875 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003876 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003877
Anders Carlssonaaeef072010-01-24 05:50:09 +00003878 OwningExprResult AsmString(SemaRef);
3879 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3880
3881 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003882
Anders Carlssonaaeef072010-01-24 05:50:09 +00003883 // Go through the outputs.
3884 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003885 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003886
Anders Carlssonaaeef072010-01-24 05:50:09 +00003887 // No need to transform the constraint literal.
3888 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003889
Anders Carlssonaaeef072010-01-24 05:50:09 +00003890 // Transform the output expr.
3891 Expr *OutputExpr = S->getOutputExpr(I);
3892 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3893 if (Result.isInvalid())
3894 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003895
Anders Carlssonaaeef072010-01-24 05:50:09 +00003896 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003897
Anders Carlssonaaeef072010-01-24 05:50:09 +00003898 Exprs.push_back(Result.takeAs<Expr>());
3899 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003900
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 // Go through the inputs.
3902 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003903 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003904
Anders Carlssonaaeef072010-01-24 05:50:09 +00003905 // No need to transform the constraint literal.
3906 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003907
Anders Carlssonaaeef072010-01-24 05:50:09 +00003908 // Transform the input expr.
3909 Expr *InputExpr = S->getInputExpr(I);
3910 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3911 if (Result.isInvalid())
3912 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003913
Anders Carlssonaaeef072010-01-24 05:50:09 +00003914 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003915
Anders Carlssonaaeef072010-01-24 05:50:09 +00003916 Exprs.push_back(Result.takeAs<Expr>());
3917 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003918
Anders Carlssonaaeef072010-01-24 05:50:09 +00003919 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3920 return SemaRef.Owned(S->Retain());
3921
3922 // Go through the clobbers.
3923 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3924 Clobbers.push_back(S->getClobber(I)->Retain());
3925
3926 // No need to transform the asm string literal.
3927 AsmString = SemaRef.Owned(S->getAsmString());
3928
3929 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3930 S->isSimple(),
3931 S->isVolatile(),
3932 S->getNumOutputs(),
3933 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003934 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003935 move_arg(Constraints),
3936 move_arg(Exprs),
3937 move(AsmString),
3938 move_arg(Clobbers),
3939 S->getRParenLoc(),
3940 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003941}
3942
3943
3944template<typename Derived>
3945Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003946TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003947 // Transform the body of the @try.
3948 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3949 if (TryBody.isInvalid())
3950 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003951
Douglas Gregor96c79492010-04-23 22:50:49 +00003952 // Transform the @catch statements (if present).
3953 bool AnyCatchChanged = false;
3954 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3955 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3956 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003957 if (Catch.isInvalid())
3958 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003959 if (Catch.get() != S->getCatchStmt(I))
3960 AnyCatchChanged = true;
3961 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003962 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003963
Douglas Gregor306de2f2010-04-22 23:59:56 +00003964 // Transform the @finally statement (if present).
3965 OwningStmtResult Finally(SemaRef);
3966 if (S->getFinallyStmt()) {
3967 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3968 if (Finally.isInvalid())
3969 return SemaRef.StmtError();
3970 }
3971
3972 // If nothing changed, just retain this statement.
3973 if (!getDerived().AlwaysRebuild() &&
3974 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003975 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003976 Finally.get() == S->getFinallyStmt())
3977 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003978
Douglas Gregor306de2f2010-04-22 23:59:56 +00003979 // Build a new statement.
3980 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003981 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003982}
Mike Stump11289f42009-09-09 15:08:12 +00003983
Douglas Gregorebe10102009-08-20 07:17:43 +00003984template<typename Derived>
3985Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003986TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003987 // Transform the @catch parameter, if there is one.
3988 VarDecl *Var = 0;
3989 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3990 TypeSourceInfo *TSInfo = 0;
3991 if (FromVar->getTypeSourceInfo()) {
3992 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3993 if (!TSInfo)
3994 return SemaRef.StmtError();
3995 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003996
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003997 QualType T;
3998 if (TSInfo)
3999 T = TSInfo->getType();
4000 else {
4001 T = getDerived().TransformType(FromVar->getType());
4002 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00004003 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004004 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004005
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004006 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4007 if (!Var)
4008 return SemaRef.StmtError();
4009 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004010
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004011 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4012 if (Body.isInvalid())
4013 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004014
4015 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004016 S->getRParenLoc(),
4017 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
Douglas Gregorebe10102009-08-20 07:17:43 +00004020template<typename Derived>
4021Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004022TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004023 // Transform the body.
4024 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4025 if (Body.isInvalid())
4026 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004027
Douglas Gregor306de2f2010-04-22 23:59:56 +00004028 // If nothing changed, just retain this statement.
4029 if (!getDerived().AlwaysRebuild() &&
4030 Body.get() == S->getFinallyBody())
4031 return SemaRef.Owned(S->Retain());
4032
4033 // Build a new statement.
4034 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4035 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004036}
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregorebe10102009-08-20 07:17:43 +00004038template<typename Derived>
4039Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004040TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00004041 OwningExprResult Operand(SemaRef);
4042 if (S->getThrowExpr()) {
4043 Operand = getDerived().TransformExpr(S->getThrowExpr());
4044 if (Operand.isInvalid())
4045 return getSema().StmtError();
4046 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004047
Douglas Gregor2900c162010-04-22 21:44:01 +00004048 if (!getDerived().AlwaysRebuild() &&
4049 Operand.get() == S->getThrowExpr())
4050 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004051
Douglas Gregor2900c162010-04-22 21:44:01 +00004052 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00004053}
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregorebe10102009-08-20 07:17:43 +00004055template<typename Derived>
4056Sema::OwningStmtResult
4057TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004058 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004059 // Transform the object we are locking.
4060 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4061 if (Object.isInvalid())
4062 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004063
Douglas Gregor6148de72010-04-22 22:01:21 +00004064 // Transform the body.
4065 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4066 if (Body.isInvalid())
4067 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004068
Douglas Gregor6148de72010-04-22 22:01:21 +00004069 // If nothing change, just retain the current statement.
4070 if (!getDerived().AlwaysRebuild() &&
4071 Object.get() == S->getSynchExpr() &&
4072 Body.get() == S->getSynchBody())
4073 return SemaRef.Owned(S->Retain());
4074
4075 // Build a new statement.
4076 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4077 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004078}
4079
4080template<typename Derived>
4081Sema::OwningStmtResult
4082TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004083 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004084 // Transform the element statement.
4085 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4086 if (Element.isInvalid())
4087 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004088
Douglas Gregorf68a5082010-04-22 23:10:45 +00004089 // Transform the collection expression.
4090 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4091 if (Collection.isInvalid())
4092 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004093
Douglas Gregorf68a5082010-04-22 23:10:45 +00004094 // Transform the body.
4095 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4096 if (Body.isInvalid())
4097 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004098
Douglas Gregorf68a5082010-04-22 23:10:45 +00004099 // If nothing changed, just retain this statement.
4100 if (!getDerived().AlwaysRebuild() &&
4101 Element.get() == S->getElement() &&
4102 Collection.get() == S->getCollection() &&
4103 Body.get() == S->getBody())
4104 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004105
Douglas Gregorf68a5082010-04-22 23:10:45 +00004106 // Build a new statement.
4107 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4108 /*FIXME:*/S->getForLoc(),
4109 move(Element),
4110 move(Collection),
4111 S->getRParenLoc(),
4112 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004113}
4114
4115
4116template<typename Derived>
4117Sema::OwningStmtResult
4118TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4119 // Transform the exception declaration, if any.
4120 VarDecl *Var = 0;
4121 if (S->getExceptionDecl()) {
4122 VarDecl *ExceptionDecl = S->getExceptionDecl();
4123 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4124 ExceptionDecl->getDeclName());
4125
4126 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4127 if (T.isNull())
4128 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004129
Douglas Gregorebe10102009-08-20 07:17:43 +00004130 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4131 T,
John McCallbcd03502009-12-07 02:54:59 +00004132 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004133 ExceptionDecl->getIdentifier(),
4134 ExceptionDecl->getLocation(),
4135 /*FIXME: Inaccurate*/
4136 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004137 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004138 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004139 }
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregorebe10102009-08-20 07:17:43 +00004141 // Transform the actual exception handler.
4142 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004143 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004144 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregorebe10102009-08-20 07:17:43 +00004146 if (!getDerived().AlwaysRebuild() &&
4147 !Var &&
4148 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004149 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004150
4151 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4152 Var,
4153 move(Handler));
4154}
Mike Stump11289f42009-09-09 15:08:12 +00004155
Douglas Gregorebe10102009-08-20 07:17:43 +00004156template<typename Derived>
4157Sema::OwningStmtResult
4158TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4159 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004160 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004161 = getDerived().TransformCompoundStmt(S->getTryBlock());
4162 if (TryBlock.isInvalid())
4163 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregorebe10102009-08-20 07:17:43 +00004165 // Transform the handlers.
4166 bool HandlerChanged = false;
4167 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4168 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004169 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004170 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4171 if (Handler.isInvalid())
4172 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregorebe10102009-08-20 07:17:43 +00004174 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4175 Handlers.push_back(Handler.takeAs<Stmt>());
4176 }
Mike Stump11289f42009-09-09 15:08:12 +00004177
Douglas Gregorebe10102009-08-20 07:17:43 +00004178 if (!getDerived().AlwaysRebuild() &&
4179 TryBlock.get() == S->getTryBlock() &&
4180 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004181 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004182
4183 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004184 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004185}
Mike Stump11289f42009-09-09 15:08:12 +00004186
Douglas Gregorebe10102009-08-20 07:17:43 +00004187//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004188// Expression transformation
4189//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004190template<typename Derived>
4191Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004192TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004193 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004194}
Mike Stump11289f42009-09-09 15:08:12 +00004195
4196template<typename Derived>
4197Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004198TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004199 NestedNameSpecifier *Qualifier = 0;
4200 if (E->getQualifier()) {
4201 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004202 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004203 if (!Qualifier)
4204 return SemaRef.ExprError();
4205 }
John McCallce546572009-12-08 09:08:17 +00004206
4207 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004208 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4209 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 if (!ND)
4211 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004212
John McCall815039a2010-08-17 21:27:17 +00004213 DeclarationNameInfo NameInfo = E->getNameInfo();
4214 if (NameInfo.getName()) {
4215 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4216 if (!NameInfo.getName())
4217 return SemaRef.ExprError();
4218 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004219
4220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004221 Qualifier == E->getQualifier() &&
4222 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004223 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004224 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004225
4226 // Mark it referenced in the new context regardless.
4227 // FIXME: this is a bit instantiation-specific.
4228 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4229
Mike Stump11289f42009-09-09 15:08:12 +00004230 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004231 }
John McCallce546572009-12-08 09:08:17 +00004232
4233 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004234 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004235 TemplateArgs = &TransArgs;
4236 TransArgs.setLAngleLoc(E->getLAngleLoc());
4237 TransArgs.setRAngleLoc(E->getRAngleLoc());
4238 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4239 TemplateArgumentLoc Loc;
4240 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4241 return SemaRef.ExprError();
4242 TransArgs.addArgument(Loc);
4243 }
4244 }
4245
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004246 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004247 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004248}
Mike Stump11289f42009-09-09 15:08:12 +00004249
Douglas Gregora16548e2009-08-11 05:31:07 +00004250template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004251Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004252TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004253 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004254}
Mike Stump11289f42009-09-09 15:08:12 +00004255
Douglas Gregora16548e2009-08-11 05:31:07 +00004256template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004257Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004259 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004260}
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004263Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004264TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004265 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004266}
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregora16548e2009-08-11 05:31:07 +00004268template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004269Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004270TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004271 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004272}
Mike Stump11289f42009-09-09 15:08:12 +00004273
Douglas Gregora16548e2009-08-11 05:31:07 +00004274template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004275Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004276TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004277 return SemaRef.Owned(E->Retain());
4278}
4279
4280template<typename Derived>
4281Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004282TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4284 if (SubExpr.isInvalid())
4285 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004288 return SemaRef.Owned(E->Retain());
4289
4290 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 E->getRParen());
4292}
4293
Mike Stump11289f42009-09-09 15:08:12 +00004294template<typename Derived>
4295Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004296TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4297 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 if (SubExpr.isInvalid())
4299 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004302 return SemaRef.Owned(E->Retain());
4303
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4305 E->getOpcode(),
4306 move(SubExpr));
4307}
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004310Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004311TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4312 // Transform the type.
4313 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4314 if (!Type)
4315 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004316
Douglas Gregor882211c2010-04-28 22:16:22 +00004317 // Transform all of the components into components similar to what the
4318 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004319 // FIXME: It would be slightly more efficient in the non-dependent case to
4320 // just map FieldDecls, rather than requiring the rebuilder to look for
4321 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004322 // template code that we don't care.
4323 bool ExprChanged = false;
4324 typedef Action::OffsetOfComponent Component;
4325 typedef OffsetOfExpr::OffsetOfNode Node;
4326 llvm::SmallVector<Component, 4> Components;
4327 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4328 const Node &ON = E->getComponent(I);
4329 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004330 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004331 Comp.LocStart = ON.getRange().getBegin();
4332 Comp.LocEnd = ON.getRange().getEnd();
4333 switch (ON.getKind()) {
4334 case Node::Array: {
4335 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4336 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4337 if (Index.isInvalid())
4338 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004339
Douglas Gregor882211c2010-04-28 22:16:22 +00004340 ExprChanged = ExprChanged || Index.get() != FromIndex;
4341 Comp.isBrackets = true;
4342 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4343 break;
4344 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004345
Douglas Gregor882211c2010-04-28 22:16:22 +00004346 case Node::Field:
4347 case Node::Identifier:
4348 Comp.isBrackets = false;
4349 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004350 if (!Comp.U.IdentInfo)
4351 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004352
Douglas Gregor882211c2010-04-28 22:16:22 +00004353 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004354
Douglas Gregord1702062010-04-29 00:18:15 +00004355 case Node::Base:
4356 // Will be recomputed during the rebuild.
4357 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004358 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004359
Douglas Gregor882211c2010-04-28 22:16:22 +00004360 Components.push_back(Comp);
4361 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004362
Douglas Gregor882211c2010-04-28 22:16:22 +00004363 // If nothing changed, retain the existing expression.
4364 if (!getDerived().AlwaysRebuild() &&
4365 Type == E->getTypeSourceInfo() &&
4366 !ExprChanged)
4367 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004368
Douglas Gregor882211c2010-04-28 22:16:22 +00004369 // Build a new offsetof expression.
4370 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4371 Components.data(), Components.size(),
4372 E->getRParenLoc());
4373}
4374
4375template<typename Derived>
4376Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004377TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004379 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004380
John McCallbcd03502009-12-07 02:54:59 +00004381 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004382 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004384
John McCall4c98fd82009-11-04 07:28:41 +00004385 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004387
John McCall4c98fd82009-11-04 07:28:41 +00004388 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004389 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 E->getSourceRange());
4391 }
Mike Stump11289f42009-09-09 15:08:12 +00004392
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004394 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004395 // C++0x [expr.sizeof]p1:
4396 // The operand is either an expression, which is an unevaluated operand
4397 // [...]
4398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004399
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4401 if (SubExpr.isInvalid())
4402 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4405 return SemaRef.Owned(E->Retain());
4406 }
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4409 E->isSizeOf(),
4410 E->getSourceRange());
4411}
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregora16548e2009-08-11 05:31:07 +00004413template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004414Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004415TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4417 if (LHS.isInvalid())
4418 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4421 if (RHS.isInvalid())
4422 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004423
4424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 if (!getDerived().AlwaysRebuild() &&
4426 LHS.get() == E->getLHS() &&
4427 RHS.get() == E->getRHS())
4428 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4431 /*FIXME:*/E->getLHS()->getLocStart(),
4432 move(RHS),
4433 E->getRBracketLoc());
4434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
4436template<typename Derived>
4437Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004438TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 // Transform the callee.
4440 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4441 if (Callee.isInvalid())
4442 return SemaRef.ExprError();
4443
4444 // Transform arguments.
4445 bool ArgChanged = false;
4446 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4447 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4448 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4449 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4450 if (Arg.isInvalid())
4451 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004452
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 // FIXME: Wrong source location information for the ','.
4454 FakeCommaLocs.push_back(
4455 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004456
4457 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 Args.push_back(Arg.takeAs<Expr>());
4459 }
Mike Stump11289f42009-09-09 15:08:12 +00004460
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 if (!getDerived().AlwaysRebuild() &&
4462 Callee.get() == E->getCallee() &&
4463 !ArgChanged)
4464 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004465
Douglas Gregora16548e2009-08-11 05:31:07 +00004466 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004467 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4469 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4470 move_arg(Args),
4471 FakeCommaLocs.data(),
4472 E->getRParenLoc());
4473}
Mike Stump11289f42009-09-09 15:08:12 +00004474
4475template<typename Derived>
4476Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004477TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4479 if (Base.isInvalid())
4480 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004481
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004482 NestedNameSpecifier *Qualifier = 0;
4483 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004484 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004485 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004486 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004487 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004488 return SemaRef.ExprError();
4489 }
Mike Stump11289f42009-09-09 15:08:12 +00004490
Eli Friedman2cfcef62009-12-04 06:40:45 +00004491 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004492 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4493 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 if (!Member)
4495 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004496
John McCall16df1e52010-03-30 21:47:33 +00004497 NamedDecl *FoundDecl = E->getFoundDecl();
4498 if (FoundDecl == E->getMemberDecl()) {
4499 FoundDecl = Member;
4500 } else {
4501 FoundDecl = cast_or_null<NamedDecl>(
4502 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4503 if (!FoundDecl)
4504 return SemaRef.ExprError();
4505 }
4506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 if (!getDerived().AlwaysRebuild() &&
4508 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004509 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004510 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004511 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004512 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004513
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004514 // Mark it referenced in the new context regardless.
4515 // FIXME: this is a bit instantiation-specific.
4516 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004517 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004518 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004519
John McCall6b51f282009-11-23 01:53:49 +00004520 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004521 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004522 TransArgs.setLAngleLoc(E->getLAngleLoc());
4523 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004524 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004525 TemplateArgumentLoc Loc;
4526 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004527 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004528 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004529 }
4530 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004531
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 // FIXME: Bogus source location for the operator
4533 SourceLocation FakeOperatorLoc
4534 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4535
John McCall38836f02010-01-15 08:34:02 +00004536 // FIXME: to do this check properly, we will need to preserve the
4537 // first-qualifier-in-scope here, just in case we had a dependent
4538 // base (and therefore couldn't do the check) and a
4539 // nested-name-qualifier (and therefore could do the lookup).
4540 NamedDecl *FirstQualifierInScope = 0;
4541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4543 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004544 Qualifier,
4545 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004546 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004547 Member,
John McCall16df1e52010-03-30 21:47:33 +00004548 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004549 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004550 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004551 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004555Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004556TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4558 if (LHS.isInvalid())
4559 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004560
Douglas Gregora16548e2009-08-11 05:31:07 +00004561 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4562 if (RHS.isInvalid())
4563 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565 if (!getDerived().AlwaysRebuild() &&
4566 LHS.get() == E->getLHS() &&
4567 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004568 return SemaRef.Owned(E->Retain());
4569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4571 move(LHS), move(RHS));
4572}
4573
Mike Stump11289f42009-09-09 15:08:12 +00004574template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004575Sema::OwningExprResult
4576TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004577 CompoundAssignOperator *E) {
4578 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004579}
Mike Stump11289f42009-09-09 15:08:12 +00004580
Douglas Gregora16548e2009-08-11 05:31:07 +00004581template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004582Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004583TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004584 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4585 if (Cond.isInvalid())
4586 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004587
Douglas Gregora16548e2009-08-11 05:31:07 +00004588 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4589 if (LHS.isInvalid())
4590 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4593 if (RHS.isInvalid())
4594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 if (!getDerived().AlwaysRebuild() &&
4597 Cond.get() == E->getCond() &&
4598 LHS.get() == E->getLHS() &&
4599 RHS.get() == E->getRHS())
4600 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004601
4602 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004603 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004604 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004605 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 move(RHS));
4607}
Mike Stump11289f42009-09-09 15:08:12 +00004608
4609template<typename Derived>
4610Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004611TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004612 // Implicit casts are eliminated during transformation, since they
4613 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004614 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004615}
Mike Stump11289f42009-09-09 15:08:12 +00004616
Douglas Gregora16548e2009-08-11 05:31:07 +00004617template<typename Derived>
4618Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004619TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004620 TypeSourceInfo *OldT;
4621 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 {
4623 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004624 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4626 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004627
John McCall97513962010-01-15 18:39:57 +00004628 OldT = E->getTypeInfoAsWritten();
4629 NewT = getDerived().TransformType(OldT);
4630 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 return SemaRef.ExprError();
4632 }
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregor6131b442009-12-12 18:16:41 +00004634 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004635 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 if (SubExpr.isInvalid())
4637 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004640 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004642 return SemaRef.Owned(E->Retain());
4643
John McCall97513962010-01-15 18:39:57 +00004644 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4645 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 E->getRParenLoc(),
4647 move(SubExpr));
4648}
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregora16548e2009-08-11 05:31:07 +00004650template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004651Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004652TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004653 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4654 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4655 if (!NewT)
4656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4659 if (Init.isInvalid())
4660 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004663 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004665 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004666
John McCall5d7aa7f2010-01-19 22:33:45 +00004667 // Note: the expression type doesn't necessarily match the
4668 // type-as-written, but that's okay, because it should always be
4669 // derivable from the initializer.
4670
John McCalle15bbff2010-01-18 19:35:47 +00004671 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 /*FIXME:*/E->getInitializer()->getLocEnd(),
4673 move(Init));
4674}
Mike Stump11289f42009-09-09 15:08:12 +00004675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676template<typename Derived>
4677Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004678TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004679 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4680 if (Base.isInvalid())
4681 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004682
Douglas Gregora16548e2009-08-11 05:31:07 +00004683 if (!getDerived().AlwaysRebuild() &&
4684 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004685 return SemaRef.Owned(E->Retain());
4686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004688 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4690 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4691 E->getAccessorLoc(),
4692 E->getAccessor());
4693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004696Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4701 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4702 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4703 if (Init.isInvalid())
4704 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 InitChanged = InitChanged || Init.get() != E->getInit(I);
4707 Inits.push_back(Init.takeAs<Expr>());
4708 }
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004711 return SemaRef.Owned(E->Retain());
4712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004714 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004715}
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregora16548e2009-08-11 05:31:07 +00004717template<typename Derived>
4718Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004719TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004720 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregorebe10102009-08-20 07:17:43 +00004722 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4724 if (Init.isInvalid())
4725 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregorebe10102009-08-20 07:17:43 +00004727 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4729 bool ExprChanged = false;
4730 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4731 DEnd = E->designators_end();
4732 D != DEnd; ++D) {
4733 if (D->isFieldDesignator()) {
4734 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4735 D->getDotLoc(),
4736 D->getFieldLoc()));
4737 continue;
4738 }
Mike Stump11289f42009-09-09 15:08:12 +00004739
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 if (D->isArrayDesignator()) {
4741 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4742 if (Index.isInvalid())
4743 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004744
4745 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4749 ArrayExprs.push_back(Index.release());
4750 continue;
4751 }
Mike Stump11289f42009-09-09 15:08:12 +00004752
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004754 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4756 if (Start.isInvalid())
4757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4760 if (End.isInvalid())
4761 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004762
4763 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 End.get(),
4765 D->getLBracketLoc(),
4766 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4769 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 ArrayExprs.push_back(Start.release());
4772 ArrayExprs.push_back(End.release());
4773 }
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 if (!getDerived().AlwaysRebuild() &&
4776 Init.get() == E->getInit() &&
4777 !ExprChanged)
4778 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4781 E->getEqualOrColonLoc(),
4782 E->usesGNUSyntax(), move(Init));
4783}
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004786Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004787TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004788 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004789 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004790
Douglas Gregor3da3c062009-10-28 00:29:27 +00004791 // FIXME: Will we ever have proper type location here? Will we actually
4792 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 QualType T = getDerived().TransformType(E->getType());
4794 if (T.isNull())
4795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004796
Douglas Gregora16548e2009-08-11 05:31:07 +00004797 if (!getDerived().AlwaysRebuild() &&
4798 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004799 return SemaRef.Owned(E->Retain());
4800
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 return getDerived().RebuildImplicitValueInitExpr(T);
4802}
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregora16548e2009-08-11 05:31:07 +00004804template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004805Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004806TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004807 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4808 if (!TInfo)
4809 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4812 if (SubExpr.isInvalid())
4813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004816 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 SubExpr.get() == E->getSubExpr())
4818 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004821 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004822}
4823
4824template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004825Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004826TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 bool ArgumentChanged = false;
4828 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4829 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4830 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4831 if (Init.isInvalid())
4832 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4835 Inits.push_back(Init.takeAs<Expr>());
4836 }
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4839 move_arg(Inits),
4840 E->getRParenLoc());
4841}
Mike Stump11289f42009-09-09 15:08:12 +00004842
Douglas Gregora16548e2009-08-11 05:31:07 +00004843/// \brief Transform an address-of-label expression.
4844///
4845/// By default, the transformation of an address-of-label expression always
4846/// rebuilds the expression, so that the label identifier can be resolved to
4847/// the corresponding label statement by semantic analysis.
4848template<typename Derived>
4849Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004850TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004851 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4852 E->getLabel());
4853}
Mike Stump11289f42009-09-09 15:08:12 +00004854
4855template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004856Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004857TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004858 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4860 if (SubStmt.isInvalid())
4861 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 if (!getDerived().AlwaysRebuild() &&
4864 SubStmt.get() == E->getSubStmt())
4865 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004866
4867 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 move(SubStmt),
4869 E->getRParenLoc());
4870}
Mike Stump11289f42009-09-09 15:08:12 +00004871
Douglas Gregora16548e2009-08-11 05:31:07 +00004872template<typename Derived>
4873Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004874TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004875 TypeSourceInfo *TInfo1;
4876 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004877
4878 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4879 if (!TInfo1)
4880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregor7058c262010-08-10 14:27:00 +00004882 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4883 if (!TInfo2)
4884 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004885
4886 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004887 TInfo1 == E->getArgTInfo1() &&
4888 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004889 return SemaRef.Owned(E->Retain());
4890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004892 TInfo1, TInfo2,
4893 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004894}
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896template<typename Derived>
4897Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004898TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4900 if (Cond.isInvalid())
4901 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4904 if (LHS.isInvalid())
4905 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004906
Douglas Gregora16548e2009-08-11 05:31:07 +00004907 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4908 if (RHS.isInvalid())
4909 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 if (!getDerived().AlwaysRebuild() &&
4912 Cond.get() == E->getCond() &&
4913 LHS.get() == E->getLHS() &&
4914 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004915 return SemaRef.Owned(E->Retain());
4916
Douglas Gregora16548e2009-08-11 05:31:07 +00004917 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4918 move(Cond), move(LHS), move(RHS),
4919 E->getRParenLoc());
4920}
Mike Stump11289f42009-09-09 15:08:12 +00004921
Douglas Gregora16548e2009-08-11 05:31:07 +00004922template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004923Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004924TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004925 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004926}
4927
4928template<typename Derived>
4929Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004930TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004931 switch (E->getOperator()) {
4932 case OO_New:
4933 case OO_Delete:
4934 case OO_Array_New:
4935 case OO_Array_Delete:
4936 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4937 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004938
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004939 case OO_Call: {
4940 // This is a call to an object's operator().
4941 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4942
4943 // Transform the object itself.
4944 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4945 if (Object.isInvalid())
4946 return SemaRef.ExprError();
4947
4948 // FIXME: Poor location information
4949 SourceLocation FakeLParenLoc
4950 = SemaRef.PP.getLocForEndOfToken(
4951 static_cast<Expr *>(Object.get())->getLocEnd());
4952
4953 // Transform the call arguments.
4954 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4955 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4956 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004957 if (getDerived().DropCallArgument(E->getArg(I)))
4958 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004959
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004960 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4961 if (Arg.isInvalid())
4962 return SemaRef.ExprError();
4963
4964 // FIXME: Poor source location information.
4965 SourceLocation FakeCommaLoc
4966 = SemaRef.PP.getLocForEndOfToken(
4967 static_cast<Expr *>(Arg.get())->getLocEnd());
4968 FakeCommaLocs.push_back(FakeCommaLoc);
4969 Args.push_back(Arg.release());
4970 }
4971
4972 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4973 move_arg(Args),
4974 FakeCommaLocs.data(),
4975 E->getLocEnd());
4976 }
4977
4978#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4979 case OO_##Name:
4980#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4981#include "clang/Basic/OperatorKinds.def"
4982 case OO_Subscript:
4983 // Handled below.
4984 break;
4985
4986 case OO_Conditional:
4987 llvm_unreachable("conditional operator is not actually overloadable");
4988 return SemaRef.ExprError();
4989
4990 case OO_None:
4991 case NUM_OVERLOADED_OPERATORS:
4992 llvm_unreachable("not an overloaded operator?");
4993 return SemaRef.ExprError();
4994 }
4995
Douglas Gregora16548e2009-08-11 05:31:07 +00004996 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4997 if (Callee.isInvalid())
4998 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004999
John McCall47f29ea2009-12-08 09:21:05 +00005000 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005001 if (First.isInvalid())
5002 return SemaRef.ExprError();
5003
5004 OwningExprResult Second(SemaRef);
5005 if (E->getNumArgs() == 2) {
5006 Second = getDerived().TransformExpr(E->getArg(1));
5007 if (Second.isInvalid())
5008 return SemaRef.ExprError();
5009 }
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (!getDerived().AlwaysRebuild() &&
5012 Callee.get() == E->getCallee() &&
5013 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005014 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5015 return SemaRef.Owned(E->Retain());
5016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5018 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005019 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 move(First),
5021 move(Second));
5022}
Mike Stump11289f42009-09-09 15:08:12 +00005023
Douglas Gregora16548e2009-08-11 05:31:07 +00005024template<typename Derived>
5025Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005026TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5027 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005028}
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregora16548e2009-08-11 05:31:07 +00005030template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005031Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005032TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005033 TypeSourceInfo *OldT;
5034 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005035 {
5036 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005037 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5039 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005040
John McCall97513962010-01-15 18:39:57 +00005041 OldT = E->getTypeInfoAsWritten();
5042 NewT = getDerived().TransformType(OldT);
5043 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 return SemaRef.ExprError();
5045 }
Mike Stump11289f42009-09-09 15:08:12 +00005046
Douglas Gregor6131b442009-12-12 18:16:41 +00005047 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005048 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005049 if (SubExpr.isInvalid())
5050 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005051
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005053 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005054 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005055 return SemaRef.Owned(E->Retain());
5056
Douglas Gregora16548e2009-08-11 05:31:07 +00005057 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005058 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5060 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5061 SourceLocation FakeRParenLoc
5062 = SemaRef.PP.getLocForEndOfToken(
5063 E->getSubExpr()->getSourceRange().getEnd());
5064 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005065 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005066 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005067 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005068 FakeRAngleLoc,
5069 FakeRAngleLoc,
5070 move(SubExpr),
5071 FakeRParenLoc);
5072}
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074template<typename Derived>
5075Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005076TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5077 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005078}
Mike Stump11289f42009-09-09 15:08:12 +00005079
5080template<typename Derived>
5081Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5083 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005084}
5085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086template<typename Derived>
5087Sema::OwningExprResult
5088TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005089 CXXReinterpretCastExpr *E) {
5090 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005091}
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregora16548e2009-08-11 05:31:07 +00005093template<typename Derived>
5094Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005095TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5096 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005097}
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregora16548e2009-08-11 05:31:07 +00005099template<typename Derived>
5100Sema::OwningExprResult
5101TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005102 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005103 TypeSourceInfo *OldT;
5104 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 {
5106 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005107
John McCall97513962010-01-15 18:39:57 +00005108 OldT = E->getTypeInfoAsWritten();
5109 NewT = getDerived().TransformType(OldT);
5110 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 return SemaRef.ExprError();
5112 }
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregor6131b442009-12-12 18:16:41 +00005114 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005115 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 if (SubExpr.isInvalid())
5117 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005118
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005120 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005122 return SemaRef.Owned(E->Retain());
5123
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 // FIXME: The end of the type's source range is wrong
5125 return getDerived().RebuildCXXFunctionalCastExpr(
5126 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005127 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 /*FIXME:*/E->getSubExpr()->getLocStart(),
5129 move(SubExpr),
5130 E->getRParenLoc());
5131}
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregora16548e2009-08-11 05:31:07 +00005133template<typename Derived>
5134Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005135TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005137 TypeSourceInfo *TInfo
5138 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5139 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005143 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregor9da64192010-04-26 22:37:10 +00005146 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5147 E->getLocStart(),
5148 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 E->getLocEnd());
5150 }
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregora16548e2009-08-11 05:31:07 +00005152 // We don't know whether the expression is potentially evaluated until
5153 // after we perform semantic analysis, so the expression is potentially
5154 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005155 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregora16548e2009-08-11 05:31:07 +00005158 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5159 if (SubExpr.isInvalid())
5160 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 if (!getDerived().AlwaysRebuild() &&
5163 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005164 return SemaRef.Owned(E->Retain());
5165
Douglas Gregor9da64192010-04-26 22:37:10 +00005166 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5167 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 move(SubExpr),
5169 E->getLocEnd());
5170}
5171
5172template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005173Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005174TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005175 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178template<typename Derived>
5179Sema::OwningExprResult
5180TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005181 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005182 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005183}
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregora16548e2009-08-11 05:31:07 +00005185template<typename Derived>
5186Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005187TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005188 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 QualType T = getDerived().TransformType(E->getType());
5191 if (T.isNull())
5192 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregora16548e2009-08-11 05:31:07 +00005194 if (!getDerived().AlwaysRebuild() &&
5195 T == E->getType())
5196 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregorb15af892010-01-07 23:12:05 +00005198 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregora16548e2009-08-11 05:31:07 +00005201template<typename Derived>
5202Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005203TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5205 if (SubExpr.isInvalid())
5206 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005207
Douglas Gregora16548e2009-08-11 05:31:07 +00005208 if (!getDerived().AlwaysRebuild() &&
5209 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005210 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005211
5212 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5213}
Mike Stump11289f42009-09-09 15:08:12 +00005214
Douglas Gregora16548e2009-08-11 05:31:07 +00005215template<typename Derived>
5216Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005218 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005219 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5220 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 if (!Param)
5222 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005223
Chandler Carruth794da4c2010-02-08 06:42:49 +00005224 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 Param == E->getParam())
5226 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregor033f6752009-12-23 23:03:06 +00005228 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005229}
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregora16548e2009-08-11 05:31:07 +00005231template<typename Derived>
5232Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005233TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5235
5236 QualType T = getDerived().TransformType(E->getType());
5237 if (T.isNull())
5238 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005239
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 if (!getDerived().AlwaysRebuild() &&
5241 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005242 return SemaRef.Owned(E->Retain());
5243
Douglas Gregor747eb782010-07-08 06:14:04 +00005244 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5245 /*FIXME:*/E->getTypeBeginLoc(),
5246 T,
5247 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248}
Mike Stump11289f42009-09-09 15:08:12 +00005249
Douglas Gregora16548e2009-08-11 05:31:07 +00005250template<typename Derived>
5251Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 // Transform the type that we're allocating
5254 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5255 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5256 if (AllocType.isNull())
5257 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 // Transform the size of the array we're allocating (if any).
5260 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5261 if (ArraySize.isInvalid())
5262 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregora16548e2009-08-11 05:31:07 +00005264 // Transform the placement arguments (if any).
5265 bool ArgumentChanged = false;
5266 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5267 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5268 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5269 if (Arg.isInvalid())
5270 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregora16548e2009-08-11 05:31:07 +00005272 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5273 PlacementArgs.push_back(Arg.take());
5274 }
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregorebe10102009-08-20 07:17:43 +00005276 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005277 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5278 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005279 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5280 break;
5281
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5283 if (Arg.isInvalid())
5284 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5287 ConstructorArgs.push_back(Arg.take());
5288 }
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregord2d9da02010-02-26 00:38:10 +00005290 // Transform constructor, new operator, and delete operator.
5291 CXXConstructorDecl *Constructor = 0;
5292 if (E->getConstructor()) {
5293 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005294 getDerived().TransformDecl(E->getLocStart(),
5295 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005296 if (!Constructor)
5297 return SemaRef.ExprError();
5298 }
5299
5300 FunctionDecl *OperatorNew = 0;
5301 if (E->getOperatorNew()) {
5302 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005303 getDerived().TransformDecl(E->getLocStart(),
5304 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005305 if (!OperatorNew)
5306 return SemaRef.ExprError();
5307 }
5308
5309 FunctionDecl *OperatorDelete = 0;
5310 if (E->getOperatorDelete()) {
5311 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005312 getDerived().TransformDecl(E->getLocStart(),
5313 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005314 if (!OperatorDelete)
5315 return SemaRef.ExprError();
5316 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
Douglas Gregora16548e2009-08-11 05:31:07 +00005318 if (!getDerived().AlwaysRebuild() &&
5319 AllocType == E->getAllocatedType() &&
5320 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005321 Constructor == E->getConstructor() &&
5322 OperatorNew == E->getOperatorNew() &&
5323 OperatorDelete == E->getOperatorDelete() &&
5324 !ArgumentChanged) {
5325 // Mark any declarations we need as referenced.
5326 // FIXME: instantiation-specific.
5327 if (Constructor)
5328 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5329 if (OperatorNew)
5330 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5331 if (OperatorDelete)
5332 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005333 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005334 }
Mike Stump11289f42009-09-09 15:08:12 +00005335
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005336 if (!ArraySize.get()) {
5337 // If no array size was specified, but the new expression was
5338 // instantiated with an array type (e.g., "new T" where T is
5339 // instantiated with "int[4]"), extract the outer bound from the
5340 // array type as our array size. We do this with constant and
5341 // dependently-sized array types.
5342 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5343 if (!ArrayT) {
5344 // Do nothing
5345 } else if (const ConstantArrayType *ConsArrayT
5346 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005347 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005348 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005349 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005350 SemaRef.Context.getSizeType(),
5351 /*FIXME:*/E->getLocStart()));
5352 AllocType = ConsArrayT->getElementType();
5353 } else if (const DependentSizedArrayType *DepArrayT
5354 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5355 if (DepArrayT->getSizeExpr()) {
5356 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5357 AllocType = DepArrayT->getElementType();
5358 }
5359 }
5360 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5362 E->isGlobalNew(),
5363 /*FIXME:*/E->getLocStart(),
5364 move_arg(PlacementArgs),
5365 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005366 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 AllocType,
5368 /*FIXME:*/E->getLocStart(),
5369 /*FIXME:*/SourceRange(),
5370 move(ArraySize),
5371 /*FIXME:*/E->getLocStart(),
5372 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005373 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005374}
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregora16548e2009-08-11 05:31:07 +00005376template<typename Derived>
5377Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005378TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5380 if (Operand.isInvalid())
5381 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005382
Douglas Gregord2d9da02010-02-26 00:38:10 +00005383 // Transform the delete operator, if known.
5384 FunctionDecl *OperatorDelete = 0;
5385 if (E->getOperatorDelete()) {
5386 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005387 getDerived().TransformDecl(E->getLocStart(),
5388 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005389 if (!OperatorDelete)
5390 return SemaRef.ExprError();
5391 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005392
Douglas Gregora16548e2009-08-11 05:31:07 +00005393 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005394 Operand.get() == E->getArgument() &&
5395 OperatorDelete == E->getOperatorDelete()) {
5396 // Mark any declarations we need as referenced.
5397 // FIXME: instantiation-specific.
5398 if (OperatorDelete)
5399 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005400 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005401 }
Mike Stump11289f42009-09-09 15:08:12 +00005402
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5404 E->isGlobalDelete(),
5405 E->isArrayForm(),
5406 move(Operand));
5407}
Mike Stump11289f42009-09-09 15:08:12 +00005408
Douglas Gregora16548e2009-08-11 05:31:07 +00005409template<typename Derived>
5410Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005411TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005412 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005413 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5414 if (Base.isInvalid())
5415 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregor678f90d2010-02-25 01:56:36 +00005417 Sema::TypeTy *ObjectTypePtr = 0;
5418 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005420 E->getOperatorLoc(),
5421 E->isArrow()? tok::arrow : tok::period,
5422 ObjectTypePtr,
5423 MayBePseudoDestructor);
5424 if (Base.isInvalid())
5425 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005426
Douglas Gregor678f90d2010-02-25 01:56:36 +00005427 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005428 NestedNameSpecifier *Qualifier
5429 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005430 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005431 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005432 if (E->getQualifier() && !Qualifier)
5433 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregor678f90d2010-02-25 01:56:36 +00005435 PseudoDestructorTypeStorage Destroyed;
5436 if (E->getDestroyedTypeInfo()) {
5437 TypeSourceInfo *DestroyedTypeInfo
5438 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5439 if (!DestroyedTypeInfo)
5440 return SemaRef.ExprError();
5441 Destroyed = DestroyedTypeInfo;
5442 } else if (ObjectType->isDependentType()) {
5443 // We aren't likely to be able to resolve the identifier down to a type
5444 // now anyway, so just retain the identifier.
5445 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5446 E->getDestroyedTypeLoc());
5447 } else {
5448 // Look for a destructor known with the given name.
5449 CXXScopeSpec SS;
5450 if (Qualifier) {
5451 SS.setScopeRep(Qualifier);
5452 SS.setRange(E->getQualifierRange());
5453 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005454
Douglas Gregor678f90d2010-02-25 01:56:36 +00005455 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5456 *E->getDestroyedTypeIdentifier(),
5457 E->getDestroyedTypeLoc(),
5458 /*Scope=*/0,
5459 SS, ObjectTypePtr,
5460 false);
5461 if (!T)
5462 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005463
Douglas Gregor678f90d2010-02-25 01:56:36 +00005464 Destroyed
5465 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5466 E->getDestroyedTypeLoc());
5467 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005468
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005469 TypeSourceInfo *ScopeTypeInfo = 0;
5470 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005471 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005472 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005473 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005474 return SemaRef.ExprError();
5475 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005476
Douglas Gregorad8a3362009-09-04 17:36:40 +00005477 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5478 E->getOperatorLoc(),
5479 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005480 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005481 E->getQualifierRange(),
5482 ScopeTypeInfo,
5483 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005484 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005485 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregorad8a3362009-09-04 17:36:40 +00005488template<typename Derived>
5489Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005490TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005491 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005492 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5493
5494 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5495 Sema::LookupOrdinaryName);
5496
5497 // Transform all the decls.
5498 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5499 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005500 NamedDecl *InstD = static_cast<NamedDecl*>(
5501 getDerived().TransformDecl(Old->getNameLoc(),
5502 *I));
John McCall84d87672009-12-10 09:41:52 +00005503 if (!InstD) {
5504 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5505 // This can happen because of dependent hiding.
5506 if (isa<UsingShadowDecl>(*I))
5507 continue;
5508 else
5509 return SemaRef.ExprError();
5510 }
John McCalle66edc12009-11-24 19:00:30 +00005511
5512 // Expand using declarations.
5513 if (isa<UsingDecl>(InstD)) {
5514 UsingDecl *UD = cast<UsingDecl>(InstD);
5515 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5516 E = UD->shadow_end(); I != E; ++I)
5517 R.addDecl(*I);
5518 continue;
5519 }
5520
5521 R.addDecl(InstD);
5522 }
5523
5524 // Resolve a kind, but don't do any further analysis. If it's
5525 // ambiguous, the callee needs to deal with it.
5526 R.resolveKind();
5527
5528 // Rebuild the nested-name qualifier, if present.
5529 CXXScopeSpec SS;
5530 NestedNameSpecifier *Qualifier = 0;
5531 if (Old->getQualifier()) {
5532 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005533 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005534 if (!Qualifier)
5535 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005536
John McCalle66edc12009-11-24 19:00:30 +00005537 SS.setScopeRep(Qualifier);
5538 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005539 }
5540
Douglas Gregor9262f472010-04-27 18:19:34 +00005541 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005542 CXXRecordDecl *NamingClass
5543 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5544 Old->getNameLoc(),
5545 Old->getNamingClass()));
5546 if (!NamingClass)
5547 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005548
Douglas Gregorda7be082010-04-27 16:10:10 +00005549 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005550 }
5551
5552 // If we have no template arguments, it's a normal declaration name.
5553 if (!Old->hasExplicitTemplateArgs())
5554 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5555
5556 // If we have template arguments, rebuild them, then rebuild the
5557 // templateid expression.
5558 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5559 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5560 TemplateArgumentLoc Loc;
5561 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5562 return SemaRef.ExprError();
5563 TransArgs.addArgument(Loc);
5564 }
5565
5566 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5567 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005568}
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregora16548e2009-08-11 05:31:07 +00005570template<typename Derived>
5571Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005572TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 QualType T = getDerived().TransformType(E->getQueriedType());
5576 if (T.isNull())
5577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 if (!getDerived().AlwaysRebuild() &&
5580 T == E->getQueriedType())
5581 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 // FIXME: Bad location information
5584 SourceLocation FakeLParenLoc
5585 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005586
5587 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 E->getLocStart(),
5589 /*FIXME:*/FakeLParenLoc,
5590 T,
5591 E->getLocEnd());
5592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregora16548e2009-08-11 05:31:07 +00005594template<typename Derived>
5595Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005596TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005597 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005599 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005600 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 if (!NNS)
5602 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005603
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005604 DeclarationNameInfo NameInfo
5605 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5606 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005607 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005608
John McCalle66edc12009-11-24 19:00:30 +00005609 if (!E->hasExplicitTemplateArgs()) {
5610 if (!getDerived().AlwaysRebuild() &&
5611 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005612 // Note: it is sufficient to compare the Name component of NameInfo:
5613 // if name has not changed, DNLoc has not changed either.
5614 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005615 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005616
John McCalle66edc12009-11-24 19:00:30 +00005617 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5618 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005619 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005620 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005621 }
John McCall6b51f282009-11-23 01:53:49 +00005622
5623 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005625 TemplateArgumentLoc Loc;
5626 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005628 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 }
5630
John McCalle66edc12009-11-24 19:00:30 +00005631 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5632 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005633 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005634 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005635}
5636
5637template<typename Derived>
5638Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005639TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005640 // CXXConstructExprs are always implicit, so when we have a
5641 // 1-argument construction we just transform that argument.
5642 if (E->getNumArgs() == 1 ||
5643 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5644 return getDerived().TransformExpr(E->getArg(0));
5645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5647
5648 QualType T = getDerived().TransformType(E->getType());
5649 if (T.isNull())
5650 return SemaRef.ExprError();
5651
5652 CXXConstructorDecl *Constructor
5653 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005654 getDerived().TransformDecl(E->getLocStart(),
5655 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005656 if (!Constructor)
5657 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 bool ArgumentChanged = false;
5660 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005661 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 ArgEnd = E->arg_end();
5663 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005664 if (getDerived().DropCallArgument(*Arg)) {
5665 ArgumentChanged = true;
5666 break;
5667 }
5668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5670 if (TransArg.isInvalid())
5671 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5674 Args.push_back(TransArg.takeAs<Expr>());
5675 }
5676
5677 if (!getDerived().AlwaysRebuild() &&
5678 T == E->getType() &&
5679 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005680 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005681 // Mark the constructor as referenced.
5682 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005683 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005685 }
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregordb121ba2009-12-14 16:27:04 +00005687 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5688 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 move_arg(Args));
5690}
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692/// \brief Transform a C++ temporary-binding expression.
5693///
Douglas Gregor363b1512009-12-24 18:51:59 +00005694/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5695/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005696template<typename Derived>
5697Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005698TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005699 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005700}
Mike Stump11289f42009-09-09 15:08:12 +00005701
Anders Carlssonba6c4372010-01-29 02:39:32 +00005702/// \brief Transform a C++ reference-binding expression.
5703///
5704/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5705/// transform the subexpression and return that.
5706template<typename Derived>
5707Sema::OwningExprResult
5708TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5709 return getDerived().TransformExpr(E->getSubExpr());
5710}
5711
Mike Stump11289f42009-09-09 15:08:12 +00005712/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005713/// be destroyed after the expression is evaluated.
5714///
Douglas Gregor363b1512009-12-24 18:51:59 +00005715/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5716/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005717template<typename Derived>
5718Sema::OwningExprResult
5719TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005720 CXXExprWithTemporaries *E) {
5721 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005722}
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregora16548e2009-08-11 05:31:07 +00005724template<typename Derived>
5725Sema::OwningExprResult
5726TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005727 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5729 QualType T = getDerived().TransformType(E->getType());
5730 if (T.isNull())
5731 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 CXXConstructorDecl *Constructor
5734 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005735 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005736 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 if (!Constructor)
5738 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 bool ArgumentChanged = false;
5741 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5742 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005743 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 ArgEnd = E->arg_end();
5745 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005746 if (getDerived().DropCallArgument(*Arg)) {
5747 ArgumentChanged = true;
5748 break;
5749 }
5750
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5752 if (TransArg.isInvalid())
5753 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005754
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5756 Args.push_back((Expr *)TransArg.release());
5757 }
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 if (!getDerived().AlwaysRebuild() &&
5760 T == E->getType() &&
5761 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005762 !ArgumentChanged) {
5763 // FIXME: Instantiation-specific
5764 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005765 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005766 }
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 // FIXME: Bogus location information
5769 SourceLocation CommaLoc;
5770 if (Args.size() > 1) {
5771 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005772 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5774 }
5775 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5776 T,
5777 /*FIXME:*/E->getTypeBeginLoc(),
5778 move_arg(Args),
5779 &CommaLoc,
5780 E->getLocEnd());
5781}
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783template<typename Derived>
5784Sema::OwningExprResult
5785TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005786 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5788 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5789 if (T.isNull())
5790 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 bool ArgumentChanged = false;
5793 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5794 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5795 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5796 ArgEnd = E->arg_end();
5797 Arg != ArgEnd; ++Arg) {
5798 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5799 if (TransArg.isInvalid())
5800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5803 FakeCommaLocs.push_back(
5804 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5805 Args.push_back(TransArg.takeAs<Expr>());
5806 }
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 if (!getDerived().AlwaysRebuild() &&
5809 T == E->getTypeAsWritten() &&
5810 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005811 return SemaRef.Owned(E->Retain());
5812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 // FIXME: we're faking the locations of the commas
5814 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5815 T,
5816 E->getLParenLoc(),
5817 move_arg(Args),
5818 FakeCommaLocs.data(),
5819 E->getRParenLoc());
5820}
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregora16548e2009-08-11 05:31:07 +00005822template<typename Derived>
5823Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005824TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005825 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005827 OwningExprResult Base(SemaRef, (Expr*) 0);
5828 Expr *OldBase;
5829 QualType BaseType;
5830 QualType ObjectType;
5831 if (!E->isImplicitAccess()) {
5832 OldBase = E->getBase();
5833 Base = getDerived().TransformExpr(OldBase);
5834 if (Base.isInvalid())
5835 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005836
John McCall2d74de92009-12-01 22:10:20 +00005837 // Start the member reference and compute the object's type.
5838 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005839 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005840 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5841 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005842 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005843 ObjectTy,
5844 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005845 if (Base.isInvalid())
5846 return SemaRef.ExprError();
5847
5848 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5849 BaseType = ((Expr*) Base.get())->getType();
5850 } else {
5851 OldBase = 0;
5852 BaseType = getDerived().TransformType(E->getBaseType());
5853 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5854 }
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005856 // Transform the first part of the nested-name-specifier that qualifies
5857 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005858 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005859 = getDerived().TransformFirstQualifierInScope(
5860 E->getFirstQualifierFoundInScope(),
5861 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005862
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005863 NestedNameSpecifier *Qualifier = 0;
5864 if (E->getQualifier()) {
5865 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5866 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005867 ObjectType,
5868 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005869 if (!Qualifier)
5870 return SemaRef.ExprError();
5871 }
Mike Stump11289f42009-09-09 15:08:12 +00005872
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005873 DeclarationNameInfo NameInfo
5874 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5875 ObjectType);
5876 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005877 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005878
John McCall2d74de92009-12-01 22:10:20 +00005879 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005880 // This is a reference to a member without an explicitly-specified
5881 // template argument list. Optimize for this common case.
5882 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005883 Base.get() == OldBase &&
5884 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005885 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005886 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005887 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005888 return SemaRef.Owned(E->Retain());
5889
John McCall8cd78132009-11-19 22:55:06 +00005890 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005891 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005892 E->isArrow(),
5893 E->getOperatorLoc(),
5894 Qualifier,
5895 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005896 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005897 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005898 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005899 }
5900
John McCall6b51f282009-11-23 01:53:49 +00005901 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005902 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005903 TemplateArgumentLoc Loc;
5904 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005905 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005906 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005907 }
Mike Stump11289f42009-09-09 15:08:12 +00005908
John McCall8cd78132009-11-19 22:55:06 +00005909 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005910 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 E->isArrow(),
5912 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005913 Qualifier,
5914 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005915 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005916 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005917 &TransArgs);
5918}
5919
5920template<typename Derived>
5921Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005923 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005924 OwningExprResult Base(SemaRef, (Expr*) 0);
5925 QualType BaseType;
5926 if (!Old->isImplicitAccess()) {
5927 Base = getDerived().TransformExpr(Old->getBase());
5928 if (Base.isInvalid())
5929 return SemaRef.ExprError();
5930 BaseType = ((Expr*) Base.get())->getType();
5931 } else {
5932 BaseType = getDerived().TransformType(Old->getBaseType());
5933 }
John McCall10eae182009-11-30 22:42:35 +00005934
5935 NestedNameSpecifier *Qualifier = 0;
5936 if (Old->getQualifier()) {
5937 Qualifier
5938 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005939 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005940 if (Qualifier == 0)
5941 return SemaRef.ExprError();
5942 }
5943
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005944 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005945 Sema::LookupOrdinaryName);
5946
5947 // Transform all the decls.
5948 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5949 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005950 NamedDecl *InstD = static_cast<NamedDecl*>(
5951 getDerived().TransformDecl(Old->getMemberLoc(),
5952 *I));
John McCall84d87672009-12-10 09:41:52 +00005953 if (!InstD) {
5954 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5955 // This can happen because of dependent hiding.
5956 if (isa<UsingShadowDecl>(*I))
5957 continue;
5958 else
5959 return SemaRef.ExprError();
5960 }
John McCall10eae182009-11-30 22:42:35 +00005961
5962 // Expand using declarations.
5963 if (isa<UsingDecl>(InstD)) {
5964 UsingDecl *UD = cast<UsingDecl>(InstD);
5965 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5966 E = UD->shadow_end(); I != E; ++I)
5967 R.addDecl(*I);
5968 continue;
5969 }
5970
5971 R.addDecl(InstD);
5972 }
5973
5974 R.resolveKind();
5975
Douglas Gregor9262f472010-04-27 18:19:34 +00005976 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005977 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005978 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005979 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005980 Old->getMemberLoc(),
5981 Old->getNamingClass()));
5982 if (!NamingClass)
5983 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005984
Douglas Gregorda7be082010-04-27 16:10:10 +00005985 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005986 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005987
John McCall10eae182009-11-30 22:42:35 +00005988 TemplateArgumentListInfo TransArgs;
5989 if (Old->hasExplicitTemplateArgs()) {
5990 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5991 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5992 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5993 TemplateArgumentLoc Loc;
5994 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5995 Loc))
5996 return SemaRef.ExprError();
5997 TransArgs.addArgument(Loc);
5998 }
5999 }
John McCall38836f02010-01-15 08:34:02 +00006000
6001 // FIXME: to do this check properly, we will need to preserve the
6002 // first-qualifier-in-scope here, just in case we had a dependent
6003 // base (and therefore couldn't do the check) and a
6004 // nested-name-qualifier (and therefore could do the lookup).
6005 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006006
John McCall10eae182009-11-30 22:42:35 +00006007 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00006008 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006009 Old->getOperatorLoc(),
6010 Old->isArrow(),
6011 Qualifier,
6012 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006013 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006014 R,
6015 (Old->hasExplicitTemplateArgs()
6016 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006017}
6018
6019template<typename Derived>
6020Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006021TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006022 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006023}
6024
Mike Stump11289f42009-09-09 15:08:12 +00006025template<typename Derived>
6026Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006027TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006028 TypeSourceInfo *EncodedTypeInfo
6029 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6030 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006031 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006032
Douglas Gregora16548e2009-08-11 05:31:07 +00006033 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006034 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006035 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006036
6037 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006038 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006039 E->getRParenLoc());
6040}
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregora16548e2009-08-11 05:31:07 +00006042template<typename Derived>
6043Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006044TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006045 // Transform arguments.
6046 bool ArgChanged = false;
6047 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6048 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6049 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6050 if (Arg.isInvalid())
6051 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006052
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006053 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6054 Args.push_back(Arg.takeAs<Expr>());
6055 }
6056
6057 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6058 // Class message: transform the receiver type.
6059 TypeSourceInfo *ReceiverTypeInfo
6060 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6061 if (!ReceiverTypeInfo)
6062 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006063
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006064 // If nothing changed, just retain the existing message send.
6065 if (!getDerived().AlwaysRebuild() &&
6066 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6067 return SemaRef.Owned(E->Retain());
6068
6069 // Build a new class message send.
6070 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6071 E->getSelector(),
6072 E->getMethodDecl(),
6073 E->getLeftLoc(),
6074 move_arg(Args),
6075 E->getRightLoc());
6076 }
6077
6078 // Instance message: transform the receiver
6079 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6080 "Only class and instance messages may be instantiated");
6081 OwningExprResult Receiver
6082 = getDerived().TransformExpr(E->getInstanceReceiver());
6083 if (Receiver.isInvalid())
6084 return SemaRef.ExprError();
6085
6086 // If nothing changed, just retain the existing message send.
6087 if (!getDerived().AlwaysRebuild() &&
6088 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6089 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006091 // Build a new instance message send.
6092 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6093 E->getSelector(),
6094 E->getMethodDecl(),
6095 E->getLeftLoc(),
6096 move_arg(Args),
6097 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006098}
6099
Mike Stump11289f42009-09-09 15:08:12 +00006100template<typename Derived>
6101Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006102TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006103 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006104}
6105
Mike Stump11289f42009-09-09 15:08:12 +00006106template<typename Derived>
6107Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006108TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006109 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110}
6111
Mike Stump11289f42009-09-09 15:08:12 +00006112template<typename Derived>
6113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006115 // Transform the base expression.
6116 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6117 if (Base.isInvalid())
6118 return SemaRef.ExprError();
6119
6120 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006121
Douglas Gregord51d90d2010-04-26 20:11:03 +00006122 // If nothing changed, just retain the existing expression.
6123 if (!getDerived().AlwaysRebuild() &&
6124 Base.get() == E->getBase())
6125 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006126
Douglas Gregord51d90d2010-04-26 20:11:03 +00006127 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6128 E->getLocation(),
6129 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006130}
6131
Mike Stump11289f42009-09-09 15:08:12 +00006132template<typename Derived>
6133Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006135 // Transform the base expression.
6136 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6137 if (Base.isInvalid())
6138 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006139
Douglas Gregor9faee212010-04-26 20:47:02 +00006140 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006141
Douglas Gregor9faee212010-04-26 20:47:02 +00006142 // If nothing changed, just retain the existing expression.
6143 if (!getDerived().AlwaysRebuild() &&
6144 Base.get() == E->getBase())
6145 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006146
Douglas Gregor9faee212010-04-26 20:47:02 +00006147 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6148 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006149}
6150
Mike Stump11289f42009-09-09 15:08:12 +00006151template<typename Derived>
6152Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006153TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006154 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006155 // If this implicit setter/getter refers to class methods, it cannot have any
6156 // dependent parts. Just retain the existing declaration.
6157 if (E->getInterfaceDecl())
6158 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006159
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006160 // Transform the base expression.
6161 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6162 if (Base.isInvalid())
6163 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006164
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006165 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006166
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006167 // If nothing changed, just retain the existing expression.
6168 if (!getDerived().AlwaysRebuild() &&
6169 Base.get() == E->getBase())
6170 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006171
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006172 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6173 E->getGetterMethod(),
6174 E->getType(),
6175 E->getSetterMethod(),
6176 E->getLocation(),
6177 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006178
Douglas Gregora16548e2009-08-11 05:31:07 +00006179}
6180
Mike Stump11289f42009-09-09 15:08:12 +00006181template<typename Derived>
6182Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006183TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006184 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006185 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006186}
6187
Mike Stump11289f42009-09-09 15:08:12 +00006188template<typename Derived>
6189Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006191 // Transform the base expression.
6192 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6193 if (Base.isInvalid())
6194 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006195
Douglas Gregord51d90d2010-04-26 20:11:03 +00006196 // If nothing changed, just retain the existing expression.
6197 if (!getDerived().AlwaysRebuild() &&
6198 Base.get() == E->getBase())
6199 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006200
Douglas Gregord51d90d2010-04-26 20:11:03 +00006201 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6202 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006203}
6204
Mike Stump11289f42009-09-09 15:08:12 +00006205template<typename Derived>
6206Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006207TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 bool ArgumentChanged = false;
6209 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6210 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6211 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6212 if (SubExpr.isInvalid())
6213 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6216 SubExprs.push_back(SubExpr.takeAs<Expr>());
6217 }
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregora16548e2009-08-11 05:31:07 +00006219 if (!getDerived().AlwaysRebuild() &&
6220 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006221 return SemaRef.Owned(E->Retain());
6222
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6224 move_arg(SubExprs),
6225 E->getRParenLoc());
6226}
6227
Mike Stump11289f42009-09-09 15:08:12 +00006228template<typename Derived>
6229Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006231 SourceLocation CaretLoc(E->getExprLoc());
6232
6233 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6234 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6235 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6236 llvm::SmallVector<ParmVarDecl*, 4> Params;
6237 llvm::SmallVector<QualType, 4> ParamTypes;
6238
6239 // Parameter substitution.
6240 const BlockDecl *BD = E->getBlockDecl();
6241 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6242 EN = BD->param_end(); P != EN; ++P) {
6243 ParmVarDecl *OldParm = (*P);
6244 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6245 QualType NewType = NewParm->getType();
6246 Params.push_back(NewParm);
6247 ParamTypes.push_back(NewParm->getType());
6248 }
6249
6250 const FunctionType *BExprFunctionType = E->getFunctionType();
6251 QualType BExprResultType = BExprFunctionType->getResultType();
6252 if (!BExprResultType.isNull()) {
6253 if (!BExprResultType->isDependentType())
6254 CurBlock->ReturnType = BExprResultType;
6255 else if (BExprResultType != SemaRef.Context.DependentTy)
6256 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6257 }
6258
6259 // Transform the body
6260 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6261 if (Body.isInvalid())
6262 return SemaRef.ExprError();
6263 // Set the parameters on the block decl.
6264 if (!Params.empty())
6265 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6266
6267 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6268 CurBlock->ReturnType,
6269 ParamTypes.data(),
6270 ParamTypes.size(),
6271 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006272 0,
6273 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006274
6275 CurBlock->FunctionType = FunctionType;
6276 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006277}
6278
Mike Stump11289f42009-09-09 15:08:12 +00006279template<typename Derived>
6280Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006281TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006282 NestedNameSpecifier *Qualifier = 0;
6283
6284 ValueDecl *ND
6285 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6286 E->getDecl()));
6287 if (!ND)
6288 return SemaRef.ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006289
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006290 if (!getDerived().AlwaysRebuild() &&
6291 ND == E->getDecl()) {
6292 // Mark it referenced in the new context regardless.
6293 // FIXME: this is a bit instantiation-specific.
6294 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6295
6296 return SemaRef.Owned(E->Retain());
6297 }
6298
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006299 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006300 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006301 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006302}
Mike Stump11289f42009-09-09 15:08:12 +00006303
Douglas Gregora16548e2009-08-11 05:31:07 +00006304//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006305// Type reconstruction
6306//===----------------------------------------------------------------------===//
6307
Mike Stump11289f42009-09-09 15:08:12 +00006308template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006309QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6310 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006311 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006312 getDerived().getBaseEntity());
6313}
6314
Mike Stump11289f42009-09-09 15:08:12 +00006315template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006316QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6317 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006318 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006319 getDerived().getBaseEntity());
6320}
6321
Mike Stump11289f42009-09-09 15:08:12 +00006322template<typename Derived>
6323QualType
John McCall70dd5f62009-10-30 00:06:24 +00006324TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6325 bool WrittenAsLValue,
6326 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006327 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006328 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006329}
6330
6331template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006332QualType
John McCall70dd5f62009-10-30 00:06:24 +00006333TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6334 QualType ClassType,
6335 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006336 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006337 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006338}
6339
6340template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006341QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006342TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6343 ArrayType::ArraySizeModifier SizeMod,
6344 const llvm::APInt *Size,
6345 Expr *SizeExpr,
6346 unsigned IndexTypeQuals,
6347 SourceRange BracketsRange) {
6348 if (SizeExpr || !Size)
6349 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6350 IndexTypeQuals, BracketsRange,
6351 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006352
6353 QualType Types[] = {
6354 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6355 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6356 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006357 };
6358 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6359 QualType SizeType;
6360 for (unsigned I = 0; I != NumTypes; ++I)
6361 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6362 SizeType = Types[I];
6363 break;
6364 }
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregord6ff3322009-08-04 16:50:30 +00006366 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006367 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006368 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006369 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370}
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregord6ff3322009-08-04 16:50:30 +00006372template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006373QualType
6374TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375 ArrayType::ArraySizeModifier SizeMod,
6376 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006377 unsigned IndexTypeQuals,
6378 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006379 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006380 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006381}
6382
6383template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006384QualType
Mike Stump11289f42009-09-09 15:08:12 +00006385TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006386 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006387 unsigned IndexTypeQuals,
6388 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006389 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006390 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391}
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregord6ff3322009-08-04 16:50:30 +00006393template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006394QualType
6395TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006396 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398 unsigned IndexTypeQuals,
6399 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006400 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401 SizeExpr.takeAs<Expr>(),
6402 IndexTypeQuals, BracketsRange);
6403}
6404
6405template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006406QualType
6407TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006408 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410 unsigned IndexTypeQuals,
6411 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006412 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006413 SizeExpr.takeAs<Expr>(),
6414 IndexTypeQuals, BracketsRange);
6415}
6416
6417template<typename Derived>
6418QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006419 unsigned NumElements,
6420 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006421 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006422 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006423}
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregord6ff3322009-08-04 16:50:30 +00006425template<typename Derived>
6426QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6427 unsigned NumElements,
6428 SourceLocation AttributeLoc) {
6429 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6430 NumElements, true);
6431 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006432 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006433 AttributeLoc);
6434 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6435 AttributeLoc);
6436}
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006439QualType
6440TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006442 SourceLocation AttributeLoc) {
6443 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6444}
Mike Stump11289f42009-09-09 15:08:12 +00006445
Douglas Gregord6ff3322009-08-04 16:50:30 +00006446template<typename Derived>
6447QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006448 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006449 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006450 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006451 unsigned Quals,
6452 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006453 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006454 Quals,
6455 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006456 getDerived().getBaseEntity(),
6457 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006458}
Mike Stump11289f42009-09-09 15:08:12 +00006459
Douglas Gregord6ff3322009-08-04 16:50:30 +00006460template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006461QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6462 return SemaRef.Context.getFunctionNoProtoType(T);
6463}
6464
6465template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006466QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6467 assert(D && "no decl found");
6468 if (D->isInvalidDecl()) return QualType();
6469
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006470 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006471 TypeDecl *Ty;
6472 if (isa<UsingDecl>(D)) {
6473 UsingDecl *Using = cast<UsingDecl>(D);
6474 assert(Using->isTypeName() &&
6475 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6476
6477 // A valid resolved using typename decl points to exactly one type decl.
6478 assert(++Using->shadow_begin() == Using->shadow_end());
6479 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006480
John McCallb96ec562009-12-04 22:46:56 +00006481 } else {
6482 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6483 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6484 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6485 }
6486
6487 return SemaRef.Context.getTypeDeclType(Ty);
6488}
6489
6490template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006491QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006492 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6493}
6494
6495template<typename Derived>
6496QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6497 return SemaRef.Context.getTypeOfType(Underlying);
6498}
6499
6500template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006501QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006502 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6503}
6504
6505template<typename Derived>
6506QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006507 TemplateName Template,
6508 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006509 const TemplateArgumentListInfo &TemplateArgs) {
6510 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006511}
Mike Stump11289f42009-09-09 15:08:12 +00006512
Douglas Gregor1135c352009-08-06 05:28:30 +00006513template<typename Derived>
6514NestedNameSpecifier *
6515TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6516 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006517 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006518 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006519 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006520 CXXScopeSpec SS;
6521 // FIXME: The source location information is all wrong.
6522 SS.setRange(Range);
6523 SS.setScopeRep(Prefix);
6524 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006525 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006526 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006527 ObjectType,
6528 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006529 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006530}
6531
6532template<typename Derived>
6533NestedNameSpecifier *
6534TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6535 SourceRange Range,
6536 NamespaceDecl *NS) {
6537 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6538}
6539
6540template<typename Derived>
6541NestedNameSpecifier *
6542TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6543 SourceRange Range,
6544 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006545 QualType T) {
6546 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006547 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006548 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006549 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6550 T.getTypePtr());
6551 }
Mike Stump11289f42009-09-09 15:08:12 +00006552
Douglas Gregor1135c352009-08-06 05:28:30 +00006553 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6554 return 0;
6555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregor71dc5092009-08-06 06:41:21 +00006557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006558TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006559TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6560 bool TemplateKW,
6561 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006562 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006563 Template);
6564}
6565
6566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006567TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006568TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006569 const IdentifierInfo &II,
6570 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006571 CXXScopeSpec SS;
6572 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006573 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006574 UnqualifiedId Name;
6575 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006576 Sema::TemplateTy Template;
6577 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6578 /*FIXME:*/getDerived().getBaseLocation(),
6579 SS,
6580 Name,
6581 ObjectType.getAsOpaquePtr(),
6582 /*EnteringContext=*/false,
6583 Template);
6584 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregora16548e2009-08-11 05:31:07 +00006587template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006588TemplateName
6589TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6590 OverloadedOperatorKind Operator,
6591 QualType ObjectType) {
6592 CXXScopeSpec SS;
6593 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6594 SS.setScopeRep(Qualifier);
6595 UnqualifiedId Name;
6596 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6597 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6598 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006599 Sema::TemplateTy Template;
6600 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006601 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006602 SS,
6603 Name,
6604 ObjectType.getAsOpaquePtr(),
6605 /*EnteringContext=*/false,
6606 Template);
6607 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006608}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006609
Douglas Gregor71395fa2009-11-04 00:56:37 +00006610template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006611Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006612TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6613 SourceLocation OpLoc,
6614 ExprArg Callee,
6615 ExprArg First,
6616 ExprArg Second) {
6617 Expr *FirstExpr = (Expr *)First.get();
6618 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006619 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006623 if (Op == OO_Subscript) {
6624 if (!FirstExpr->getType()->isOverloadableType() &&
6625 !SecondExpr->getType()->isOverloadableType())
6626 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006627 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006628 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006629 } else if (Op == OO_Arrow) {
6630 // -> is never a builtin operation.
6631 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006632 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006633 if (!FirstExpr->getType()->isOverloadableType()) {
6634 // The argument is not of overloadable type, so try to create a
6635 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006636 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregora16548e2009-08-11 05:31:07 +00006639 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6640 }
6641 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006642 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 !SecondExpr->getType()->isOverloadableType()) {
6644 // Neither of the arguments is an overloadable type, so try to
6645 // create a built-in binary operation.
6646 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006647 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6649 if (Result.isInvalid())
6650 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006651
Douglas Gregora16548e2009-08-11 05:31:07 +00006652 First.release();
6653 Second.release();
6654 return move(Result);
6655 }
6656 }
Mike Stump11289f42009-09-09 15:08:12 +00006657
6658 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006660 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006661
John McCalld14a8642009-11-21 08:51:07 +00006662 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6663 assert(ULE->requiresADL());
6664
6665 // FIXME: Do we have to check
6666 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006667 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006668 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006669 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006670 }
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregora16548e2009-08-11 05:31:07 +00006672 // Add any functions found via argument-dependent lookup.
6673 Expr *Args[2] = { FirstExpr, SecondExpr };
6674 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006675
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 // Create the overloaded operator invocation for unary operators.
6677 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006678 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006679 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6680 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6681 }
Mike Stump11289f42009-09-09 15:08:12 +00006682
Sebastian Redladba46e2009-10-29 20:17:01 +00006683 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006684 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6685 OpLoc,
6686 move(First),
6687 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006688
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006690 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006691 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006692 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006693 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6694 if (Result.isInvalid())
6695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 First.release();
6698 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006699 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006700}
Mike Stump11289f42009-09-09 15:08:12 +00006701
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006702template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006703Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006704TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6705 SourceLocation OperatorLoc,
6706 bool isArrow,
6707 NestedNameSpecifier *Qualifier,
6708 SourceRange QualifierRange,
6709 TypeSourceInfo *ScopeType,
6710 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006711 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006712 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006713 CXXScopeSpec SS;
6714 if (Qualifier) {
6715 SS.setRange(QualifierRange);
6716 SS.setScopeRep(Qualifier);
6717 }
6718
6719 Expr *BaseE = (Expr *)Base.get();
6720 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006721 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006722 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006723 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006724 !BaseType->getAs<PointerType>()->getPointeeType()
6725 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006726 // This pseudo-destructor expression is still a pseudo-destructor.
6727 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6728 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006729 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006730 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006731 /*FIXME?*/true);
6732 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006733
Douglas Gregor678f90d2010-02-25 01:56:36 +00006734 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006735 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6736 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6737 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6738 NameInfo.setNamedTypeInfo(DestroyedType);
6739
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006740 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006741
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006742 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6743 OperatorLoc, isArrow,
6744 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006745 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006746 /*TemplateArgs*/ 0);
6747}
6748
Douglas Gregord6ff3322009-08-04 16:50:30 +00006749} // end namespace clang
6750
6751#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H