blob: 8f869e0cfb4c280e88094bae1f291a4069e8b44c [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::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000093 typedef Sema::MultiStmtArg MultiStmtArg;
Alexis Hunta8136cc2010-05-05 15:23:54 +000094
Douglas Gregord6ff3322009-08-04 16:50:30 +000095 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000097
Douglas Gregord6ff3322009-08-04 16:50:30 +000098 /// \brief Retrieves a reference to the derived class.
99 Derived &getDerived() { return static_cast<Derived&>(*this); }
100
101 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000102 const Derived &getDerived() const {
103 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000104 }
105
John McCalldadc5752010-08-24 06:29:42 +0000106 static inline ExprResult Owned(Expr *E) { return E; }
107 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
115 ///
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000119
Douglas Gregord6ff3322009-08-04 16:50:30 +0000120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
122 ///
Mike Stump11289f42009-09-09 15:08:12 +0000123 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// provide an alternative implementation that provides better location
125 /// information.
126 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
130 ///
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName getBaseEntity() { return DeclarationName(); }
134
Douglas Gregora16548e2009-08-11 05:31:07 +0000135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
137 ///
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000141
Douglas Gregora16548e2009-08-11 05:31:07 +0000142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase {
145 TreeTransform &Self;
146 SourceLocation OldLocation;
147 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregora16548e2009-08-11 05:31:07 +0000149 public:
150 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000151 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000152 OldLocation = Self.getDerived().getBaseLocation();
153 OldEntity = Self.getDerived().getBaseEntity();
154 Self.getDerived().setBase(Location, Entity);
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Douglas Gregora16548e2009-08-11 05:31:07 +0000157 ~TemporaryBase() {
158 Self.getDerived().setBase(OldLocation, OldEntity);
159 }
160 };
Mike Stump11289f42009-09-09 15:08:12 +0000161
162 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000163 /// transformed.
164 ///
165 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000166 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T) {
170 return T.isNull();
171 }
172
Douglas Gregord196a582009-12-14 19:27:10 +0000173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
175 ///
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr *E) {
180 return E->isDefaultArgument();
181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000182
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// \brief Transforms the given type into another type.
184 ///
John McCall550e0c22009-10-21 00:40:46 +0000185 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000186 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000189 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 ///
191 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000192 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000193
John McCall550e0c22009-10-21 00:40:46 +0000194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 ///
John McCall550e0c22009-10-21 00:40:46 +0000197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000202 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000203 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000204
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
207 /// as necessary.
208 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000210 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000213 ///
Mike Stump11289f42009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000221 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000231 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000251 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000259 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000270
Douglas Gregorf816bd72009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000277 DeclarationNameInfo
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000282 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump11289f42009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCallbcd03502009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
John McCall550e0c22009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000315
John McCall58f10c32010-03-11 09:03:00 +0000316 /// \brief Transforms the parameters of a function type into the
317 /// given vectors.
318 ///
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
321 ///
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
326
327 /// \brief Transforms a single function-type parameter. Return null
328 /// on error.
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
330
Alexis Hunta8136cc2010-05-05 15:23:54 +0000331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000332 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000333
Alexis Hunta8136cc2010-05-05 15:23:54 +0000334 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000337
John McCalldadc5752010-08-24 06:29:42 +0000338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Douglas Gregorebe10102009-08-20 07:17:43 +0000341#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000342 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000343#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000344 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000345#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000346#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000347
Douglas Gregord6ff3322009-08-04 16:50:30 +0000348 /// \brief Build a new pointer type given its pointee type.
349 ///
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000353
354 /// \brief Build a new block pointer type given its pointee type.
355 ///
Mike Stump11289f42009-09-09 15:08:12 +0000356 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359
John McCall70dd5f62009-10-30 00:06:24 +0000360 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361 ///
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000365 ///
John McCall70dd5f62009-10-30 00:06:24 +0000366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
369 bool LValue,
370 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000371
Douglas Gregord6ff3322009-08-04 16:50:30 +0000372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
374 ///
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000379
Douglas Gregord6ff3322009-08-04 16:50:30 +0000380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
382 /// qualifiers.
383 ///
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000386 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
390 Expr *SizeExpr,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000410 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000422 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
Mike Stump11289f42009-09-09 15:08:12 +0000426 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000427 /// size modifier, size expression, and index type qualifiers.
428 ///
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000431 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000433 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
436
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
439 ///
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Chris Lattner37141f42010-06-23 06:00:24 +0000443 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000444
Douglas Gregord6ff3322009-08-04 16:50:30 +0000445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
447 ///
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000452
453 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000454 /// given the element type and number of elements.
455 ///
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000459 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000460 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000461
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 /// \brief Build a new function type.
463 ///
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000467 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000471
John McCall550e0c22009-10-21 00:40:46 +0000472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
474
John McCallb96ec562009-12-04 22:46:56 +0000475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
478
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
482 }
483
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
487 }
488
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
492 }
John McCallfcc33b02009-09-05 00:15:47 +0000493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000498 QualType RebuildTypeOfExprType(Expr *Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
504
Mike Stump11289f42009-09-09 15:08:12 +0000505 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 ///
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
John McCallb268a282010-08-23 23:25:46 +0000509 QualType RebuildDecltypeType(Expr *Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000510
Douglas Gregord6ff3322009-08-04 16:50:30 +0000511 /// \brief Build a new template specialization type.
512 ///
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000517 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000518 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000519
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 /// \brief Build a new qualified name type.
521 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
525 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
526 NestedNameSpecifier *NNS, QualType Named) {
527 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000528 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529
530 /// \brief Build a new typename type that refers to a template-id.
531 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000532 /// By default, builds a new DependentNameType type from the
533 /// nested-name-specifier and the given type. Subclasses may override
534 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000535 QualType RebuildDependentTemplateSpecializationType(
536 ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS,
538 const IdentifierInfo *Name,
539 SourceLocation NameLoc,
540 const TemplateArgumentListInfo &Args) {
541 // Rebuild the template name.
542 // TODO: avoid TemplateName abstraction
543 TemplateName InstName =
544 getDerived().RebuildTemplateName(NNS, *Name, QualType());
545
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000546 if (InstName.isNull())
547 return QualType();
548
John McCallc392f372010-06-11 00:33:02 +0000549 // If it's still dependent, make a dependent specialization.
550 if (InstName.getAsDependentTemplateName())
551 return SemaRef.Context.getDependentTemplateSpecializationType(
552 Keyword, NNS, Name, Args);
553
554 // Otherwise, make an elaborated type wrapping a non-dependent
555 // specialization.
556 QualType T =
557 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
558 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000559
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000560 // NOTE: NNS is already recorded in template specialization type T.
561 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000562 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563
564 /// \brief Build a new typename type that refers to an identifier.
565 ///
566 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000567 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000575 CXXScopeSpec SS;
576 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SS.setRange(NNSRange);
578
Douglas Gregore677daf2010-03-31 22:19:08 +0000579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
583 }
584
Abramo Bagnara6150c882010-05-11 21:36:43 +0000585 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000588
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
590
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
John McCallbf8c5192010-05-27 06:40:31 +0000599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
600 return QualType();
601
Douglas Gregore677daf2010-03-31 22:19:08 +0000602 TagDecl *Tag = 0;
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
607 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000608
Douglas Gregore677daf2010-03-31 22:19:08 +0000609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
611 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000612
Douglas Gregore677daf2010-03-31 22:19:08 +0000613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
616 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
620 return QualType();
621 }
622
623 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000624 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000627 return QualType();
628 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000629
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
633 return QualType();
634 }
635
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
643 ///
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
648 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000649 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000650 QualType ObjectType,
651 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000652
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
655 ///
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
660 SourceRange Range,
661 NamespaceDecl *NS);
662
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
665 ///
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
670 SourceRange Range,
671 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000672 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000673
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
677 ///
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
681 bool TemplateKW,
682 TemplateDecl *Template);
683
Douglas Gregor71dc5092009-08-06 06:41:21 +0000684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
686 ///
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
690 /// behavior.
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000692 const IdentifierInfo &II,
693 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Douglas Gregor71395fa2009-11-04 00:56:37 +0000695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
697 ///
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
701 /// behavior.
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000705
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 /// \brief Build a new compound statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000710 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
713 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000715 IsStmtExpr);
716 }
717
718 /// \brief Build a new case statement.
719 ///
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000722 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000723 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000725 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000727 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 ColonLoc);
729 }
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 /// \brief Attach the body to a new case statement.
732 ///
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000735 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000736 getSema().ActOnCaseStmtBody(S, Body);
737 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000738 }
Mike Stump11289f42009-09-09 15:08:12 +0000739
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 /// \brief Build a new default statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000744 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000746 Stmt *SubStmt) {
747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 /*CurScope=*/0);
749 }
Mike Stump11289f42009-09-09 15:08:12 +0000750
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 /// \brief Build a new label statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000755 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 IdentifierInfo *Id,
757 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000758 Stmt *SubStmt) {
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new "if" statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000766 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000767 VarDecl *CondVar, Stmt *Then,
768 SourceLocation ElseLoc, Stmt *Else) {
769 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 /// \brief Start building a new switch statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000776 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000777 Expr *Cond, VarDecl *CondVar) {
778 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000779 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 }
Mike Stump11289f42009-09-09 15:08:12 +0000781
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 /// \brief Attach the body to the switch statement.
783 ///
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000786 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000787 Stmt *Switch, Stmt *Body) {
788 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 }
790
791 /// \brief Build a new while statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000795 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000796 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000797 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000798 Stmt *Body) {
799 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000800 }
Mike Stump11289f42009-09-09 15:08:12 +0000801
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 /// \brief Build a new do-while statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000806 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 SourceLocation WhileLoc,
808 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000809 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000811 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
812 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 }
814
815 /// \brief Build a new for statement.
816 ///
817 /// By default, performs semantic analysis to build the new statement.
818 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000819 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000821 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000822 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000823 SourceLocation RParenLoc, Stmt *Body) {
824 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000825 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000826 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 }
Mike Stump11289f42009-09-09 15:08:12 +0000828
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 /// \brief Build a new goto statement.
830 ///
831 /// By default, performs semantic analysis to build the new statement.
832 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000833 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 SourceLocation LabelLoc,
835 LabelStmt *Label) {
836 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
837 }
838
839 /// \brief Build a new indirect goto statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000843 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000845 Expr *Target) {
846 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 }
Mike Stump11289f42009-09-09 15:08:12 +0000848
Douglas Gregorebe10102009-08-20 07:17:43 +0000849 /// \brief Build a new return statement.
850 ///
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000853 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000854 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000855
John McCallb268a282010-08-23 23:25:46 +0000856 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 }
Mike Stump11289f42009-09-09 15:08:12 +0000858
Douglas Gregorebe10102009-08-20 07:17:43 +0000859 /// \brief Build a new declaration statement.
860 ///
861 /// By default, performs semantic analysis to build the new statement.
862 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000863 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000864 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 SourceLocation EndLoc) {
866 return getSema().Owned(
867 new (getSema().Context) DeclStmt(
868 DeclGroupRef::Create(getSema().Context,
869 Decls, NumDecls),
870 StartLoc, EndLoc));
871 }
Mike Stump11289f42009-09-09 15:08:12 +0000872
Anders Carlssonaaeef072010-01-24 05:50:09 +0000873 /// \brief Build a new inline asm statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000877 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000878 bool IsSimple,
879 bool IsVolatile,
880 unsigned NumOutputs,
881 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000882 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000883 MultiExprArg Constraints,
884 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000885 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 MultiExprArg Clobbers,
887 SourceLocation RParenLoc,
888 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000889 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000890 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000891 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000892 RParenLoc, MSAsm);
893 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000894
895 /// \brief Build a new Objective-C @try statement.
896 ///
897 /// By default, performs semantic analysis to build the new statement.
898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000899 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000900 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000901 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000902 Stmt *Finally) {
903 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
904 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000905 }
906
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000907 /// \brief Rebuild an Objective-C exception declaration.
908 ///
909 /// By default, performs semantic analysis to build the new declaration.
910 /// Subclasses may override this routine to provide different behavior.
911 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
912 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000913 return getSema().BuildObjCExceptionDecl(TInfo, T,
914 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000915 ExceptionDecl->getLocation());
916 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000917
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000918 /// \brief Build a new Objective-C @catch statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000922 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 SourceLocation RParenLoc,
924 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000925 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000927 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000928 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000929
Douglas Gregor306de2f2010-04-22 23:59:56 +0000930 /// \brief Build a new Objective-C @finally statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000934 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000935 Stmt *Body) {
936 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000937 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000938
Douglas Gregor6148de72010-04-22 22:01:21 +0000939 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000940 ///
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000943 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000944 Expr *Operand) {
945 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000946 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000947
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// \brief Build a new Objective-C @synchronized statement.
949 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000950 /// By default, performs semantic analysis to build the new statement.
951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000952 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000953 Expr *Object,
954 Stmt *Body) {
955 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
956 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000957 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000958
959 /// \brief Build a new Objective-C fast enumeration statement.
960 ///
961 /// By default, performs semantic analysis to build the new statement.
962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000963 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000964 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000965 Stmt *Element,
966 Expr *Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000967 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000968 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000969 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000970 Element,
971 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000972 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000973 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000974 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000975
Douglas Gregorebe10102009-08-20 07:17:43 +0000976 /// \brief Build a new C++ exception declaration.
977 ///
978 /// By default, performs semantic analysis to build the new decaration.
979 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000980 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000981 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 IdentifierInfo *Name,
983 SourceLocation Loc,
984 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000985 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 TypeRange);
987 }
988
989 /// \brief Build a new C++ catch statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 VarDecl *ExceptionDecl,
John McCallb268a282010-08-23 23:25:46 +0000995 Stmt *Handler) {
996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
997 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +0000998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new C++ try statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallb268a282010-08-23 23:25:46 +00001005 Stmt *TryBlock,
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001007 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// \brief Build a new expression that references a declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001014 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001015 LookupResult &R,
1016 bool RequiresADL) {
1017 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1018 }
1019
1020
1021 /// \brief Build a new expression that references a declaration.
1022 ///
1023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001025 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001026 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001027 ValueDecl *VD,
1028 const DeclarationNameInfo &NameInfo,
John McCallce546572009-12-08 09:08:17 +00001029 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001030 CXXScopeSpec SS;
1031 SS.setScopeRep(Qualifier);
1032 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001033
1034 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001035
1036 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 }
Mike Stump11289f42009-09-09 15:08:12 +00001038
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001040 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001045 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 }
1047
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001052 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001053 SourceLocation OperatorLoc,
1054 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001055 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001056 SourceRange QualifierRange,
1057 TypeSourceInfo *ScopeType,
1058 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001059 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001060 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001061
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001063 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001066 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001067 UnaryOperator::Opcode Opc,
John McCallb268a282010-08-23 23:25:46 +00001068 Expr *SubExpr) {
1069 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor882211c2010-04-28 22:16:22 +00001072 /// \brief Build a new builtin offsetof expression.
1073 ///
1074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001077 TypeSourceInfo *Type,
1078 Action::OffsetOfComponent *Components,
1079 unsigned NumComponents,
1080 SourceLocation RParenLoc) {
1081 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1082 NumComponents, RParenLoc);
1083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001084
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001086 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// By default, performs semantic analysis to build the new expression.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001090 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001092 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 }
1094
Mike Stump11289f42009-09-09 15:08:12 +00001095 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// By default, performs semantic analysis to build the new expression.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001102 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001103 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 if (Result.isInvalid())
1105 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 return move(Result);
1108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001116 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1119 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 RBracketLoc);
1121 }
1122
1123 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001127 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 MultiExprArg Args,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 move(Args), CommaLocs, RParenLoc);
1133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001143 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001151
John McCallb268a282010-08-23 23:25:46 +00001152 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001153 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001154 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001155
Mike Stump11289f42009-09-09 15:08:12 +00001156 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001157 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001158 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001159 cast<FieldDecl>(Member)->getType());
1160 return getSema().Owned(ME);
1161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001163 CXXScopeSpec SS;
1164 if (Qualifier) {
1165 SS.setRange(QualifierRange);
1166 SS.setScopeRep(Qualifier);
1167 }
1168
John McCallb268a282010-08-23 23:25:46 +00001169 getSema().DefaultFunctionArrayConversion(Base);
1170 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001171
John McCall16df1e52010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001174 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001175 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001176 R.resolveKind();
1177
John McCallb268a282010-08-23 23:25:46 +00001178 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001179 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001180 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 BinaryOperator::Opcode Opc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *LHS, Expr *RHS) {
1190 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 }
1192
1193 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001194 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 /// By default, performs semantic analysis to build the new expression.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001201 Expr *RHS) {
1202 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1203 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 }
1205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001207 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001210 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001211 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001213 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001214 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new compound literal 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 McCalldadc5752010-08-24 06:29:42 +00001222 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001225 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001226 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001227 Init);
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 extended vector element access 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.
John McCalldadc5752010-08-24 06:29:42 +00001234 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation OpLoc,
1236 SourceLocation AccessorLoc,
1237 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001238
John McCall10eae182009-11-30 22:42:35 +00001239 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001240 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001241 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001242 OpLoc, /*IsArrow*/ false,
1243 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001244 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001245 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001252 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001254 SourceLocation RBraceLoc,
1255 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001256 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001257 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1258 if (Result.isInvalid() || ResultTy->isDependentType())
1259 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001260
Douglas Gregord3d93062009-11-09 17:16:50 +00001261 // Patch in the result type we were given, which may have been computed
1262 // when the initial InitListExpr was built.
1263 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1264 ILE->setType(ResultTy);
1265 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 }
Mike Stump11289f42009-09-09 15:08:12 +00001267
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001269 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001272 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 MultiExprArg ArrayExprs,
1274 SourceLocation EqualOrColonLoc,
1275 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001276 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001279 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 if (Result.isInvalid())
1281 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 ArrayExprs.release();
1284 return move(Result);
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, builds the implicit value initialization without performing
1290 /// any semantic analysis. Subclasses may override this routine to provide
1291 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1294 }
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001301 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001302 SourceLocation RParenLoc) {
1303 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001304 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001305 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
1307
1308 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001312 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 MultiExprArg SubExprs,
1314 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001315 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001316 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
1321 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// rather than attempting to map the label statement itself.
1323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001324 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 SourceLocation LabelLoc,
1326 LabelStmt *Label) {
1327 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001337 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 }
Mike Stump11289f42009-09-09 15:08:12 +00001339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// \brief Build a new __builtin_types_compatible_p expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001344 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001345 TypeSourceInfo *TInfo1,
1346 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001348 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1349 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 RParenLoc);
1351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new __builtin_choose_expr expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 SourceLocation RParenLoc) {
1360 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001361 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 RParenLoc);
1363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// \brief Build a new overloaded operator call expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// The semantic analysis provides the behavior of template instantiation,
1369 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001370 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// argument-dependent lookup, etc. Subclasses may override this routine to
1372 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001373 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *Callee,
1376 Expr *First,
1377 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001378
1379 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// reinterpret_cast.
1381 ///
1382 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001383 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001385 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 Stmt::StmtClass Class,
1387 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001388 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001391 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation RParenLoc) {
1393 switch (Class) {
1394 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001397 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001398
1399 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 default:
1416 assert(false && "Invalid C++ named cast");
1417 break;
1418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 return getSema().ExprError();
1421 }
Mike Stump11289f42009-09-09 15:08:12 +00001422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new C++ static_cast expression.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new C++ dynamic_cast expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001444 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001446 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001452 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 }
1456
1457 /// \brief Build a new C++ reinterpret_cast expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001463 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 SourceLocation RAngleLoc,
1465 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001466 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001469 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001470 SourceRange(LAngleLoc, RAngleLoc),
1471 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new C++ const_cast expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001480 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001483 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001485 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001486 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001487 SourceRange(LAngleLoc, RAngleLoc),
1488 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
Mike Stump11289f42009-09-09 15:08:12 +00001490
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// \brief Build a new C++ functional-style cast expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001495 ExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001496 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001498 Expr *Sub,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCallba7bf592010-08-24 05:47:05 +00001501 ParsedType::make(TInfo->getType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001503 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001504 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 RParenLoc);
1506 }
Mike Stump11289f42009-09-09 15:08:12 +00001507
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// \brief Build a new C++ typeid(type) expression.
1509 ///
1510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001512 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001513 SourceLocation TypeidLoc,
1514 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001516 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001517 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new C++ typeid(expr) expression.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001525 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001526 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001528 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001529 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001530 }
1531
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// \brief Build a new C++ "this" expression.
1533 ///
1534 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001535 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001537 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001538 QualType ThisType,
1539 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001541 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1542 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
1544
1545 /// \brief Build a new C++ throw expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001549 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001550 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 }
1552
1553 /// \brief Build a new C++ default-argument expression.
1554 ///
1555 /// By default, builds a new default-argument expression, which does not
1556 /// require any semantic analysis. Subclasses may override this routine to
1557 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001559 ParmVarDecl *Param) {
1560 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1561 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 }
1563
1564 /// \brief Build a new C++ zero-initialization expression.
1565 ///
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001568 ExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 SourceLocation LParenLoc,
1570 QualType T,
1571 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001572 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
John McCallba7bf592010-08-24 05:47:05 +00001573 ParsedType::make(T), LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001574 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 0, RParenLoc);
1576 }
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// \brief Build a new C++ "new" expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001582 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 bool UseGlobal,
1584 SourceLocation PlacementLParen,
1585 MultiExprArg PlacementArgs,
1586 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001587 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 QualType AllocType,
1589 SourceLocation TypeLoc,
1590 SourceRange TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001591 Expr *ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 SourceLocation ConstructorLParen,
1593 MultiExprArg ConstructorArgs,
1594 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001595 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 PlacementLParen,
1597 move(PlacementArgs),
1598 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001599 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 AllocType,
1601 TypeLoc,
1602 TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001603 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 ConstructorLParen,
1605 move(ConstructorArgs),
1606 ConstructorRParen);
1607 }
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new C++ "delete" expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 bool IsGlobalDelete,
1615 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001616 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001618 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// \brief Build a new unary type trait expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1628 QualType T,
1629 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001630 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallba7bf592010-08-24 05:47:05 +00001631 ParsedType::make(T), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
1633
Mike Stump11289f42009-09-09 15:08:12 +00001634 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001639 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001641 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001642 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 CXXScopeSpec SS;
1644 SS.setRange(QualifierRange);
1645 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001646
1647 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001648 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001649 *TemplateArgs);
1650
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001651 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 }
1653
1654 /// \brief Build a new template-id expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001658 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001659 LookupResult &R,
1660 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001661 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001662 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 }
1664
1665 /// \brief Build a new object-construction expression.
1666 ///
1667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001669 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001670 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 CXXConstructorDecl *Constructor,
1672 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001673 MultiExprArg Args,
1674 bool RequiresZeroInit,
1675 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001676 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001677 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001678 ConvertedArgs))
1679 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001680
Douglas Gregordb121ba2009-12-14 16:27:04 +00001681 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001682 move_arg(ConvertedArgs),
1683 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 }
1685
1686 /// \brief Build a new object-construction expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001690 ExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 QualType T,
1692 SourceLocation LParenLoc,
1693 MultiExprArg Args,
1694 SourceLocation *Commas,
1695 SourceLocation RParenLoc) {
1696 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
John McCallba7bf592010-08-24 05:47:05 +00001697 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 LParenLoc,
1699 move(Args),
1700 Commas,
1701 RParenLoc);
1702 }
1703
1704 /// \brief Build a new object-construction expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001708 ExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 QualType T,
1710 SourceLocation LParenLoc,
1711 MultiExprArg Args,
1712 SourceLocation *Commas,
1713 SourceLocation RParenLoc) {
1714 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1715 /*FIXME*/LParenLoc),
John McCallba7bf592010-08-24 05:47:05 +00001716 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 LParenLoc,
1718 move(Args),
1719 Commas,
1720 RParenLoc);
1721 }
Mike Stump11289f42009-09-09 15:08:12 +00001722
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// \brief Build a new member reference expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001727 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001728 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 bool IsArrow,
1730 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001731 NestedNameSpecifier *Qualifier,
1732 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001733 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001734 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001735 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001737 SS.setRange(QualifierRange);
1738 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001739
John McCallb268a282010-08-23 23:25:46 +00001740 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001741 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001742 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001743 MemberNameInfo,
1744 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 }
1746
John McCall10eae182009-11-30 22:42:35 +00001747 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001748 ///
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001751 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001752 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001753 SourceLocation OperatorLoc,
1754 bool IsArrow,
1755 NestedNameSpecifier *Qualifier,
1756 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001757 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001758 LookupResult &R,
1759 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001760 CXXScopeSpec SS;
1761 SS.setRange(QualifierRange);
1762 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001763
John McCallb268a282010-08-23 23:25:46 +00001764 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001765 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001766 SS, FirstQualifierInScope,
1767 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001768 }
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 /// \brief Build a new Objective-C @encode expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001774 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001775 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001777 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001779 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001780
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001781 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001783 Selector Sel,
1784 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001785 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001786 MultiExprArg Args,
1787 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001788 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1789 ReceiverTypeInfo->getType(),
1790 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001791 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001792 move(Args));
1793 }
1794
1795 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001796 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001797 Selector Sel,
1798 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001799 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 MultiExprArg Args,
1801 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001802 return SemaRef.BuildInstanceMessage(Receiver,
1803 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001804 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001805 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 move(Args));
1807 }
1808
Douglas Gregord51d90d2010-04-26 20:11:03 +00001809 /// \brief Build a new Objective-C ivar reference expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001813 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001814 SourceLocation IvarLoc,
1815 bool IsArrow, bool IsFreeIvar) {
1816 // FIXME: We lose track of the IsFreeIvar bit.
1817 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001818 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001819 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1820 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001822 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001823 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001824 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001825 if (Result.isInvalid())
1826 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001827
Douglas Gregord51d90d2010-04-26 20:11:03 +00001828 if (Result.get())
1829 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001830
John McCallb268a282010-08-23 23:25:46 +00001831 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001833 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001834 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001835 /*TemplateArgs=*/0);
1836 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001837
1838 /// \brief Build a new Objective-C property reference expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001843 ObjCPropertyDecl *Property,
1844 SourceLocation PropertyLoc) {
1845 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001846 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001847 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1848 Sema::LookupMemberName);
1849 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001850 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001851 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001852 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001853 if (Result.isInvalid())
1854 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001855
Douglas Gregor9faee212010-04-26 20:47:02 +00001856 if (Result.get())
1857 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001858
John McCallb268a282010-08-23 23:25:46 +00001859 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001860 /*FIXME:*/PropertyLoc, IsArrow,
1861 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001862 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001863 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 /*TemplateArgs=*/0);
1865 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001866
1867 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001868 /// expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001872 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001873 ObjCMethodDecl *Getter,
1874 QualType T,
1875 ObjCMethodDecl *Setter,
1876 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001877 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001878 // Since these expressions can only be value-dependent, we do not need to
1879 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001880 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001881 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1882 Setter,
1883 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001884 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001885 }
1886
Douglas Gregord51d90d2010-04-26 20:11:03 +00001887 /// \brief Build a new Objective-C "isa" expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001891 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001892 bool IsArrow) {
1893 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001894 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001895 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1896 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001897 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001898 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001899 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 if (Result.isInvalid())
1901 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001902
Douglas Gregord51d90d2010-04-26 20:11:03 +00001903 if (Result.get())
1904 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001905
John McCallb268a282010-08-23 23:25:46 +00001906 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001907 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001908 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001909 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001910 /*TemplateArgs=*/0);
1911 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001912
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 /// \brief Build a new shuffle vector expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001917 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 MultiExprArg SubExprs,
1919 SourceLocation RParenLoc) {
1920 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001921 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1923 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1924 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1925 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 // Build a reference to the __builtin_shufflevector builtin
1928 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001929 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001931 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001933
1934 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 unsigned NumSubExprs = SubExprs.size();
1936 Expr **Subs = (Expr **)SubExprs.release();
1937 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1938 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001939 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001944 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 if (Result.isInvalid())
1946 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001949 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001951};
Douglas Gregora16548e2009-08-11 05:31:07 +00001952
Douglas Gregorebe10102009-08-20 07:17:43 +00001953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001954StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 if (!S)
1956 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregorebe10102009-08-20 07:17:43 +00001958 switch (S->getStmtClass()) {
1959 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregorebe10102009-08-20 07:17:43 +00001961 // Transform individual statement nodes
1962#define STMT(Node, Parent) \
1963 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1964#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001965#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregorebe10102009-08-20 07:17:43 +00001967 // Transform expressions by calling TransformExpr.
1968#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001969#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001970#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001971#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 {
John McCalldadc5752010-08-24 06:29:42 +00001973 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001974 if (E.isInvalid())
1975 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001976
John McCallb268a282010-08-23 23:25:46 +00001977 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979 }
1980
Douglas Gregorebe10102009-08-20 07:17:43 +00001981 return SemaRef.Owned(S->Retain());
1982}
Mike Stump11289f42009-09-09 15:08:12 +00001983
1984
Douglas Gregore922c772009-08-04 22:27:00 +00001985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001986ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 if (!E)
1988 return SemaRef.Owned(E);
1989
1990 switch (E->getStmtClass()) {
1991 case Stmt::NoStmtClass: break;
1992#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00001993#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001994#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001995 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001996#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001997 }
1998
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002000}
2001
2002template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002003NestedNameSpecifier *
2004TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002005 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002006 QualType ObjectType,
2007 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002008 if (!NNS)
2009 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002010
Douglas Gregorebe10102009-08-20 07:17:43 +00002011 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002012 NestedNameSpecifier *Prefix = NNS->getPrefix();
2013 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002014 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002015 ObjectType,
2016 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002017 if (!Prefix)
2018 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002019
2020 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002021 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002022 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002023 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002024 }
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 switch (NNS->getKind()) {
2027 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002028 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002029 "Identifier nested-name-specifier with no prefix or object type");
2030 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2031 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002033
2034 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002035 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002036 ObjectType,
2037 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002038
Douglas Gregor1135c352009-08-06 05:28:30 +00002039 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002040 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002042 getDerived().TransformDecl(Range.getBegin(),
2043 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002045 Prefix == NNS->getPrefix() &&
2046 NS == NNS->getAsNamespace())
2047 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2050 }
Mike Stump11289f42009-09-09 15:08:12 +00002051
Douglas Gregor1135c352009-08-06 05:28:30 +00002052 case NestedNameSpecifier::Global:
2053 // There is no meaningful transformation that one could perform on the
2054 // global scope.
2055 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 case NestedNameSpecifier::TypeSpecWithTemplate:
2058 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002059 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002060 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2061 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002062 if (T.isNull())
2063 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002064
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 if (!getDerived().AlwaysRebuild() &&
2066 Prefix == NNS->getPrefix() &&
2067 T == QualType(NNS->getAsType(), 0))
2068 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002069
2070 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2071 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002072 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 }
2074 }
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregor1135c352009-08-06 05:28:30 +00002076 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002077 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002078}
2079
2080template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002081DeclarationNameInfo
2082TreeTransform<Derived>
2083::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2084 QualType ObjectType) {
2085 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002086 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002087 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002088
2089 switch (Name.getNameKind()) {
2090 case DeclarationName::Identifier:
2091 case DeclarationName::ObjCZeroArgSelector:
2092 case DeclarationName::ObjCOneArgSelector:
2093 case DeclarationName::ObjCMultiArgSelector:
2094 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002095 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002096 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002097 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregorf816bd72009-09-03 22:13:48 +00002099 case DeclarationName::CXXConstructorName:
2100 case DeclarationName::CXXDestructorName:
2101 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002102 TypeSourceInfo *NewTInfo;
2103 CanQualType NewCanTy;
2104 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2105 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2106 if (!NewTInfo)
2107 return DeclarationNameInfo();
2108 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2109 }
2110 else {
2111 NewTInfo = 0;
2112 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2113 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2114 ObjectType);
2115 if (NewT.isNull())
2116 return DeclarationNameInfo();
2117 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2118 }
Mike Stump11289f42009-09-09 15:08:12 +00002119
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002120 DeclarationName NewName
2121 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2122 NewCanTy);
2123 DeclarationNameInfo NewNameInfo(NameInfo);
2124 NewNameInfo.setName(NewName);
2125 NewNameInfo.setNamedTypeInfo(NewTInfo);
2126 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128 }
2129
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002130 assert(0 && "Unknown name kind.");
2131 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002132}
2133
2134template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002135TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002136TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2137 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002138 SourceLocation Loc = getDerived().getBaseLocation();
2139
Douglas Gregor71dc5092009-08-06 06:41:21 +00002140 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002141 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002142 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002143 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2144 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002145 if (!NNS)
2146 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002147
Douglas Gregor71dc5092009-08-06 06:41:21 +00002148 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002149 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002150 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 if (!TransTemplate)
2152 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 if (!getDerived().AlwaysRebuild() &&
2155 NNS == QTN->getQualifier() &&
2156 TransTemplate == Template)
2157 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002158
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2160 TransTemplate);
2161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162
John McCalle66edc12009-11-24 19:00:30 +00002163 // These should be getting filtered out before they make it into the AST.
2164 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002168 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002170 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2171 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002172 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002173 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002174
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002176 NNS == DTN->getQualifier() &&
2177 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregor71395fa2009-11-04 00:56:37 +00002180 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002181 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002182 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002183
2184 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002185 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002186 }
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002189 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002190 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002191 if (!TransTemplate)
2192 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 if (!getDerived().AlwaysRebuild() &&
2195 TransTemplate == Template)
2196 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002197
Douglas Gregor71dc5092009-08-06 06:41:21 +00002198 return TemplateName(TransTemplate);
2199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
John McCalle66edc12009-11-24 19:00:30 +00002201 // These should be getting filtered out before they reach the AST.
2202 assert(false && "overloaded function decl survived to here");
2203 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204}
2205
2206template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002207void TreeTransform<Derived>::InventTemplateArgumentLoc(
2208 const TemplateArgument &Arg,
2209 TemplateArgumentLoc &Output) {
2210 SourceLocation Loc = getDerived().getBaseLocation();
2211 switch (Arg.getKind()) {
2212 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002213 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002214 break;
2215
2216 case TemplateArgument::Type:
2217 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002218 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002219
John McCall0ad16662009-10-29 08:12:44 +00002220 break;
2221
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002222 case TemplateArgument::Template:
2223 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2224 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002225
John McCall0ad16662009-10-29 08:12:44 +00002226 case TemplateArgument::Expression:
2227 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2228 break;
2229
2230 case TemplateArgument::Declaration:
2231 case TemplateArgument::Integral:
2232 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002233 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002234 break;
2235 }
2236}
2237
2238template<typename Derived>
2239bool TreeTransform<Derived>::TransformTemplateArgument(
2240 const TemplateArgumentLoc &Input,
2241 TemplateArgumentLoc &Output) {
2242 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002243 switch (Arg.getKind()) {
2244 case TemplateArgument::Null:
2245 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002246 Output = Input;
2247 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002248
Douglas Gregore922c772009-08-04 22:27:00 +00002249 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002250 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002251 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002252 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002253
2254 DI = getDerived().TransformType(DI);
2255 if (!DI) return true;
2256
2257 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2258 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002259 }
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregore922c772009-08-04 22:27:00 +00002261 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002262 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002263 DeclarationName Name;
2264 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2265 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002266 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002267 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002268 if (!D) return true;
2269
John McCall0d07eb32009-10-29 18:45:58 +00002270 Expr *SourceExpr = Input.getSourceDeclExpression();
2271 if (SourceExpr) {
2272 EnterExpressionEvaluationContext Unevaluated(getSema(),
2273 Action::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002275 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002276 }
2277
2278 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002279 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002280 }
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002282 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002283 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002284 TemplateName Template
2285 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2286 if (Template.isNull())
2287 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002288
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002289 Output = TemplateArgumentLoc(TemplateArgument(Template),
2290 Input.getTemplateQualifierRange(),
2291 Input.getTemplateNameLoc());
2292 return false;
2293 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002294
Douglas Gregore922c772009-08-04 22:27:00 +00002295 case TemplateArgument::Expression: {
2296 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002297 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002298 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002299
John McCall0ad16662009-10-29 08:12:44 +00002300 Expr *InputExpr = Input.getSourceExpression();
2301 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2302
John McCalldadc5752010-08-24 06:29:42 +00002303 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002304 = getDerived().TransformExpr(InputExpr);
2305 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002306 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002307 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregore922c772009-08-04 22:27:00 +00002310 case TemplateArgument::Pack: {
2311 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2312 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002313 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002314 AEnd = Arg.pack_end();
2315 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002316
John McCall0ad16662009-10-29 08:12:44 +00002317 // FIXME: preserve source information here when we start
2318 // caring about parameter packs.
2319
John McCall0d07eb32009-10-29 18:45:58 +00002320 TemplateArgumentLoc InputArg;
2321 TemplateArgumentLoc OutputArg;
2322 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2323 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002324 return true;
2325
John McCall0d07eb32009-10-29 18:45:58 +00002326 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002327 }
2328 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002329 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002330 true);
John McCall0d07eb32009-10-29 18:45:58 +00002331 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002332 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002333 }
2334 }
Mike Stump11289f42009-09-09 15:08:12 +00002335
Douglas Gregore922c772009-08-04 22:27:00 +00002336 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002337 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002338}
2339
Douglas Gregord6ff3322009-08-04 16:50:30 +00002340//===----------------------------------------------------------------------===//
2341// Type transformation
2342//===----------------------------------------------------------------------===//
2343
2344template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002345QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002346 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002347 if (getDerived().AlreadyTransformed(T))
2348 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002349
John McCall550e0c22009-10-21 00:40:46 +00002350 // Temporary workaround. All of these transformations should
2351 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002352 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002353 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002354
Douglas Gregorfe17d252010-02-16 19:09:40 +00002355 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002356
John McCall550e0c22009-10-21 00:40:46 +00002357 if (!NewDI)
2358 return QualType();
2359
2360 return NewDI->getType();
2361}
2362
2363template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002364TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2365 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002366 if (getDerived().AlreadyTransformed(DI->getType()))
2367 return DI;
2368
2369 TypeLocBuilder TLB;
2370
2371 TypeLoc TL = DI->getTypeLoc();
2372 TLB.reserve(TL.getFullDataSize());
2373
Douglas Gregorfe17d252010-02-16 19:09:40 +00002374 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002375 if (Result.isNull())
2376 return 0;
2377
John McCallbcd03502009-12-07 02:54:59 +00002378 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002379}
2380
2381template<typename Derived>
2382QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002383TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2384 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002385 switch (T.getTypeLocClass()) {
2386#define ABSTRACT_TYPELOC(CLASS, PARENT)
2387#define TYPELOC(CLASS, PARENT) \
2388 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002389 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2390 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002391#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002392 }
Mike Stump11289f42009-09-09 15:08:12 +00002393
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002394 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002395 return QualType();
2396}
2397
2398/// FIXME: By default, this routine adds type qualifiers only to types
2399/// that can have qualifiers, and silently suppresses those qualifiers
2400/// that are not permitted (e.g., qualifiers on reference or function
2401/// types). This is the right thing for template instantiation, but
2402/// probably not for other clients.
2403template<typename Derived>
2404QualType
2405TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002406 QualifiedTypeLoc T,
2407 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002408 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002409
Douglas Gregorfe17d252010-02-16 19:09:40 +00002410 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2411 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002412 if (Result.isNull())
2413 return QualType();
2414
2415 // Silently suppress qualifiers if the result type can't be qualified.
2416 // FIXME: this is the right thing for template instantiation, but
2417 // probably not for other clients.
2418 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002419 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002420
John McCallcb0f89a2010-06-05 06:41:15 +00002421 if (!Quals.empty()) {
2422 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2423 TLB.push<QualifiedTypeLoc>(Result);
2424 // No location information to preserve.
2425 }
John McCall550e0c22009-10-21 00:40:46 +00002426
2427 return Result;
2428}
2429
2430template <class TyLoc> static inline
2431QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2432 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2433 NewT.setNameLoc(T.getNameLoc());
2434 return T.getType();
2435}
2436
John McCall550e0c22009-10-21 00:40:46 +00002437template<typename Derived>
2438QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002439 BuiltinTypeLoc T,
2440 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002441 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2442 NewT.setBuiltinLoc(T.getBuiltinLoc());
2443 if (T.needsExtraLocalData())
2444 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2445 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002446}
Mike Stump11289f42009-09-09 15:08:12 +00002447
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002449QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002450 ComplexTypeLoc T,
2451 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002452 // FIXME: recurse?
2453 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002454}
Mike Stump11289f42009-09-09 15:08:12 +00002455
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002457QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002458 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002459 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002460 QualType PointeeType
2461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002462 if (PointeeType.isNull())
2463 return QualType();
2464
2465 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002466 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002467 // A dependent pointer type 'T *' has is being transformed such
2468 // that an Objective-C class type is being replaced for 'T'. The
2469 // resulting pointer type is an ObjCObjectPointerType, not a
2470 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002471 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002472
John McCall8b07ec22010-05-15 11:32:37 +00002473 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2474 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002475 return Result;
2476 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002477
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002478 if (getDerived().AlwaysRebuild() ||
2479 PointeeType != TL.getPointeeLoc().getType()) {
2480 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2481 if (Result.isNull())
2482 return QualType();
2483 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002484
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002485 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2486 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002487 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002488}
Mike Stump11289f42009-09-09 15:08:12 +00002489
2490template<typename Derived>
2491QualType
John McCall550e0c22009-10-21 00:40:46 +00002492TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002493 BlockPointerTypeLoc TL,
2494 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002495 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002496 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2497 if (PointeeType.isNull())
2498 return QualType();
2499
2500 QualType Result = TL.getType();
2501 if (getDerived().AlwaysRebuild() ||
2502 PointeeType != TL.getPointeeLoc().getType()) {
2503 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002504 TL.getSigilLoc());
2505 if (Result.isNull())
2506 return QualType();
2507 }
2508
Douglas Gregor049211a2010-04-22 16:50:51 +00002509 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002510 NewT.setSigilLoc(TL.getSigilLoc());
2511 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002512}
2513
John McCall70dd5f62009-10-30 00:06:24 +00002514/// Transforms a reference type. Note that somewhat paradoxically we
2515/// don't care whether the type itself is an l-value type or an r-value
2516/// type; we only care if the type was *written* as an l-value type
2517/// or an r-value type.
2518template<typename Derived>
2519QualType
2520TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002521 ReferenceTypeLoc TL,
2522 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002523 const ReferenceType *T = TL.getTypePtr();
2524
2525 // Note that this works with the pointee-as-written.
2526 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2527 if (PointeeType.isNull())
2528 return QualType();
2529
2530 QualType Result = TL.getType();
2531 if (getDerived().AlwaysRebuild() ||
2532 PointeeType != T->getPointeeTypeAsWritten()) {
2533 Result = getDerived().RebuildReferenceType(PointeeType,
2534 T->isSpelledAsLValue(),
2535 TL.getSigilLoc());
2536 if (Result.isNull())
2537 return QualType();
2538 }
2539
2540 // r-value references can be rebuilt as l-value references.
2541 ReferenceTypeLoc NewTL;
2542 if (isa<LValueReferenceType>(Result))
2543 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2544 else
2545 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2546 NewTL.setSigilLoc(TL.getSigilLoc());
2547
2548 return Result;
2549}
2550
Mike Stump11289f42009-09-09 15:08:12 +00002551template<typename Derived>
2552QualType
John McCall550e0c22009-10-21 00:40:46 +00002553TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002554 LValueReferenceTypeLoc TL,
2555 QualType ObjectType) {
2556 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002557}
2558
Mike Stump11289f42009-09-09 15:08:12 +00002559template<typename Derived>
2560QualType
John McCall550e0c22009-10-21 00:40:46 +00002561TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002562 RValueReferenceTypeLoc TL,
2563 QualType ObjectType) {
2564 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565}
Mike Stump11289f42009-09-09 15:08:12 +00002566
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002568QualType
John McCall550e0c22009-10-21 00:40:46 +00002569TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002570 MemberPointerTypeLoc TL,
2571 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002572 MemberPointerType *T = TL.getTypePtr();
2573
2574 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002575 if (PointeeType.isNull())
2576 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002577
John McCall550e0c22009-10-21 00:40:46 +00002578 // TODO: preserve source information for this.
2579 QualType ClassType
2580 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581 if (ClassType.isNull())
2582 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002583
John McCall550e0c22009-10-21 00:40:46 +00002584 QualType Result = TL.getType();
2585 if (getDerived().AlwaysRebuild() ||
2586 PointeeType != T->getPointeeType() ||
2587 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002588 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2589 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002590 if (Result.isNull())
2591 return QualType();
2592 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002593
John McCall550e0c22009-10-21 00:40:46 +00002594 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2595 NewTL.setSigilLoc(TL.getSigilLoc());
2596
2597 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002598}
2599
Mike Stump11289f42009-09-09 15:08:12 +00002600template<typename Derived>
2601QualType
John McCall550e0c22009-10-21 00:40:46 +00002602TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002603 ConstantArrayTypeLoc TL,
2604 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002605 ConstantArrayType *T = TL.getTypePtr();
2606 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002607 if (ElementType.isNull())
2608 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002609
John McCall550e0c22009-10-21 00:40:46 +00002610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 ElementType != T->getElementType()) {
2613 Result = getDerived().RebuildConstantArrayType(ElementType,
2614 T->getSizeModifier(),
2615 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002616 T->getIndexTypeCVRQualifiers(),
2617 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002618 if (Result.isNull())
2619 return QualType();
2620 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002621
John McCall550e0c22009-10-21 00:40:46 +00002622 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2623 NewTL.setLBracketLoc(TL.getLBracketLoc());
2624 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002625
John McCall550e0c22009-10-21 00:40:46 +00002626 Expr *Size = TL.getSizeExpr();
2627 if (Size) {
2628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2629 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2630 }
2631 NewTL.setSizeExpr(Size);
2632
2633 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634}
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002638 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002639 IncompleteArrayTypeLoc TL,
2640 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002641 IncompleteArrayType *T = TL.getTypePtr();
2642 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002643 if (ElementType.isNull())
2644 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002645
John McCall550e0c22009-10-21 00:40:46 +00002646 QualType Result = TL.getType();
2647 if (getDerived().AlwaysRebuild() ||
2648 ElementType != T->getElementType()) {
2649 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002651 T->getIndexTypeCVRQualifiers(),
2652 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002653 if (Result.isNull())
2654 return QualType();
2655 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002656
John McCall550e0c22009-10-21 00:40:46 +00002657 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2658 NewTL.setLBracketLoc(TL.getLBracketLoc());
2659 NewTL.setRBracketLoc(TL.getRBracketLoc());
2660 NewTL.setSizeExpr(0);
2661
2662 return Result;
2663}
2664
2665template<typename Derived>
2666QualType
2667TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002668 VariableArrayTypeLoc TL,
2669 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002670 VariableArrayType *T = TL.getTypePtr();
2671 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2672 if (ElementType.isNull())
2673 return QualType();
2674
2675 // Array bounds are not potentially evaluated contexts
2676 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2677
John McCalldadc5752010-08-24 06:29:42 +00002678 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002679 = getDerived().TransformExpr(T->getSizeExpr());
2680 if (SizeResult.isInvalid())
2681 return QualType();
2682
John McCallb268a282010-08-23 23:25:46 +00002683 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002684
2685 QualType Result = TL.getType();
2686 if (getDerived().AlwaysRebuild() ||
2687 ElementType != T->getElementType() ||
2688 Size != T->getSizeExpr()) {
2689 Result = getDerived().RebuildVariableArrayType(ElementType,
2690 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002691 Size,
John McCall550e0c22009-10-21 00:40:46 +00002692 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002693 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002694 if (Result.isNull())
2695 return QualType();
2696 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002697
John McCall550e0c22009-10-21 00:40:46 +00002698 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2699 NewTL.setLBracketLoc(TL.getLBracketLoc());
2700 NewTL.setRBracketLoc(TL.getRBracketLoc());
2701 NewTL.setSizeExpr(Size);
2702
2703 return Result;
2704}
2705
2706template<typename Derived>
2707QualType
2708TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002709 DependentSizedArrayTypeLoc TL,
2710 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002711 DependentSizedArrayType *T = TL.getTypePtr();
2712 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2713 if (ElementType.isNull())
2714 return QualType();
2715
2716 // Array bounds are not potentially evaluated contexts
2717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2718
John McCalldadc5752010-08-24 06:29:42 +00002719 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002720 = getDerived().TransformExpr(T->getSizeExpr());
2721 if (SizeResult.isInvalid())
2722 return QualType();
2723
2724 Expr *Size = static_cast<Expr*>(SizeResult.get());
2725
2726 QualType Result = TL.getType();
2727 if (getDerived().AlwaysRebuild() ||
2728 ElementType != T->getElementType() ||
2729 Size != T->getSizeExpr()) {
2730 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2731 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002732 Size,
John McCall550e0c22009-10-21 00:40:46 +00002733 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002734 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002735 if (Result.isNull())
2736 return QualType();
2737 }
2738 else SizeResult.take();
2739
2740 // We might have any sort of array type now, but fortunately they
2741 // all have the same location layout.
2742 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2743 NewTL.setLBracketLoc(TL.getLBracketLoc());
2744 NewTL.setRBracketLoc(TL.getRBracketLoc());
2745 NewTL.setSizeExpr(Size);
2746
2747 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002748}
Mike Stump11289f42009-09-09 15:08:12 +00002749
2750template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002752 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002753 DependentSizedExtVectorTypeLoc TL,
2754 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002755 DependentSizedExtVectorType *T = TL.getTypePtr();
2756
2757 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 QualType ElementType = getDerived().TransformType(T->getElementType());
2759 if (ElementType.isNull())
2760 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002761
Douglas Gregore922c772009-08-04 22:27:00 +00002762 // Vector sizes are not potentially evaluated contexts
2763 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2764
John McCalldadc5752010-08-24 06:29:42 +00002765 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766 if (Size.isInvalid())
2767 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002768
John McCall550e0c22009-10-21 00:40:46 +00002769 QualType Result = TL.getType();
2770 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002771 ElementType != T->getElementType() ||
2772 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002773 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002774 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002776 if (Result.isNull())
2777 return QualType();
2778 }
John McCall550e0c22009-10-21 00:40:46 +00002779
2780 // Result might be dependent or not.
2781 if (isa<DependentSizedExtVectorType>(Result)) {
2782 DependentSizedExtVectorTypeLoc NewTL
2783 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785 } else {
2786 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 }
2789
2790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791}
Mike Stump11289f42009-09-09 15:08:12 +00002792
2793template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002795 VectorTypeLoc TL,
2796 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002797 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002798 QualType ElementType = getDerived().TransformType(T->getElementType());
2799 if (ElementType.isNull())
2800 return QualType();
2801
John McCall550e0c22009-10-21 00:40:46 +00002802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
2804 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002805 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002806 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002810
John McCall550e0c22009-10-21 00:40:46 +00002811 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002813
John McCall550e0c22009-10-21 00:40:46 +00002814 return Result;
2815}
2816
2817template<typename Derived>
2818QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002819 ExtVectorTypeLoc TL,
2820 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002821 VectorType *T = TL.getTypePtr();
2822 QualType ElementType = getDerived().TransformType(T->getElementType());
2823 if (ElementType.isNull())
2824 return QualType();
2825
2826 QualType Result = TL.getType();
2827 if (getDerived().AlwaysRebuild() ||
2828 ElementType != T->getElementType()) {
2829 Result = getDerived().RebuildExtVectorType(ElementType,
2830 T->getNumElements(),
2831 /*FIXME*/ SourceLocation());
2832 if (Result.isNull())
2833 return QualType();
2834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002835
John McCall550e0c22009-10-21 00:40:46 +00002836 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
2838
2839 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002840}
Mike Stump11289f42009-09-09 15:08:12 +00002841
2842template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002843ParmVarDecl *
2844TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2845 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2846 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2847 if (!NewDI)
2848 return 0;
2849
2850 if (NewDI == OldDI)
2851 return OldParm;
2852 else
2853 return ParmVarDecl::Create(SemaRef.Context,
2854 OldParm->getDeclContext(),
2855 OldParm->getLocation(),
2856 OldParm->getIdentifier(),
2857 NewDI->getType(),
2858 NewDI,
2859 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002860 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002861 /* DefArg */ NULL);
2862}
2863
2864template<typename Derived>
2865bool TreeTransform<Derived>::
2866 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2867 llvm::SmallVectorImpl<QualType> &PTypes,
2868 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2869 FunctionProtoType *T = TL.getTypePtr();
2870
2871 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2872 ParmVarDecl *OldParm = TL.getArg(i);
2873
2874 QualType NewType;
2875 ParmVarDecl *NewParm;
2876
2877 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002878 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2879 if (!NewParm)
2880 return true;
2881 NewType = NewParm->getType();
2882
2883 // Deal with the possibility that we don't have a parameter
2884 // declaration for this parameter.
2885 } else {
2886 NewParm = 0;
2887
2888 QualType OldType = T->getArgType(i);
2889 NewType = getDerived().TransformType(OldType);
2890 if (NewType.isNull())
2891 return true;
2892 }
2893
2894 PTypes.push_back(NewType);
2895 PVars.push_back(NewParm);
2896 }
2897
2898 return false;
2899}
2900
2901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002902QualType
John McCall550e0c22009-10-21 00:40:46 +00002903TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002904 FunctionProtoTypeLoc TL,
2905 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002906 // Transform the parameters. We do this first for the benefit of template
2907 // instantiations, so that the ParmVarDecls get/ placed into the template
2908 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002910 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002911 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2912 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002913
Douglas Gregor14cf7522010-04-30 18:55:50 +00002914 FunctionProtoType *T = TL.getTypePtr();
2915 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2916 if (ResultType.isNull())
2917 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002918
John McCall550e0c22009-10-21 00:40:46 +00002919 QualType Result = TL.getType();
2920 if (getDerived().AlwaysRebuild() ||
2921 ResultType != T->getResultType() ||
2922 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2923 Result = getDerived().RebuildFunctionProtoType(ResultType,
2924 ParamTypes.data(),
2925 ParamTypes.size(),
2926 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002927 T->getTypeQuals(),
2928 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002929 if (Result.isNull())
2930 return QualType();
2931 }
Mike Stump11289f42009-09-09 15:08:12 +00002932
John McCall550e0c22009-10-21 00:40:46 +00002933 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2934 NewTL.setLParenLoc(TL.getLParenLoc());
2935 NewTL.setRParenLoc(TL.getRParenLoc());
2936 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2937 NewTL.setArg(i, ParamDecls[i]);
2938
2939 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940}
Mike Stump11289f42009-09-09 15:08:12 +00002941
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942template<typename Derived>
2943QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002944 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002945 FunctionNoProtoTypeLoc TL,
2946 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002947 FunctionNoProtoType *T = TL.getTypePtr();
2948 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2949 if (ResultType.isNull())
2950 return QualType();
2951
2952 QualType Result = TL.getType();
2953 if (getDerived().AlwaysRebuild() ||
2954 ResultType != T->getResultType())
2955 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2956
2957 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2958 NewTL.setLParenLoc(TL.getLParenLoc());
2959 NewTL.setRParenLoc(TL.getRParenLoc());
2960
2961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962}
Mike Stump11289f42009-09-09 15:08:12 +00002963
John McCallb96ec562009-12-04 22:46:56 +00002964template<typename Derived> QualType
2965TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002966 UnresolvedUsingTypeLoc TL,
2967 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002968 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002969 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002970 if (!D)
2971 return QualType();
2972
2973 QualType Result = TL.getType();
2974 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2975 Result = getDerived().RebuildUnresolvedUsingType(D);
2976 if (Result.isNull())
2977 return QualType();
2978 }
2979
2980 // We might get an arbitrary type spec type back. We should at
2981 // least always get a type spec type, though.
2982 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2983 NewTL.setNameLoc(TL.getNameLoc());
2984
2985 return Result;
2986}
2987
Douglas Gregord6ff3322009-08-04 16:50:30 +00002988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002989QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002990 TypedefTypeLoc TL,
2991 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002992 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002993 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002994 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2995 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996 if (!Typedef)
2997 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002998
John McCall550e0c22009-10-21 00:40:46 +00002999 QualType Result = TL.getType();
3000 if (getDerived().AlwaysRebuild() ||
3001 Typedef != T->getDecl()) {
3002 Result = getDerived().RebuildTypedefType(Typedef);
3003 if (Result.isNull())
3004 return QualType();
3005 }
Mike Stump11289f42009-09-09 15:08:12 +00003006
John McCall550e0c22009-10-21 00:40:46 +00003007 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3008 NewTL.setNameLoc(TL.getNameLoc());
3009
3010 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003011}
Mike Stump11289f42009-09-09 15:08:12 +00003012
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003014QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003015 TypeOfExprTypeLoc TL,
3016 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003017 // typeof expressions are not potentially evaluated contexts
3018 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003019
John McCalldadc5752010-08-24 06:29:42 +00003020 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 if (E.isInvalid())
3022 return QualType();
3023
John McCall550e0c22009-10-21 00:40:46 +00003024 QualType Result = TL.getType();
3025 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003026 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003027 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003028 if (Result.isNull())
3029 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003030 }
John McCall550e0c22009-10-21 00:40:46 +00003031 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003032
John McCall550e0c22009-10-21 00:40:46 +00003033 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003034 NewTL.setTypeofLoc(TL.getTypeofLoc());
3035 NewTL.setLParenLoc(TL.getLParenLoc());
3036 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003037
3038 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003039}
Mike Stump11289f42009-09-09 15:08:12 +00003040
3041template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003042QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003043 TypeOfTypeLoc TL,
3044 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003045 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3046 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3047 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003048 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003049
John McCall550e0c22009-10-21 00:40:46 +00003050 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003051 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3052 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003053 if (Result.isNull())
3054 return QualType();
3055 }
Mike Stump11289f42009-09-09 15:08:12 +00003056
John McCall550e0c22009-10-21 00:40:46 +00003057 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003058 NewTL.setTypeofLoc(TL.getTypeofLoc());
3059 NewTL.setLParenLoc(TL.getLParenLoc());
3060 NewTL.setRParenLoc(TL.getRParenLoc());
3061 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003068 DecltypeTypeLoc TL,
3069 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003070 DecltypeType *T = TL.getTypePtr();
3071
Douglas Gregore922c772009-08-04 22:27:00 +00003072 // decltype expressions are not potentially evaluated contexts
3073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCalldadc5752010-08-24 06:29:42 +00003075 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 if (E.isInvalid())
3077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall550e0c22009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
3080 if (getDerived().AlwaysRebuild() ||
3081 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003082 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003083 if (Result.isNull())
3084 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003085 }
John McCall550e0c22009-10-21 00:40:46 +00003086 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003087
John McCall550e0c22009-10-21 00:40:46 +00003088 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3089 NewTL.setNameLoc(TL.getNameLoc());
3090
3091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003092}
3093
3094template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003095QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003096 RecordTypeLoc TL,
3097 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003098 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003100 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3101 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102 if (!Record)
3103 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003104
John McCall550e0c22009-10-21 00:40:46 +00003105 QualType Result = TL.getType();
3106 if (getDerived().AlwaysRebuild() ||
3107 Record != T->getDecl()) {
3108 Result = getDerived().RebuildRecordType(Record);
3109 if (Result.isNull())
3110 return QualType();
3111 }
Mike Stump11289f42009-09-09 15:08:12 +00003112
John McCall550e0c22009-10-21 00:40:46 +00003113 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3114 NewTL.setNameLoc(TL.getNameLoc());
3115
3116 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117}
Mike Stump11289f42009-09-09 15:08:12 +00003118
3119template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003120QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003121 EnumTypeLoc TL,
3122 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003123 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003125 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3126 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 if (!Enum)
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 Enum != T->getDecl()) {
3133 Result = getDerived().RebuildEnumType(Enum);
3134 if (Result.isNull())
3135 return QualType();
3136 }
Mike Stump11289f42009-09-09 15:08:12 +00003137
John McCall550e0c22009-10-21 00:40:46 +00003138 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3139 NewTL.setNameLoc(TL.getNameLoc());
3140
3141 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142}
John McCallfcc33b02009-09-05 00:15:47 +00003143
John McCalle78aac42010-03-10 03:28:59 +00003144template<typename Derived>
3145QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3146 TypeLocBuilder &TLB,
3147 InjectedClassNameTypeLoc TL,
3148 QualType ObjectType) {
3149 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3150 TL.getTypePtr()->getDecl());
3151 if (!D) return QualType();
3152
3153 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3154 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3155 return T;
3156}
3157
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159template<typename Derived>
3160QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003161 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003162 TemplateTypeParmTypeLoc TL,
3163 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003164 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003165}
3166
Mike Stump11289f42009-09-09 15:08:12 +00003167template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003168QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003169 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003170 SubstTemplateTypeParmTypeLoc TL,
3171 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003172 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003173}
3174
3175template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003176QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3177 const TemplateSpecializationType *TST,
3178 QualType ObjectType) {
3179 // FIXME: this entire method is a temporary workaround; callers
3180 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003181
John McCall0ad16662009-10-29 08:12:44 +00003182 // Fake up a TemplateSpecializationTypeLoc.
3183 TypeLocBuilder TLB;
3184 TemplateSpecializationTypeLoc TL
3185 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3186
John McCall0d07eb32009-10-29 18:45:58 +00003187 SourceLocation BaseLoc = getDerived().getBaseLocation();
3188
3189 TL.setTemplateNameLoc(BaseLoc);
3190 TL.setLAngleLoc(BaseLoc);
3191 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003192 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3193 const TemplateArgument &TA = TST->getArg(i);
3194 TemplateArgumentLoc TAL;
3195 getDerived().InventTemplateArgumentLoc(TA, TAL);
3196 TL.setArgLocInfo(i, TAL.getLocInfo());
3197 }
3198
3199 TypeLocBuilder IgnoredTLB;
3200 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003201}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003202
Douglas Gregorc59e5612009-10-19 22:04:39 +00003203template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003204QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003205 TypeLocBuilder &TLB,
3206 TemplateSpecializationTypeLoc TL,
3207 QualType ObjectType) {
3208 const TemplateSpecializationType *T = TL.getTypePtr();
3209
Mike Stump11289f42009-09-09 15:08:12 +00003210 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003211 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003212 if (Template.isNull())
3213 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003214
John McCall6b51f282009-11-23 01:53:49 +00003215 TemplateArgumentListInfo NewTemplateArgs;
3216 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3217 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3218
3219 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3220 TemplateArgumentLoc Loc;
3221 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003222 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003223 NewTemplateArgs.addArgument(Loc);
3224 }
Mike Stump11289f42009-09-09 15:08:12 +00003225
John McCall0ad16662009-10-29 08:12:44 +00003226 // FIXME: maybe don't rebuild if all the template arguments are the same.
3227
3228 QualType Result =
3229 getDerived().RebuildTemplateSpecializationType(Template,
3230 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003231 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003232
3233 if (!Result.isNull()) {
3234 TemplateSpecializationTypeLoc NewTL
3235 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3236 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3237 NewTL.setLAngleLoc(TL.getLAngleLoc());
3238 NewTL.setRAngleLoc(TL.getRAngleLoc());
3239 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3240 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 }
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall0ad16662009-10-29 08:12:44 +00003243 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003244}
Mike Stump11289f42009-09-09 15:08:12 +00003245
3246template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003247QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003248TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3249 ElaboratedTypeLoc TL,
3250 QualType ObjectType) {
3251 ElaboratedType *T = TL.getTypePtr();
3252
3253 NestedNameSpecifier *NNS = 0;
3254 // NOTE: the qualifier in an ElaboratedType is optional.
3255 if (T->getQualifier() != 0) {
3256 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003257 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003258 ObjectType);
3259 if (!NNS)
3260 return QualType();
3261 }
Mike Stump11289f42009-09-09 15:08:12 +00003262
Abramo Bagnarad7548482010-05-19 21:37:53 +00003263 QualType NamedT;
3264 // FIXME: this test is meant to workaround a problem (failing assertion)
3265 // occurring if directly executing the code in the else branch.
3266 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3267 TemplateSpecializationTypeLoc OldNamedTL
3268 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3269 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003270 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003271 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3272 if (NamedT.isNull())
3273 return QualType();
3274 TemplateSpecializationTypeLoc NewNamedTL
3275 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3276 NewNamedTL.copy(OldNamedTL);
3277 }
3278 else {
3279 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3280 if (NamedT.isNull())
3281 return QualType();
3282 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003283
John McCall550e0c22009-10-21 00:40:46 +00003284 QualType Result = TL.getType();
3285 if (getDerived().AlwaysRebuild() ||
3286 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003287 NamedT != T->getNamedType()) {
3288 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003289 if (Result.isNull())
3290 return QualType();
3291 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003292
Abramo Bagnara6150c882010-05-11 21:36:43 +00003293 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003294 NewTL.setKeywordLoc(TL.getKeywordLoc());
3295 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003296
3297 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298}
Mike Stump11289f42009-09-09 15:08:12 +00003299
3300template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003301QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3302 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003303 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003304 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003305
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003307 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3308 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003309 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310 if (!NNS)
3311 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003312
John McCallc392f372010-06-11 00:33:02 +00003313 QualType Result
3314 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3315 T->getIdentifier(),
3316 TL.getKeywordLoc(),
3317 TL.getQualifierRange(),
3318 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003319 if (Result.isNull())
3320 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321
Abramo Bagnarad7548482010-05-19 21:37:53 +00003322 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3323 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003324 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3325
Abramo Bagnarad7548482010-05-19 21:37:53 +00003326 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3327 NewTL.setKeywordLoc(TL.getKeywordLoc());
3328 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003329 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003330 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3331 NewTL.setKeywordLoc(TL.getKeywordLoc());
3332 NewTL.setQualifierRange(TL.getQualifierRange());
3333 NewTL.setNameLoc(TL.getNameLoc());
3334 }
John McCall550e0c22009-10-21 00:40:46 +00003335 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003336}
Mike Stump11289f42009-09-09 15:08:12 +00003337
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003339QualType TreeTransform<Derived>::
3340 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3341 DependentTemplateSpecializationTypeLoc TL,
3342 QualType ObjectType) {
3343 DependentTemplateSpecializationType *T = TL.getTypePtr();
3344
3345 NestedNameSpecifier *NNS
3346 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3347 TL.getQualifierRange(),
3348 ObjectType);
3349 if (!NNS)
3350 return QualType();
3351
3352 TemplateArgumentListInfo NewTemplateArgs;
3353 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3354 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3355
3356 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3357 TemplateArgumentLoc Loc;
3358 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3359 return QualType();
3360 NewTemplateArgs.addArgument(Loc);
3361 }
3362
3363 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3364 T->getKeyword(),
3365 NNS,
3366 T->getIdentifier(),
3367 TL.getNameLoc(),
3368 NewTemplateArgs);
3369 if (Result.isNull())
3370 return QualType();
3371
3372 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3373 QualType NamedT = ElabT->getNamedType();
3374
3375 // Copy information relevant to the template specialization.
3376 TemplateSpecializationTypeLoc NamedTL
3377 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3378 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3379 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3380 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3381 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3382
3383 // Copy information relevant to the elaborated type.
3384 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3385 NewTL.setKeywordLoc(TL.getKeywordLoc());
3386 NewTL.setQualifierRange(TL.getQualifierRange());
3387 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003388 TypeLoc NewTL(Result, TL.getOpaqueData());
3389 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003390 }
3391 return Result;
3392}
3393
3394template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003395QualType
3396TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003397 ObjCInterfaceTypeLoc TL,
3398 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003399 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003400 TLB.pushFullCopy(TL);
3401 return TL.getType();
3402}
3403
3404template<typename Derived>
3405QualType
3406TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3407 ObjCObjectTypeLoc TL,
3408 QualType ObjectType) {
3409 // ObjCObjectType is never dependent.
3410 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003411 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412}
Mike Stump11289f42009-09-09 15:08:12 +00003413
3414template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003415QualType
3416TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003417 ObjCObjectPointerTypeLoc TL,
3418 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003419 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003420 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003421 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003422}
3423
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003425// Statement transformation
3426//===----------------------------------------------------------------------===//
3427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003428StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003429TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3430 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003431}
3432
3433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003434StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003435TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3436 return getDerived().TransformCompoundStmt(S, false);
3437}
3438
3439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003441TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 bool IsStmtExpr) {
3443 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003444 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003445 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3446 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003447 StmtResult Result = getDerived().TransformStmt(*B);
Douglas Gregorebe10102009-08-20 07:17:43 +00003448 if (Result.isInvalid())
3449 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003450
Douglas Gregorebe10102009-08-20 07:17:43 +00003451 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3452 Statements.push_back(Result.takeAs<Stmt>());
3453 }
Mike Stump11289f42009-09-09 15:08:12 +00003454
Douglas Gregorebe10102009-08-20 07:17:43 +00003455 if (!getDerived().AlwaysRebuild() &&
3456 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003457 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003458
3459 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3460 move_arg(Statements),
3461 S->getRBracLoc(),
3462 IsStmtExpr);
3463}
Mike Stump11289f42009-09-09 15:08:12 +00003464
Douglas Gregorebe10102009-08-20 07:17:43 +00003465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003466StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003467TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003468 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003469 {
3470 // The case value expressions are not potentially evaluated.
3471 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003472
Eli Friedman06577382009-11-19 03:14:00 +00003473 // Transform the left-hand case value.
3474 LHS = getDerived().TransformExpr(S->getLHS());
3475 if (LHS.isInvalid())
3476 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003477
Eli Friedman06577382009-11-19 03:14:00 +00003478 // Transform the right-hand case value (for the GNU case-range extension).
3479 RHS = getDerived().TransformExpr(S->getRHS());
3480 if (RHS.isInvalid())
3481 return SemaRef.StmtError();
3482 }
Mike Stump11289f42009-09-09 15:08:12 +00003483
Douglas Gregorebe10102009-08-20 07:17:43 +00003484 // Build the case statement.
3485 // Case statements are always rebuilt so that they will attached to their
3486 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003487 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003488 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003489 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003490 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003491 S->getColonLoc());
3492 if (Case.isInvalid())
3493 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003494
Douglas Gregorebe10102009-08-20 07:17:43 +00003495 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003496 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003497 if (SubStmt.isInvalid())
3498 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003499
Douglas Gregorebe10102009-08-20 07:17:43 +00003500 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003501 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003502}
3503
3504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003505StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003506TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003508 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 if (SubStmt.isInvalid())
3510 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003511
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Default statements are always rebuilt
3513 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003514 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003515}
Mike Stump11289f42009-09-09 15:08:12 +00003516
Douglas Gregorebe10102009-08-20 07:17:43 +00003517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003518StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003519TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003520 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 if (SubStmt.isInvalid())
3522 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 // FIXME: Pass the real colon location in.
3525 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3526 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003527 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003528}
Mike Stump11289f42009-09-09 15:08:12 +00003529
Douglas Gregorebe10102009-08-20 07:17:43 +00003530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003531StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003532TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003534 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003535 VarDecl *ConditionVar = 0;
3536 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003537 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003538 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003539 getDerived().TransformDefinition(
3540 S->getConditionVariable()->getLocation(),
3541 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003542 if (!ConditionVar)
3543 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003544 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003545 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003546
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003547 if (Cond.isInvalid())
3548 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003549
3550 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003551 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003552 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003553 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003554 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003555 if (CondE.isInvalid())
3556 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003557
John McCallb268a282010-08-23 23:25:46 +00003558 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003559 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003560 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003561
John McCallb268a282010-08-23 23:25:46 +00003562 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3563 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003564 return SemaRef.StmtError();
3565
Douglas Gregorebe10102009-08-20 07:17:43 +00003566 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003567 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 if (Then.isInvalid())
3569 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003570
Douglas Gregorebe10102009-08-20 07:17:43 +00003571 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003572 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 if (Else.isInvalid())
3574 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregorebe10102009-08-20 07:17:43 +00003576 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003577 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003578 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 Then.get() == S->getThen() &&
3580 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003581 return SemaRef.Owned(S->Retain());
3582
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003583 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003584 Then.get(),
3585 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003586}
3587
3588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003589StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003590TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003591 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003592 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003593 VarDecl *ConditionVar = 0;
3594 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003595 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003596 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003597 getDerived().TransformDefinition(
3598 S->getConditionVariable()->getLocation(),
3599 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003600 if (!ConditionVar)
3601 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003602 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003603 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003604
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003605 if (Cond.isInvalid())
3606 return SemaRef.StmtError();
3607 }
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregorebe10102009-08-20 07:17:43 +00003609 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003610 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003611 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003612 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003613 if (Switch.isInvalid())
3614 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003617 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 if (Body.isInvalid())
3619 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003622 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3623 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003624}
Mike Stump11289f42009-09-09 15:08:12 +00003625
Douglas Gregorebe10102009-08-20 07:17:43 +00003626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003628TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003629 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003630 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003631 VarDecl *ConditionVar = 0;
3632 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003633 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003634 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003635 getDerived().TransformDefinition(
3636 S->getConditionVariable()->getLocation(),
3637 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003638 if (!ConditionVar)
3639 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003640 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003641 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003642
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003643 if (Cond.isInvalid())
3644 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003645
3646 if (S->getCond()) {
3647 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003648 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003649 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003650 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003651 if (CondE.isInvalid())
3652 return getSema().StmtError();
John McCallb268a282010-08-23 23:25:46 +00003653 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003654 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003655 }
Mike Stump11289f42009-09-09 15:08:12 +00003656
John McCallb268a282010-08-23 23:25:46 +00003657 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3658 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003659 return SemaRef.StmtError();
3660
Douglas Gregorebe10102009-08-20 07:17:43 +00003661 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003662 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003663 if (Body.isInvalid())
3664 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregorebe10102009-08-20 07:17:43 +00003666 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003667 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003668 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003669 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003670 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003672 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003673 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003674}
Mike Stump11289f42009-09-09 15:08:12 +00003675
Douglas Gregorebe10102009-08-20 07:17:43 +00003676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003677StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003678TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003679 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003680 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 if (Body.isInvalid())
3682 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003684 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003685 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003686 if (Cond.isInvalid())
3687 return SemaRef.StmtError();
3688
Douglas Gregorebe10102009-08-20 07:17:43 +00003689 if (!getDerived().AlwaysRebuild() &&
3690 Cond.get() == S->getCond() &&
3691 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003692 return SemaRef.Owned(S->Retain());
3693
John McCallb268a282010-08-23 23:25:46 +00003694 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3695 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003696 S->getRParenLoc());
3697}
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregorebe10102009-08-20 07:17:43 +00003699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003700StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003701TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003702 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003703 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003704 if (Init.isInvalid())
3705 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregorebe10102009-08-20 07:17:43 +00003707 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003708 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003709 VarDecl *ConditionVar = 0;
3710 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003711 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003712 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003713 getDerived().TransformDefinition(
3714 S->getConditionVariable()->getLocation(),
3715 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003716 if (!ConditionVar)
3717 return SemaRef.StmtError();
3718 } else {
3719 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003720
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003721 if (Cond.isInvalid())
3722 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003723
3724 if (S->getCond()) {
3725 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003726 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003727 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003728 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003729 if (CondE.isInvalid())
3730 return getSema().StmtError();
3731
John McCallb268a282010-08-23 23:25:46 +00003732 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003733 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003734 }
Mike Stump11289f42009-09-09 15:08:12 +00003735
John McCallb268a282010-08-23 23:25:46 +00003736 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3737 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003738 return SemaRef.StmtError();
3739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003741 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003742 if (Inc.isInvalid())
3743 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003744
John McCallb268a282010-08-23 23:25:46 +00003745 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3746 if (S->getInc() && !FullInc.get())
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003747 return SemaRef.StmtError();
3748
Douglas Gregorebe10102009-08-20 07:17:43 +00003749 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003750 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003751 if (Body.isInvalid())
3752 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003753
Douglas Gregorebe10102009-08-20 07:17:43 +00003754 if (!getDerived().AlwaysRebuild() &&
3755 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003756 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 Inc.get() == S->getInc() &&
3758 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003759 return SemaRef.Owned(S->Retain());
3760
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003762 Init.get(), FullCond, ConditionVar,
3763 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003764}
3765
3766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003767StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003768TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003769 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003770 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003771 S->getLabel());
3772}
3773
3774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003775StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003776TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003777 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 if (Target.isInvalid())
3779 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003780
Douglas Gregorebe10102009-08-20 07:17:43 +00003781 if (!getDerived().AlwaysRebuild() &&
3782 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003783 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003784
3785 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003786 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003787}
3788
3789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003790StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003791TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3792 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003793}
Mike Stump11289f42009-09-09 15:08:12 +00003794
Douglas Gregorebe10102009-08-20 07:17:43 +00003795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003796StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003797TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3798 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003799}
Mike Stump11289f42009-09-09 15:08:12 +00003800
Douglas Gregorebe10102009-08-20 07:17:43 +00003801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003803TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003804 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003805 if (Result.isInvalid())
3806 return SemaRef.StmtError();
3807
Mike Stump11289f42009-09-09 15:08:12 +00003808 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003809 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003810 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003811}
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregorebe10102009-08-20 07:17:43 +00003813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003814StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003815TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003816 bool DeclChanged = false;
3817 llvm::SmallVector<Decl *, 4> Decls;
3818 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3819 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003820 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3821 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003822 if (!Transformed)
3823 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregorebe10102009-08-20 07:17:43 +00003825 if (Transformed != *D)
3826 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregorebe10102009-08-20 07:17:43 +00003828 Decls.push_back(Transformed);
3829 }
Mike Stump11289f42009-09-09 15:08:12 +00003830
Douglas Gregorebe10102009-08-20 07:17:43 +00003831 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003832 return SemaRef.Owned(S->Retain());
3833
3834 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003835 S->getStartLoc(), S->getEndLoc());
3836}
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregorebe10102009-08-20 07:17:43 +00003838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003839StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003840TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003841 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003842 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003843}
3844
3845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003846StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003847TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003848
John McCall37ad5512010-08-23 06:44:23 +00003849 ASTOwningVector<Expr*> Constraints(getSema());
3850 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003851 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003852
John McCalldadc5752010-08-24 06:29:42 +00003853 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003854 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003855
3856 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003857
Anders Carlssonaaeef072010-01-24 05:50:09 +00003858 // Go through the outputs.
3859 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003860 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003861
Anders Carlssonaaeef072010-01-24 05:50:09 +00003862 // No need to transform the constraint literal.
3863 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003864
Anders Carlssonaaeef072010-01-24 05:50:09 +00003865 // Transform the output expr.
3866 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003867 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003868 if (Result.isInvalid())
3869 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003870
Anders Carlssonaaeef072010-01-24 05:50:09 +00003871 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003872
John McCallb268a282010-08-23 23:25:46 +00003873 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003874 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003875
Anders Carlssonaaeef072010-01-24 05:50:09 +00003876 // Go through the inputs.
3877 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003878 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003879
Anders Carlssonaaeef072010-01-24 05:50:09 +00003880 // No need to transform the constraint literal.
3881 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003882
Anders Carlssonaaeef072010-01-24 05:50:09 +00003883 // Transform the input expr.
3884 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003885 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003886 if (Result.isInvalid())
3887 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003888
Anders Carlssonaaeef072010-01-24 05:50:09 +00003889 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003890
John McCallb268a282010-08-23 23:25:46 +00003891 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003892 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003893
Anders Carlssonaaeef072010-01-24 05:50:09 +00003894 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3895 return SemaRef.Owned(S->Retain());
3896
3897 // Go through the clobbers.
3898 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3899 Clobbers.push_back(S->getClobber(I)->Retain());
3900
3901 // No need to transform the asm string literal.
3902 AsmString = SemaRef.Owned(S->getAsmString());
3903
3904 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3905 S->isSimple(),
3906 S->isVolatile(),
3907 S->getNumOutputs(),
3908 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003909 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003910 move_arg(Constraints),
3911 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003912 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003913 move_arg(Clobbers),
3914 S->getRParenLoc(),
3915 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003916}
3917
3918
3919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003920StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003921TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003922 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003923 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003924 if (TryBody.isInvalid())
3925 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003926
Douglas Gregor96c79492010-04-23 22:50:49 +00003927 // Transform the @catch statements (if present).
3928 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003929 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003930 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003931 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003932 if (Catch.isInvalid())
3933 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003934 if (Catch.get() != S->getCatchStmt(I))
3935 AnyCatchChanged = true;
3936 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003937 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003938
Douglas Gregor306de2f2010-04-22 23:59:56 +00003939 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00003940 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003941 if (S->getFinallyStmt()) {
3942 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3943 if (Finally.isInvalid())
3944 return SemaRef.StmtError();
3945 }
3946
3947 // If nothing changed, just retain this statement.
3948 if (!getDerived().AlwaysRebuild() &&
3949 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003950 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003951 Finally.get() == S->getFinallyStmt())
3952 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003953
Douglas Gregor306de2f2010-04-22 23:59:56 +00003954 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003955 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3956 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003957}
Mike Stump11289f42009-09-09 15:08:12 +00003958
Douglas Gregorebe10102009-08-20 07:17:43 +00003959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003960StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003961TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003962 // Transform the @catch parameter, if there is one.
3963 VarDecl *Var = 0;
3964 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3965 TypeSourceInfo *TSInfo = 0;
3966 if (FromVar->getTypeSourceInfo()) {
3967 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3968 if (!TSInfo)
3969 return SemaRef.StmtError();
3970 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003971
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003972 QualType T;
3973 if (TSInfo)
3974 T = TSInfo->getType();
3975 else {
3976 T = getDerived().TransformType(FromVar->getType());
3977 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003978 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003980
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003981 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3982 if (!Var)
3983 return SemaRef.StmtError();
3984 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003985
John McCalldadc5752010-08-24 06:29:42 +00003986 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003987 if (Body.isInvalid())
3988 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003989
3990 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003991 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003992 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003993}
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregorebe10102009-08-20 07:17:43 +00003995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003996StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003997TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003998 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00003999 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004000 if (Body.isInvalid())
4001 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004002
Douglas Gregor306de2f2010-04-22 23:59:56 +00004003 // If nothing changed, just retain this statement.
4004 if (!getDerived().AlwaysRebuild() &&
4005 Body.get() == S->getFinallyBody())
4006 return SemaRef.Owned(S->Retain());
4007
4008 // Build a new statement.
4009 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004010 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004011}
Mike Stump11289f42009-09-09 15:08:12 +00004012
Douglas Gregorebe10102009-08-20 07:17:43 +00004013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004014StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004015TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004016 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004017 if (S->getThrowExpr()) {
4018 Operand = getDerived().TransformExpr(S->getThrowExpr());
4019 if (Operand.isInvalid())
4020 return getSema().StmtError();
4021 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004022
Douglas Gregor2900c162010-04-22 21:44:01 +00004023 if (!getDerived().AlwaysRebuild() &&
4024 Operand.get() == S->getThrowExpr())
4025 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004026
John McCallb268a282010-08-23 23:25:46 +00004027 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004028}
Mike Stump11289f42009-09-09 15:08:12 +00004029
Douglas Gregorebe10102009-08-20 07:17:43 +00004030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004031StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004032TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004033 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004034 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004035 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004036 if (Object.isInvalid())
4037 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004038
Douglas Gregor6148de72010-04-22 22:01:21 +00004039 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004040 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004041 if (Body.isInvalid())
4042 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004043
Douglas Gregor6148de72010-04-22 22:01:21 +00004044 // If nothing change, just retain the current statement.
4045 if (!getDerived().AlwaysRebuild() &&
4046 Object.get() == S->getSynchExpr() &&
4047 Body.get() == S->getSynchBody())
4048 return SemaRef.Owned(S->Retain());
4049
4050 // Build a new statement.
4051 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004052 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004053}
4054
4055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004056StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004057TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004058 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004059 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004060 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004061 if (Element.isInvalid())
4062 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004063
Douglas Gregorf68a5082010-04-22 23:10:45 +00004064 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004065 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004066 if (Collection.isInvalid())
4067 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004068
Douglas Gregorf68a5082010-04-22 23:10:45 +00004069 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004070 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004071 if (Body.isInvalid())
4072 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004073
Douglas Gregorf68a5082010-04-22 23:10:45 +00004074 // If nothing changed, just retain this statement.
4075 if (!getDerived().AlwaysRebuild() &&
4076 Element.get() == S->getElement() &&
4077 Collection.get() == S->getCollection() &&
4078 Body.get() == S->getBody())
4079 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004080
Douglas Gregorf68a5082010-04-22 23:10:45 +00004081 // Build a new statement.
4082 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4083 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004084 Element.get(),
4085 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004086 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004087 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004088}
4089
4090
4091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004092StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004093TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4094 // Transform the exception declaration, if any.
4095 VarDecl *Var = 0;
4096 if (S->getExceptionDecl()) {
4097 VarDecl *ExceptionDecl = S->getExceptionDecl();
4098 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4099 ExceptionDecl->getDeclName());
4100
4101 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4102 if (T.isNull())
4103 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004104
Douglas Gregorebe10102009-08-20 07:17:43 +00004105 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4106 T,
John McCallbcd03502009-12-07 02:54:59 +00004107 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004108 ExceptionDecl->getIdentifier(),
4109 ExceptionDecl->getLocation(),
4110 /*FIXME: Inaccurate*/
4111 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004112 if (!Var || Var->isInvalidDecl())
Douglas Gregorebe10102009-08-20 07:17:43 +00004113 return SemaRef.StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004114 }
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregorebe10102009-08-20 07:17:43 +00004116 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004117 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004118 if (Handler.isInvalid())
Douglas Gregorebe10102009-08-20 07:17:43 +00004119 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004120
Douglas Gregorebe10102009-08-20 07:17:43 +00004121 if (!getDerived().AlwaysRebuild() &&
4122 !Var &&
4123 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004124 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004125
4126 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4127 Var,
John McCallb268a282010-08-23 23:25:46 +00004128 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004129}
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregorebe10102009-08-20 07:17:43 +00004131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004132StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004133TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4134 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004135 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004136 = getDerived().TransformCompoundStmt(S->getTryBlock());
4137 if (TryBlock.isInvalid())
4138 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004139
Douglas Gregorebe10102009-08-20 07:17:43 +00004140 // Transform the handlers.
4141 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004142 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004143 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004144 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004145 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4146 if (Handler.isInvalid())
4147 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregorebe10102009-08-20 07:17:43 +00004149 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4150 Handlers.push_back(Handler.takeAs<Stmt>());
4151 }
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregorebe10102009-08-20 07:17:43 +00004153 if (!getDerived().AlwaysRebuild() &&
4154 TryBlock.get() == S->getTryBlock() &&
4155 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004156 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004157
John McCallb268a282010-08-23 23:25:46 +00004158 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004159 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004160}
Mike Stump11289f42009-09-09 15:08:12 +00004161
Douglas Gregorebe10102009-08-20 07:17:43 +00004162//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004163// Expression transformation
4164//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004167TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004168 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004169}
Mike Stump11289f42009-09-09 15:08:12 +00004170
4171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004173TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004174 NestedNameSpecifier *Qualifier = 0;
4175 if (E->getQualifier()) {
4176 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004177 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004178 if (!Qualifier)
4179 return SemaRef.ExprError();
4180 }
John McCallce546572009-12-08 09:08:17 +00004181
4182 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004183 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4184 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004185 if (!ND)
4186 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004187
John McCall815039a2010-08-17 21:27:17 +00004188 DeclarationNameInfo NameInfo = E->getNameInfo();
4189 if (NameInfo.getName()) {
4190 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4191 if (!NameInfo.getName())
4192 return SemaRef.ExprError();
4193 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004194
4195 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004196 Qualifier == E->getQualifier() &&
4197 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004198 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004199 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004200
4201 // Mark it referenced in the new context regardless.
4202 // FIXME: this is a bit instantiation-specific.
4203 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4204
Mike Stump11289f42009-09-09 15:08:12 +00004205 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004206 }
John McCallce546572009-12-08 09:08:17 +00004207
4208 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004209 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004210 TemplateArgs = &TransArgs;
4211 TransArgs.setLAngleLoc(E->getLAngleLoc());
4212 TransArgs.setRAngleLoc(E->getRAngleLoc());
4213 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4214 TemplateArgumentLoc Loc;
4215 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4216 return SemaRef.ExprError();
4217 TransArgs.addArgument(Loc);
4218 }
4219 }
4220
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004221 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004222 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004223}
Mike Stump11289f42009-09-09 15:08:12 +00004224
Douglas Gregora16548e2009-08-11 05:31:07 +00004225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004227TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004228 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004229}
Mike Stump11289f42009-09-09 15:08:12 +00004230
Douglas Gregora16548e2009-08-11 05:31:07 +00004231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004233TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004234 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004235}
Mike Stump11289f42009-09-09 15:08:12 +00004236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004239TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004240 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004241}
Mike Stump11289f42009-09-09 15:08:12 +00004242
Douglas Gregora16548e2009-08-11 05:31:07 +00004243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004245TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004246 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004247}
Mike Stump11289f42009-09-09 15:08:12 +00004248
Douglas Gregora16548e2009-08-11 05:31:07 +00004249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004251TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004252 return SemaRef.Owned(E->Retain());
4253}
4254
4255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004257TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004258 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004259 if (SubExpr.isInvalid())
4260 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004263 return SemaRef.Owned(E->Retain());
4264
John McCallb268a282010-08-23 23:25:46 +00004265 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 E->getRParen());
4267}
4268
Mike Stump11289f42009-09-09 15:08:12 +00004269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004271TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004272 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004273 if (SubExpr.isInvalid())
4274 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004277 return SemaRef.Owned(E->Retain());
4278
Douglas Gregora16548e2009-08-11 05:31:07 +00004279 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4280 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004281 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004282}
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregora16548e2009-08-11 05:31:07 +00004284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004285ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004286TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4287 // Transform the type.
4288 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4289 if (!Type)
4290 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004291
Douglas Gregor882211c2010-04-28 22:16:22 +00004292 // Transform all of the components into components similar to what the
4293 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004294 // FIXME: It would be slightly more efficient in the non-dependent case to
4295 // just map FieldDecls, rather than requiring the rebuilder to look for
4296 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004297 // template code that we don't care.
4298 bool ExprChanged = false;
4299 typedef Action::OffsetOfComponent Component;
4300 typedef OffsetOfExpr::OffsetOfNode Node;
4301 llvm::SmallVector<Component, 4> Components;
4302 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4303 const Node &ON = E->getComponent(I);
4304 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004305 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004306 Comp.LocStart = ON.getRange().getBegin();
4307 Comp.LocEnd = ON.getRange().getEnd();
4308 switch (ON.getKind()) {
4309 case Node::Array: {
4310 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004311 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004312 if (Index.isInvalid())
4313 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004314
Douglas Gregor882211c2010-04-28 22:16:22 +00004315 ExprChanged = ExprChanged || Index.get() != FromIndex;
4316 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004317 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004318 break;
4319 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004320
Douglas Gregor882211c2010-04-28 22:16:22 +00004321 case Node::Field:
4322 case Node::Identifier:
4323 Comp.isBrackets = false;
4324 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004325 if (!Comp.U.IdentInfo)
4326 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004327
Douglas Gregor882211c2010-04-28 22:16:22 +00004328 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004329
Douglas Gregord1702062010-04-29 00:18:15 +00004330 case Node::Base:
4331 // Will be recomputed during the rebuild.
4332 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004333 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004334
Douglas Gregor882211c2010-04-28 22:16:22 +00004335 Components.push_back(Comp);
4336 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004337
Douglas Gregor882211c2010-04-28 22:16:22 +00004338 // If nothing changed, retain the existing expression.
4339 if (!getDerived().AlwaysRebuild() &&
4340 Type == E->getTypeSourceInfo() &&
4341 !ExprChanged)
4342 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004343
Douglas Gregor882211c2010-04-28 22:16:22 +00004344 // Build a new offsetof expression.
4345 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4346 Components.data(), Components.size(),
4347 E->getRParenLoc());
4348}
4349
4350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004354 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004355
John McCallbcd03502009-12-07 02:54:59 +00004356 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004357 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004359
John McCall4c98fd82009-11-04 07:28:41 +00004360 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004362
John McCall4c98fd82009-11-04 07:28:41 +00004363 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004364 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 E->getSourceRange());
4366 }
Mike Stump11289f42009-09-09 15:08:12 +00004367
John McCalldadc5752010-08-24 06:29:42 +00004368 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004369 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004370 // C++0x [expr.sizeof]p1:
4371 // The operand is either an expression, which is an unevaluated operand
4372 // [...]
4373 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4376 if (SubExpr.isInvalid())
4377 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4380 return SemaRef.Owned(E->Retain());
4381 }
Mike Stump11289f42009-09-09 15:08:12 +00004382
John McCallb268a282010-08-23 23:25:46 +00004383 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 E->isSizeOf(),
4385 E->getSourceRange());
4386}
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004389ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004390TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004391 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 if (LHS.isInvalid())
4393 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004394
John McCalldadc5752010-08-24 06:29:42 +00004395 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 if (RHS.isInvalid())
4397 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004398
4399
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 if (!getDerived().AlwaysRebuild() &&
4401 LHS.get() == E->getLHS() &&
4402 RHS.get() == E->getRHS())
4403 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004404
John McCallb268a282010-08-23 23:25:46 +00004405 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004407 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 E->getRBracketLoc());
4409}
Mike Stump11289f42009-09-09 15:08:12 +00004410
4411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004413TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004415 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 if (Callee.isInvalid())
4417 return SemaRef.ExprError();
4418
4419 // Transform arguments.
4420 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004421 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004422 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4423 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004424 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 if (Arg.isInvalid())
4426 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004427
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 // FIXME: Wrong source location information for the ','.
4429 FakeCommaLocs.push_back(
4430 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004431
4432 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004433 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 }
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 if (!getDerived().AlwaysRebuild() &&
4437 Callee.get() == E->getCallee() &&
4438 !ArgChanged)
4439 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004440
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004442 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004444 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 move_arg(Args),
4446 FakeCommaLocs.data(),
4447 E->getRParenLoc());
4448}
Mike Stump11289f42009-09-09 15:08:12 +00004449
4450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004452TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004453 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 if (Base.isInvalid())
4455 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004456
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004457 NestedNameSpecifier *Qualifier = 0;
4458 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004459 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004460 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004461 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004462 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004463 return SemaRef.ExprError();
4464 }
Mike Stump11289f42009-09-09 15:08:12 +00004465
Eli Friedman2cfcef62009-12-04 06:40:45 +00004466 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004467 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4468 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004469 if (!Member)
4470 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004471
John McCall16df1e52010-03-30 21:47:33 +00004472 NamedDecl *FoundDecl = E->getFoundDecl();
4473 if (FoundDecl == E->getMemberDecl()) {
4474 FoundDecl = Member;
4475 } else {
4476 FoundDecl = cast_or_null<NamedDecl>(
4477 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4478 if (!FoundDecl)
4479 return SemaRef.ExprError();
4480 }
4481
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 if (!getDerived().AlwaysRebuild() &&
4483 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004484 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004485 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004486 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004487 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004488
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004489 // Mark it referenced in the new context regardless.
4490 // FIXME: this is a bit instantiation-specific.
4491 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004492 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004493 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004494
John McCall6b51f282009-11-23 01:53:49 +00004495 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004496 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004497 TransArgs.setLAngleLoc(E->getLAngleLoc());
4498 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004499 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004500 TemplateArgumentLoc Loc;
4501 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004502 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004503 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004504 }
4505 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004506
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 // FIXME: Bogus source location for the operator
4508 SourceLocation FakeOperatorLoc
4509 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4510
John McCall38836f02010-01-15 08:34:02 +00004511 // FIXME: to do this check properly, we will need to preserve the
4512 // first-qualifier-in-scope here, just in case we had a dependent
4513 // base (and therefore couldn't do the check) and a
4514 // nested-name-qualifier (and therefore could do the lookup).
4515 NamedDecl *FirstQualifierInScope = 0;
4516
John McCallb268a282010-08-23 23:25:46 +00004517 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004518 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004519 Qualifier,
4520 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004521 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004522 Member,
John McCall16df1e52010-03-30 21:47:33 +00004523 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004524 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004525 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004526 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004527}
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregora16548e2009-08-11 05:31:07 +00004529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004531TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004532 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 if (LHS.isInvalid())
4534 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004535
John McCalldadc5752010-08-24 06:29:42 +00004536 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 if (RHS.isInvalid())
4538 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 if (!getDerived().AlwaysRebuild() &&
4541 LHS.get() == E->getLHS() &&
4542 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004543 return SemaRef.Owned(E->Retain());
4544
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004546 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004547}
4548
Mike Stump11289f42009-09-09 15:08:12 +00004549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004550ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004551TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004552 CompoundAssignOperator *E) {
4553 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004554}
Mike Stump11289f42009-09-09 15:08:12 +00004555
Douglas Gregora16548e2009-08-11 05:31:07 +00004556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004558TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004559 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 if (Cond.isInvalid())
4561 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
John McCalldadc5752010-08-24 06:29:42 +00004563 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 if (LHS.isInvalid())
4565 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004566
John McCalldadc5752010-08-24 06:29:42 +00004567 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 if (RHS.isInvalid())
4569 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 if (!getDerived().AlwaysRebuild() &&
4572 Cond.get() == E->getCond() &&
4573 LHS.get() == E->getLHS() &&
4574 RHS.get() == E->getRHS())
4575 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004576
John McCallb268a282010-08-23 23:25:46 +00004577 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004578 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004579 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004580 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004581 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004582}
Mike Stump11289f42009-09-09 15:08:12 +00004583
4584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004585ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004586TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004587 // Implicit casts are eliminated during transformation, since they
4588 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004589 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregora16548e2009-08-11 05:31:07 +00004592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004593ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004594TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004595 TypeSourceInfo *OldT;
4596 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 {
4598 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004599 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004600 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4601 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004602
John McCall97513962010-01-15 18:39:57 +00004603 OldT = E->getTypeInfoAsWritten();
4604 NewT = getDerived().TransformType(OldT);
4605 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 return SemaRef.ExprError();
4607 }
Mike Stump11289f42009-09-09 15:08:12 +00004608
John McCalldadc5752010-08-24 06:29:42 +00004609 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004610 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004611 if (SubExpr.isInvalid())
4612 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004613
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004615 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004617 return SemaRef.Owned(E->Retain());
4618
John McCall97513962010-01-15 18:39:57 +00004619 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4620 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004622 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004623}
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregora16548e2009-08-11 05:31:07 +00004625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004627TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004628 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4629 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4630 if (!NewT)
4631 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004632
John McCalldadc5752010-08-24 06:29:42 +00004633 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 if (Init.isInvalid())
4635 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004638 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004640 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004641
John McCall5d7aa7f2010-01-19 22:33:45 +00004642 // Note: the expression type doesn't necessarily match the
4643 // type-as-written, but that's okay, because it should always be
4644 // derivable from the initializer.
4645
John McCalle15bbff2010-01-18 19:35:47 +00004646 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004648 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004649}
Mike Stump11289f42009-09-09 15:08:12 +00004650
Douglas Gregora16548e2009-08-11 05:31:07 +00004651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004653TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004654 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 if (Base.isInvalid())
4656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004660 return SemaRef.Owned(E->Retain());
4661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004663 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004665 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 E->getAccessorLoc(),
4667 E->getAccessor());
4668}
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregora16548e2009-08-11 05:31:07 +00004670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004672TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004674
John McCall37ad5512010-08-23 06:44:23 +00004675 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004677 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 if (Init.isInvalid())
4679 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregora16548e2009-08-11 05:31:07 +00004681 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004682 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004683 }
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004686 return SemaRef.Owned(E->Retain());
4687
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004689 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004690}
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004694TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregorebe10102009-08-20 07:17:43 +00004697 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004698 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 if (Init.isInvalid())
4700 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004703 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 bool ExprChanged = false;
4705 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4706 DEnd = E->designators_end();
4707 D != DEnd; ++D) {
4708 if (D->isFieldDesignator()) {
4709 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4710 D->getDotLoc(),
4711 D->getFieldLoc()));
4712 continue;
4713 }
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004716 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 if (Index.isInvalid())
4718 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004719
4720 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004722
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4724 ArrayExprs.push_back(Index.release());
4725 continue;
4726 }
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004729 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4731 if (Start.isInvalid())
4732 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004733
John McCalldadc5752010-08-24 06:29:42 +00004734 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 if (End.isInvalid())
4736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004737
4738 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 End.get(),
4740 D->getLBracketLoc(),
4741 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4744 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004745
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 ArrayExprs.push_back(Start.release());
4747 ArrayExprs.push_back(End.release());
4748 }
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 if (!getDerived().AlwaysRebuild() &&
4751 Init.get() == E->getInit() &&
4752 !ExprChanged)
4753 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4756 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004757 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004758}
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregora16548e2009-08-11 05:31:07 +00004760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004761ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004762TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004763 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004764 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004765
Douglas Gregor3da3c062009-10-28 00:29:27 +00004766 // FIXME: Will we ever have proper type location here? Will we actually
4767 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 QualType T = getDerived().TransformType(E->getType());
4769 if (T.isNull())
4770 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 if (!getDerived().AlwaysRebuild() &&
4773 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004774 return SemaRef.Owned(E->Retain());
4775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 return getDerived().RebuildImplicitValueInitExpr(T);
4777}
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004781TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004782 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4783 if (!TInfo)
4784 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004785
John McCalldadc5752010-08-24 06:29:42 +00004786 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004787 if (SubExpr.isInvalid())
4788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004791 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 SubExpr.get() == E->getSubExpr())
4793 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004794
John McCallb268a282010-08-23 23:25:46 +00004795 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004796 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004797}
4798
4799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004801TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004803 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004805 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 if (Init.isInvalid())
4807 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004808
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004810 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 }
Mike Stump11289f42009-09-09 15:08:12 +00004812
Douglas Gregora16548e2009-08-11 05:31:07 +00004813 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4814 move_arg(Inits),
4815 E->getRParenLoc());
4816}
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregora16548e2009-08-11 05:31:07 +00004818/// \brief Transform an address-of-label expression.
4819///
4820/// By default, the transformation of an address-of-label expression always
4821/// rebuilds the expression, so that the label identifier can be resolved to
4822/// the corresponding label statement by semantic analysis.
4823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004825TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4827 E->getLabel());
4828}
Mike Stump11289f42009-09-09 15:08:12 +00004829
4830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004832TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004833 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004834 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4835 if (SubStmt.isInvalid())
4836 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 if (!getDerived().AlwaysRebuild() &&
4839 SubStmt.get() == E->getSubStmt())
4840 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004841
4842 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004843 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 E->getRParenLoc());
4845}
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregora16548e2009-08-11 05:31:07 +00004847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004848ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004849TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004850 TypeSourceInfo *TInfo1;
4851 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004852
4853 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4854 if (!TInfo1)
4855 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregor7058c262010-08-10 14:27:00 +00004857 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4858 if (!TInfo2)
4859 return SemaRef.ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004860
4861 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004862 TInfo1 == E->getArgTInfo1() &&
4863 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004864 return SemaRef.Owned(E->Retain());
4865
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004867 TInfo1, TInfo2,
4868 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregora16548e2009-08-11 05:31:07 +00004871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004873TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004874 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 if (Cond.isInvalid())
4876 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004877
John McCalldadc5752010-08-24 06:29:42 +00004878 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004879 if (LHS.isInvalid())
4880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
John McCalldadc5752010-08-24 06:29:42 +00004882 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004883 if (RHS.isInvalid())
4884 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregora16548e2009-08-11 05:31:07 +00004886 if (!getDerived().AlwaysRebuild() &&
4887 Cond.get() == E->getCond() &&
4888 LHS.get() == E->getLHS() &&
4889 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004890 return SemaRef.Owned(E->Retain());
4891
Douglas Gregora16548e2009-08-11 05:31:07 +00004892 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004893 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004894 E->getRParenLoc());
4895}
Mike Stump11289f42009-09-09 15:08:12 +00004896
Douglas Gregora16548e2009-08-11 05:31:07 +00004897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004899TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004900 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004901}
4902
4903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004904ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004905TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004906 switch (E->getOperator()) {
4907 case OO_New:
4908 case OO_Delete:
4909 case OO_Array_New:
4910 case OO_Array_Delete:
4911 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4912 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004913
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004914 case OO_Call: {
4915 // This is a call to an object's operator().
4916 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4917
4918 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004919 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004920 if (Object.isInvalid())
4921 return SemaRef.ExprError();
4922
4923 // FIXME: Poor location information
4924 SourceLocation FakeLParenLoc
4925 = SemaRef.PP.getLocForEndOfToken(
4926 static_cast<Expr *>(Object.get())->getLocEnd());
4927
4928 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004929 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004930 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4931 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004932 if (getDerived().DropCallArgument(E->getArg(I)))
4933 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004934
John McCalldadc5752010-08-24 06:29:42 +00004935 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004936 if (Arg.isInvalid())
4937 return SemaRef.ExprError();
4938
4939 // FIXME: Poor source location information.
4940 SourceLocation FakeCommaLoc
4941 = SemaRef.PP.getLocForEndOfToken(
4942 static_cast<Expr *>(Arg.get())->getLocEnd());
4943 FakeCommaLocs.push_back(FakeCommaLoc);
4944 Args.push_back(Arg.release());
4945 }
4946
John McCallb268a282010-08-23 23:25:46 +00004947 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004948 move_arg(Args),
4949 FakeCommaLocs.data(),
4950 E->getLocEnd());
4951 }
4952
4953#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4954 case OO_##Name:
4955#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4956#include "clang/Basic/OperatorKinds.def"
4957 case OO_Subscript:
4958 // Handled below.
4959 break;
4960
4961 case OO_Conditional:
4962 llvm_unreachable("conditional operator is not actually overloadable");
4963 return SemaRef.ExprError();
4964
4965 case OO_None:
4966 case NUM_OVERLOADED_OPERATORS:
4967 llvm_unreachable("not an overloaded operator?");
4968 return SemaRef.ExprError();
4969 }
4970
John McCalldadc5752010-08-24 06:29:42 +00004971 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 if (Callee.isInvalid())
4973 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCalldadc5752010-08-24 06:29:42 +00004975 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004976 if (First.isInvalid())
4977 return SemaRef.ExprError();
4978
John McCalldadc5752010-08-24 06:29:42 +00004979 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00004980 if (E->getNumArgs() == 2) {
4981 Second = getDerived().TransformExpr(E->getArg(1));
4982 if (Second.isInvalid())
4983 return SemaRef.ExprError();
4984 }
Mike Stump11289f42009-09-09 15:08:12 +00004985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 if (!getDerived().AlwaysRebuild() &&
4987 Callee.get() == E->getCallee() &&
4988 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004989 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4990 return SemaRef.Owned(E->Retain());
4991
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4993 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00004994 Callee.get(),
4995 First.get(),
4996 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
Douglas Gregora16548e2009-08-11 05:31:07 +00004999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005000ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005001TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5002 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005007TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005008 TypeSourceInfo *OldT;
5009 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005010 {
5011 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005012 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5014 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005015
John McCall97513962010-01-15 18:39:57 +00005016 OldT = E->getTypeInfoAsWritten();
5017 NewT = getDerived().TransformType(OldT);
5018 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 return SemaRef.ExprError();
5020 }
Mike Stump11289f42009-09-09 15:08:12 +00005021
John McCalldadc5752010-08-24 06:29:42 +00005022 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005023 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 if (SubExpr.isInvalid())
5025 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregora16548e2009-08-11 05:31:07 +00005027 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005028 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005029 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005030 return SemaRef.Owned(E->Retain());
5031
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005033 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5035 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5036 SourceLocation FakeRParenLoc
5037 = SemaRef.PP.getLocForEndOfToken(
5038 E->getSubExpr()->getSourceRange().getEnd());
5039 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005040 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005042 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 FakeRAngleLoc,
5044 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005045 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 FakeRParenLoc);
5047}
Mike Stump11289f42009-09-09 15:08:12 +00005048
Douglas Gregora16548e2009-08-11 05:31:07 +00005049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005051TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5052 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005053}
Mike Stump11289f42009-09-09 15:08:12 +00005054
5055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005056ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005057TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5058 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005059}
5060
Douglas Gregora16548e2009-08-11 05:31:07 +00005061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005062ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005063TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005064 CXXReinterpretCastExpr *E) {
5065 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005066}
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregora16548e2009-08-11 05:31:07 +00005068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5071 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005072}
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005075ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005076TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005077 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005078 TypeSourceInfo *OldT;
5079 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005080 {
5081 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005082
John McCall97513962010-01-15 18:39:57 +00005083 OldT = E->getTypeInfoAsWritten();
5084 NewT = getDerived().TransformType(OldT);
5085 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 return SemaRef.ExprError();
5087 }
Mike Stump11289f42009-09-09 15:08:12 +00005088
John McCalldadc5752010-08-24 06:29:42 +00005089 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005090 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005091 if (SubExpr.isInvalid())
5092 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005095 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005097 return SemaRef.Owned(E->Retain());
5098
Douglas Gregora16548e2009-08-11 05:31:07 +00005099 // FIXME: The end of the type's source range is wrong
5100 return getDerived().RebuildCXXFunctionalCastExpr(
5101 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005102 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005104 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005105 E->getRParenLoc());
5106}
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregora16548e2009-08-11 05:31:07 +00005108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005110TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005112 TypeSourceInfo *TInfo
5113 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5114 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005118 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005119 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregor9da64192010-04-26 22:37:10 +00005121 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5122 E->getLocStart(),
5123 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 E->getLocEnd());
5125 }
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 // We don't know whether the expression is potentially evaluated until
5128 // after we perform semantic analysis, so the expression is potentially
5129 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005130 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005132
John McCalldadc5752010-08-24 06:29:42 +00005133 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 if (SubExpr.isInvalid())
5135 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005139 return SemaRef.Owned(E->Retain());
5140
Douglas Gregor9da64192010-04-26 22:37:10 +00005141 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5142 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005143 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 E->getLocEnd());
5145}
5146
5147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005149TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005150 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005151}
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregora16548e2009-08-11 05:31:07 +00005153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005154ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005155TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005156 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005157 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005158}
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregora16548e2009-08-11 05:31:07 +00005160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005162TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 QualType T = getDerived().TransformType(E->getType());
5166 if (T.isNull())
5167 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 if (!getDerived().AlwaysRebuild() &&
5170 T == E->getType())
5171 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregorb15af892010-01-07 23:12:05 +00005173 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005174}
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregora16548e2009-08-11 05:31:07 +00005176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005177ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005178TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005179 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005180 if (SubExpr.isInvalid())
5181 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 if (!getDerived().AlwaysRebuild() &&
5184 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005185 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186
John McCallb268a282010-08-23 23:25:46 +00005187 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005188}
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregora16548e2009-08-11 05:31:07 +00005190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005192TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005193 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005194 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5195 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005196 if (!Param)
5197 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005198
Chandler Carruth794da4c2010-02-08 06:42:49 +00005199 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 Param == E->getParam())
5201 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005202
Douglas Gregor033f6752009-12-23 23:03:06 +00005203 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
Mike Stump11289f42009-09-09 15:08:12 +00005205
Douglas Gregora16548e2009-08-11 05:31:07 +00005206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005207ExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005208TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005209 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5210
5211 QualType T = getDerived().TransformType(E->getType());
5212 if (T.isNull())
5213 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005214
Douglas Gregora16548e2009-08-11 05:31:07 +00005215 if (!getDerived().AlwaysRebuild() &&
5216 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005217 return SemaRef.Owned(E->Retain());
5218
Douglas Gregor747eb782010-07-08 06:14:04 +00005219 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5220 /*FIXME:*/E->getTypeBeginLoc(),
5221 T,
5222 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005223}
Mike Stump11289f42009-09-09 15:08:12 +00005224
Douglas Gregora16548e2009-08-11 05:31:07 +00005225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005227TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005228 // Transform the type that we're allocating
5229 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5230 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5231 if (AllocType.isNull())
5232 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005235 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 if (ArraySize.isInvalid())
5237 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 // Transform the placement arguments (if any).
5240 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005241 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005243 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 if (Arg.isInvalid())
5245 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5248 PlacementArgs.push_back(Arg.take());
5249 }
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregorebe10102009-08-20 07:17:43 +00005251 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005252 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005254 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5255 break;
5256
John McCalldadc5752010-08-24 06:29:42 +00005257 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 if (Arg.isInvalid())
5259 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5262 ConstructorArgs.push_back(Arg.take());
5263 }
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregord2d9da02010-02-26 00:38:10 +00005265 // Transform constructor, new operator, and delete operator.
5266 CXXConstructorDecl *Constructor = 0;
5267 if (E->getConstructor()) {
5268 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005269 getDerived().TransformDecl(E->getLocStart(),
5270 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005271 if (!Constructor)
5272 return SemaRef.ExprError();
5273 }
5274
5275 FunctionDecl *OperatorNew = 0;
5276 if (E->getOperatorNew()) {
5277 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005278 getDerived().TransformDecl(E->getLocStart(),
5279 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005280 if (!OperatorNew)
5281 return SemaRef.ExprError();
5282 }
5283
5284 FunctionDecl *OperatorDelete = 0;
5285 if (E->getOperatorDelete()) {
5286 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005287 getDerived().TransformDecl(E->getLocStart(),
5288 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005289 if (!OperatorDelete)
5290 return SemaRef.ExprError();
5291 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005292
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 if (!getDerived().AlwaysRebuild() &&
5294 AllocType == E->getAllocatedType() &&
5295 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005296 Constructor == E->getConstructor() &&
5297 OperatorNew == E->getOperatorNew() &&
5298 OperatorDelete == E->getOperatorDelete() &&
5299 !ArgumentChanged) {
5300 // Mark any declarations we need as referenced.
5301 // FIXME: instantiation-specific.
5302 if (Constructor)
5303 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5304 if (OperatorNew)
5305 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5306 if (OperatorDelete)
5307 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005308 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005309 }
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005311 if (!ArraySize.get()) {
5312 // If no array size was specified, but the new expression was
5313 // instantiated with an array type (e.g., "new T" where T is
5314 // instantiated with "int[4]"), extract the outer bound from the
5315 // array type as our array size. We do this with constant and
5316 // dependently-sized array types.
5317 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5318 if (!ArrayT) {
5319 // Do nothing
5320 } else if (const ConstantArrayType *ConsArrayT
5321 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005322 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005323 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005325 SemaRef.Context.getSizeType(),
5326 /*FIXME:*/E->getLocStart()));
5327 AllocType = ConsArrayT->getElementType();
5328 } else if (const DependentSizedArrayType *DepArrayT
5329 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5330 if (DepArrayT->getSizeExpr()) {
5331 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5332 AllocType = DepArrayT->getElementType();
5333 }
5334 }
5335 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005336 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5337 E->isGlobalNew(),
5338 /*FIXME:*/E->getLocStart(),
5339 move_arg(PlacementArgs),
5340 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005341 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005342 AllocType,
5343 /*FIXME:*/E->getLocStart(),
5344 /*FIXME:*/SourceRange(),
John McCallb268a282010-08-23 23:25:46 +00005345 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005346 /*FIXME:*/E->getLocStart(),
5347 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005348 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005349}
Mike Stump11289f42009-09-09 15:08:12 +00005350
Douglas Gregora16548e2009-08-11 05:31:07 +00005351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005353TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005354 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 if (Operand.isInvalid())
5356 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005357
Douglas Gregord2d9da02010-02-26 00:38:10 +00005358 // Transform the delete operator, if known.
5359 FunctionDecl *OperatorDelete = 0;
5360 if (E->getOperatorDelete()) {
5361 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005362 getDerived().TransformDecl(E->getLocStart(),
5363 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005364 if (!OperatorDelete)
5365 return SemaRef.ExprError();
5366 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005367
Douglas Gregora16548e2009-08-11 05:31:07 +00005368 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005369 Operand.get() == E->getArgument() &&
5370 OperatorDelete == E->getOperatorDelete()) {
5371 // Mark any declarations we need as referenced.
5372 // FIXME: instantiation-specific.
5373 if (OperatorDelete)
5374 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005375 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005376 }
Mike Stump11289f42009-09-09 15:08:12 +00005377
Douglas Gregora16548e2009-08-11 05:31:07 +00005378 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5379 E->isGlobalDelete(),
5380 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005381 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005382}
Mike Stump11289f42009-09-09 15:08:12 +00005383
Douglas Gregora16548e2009-08-11 05:31:07 +00005384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005385ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005386TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005387 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005388 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005389 if (Base.isInvalid())
5390 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005391
John McCallba7bf592010-08-24 05:47:05 +00005392 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005393 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005394 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005395 E->getOperatorLoc(),
5396 E->isArrow()? tok::arrow : tok::period,
5397 ObjectTypePtr,
5398 MayBePseudoDestructor);
5399 if (Base.isInvalid())
5400 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005401
John McCallba7bf592010-08-24 05:47:05 +00005402 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005403 NestedNameSpecifier *Qualifier
5404 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005405 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005406 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005407 if (E->getQualifier() && !Qualifier)
5408 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005409
Douglas Gregor678f90d2010-02-25 01:56:36 +00005410 PseudoDestructorTypeStorage Destroyed;
5411 if (E->getDestroyedTypeInfo()) {
5412 TypeSourceInfo *DestroyedTypeInfo
5413 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5414 if (!DestroyedTypeInfo)
5415 return SemaRef.ExprError();
5416 Destroyed = DestroyedTypeInfo;
5417 } else if (ObjectType->isDependentType()) {
5418 // We aren't likely to be able to resolve the identifier down to a type
5419 // now anyway, so just retain the identifier.
5420 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5421 E->getDestroyedTypeLoc());
5422 } else {
5423 // Look for a destructor known with the given name.
5424 CXXScopeSpec SS;
5425 if (Qualifier) {
5426 SS.setScopeRep(Qualifier);
5427 SS.setRange(E->getQualifierRange());
5428 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005429
John McCallba7bf592010-08-24 05:47:05 +00005430 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005431 *E->getDestroyedTypeIdentifier(),
5432 E->getDestroyedTypeLoc(),
5433 /*Scope=*/0,
5434 SS, ObjectTypePtr,
5435 false);
5436 if (!T)
5437 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005438
Douglas Gregor678f90d2010-02-25 01:56:36 +00005439 Destroyed
5440 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5441 E->getDestroyedTypeLoc());
5442 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005443
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005444 TypeSourceInfo *ScopeTypeInfo = 0;
5445 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005446 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005447 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005448 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005449 return SemaRef.ExprError();
5450 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005451
John McCallb268a282010-08-23 23:25:46 +00005452 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005453 E->getOperatorLoc(),
5454 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005455 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005456 E->getQualifierRange(),
5457 ScopeTypeInfo,
5458 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005459 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005460 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005461}
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregorad8a3362009-09-04 17:36:40 +00005463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005464ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005465TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005466 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005467 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5468
5469 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5470 Sema::LookupOrdinaryName);
5471
5472 // Transform all the decls.
5473 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5474 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005475 NamedDecl *InstD = static_cast<NamedDecl*>(
5476 getDerived().TransformDecl(Old->getNameLoc(),
5477 *I));
John McCall84d87672009-12-10 09:41:52 +00005478 if (!InstD) {
5479 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5480 // This can happen because of dependent hiding.
5481 if (isa<UsingShadowDecl>(*I))
5482 continue;
5483 else
5484 return SemaRef.ExprError();
5485 }
John McCalle66edc12009-11-24 19:00:30 +00005486
5487 // Expand using declarations.
5488 if (isa<UsingDecl>(InstD)) {
5489 UsingDecl *UD = cast<UsingDecl>(InstD);
5490 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5491 E = UD->shadow_end(); I != E; ++I)
5492 R.addDecl(*I);
5493 continue;
5494 }
5495
5496 R.addDecl(InstD);
5497 }
5498
5499 // Resolve a kind, but don't do any further analysis. If it's
5500 // ambiguous, the callee needs to deal with it.
5501 R.resolveKind();
5502
5503 // Rebuild the nested-name qualifier, if present.
5504 CXXScopeSpec SS;
5505 NestedNameSpecifier *Qualifier = 0;
5506 if (Old->getQualifier()) {
5507 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005508 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005509 if (!Qualifier)
5510 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005511
John McCalle66edc12009-11-24 19:00:30 +00005512 SS.setScopeRep(Qualifier);
5513 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005514 }
5515
Douglas Gregor9262f472010-04-27 18:19:34 +00005516 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005517 CXXRecordDecl *NamingClass
5518 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5519 Old->getNameLoc(),
5520 Old->getNamingClass()));
5521 if (!NamingClass)
5522 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005523
Douglas Gregorda7be082010-04-27 16:10:10 +00005524 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005525 }
5526
5527 // If we have no template arguments, it's a normal declaration name.
5528 if (!Old->hasExplicitTemplateArgs())
5529 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5530
5531 // If we have template arguments, rebuild them, then rebuild the
5532 // templateid expression.
5533 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5534 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5535 TemplateArgumentLoc Loc;
5536 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5537 return SemaRef.ExprError();
5538 TransArgs.addArgument(Loc);
5539 }
5540
5541 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5542 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005543}
Mike Stump11289f42009-09-09 15:08:12 +00005544
Douglas Gregora16548e2009-08-11 05:31:07 +00005545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005547TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005549
Douglas Gregora16548e2009-08-11 05:31:07 +00005550 QualType T = getDerived().TransformType(E->getQueriedType());
5551 if (T.isNull())
5552 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 if (!getDerived().AlwaysRebuild() &&
5555 T == E->getQueriedType())
5556 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 // FIXME: Bad location information
5559 SourceLocation FakeLParenLoc
5560 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005561
5562 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005563 E->getLocStart(),
5564 /*FIXME:*/FakeLParenLoc,
5565 T,
5566 E->getLocEnd());
5567}
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregora16548e2009-08-11 05:31:07 +00005569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005570ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005571TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005572 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005574 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005575 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 if (!NNS)
5577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005578
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005579 DeclarationNameInfo NameInfo
5580 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5581 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005582 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005583
John McCalle66edc12009-11-24 19:00:30 +00005584 if (!E->hasExplicitTemplateArgs()) {
5585 if (!getDerived().AlwaysRebuild() &&
5586 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005587 // Note: it is sufficient to compare the Name component of NameInfo:
5588 // if name has not changed, DNLoc has not changed either.
5589 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005590 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005591
John McCalle66edc12009-11-24 19:00:30 +00005592 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5593 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005594 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005595 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005596 }
John McCall6b51f282009-11-23 01:53:49 +00005597
5598 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005600 TemplateArgumentLoc Loc;
5601 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005603 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 }
5605
John McCalle66edc12009-11-24 19:00:30 +00005606 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5607 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005608 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005609 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005610}
5611
5612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005614TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005615 // CXXConstructExprs are always implicit, so when we have a
5616 // 1-argument construction we just transform that argument.
5617 if (E->getNumArgs() == 1 ||
5618 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5619 return getDerived().TransformExpr(E->getArg(0));
5620
Douglas Gregora16548e2009-08-11 05:31:07 +00005621 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5622
5623 QualType T = getDerived().TransformType(E->getType());
5624 if (T.isNull())
5625 return SemaRef.ExprError();
5626
5627 CXXConstructorDecl *Constructor
5628 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005629 getDerived().TransformDecl(E->getLocStart(),
5630 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 if (!Constructor)
5632 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005635 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005636 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 ArgEnd = E->arg_end();
5638 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005639 if (getDerived().DropCallArgument(*Arg)) {
5640 ArgumentChanged = true;
5641 break;
5642 }
5643
John McCalldadc5752010-08-24 06:29:42 +00005644 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005645 if (TransArg.isInvalid())
5646 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005647
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005649 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 }
5651
5652 if (!getDerived().AlwaysRebuild() &&
5653 T == E->getType() &&
5654 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005655 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005656 // Mark the constructor as referenced.
5657 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005658 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005660 }
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregordb121ba2009-12-14 16:27:04 +00005662 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5663 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005664 move_arg(Args),
5665 E->requiresZeroInitialization(),
5666 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005667}
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669/// \brief Transform a C++ temporary-binding expression.
5670///
Douglas Gregor363b1512009-12-24 18:51:59 +00005671/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5672/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005675TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005676 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005677}
Mike Stump11289f42009-09-09 15:08:12 +00005678
Anders Carlssonba6c4372010-01-29 02:39:32 +00005679/// \brief Transform a C++ reference-binding expression.
5680///
5681/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5682/// transform the subexpression and return that.
5683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005684ExprResult
Anders Carlssonba6c4372010-01-29 02:39:32 +00005685TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5686 return getDerived().TransformExpr(E->getSubExpr());
5687}
5688
Mike Stump11289f42009-09-09 15:08:12 +00005689/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005690/// be destroyed after the expression is evaluated.
5691///
Douglas Gregor363b1512009-12-24 18:51:59 +00005692/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5693/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005695ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005696TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005697 CXXExprWithTemporaries *E) {
5698 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005699}
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005702ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005703TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005704 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5706 QualType T = getDerived().TransformType(E->getType());
5707 if (T.isNull())
5708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 CXXConstructorDecl *Constructor
5711 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005712 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005713 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 if (!Constructor)
5715 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregora16548e2009-08-11 05:31:07 +00005717 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005718 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005720 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 ArgEnd = E->arg_end();
5722 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005723 if (getDerived().DropCallArgument(*Arg)) {
5724 ArgumentChanged = true;
5725 break;
5726 }
5727
John McCalldadc5752010-08-24 06:29:42 +00005728 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005729 if (TransArg.isInvalid())
5730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5733 Args.push_back((Expr *)TransArg.release());
5734 }
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 if (!getDerived().AlwaysRebuild() &&
5737 T == E->getType() &&
5738 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005739 !ArgumentChanged) {
5740 // FIXME: Instantiation-specific
5741 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005742 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005743 }
Mike Stump11289f42009-09-09 15:08:12 +00005744
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 // FIXME: Bogus location information
5746 SourceLocation CommaLoc;
5747 if (Args.size() > 1) {
5748 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005749 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5751 }
5752 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5753 T,
5754 /*FIXME:*/E->getTypeBeginLoc(),
5755 move_arg(Args),
5756 &CommaLoc,
5757 E->getLocEnd());
5758}
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005761ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005762TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005763 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5765 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5766 if (T.isNull())
5767 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005770 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005771 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5772 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5773 ArgEnd = E->arg_end();
5774 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005775 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 if (TransArg.isInvalid())
5777 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005778
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5780 FakeCommaLocs.push_back(
5781 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
John McCallb268a282010-08-23 23:25:46 +00005782 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 }
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 if (!getDerived().AlwaysRebuild() &&
5786 T == E->getTypeAsWritten() &&
5787 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005788 return SemaRef.Owned(E->Retain());
5789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 // FIXME: we're faking the locations of the commas
5791 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5792 T,
5793 E->getLParenLoc(),
5794 move_arg(Args),
5795 FakeCommaLocs.data(),
5796 E->getRParenLoc());
5797}
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregora16548e2009-08-11 05:31:07 +00005799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005800ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005801TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005802 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005804 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005805 Expr *OldBase;
5806 QualType BaseType;
5807 QualType ObjectType;
5808 if (!E->isImplicitAccess()) {
5809 OldBase = E->getBase();
5810 Base = getDerived().TransformExpr(OldBase);
5811 if (Base.isInvalid())
5812 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005813
John McCall2d74de92009-12-01 22:10:20 +00005814 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005815 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005816 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005817 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005818 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005819 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005820 ObjectTy,
5821 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005822 if (Base.isInvalid())
5823 return SemaRef.ExprError();
5824
John McCallba7bf592010-08-24 05:47:05 +00005825 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005826 BaseType = ((Expr*) Base.get())->getType();
5827 } else {
5828 OldBase = 0;
5829 BaseType = getDerived().TransformType(E->getBaseType());
5830 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5831 }
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005833 // Transform the first part of the nested-name-specifier that qualifies
5834 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005835 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005836 = getDerived().TransformFirstQualifierInScope(
5837 E->getFirstQualifierFoundInScope(),
5838 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005840 NestedNameSpecifier *Qualifier = 0;
5841 if (E->getQualifier()) {
5842 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5843 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005844 ObjectType,
5845 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005846 if (!Qualifier)
5847 return SemaRef.ExprError();
5848 }
Mike Stump11289f42009-09-09 15:08:12 +00005849
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005850 DeclarationNameInfo NameInfo
5851 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5852 ObjectType);
5853 if (!NameInfo.getName())
Douglas Gregorf816bd72009-09-03 22:13:48 +00005854 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005855
John McCall2d74de92009-12-01 22:10:20 +00005856 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005857 // This is a reference to a member without an explicitly-specified
5858 // template argument list. Optimize for this common case.
5859 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005860 Base.get() == OldBase &&
5861 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005862 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005863 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005864 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005865 return SemaRef.Owned(E->Retain());
5866
John McCallb268a282010-08-23 23:25:46 +00005867 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005868 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005869 E->isArrow(),
5870 E->getOperatorLoc(),
5871 Qualifier,
5872 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005873 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005874 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005875 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005876 }
5877
John McCall6b51f282009-11-23 01:53:49 +00005878 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005879 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005880 TemplateArgumentLoc Loc;
5881 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005882 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005883 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005884 }
Mike Stump11289f42009-09-09 15:08:12 +00005885
John McCallb268a282010-08-23 23:25:46 +00005886 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005887 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005888 E->isArrow(),
5889 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005890 Qualifier,
5891 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005892 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005893 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005894 &TransArgs);
5895}
5896
5897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005899TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005900 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005901 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005902 QualType BaseType;
5903 if (!Old->isImplicitAccess()) {
5904 Base = getDerived().TransformExpr(Old->getBase());
5905 if (Base.isInvalid())
5906 return SemaRef.ExprError();
5907 BaseType = ((Expr*) Base.get())->getType();
5908 } else {
5909 BaseType = getDerived().TransformType(Old->getBaseType());
5910 }
John McCall10eae182009-11-30 22:42:35 +00005911
5912 NestedNameSpecifier *Qualifier = 0;
5913 if (Old->getQualifier()) {
5914 Qualifier
5915 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005916 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005917 if (Qualifier == 0)
5918 return SemaRef.ExprError();
5919 }
5920
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005921 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005922 Sema::LookupOrdinaryName);
5923
5924 // Transform all the decls.
5925 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5926 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005927 NamedDecl *InstD = static_cast<NamedDecl*>(
5928 getDerived().TransformDecl(Old->getMemberLoc(),
5929 *I));
John McCall84d87672009-12-10 09:41:52 +00005930 if (!InstD) {
5931 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5932 // This can happen because of dependent hiding.
5933 if (isa<UsingShadowDecl>(*I))
5934 continue;
5935 else
5936 return SemaRef.ExprError();
5937 }
John McCall10eae182009-11-30 22:42:35 +00005938
5939 // Expand using declarations.
5940 if (isa<UsingDecl>(InstD)) {
5941 UsingDecl *UD = cast<UsingDecl>(InstD);
5942 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5943 E = UD->shadow_end(); I != E; ++I)
5944 R.addDecl(*I);
5945 continue;
5946 }
5947
5948 R.addDecl(InstD);
5949 }
5950
5951 R.resolveKind();
5952
Douglas Gregor9262f472010-04-27 18:19:34 +00005953 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005954 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005955 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005956 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005957 Old->getMemberLoc(),
5958 Old->getNamingClass()));
5959 if (!NamingClass)
5960 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005961
Douglas Gregorda7be082010-04-27 16:10:10 +00005962 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005963 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005964
John McCall10eae182009-11-30 22:42:35 +00005965 TemplateArgumentListInfo TransArgs;
5966 if (Old->hasExplicitTemplateArgs()) {
5967 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5968 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5969 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5970 TemplateArgumentLoc Loc;
5971 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5972 Loc))
5973 return SemaRef.ExprError();
5974 TransArgs.addArgument(Loc);
5975 }
5976 }
John McCall38836f02010-01-15 08:34:02 +00005977
5978 // FIXME: to do this check properly, we will need to preserve the
5979 // first-qualifier-in-scope here, just in case we had a dependent
5980 // base (and therefore couldn't do the check) and a
5981 // nested-name-qualifier (and therefore could do the lookup).
5982 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005983
John McCallb268a282010-08-23 23:25:46 +00005984 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005985 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005986 Old->getOperatorLoc(),
5987 Old->isArrow(),
5988 Qualifier,
5989 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005990 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005991 R,
5992 (Old->hasExplicitTemplateArgs()
5993 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005994}
5995
5996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005997ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005998TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005999 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006000}
6001
Mike Stump11289f42009-09-09 15:08:12 +00006002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006003ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006004TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006005 TypeSourceInfo *EncodedTypeInfo
6006 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6007 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006011 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006012 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006013
6014 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006015 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 E->getRParenLoc());
6017}
Mike Stump11289f42009-09-09 15:08:12 +00006018
Douglas Gregora16548e2009-08-11 05:31:07 +00006019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006021TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006022 // Transform arguments.
6023 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006024 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006025 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006026 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006027 if (Arg.isInvalid())
6028 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006029
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006030 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006031 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006032 }
6033
6034 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6035 // Class message: transform the receiver type.
6036 TypeSourceInfo *ReceiverTypeInfo
6037 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6038 if (!ReceiverTypeInfo)
6039 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006040
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006041 // If nothing changed, just retain the existing message send.
6042 if (!getDerived().AlwaysRebuild() &&
6043 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6044 return SemaRef.Owned(E->Retain());
6045
6046 // Build a new class message send.
6047 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6048 E->getSelector(),
6049 E->getMethodDecl(),
6050 E->getLeftLoc(),
6051 move_arg(Args),
6052 E->getRightLoc());
6053 }
6054
6055 // Instance message: transform the receiver
6056 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6057 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006058 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006059 = getDerived().TransformExpr(E->getInstanceReceiver());
6060 if (Receiver.isInvalid())
6061 return SemaRef.ExprError();
6062
6063 // If nothing changed, just retain the existing message send.
6064 if (!getDerived().AlwaysRebuild() &&
6065 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6066 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006067
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006068 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006069 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006070 E->getSelector(),
6071 E->getMethodDecl(),
6072 E->getLeftLoc(),
6073 move_arg(Args),
6074 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006075}
6076
Mike Stump11289f42009-09-09 15:08:12 +00006077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006080 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006081}
6082
Mike Stump11289f42009-09-09 15:08:12 +00006083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006085TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006086 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006087}
6088
Mike Stump11289f42009-09-09 15:08:12 +00006089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006092 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006093 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006094 if (Base.isInvalid())
6095 return SemaRef.ExprError();
6096
6097 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006098
Douglas Gregord51d90d2010-04-26 20:11:03 +00006099 // If nothing changed, just retain the existing expression.
6100 if (!getDerived().AlwaysRebuild() &&
6101 Base.get() == E->getBase())
6102 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006103
John McCallb268a282010-08-23 23:25:46 +00006104 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006105 E->getLocation(),
6106 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006107}
6108
Mike Stump11289f42009-09-09 15:08:12 +00006109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006110ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006112 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006113 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006114 if (Base.isInvalid())
6115 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006116
Douglas Gregor9faee212010-04-26 20:47:02 +00006117 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006118
Douglas Gregor9faee212010-04-26 20:47:02 +00006119 // If nothing changed, just retain the existing expression.
6120 if (!getDerived().AlwaysRebuild() &&
6121 Base.get() == E->getBase())
6122 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006123
John McCallb268a282010-08-23 23:25:46 +00006124 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006125 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006126}
6127
Mike Stump11289f42009-09-09 15:08:12 +00006128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006129ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006130TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006131 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006132 // If this implicit setter/getter refers to class methods, it cannot have any
6133 // dependent parts. Just retain the existing declaration.
6134 if (E->getInterfaceDecl())
6135 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006136
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006137 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006138 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006139 if (Base.isInvalid())
6140 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006141
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006142 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006143
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006144 // If nothing changed, just retain the existing expression.
6145 if (!getDerived().AlwaysRebuild() &&
6146 Base.get() == E->getBase())
6147 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006148
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006149 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6150 E->getGetterMethod(),
6151 E->getType(),
6152 E->getSetterMethod(),
6153 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006154 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006155
Douglas Gregora16548e2009-08-11 05:31:07 +00006156}
6157
Mike Stump11289f42009-09-09 15:08:12 +00006158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006160TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006161 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006162 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006163}
6164
Mike Stump11289f42009-09-09 15:08:12 +00006165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006167TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006168 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006169 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006170 if (Base.isInvalid())
6171 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006172
Douglas Gregord51d90d2010-04-26 20:11:03 +00006173 // If nothing changed, just retain the existing expression.
6174 if (!getDerived().AlwaysRebuild() &&
6175 Base.get() == E->getBase())
6176 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006177
John McCallb268a282010-08-23 23:25:46 +00006178 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006179 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006180}
6181
Mike Stump11289f42009-09-09 15:08:12 +00006182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006184TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006185 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006186 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006188 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 if (SubExpr.isInvalid())
6190 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006191
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006193 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 }
Mike Stump11289f42009-09-09 15:08:12 +00006195
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 if (!getDerived().AlwaysRebuild() &&
6197 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006198 return SemaRef.Owned(E->Retain());
6199
Douglas Gregora16548e2009-08-11 05:31:07 +00006200 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6201 move_arg(SubExprs),
6202 E->getRParenLoc());
6203}
6204
Mike Stump11289f42009-09-09 15:08:12 +00006205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006207TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006208 SourceLocation CaretLoc(E->getExprLoc());
6209
6210 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6211 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6212 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6213 llvm::SmallVector<ParmVarDecl*, 4> Params;
6214 llvm::SmallVector<QualType, 4> ParamTypes;
6215
6216 // Parameter substitution.
6217 const BlockDecl *BD = E->getBlockDecl();
6218 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6219 EN = BD->param_end(); P != EN; ++P) {
6220 ParmVarDecl *OldParm = (*P);
6221 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6222 QualType NewType = NewParm->getType();
6223 Params.push_back(NewParm);
6224 ParamTypes.push_back(NewParm->getType());
6225 }
6226
6227 const FunctionType *BExprFunctionType = E->getFunctionType();
6228 QualType BExprResultType = BExprFunctionType->getResultType();
6229 if (!BExprResultType.isNull()) {
6230 if (!BExprResultType->isDependentType())
6231 CurBlock->ReturnType = BExprResultType;
6232 else if (BExprResultType != SemaRef.Context.DependentTy)
6233 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6234 }
6235
6236 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006237 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006238 if (Body.isInvalid())
6239 return SemaRef.ExprError();
6240 // Set the parameters on the block decl.
6241 if (!Params.empty())
6242 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6243
6244 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6245 CurBlock->ReturnType,
6246 ParamTypes.data(),
6247 ParamTypes.size(),
6248 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006249 0,
6250 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006251
6252 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006253 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006254}
6255
Mike Stump11289f42009-09-09 15:08:12 +00006256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006258TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006259 NestedNameSpecifier *Qualifier = 0;
6260
6261 ValueDecl *ND
6262 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6263 E->getDecl()));
6264 if (!ND)
6265 return SemaRef.ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006266
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006267 if (!getDerived().AlwaysRebuild() &&
6268 ND == E->getDecl()) {
6269 // Mark it referenced in the new context regardless.
6270 // FIXME: this is a bit instantiation-specific.
6271 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6272
6273 return SemaRef.Owned(E->Retain());
6274 }
6275
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006276 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006277 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006278 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006279}
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006282// Type reconstruction
6283//===----------------------------------------------------------------------===//
6284
Mike Stump11289f42009-09-09 15:08:12 +00006285template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006286QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6287 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006288 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006289 getDerived().getBaseEntity());
6290}
6291
Mike Stump11289f42009-09-09 15:08:12 +00006292template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006293QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6294 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006295 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006296 getDerived().getBaseEntity());
6297}
6298
Mike Stump11289f42009-09-09 15:08:12 +00006299template<typename Derived>
6300QualType
John McCall70dd5f62009-10-30 00:06:24 +00006301TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6302 bool WrittenAsLValue,
6303 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006304 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006305 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006306}
6307
6308template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006309QualType
John McCall70dd5f62009-10-30 00:06:24 +00006310TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6311 QualType ClassType,
6312 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006313 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006314 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006315}
6316
6317template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006318QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006319TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6320 ArrayType::ArraySizeModifier SizeMod,
6321 const llvm::APInt *Size,
6322 Expr *SizeExpr,
6323 unsigned IndexTypeQuals,
6324 SourceRange BracketsRange) {
6325 if (SizeExpr || !Size)
6326 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6327 IndexTypeQuals, BracketsRange,
6328 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006329
6330 QualType Types[] = {
6331 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6332 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6333 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006334 };
6335 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6336 QualType SizeType;
6337 for (unsigned I = 0; I != NumTypes; ++I)
6338 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6339 SizeType = Types[I];
6340 break;
6341 }
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregord6ff3322009-08-04 16:50:30 +00006343 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006344 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006345 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006346 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347}
Mike Stump11289f42009-09-09 15:08:12 +00006348
Douglas Gregord6ff3322009-08-04 16:50:30 +00006349template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006350QualType
6351TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006352 ArrayType::ArraySizeModifier SizeMod,
6353 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006354 unsigned IndexTypeQuals,
6355 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006356 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006357 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006358}
6359
6360template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006361QualType
Mike Stump11289f42009-09-09 15:08:12 +00006362TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006363 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006364 unsigned IndexTypeQuals,
6365 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006366 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006367 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006368}
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006371QualType
6372TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006373 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006374 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375 unsigned IndexTypeQuals,
6376 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006377 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006378 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006379 IndexTypeQuals, BracketsRange);
6380}
6381
6382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006383QualType
6384TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006385 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006386 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006387 unsigned IndexTypeQuals,
6388 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006389 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006390 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 IndexTypeQuals, BracketsRange);
6392}
6393
6394template<typename Derived>
6395QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006396 unsigned NumElements,
6397 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006399 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006400}
Mike Stump11289f42009-09-09 15:08:12 +00006401
Douglas Gregord6ff3322009-08-04 16:50:30 +00006402template<typename Derived>
6403QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6404 unsigned NumElements,
6405 SourceLocation AttributeLoc) {
6406 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6407 NumElements, true);
6408 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006409 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006411 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006415QualType
6416TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006417 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006418 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006419 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregord6ff3322009-08-04 16:50:30 +00006422template<typename Derived>
6423QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006424 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006425 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006426 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006427 unsigned Quals,
6428 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006429 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006430 Quals,
6431 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006432 getDerived().getBaseEntity(),
6433 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434}
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006437QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6438 return SemaRef.Context.getFunctionNoProtoType(T);
6439}
6440
6441template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006442QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6443 assert(D && "no decl found");
6444 if (D->isInvalidDecl()) return QualType();
6445
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006446 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006447 TypeDecl *Ty;
6448 if (isa<UsingDecl>(D)) {
6449 UsingDecl *Using = cast<UsingDecl>(D);
6450 assert(Using->isTypeName() &&
6451 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6452
6453 // A valid resolved using typename decl points to exactly one type decl.
6454 assert(++Using->shadow_begin() == Using->shadow_end());
6455 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006456
John McCallb96ec562009-12-04 22:46:56 +00006457 } else {
6458 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6459 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6460 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6461 }
6462
6463 return SemaRef.Context.getTypeDeclType(Ty);
6464}
6465
6466template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006467QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6468 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006469}
6470
6471template<typename Derived>
6472QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6473 return SemaRef.Context.getTypeOfType(Underlying);
6474}
6475
6476template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006477QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6478 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006479}
6480
6481template<typename Derived>
6482QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006483 TemplateName Template,
6484 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006485 const TemplateArgumentListInfo &TemplateArgs) {
6486 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006487}
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregor1135c352009-08-06 05:28:30 +00006489template<typename Derived>
6490NestedNameSpecifier *
6491TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6492 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006493 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006494 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006495 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006496 CXXScopeSpec SS;
6497 // FIXME: The source location information is all wrong.
6498 SS.setRange(Range);
6499 SS.setScopeRep(Prefix);
6500 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006501 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006502 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006503 ObjectType,
6504 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006505 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006506}
6507
6508template<typename Derived>
6509NestedNameSpecifier *
6510TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6511 SourceRange Range,
6512 NamespaceDecl *NS) {
6513 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6514}
6515
6516template<typename Derived>
6517NestedNameSpecifier *
6518TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6519 SourceRange Range,
6520 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006521 QualType T) {
6522 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006523 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006524 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006525 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6526 T.getTypePtr());
6527 }
Mike Stump11289f42009-09-09 15:08:12 +00006528
Douglas Gregor1135c352009-08-06 05:28:30 +00006529 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6530 return 0;
6531}
Mike Stump11289f42009-09-09 15:08:12 +00006532
Douglas Gregor71dc5092009-08-06 06:41:21 +00006533template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006534TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006535TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6536 bool TemplateKW,
6537 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006538 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006539 Template);
6540}
6541
6542template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006543TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006544TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006545 const IdentifierInfo &II,
6546 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006547 CXXScopeSpec SS;
6548 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006549 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006550 UnqualifiedId Name;
6551 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006552 Sema::TemplateTy Template;
6553 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6554 /*FIXME:*/getDerived().getBaseLocation(),
6555 SS,
6556 Name,
John McCallba7bf592010-08-24 05:47:05 +00006557 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006558 /*EnteringContext=*/false,
6559 Template);
6560 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006561}
Mike Stump11289f42009-09-09 15:08:12 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006564TemplateName
6565TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6566 OverloadedOperatorKind Operator,
6567 QualType ObjectType) {
6568 CXXScopeSpec SS;
6569 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6570 SS.setScopeRep(Qualifier);
6571 UnqualifiedId Name;
6572 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6573 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6574 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006575 Sema::TemplateTy Template;
6576 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006577 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006578 SS,
6579 Name,
John McCallba7bf592010-08-24 05:47:05 +00006580 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006581 /*EnteringContext=*/false,
6582 Template);
6583 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006584}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006585
Douglas Gregor71395fa2009-11-04 00:56:37 +00006586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006587ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006588TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6589 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006590 Expr *OrigCallee,
6591 Expr *First,
6592 Expr *Second) {
6593 Expr *Callee = OrigCallee->IgnoreParenCasts();
6594 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006595
Douglas Gregora16548e2009-08-11 05:31:07 +00006596 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006597 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006598 if (!First->getType()->isOverloadableType() &&
6599 !Second->getType()->isOverloadableType())
6600 return getSema().CreateBuiltinArraySubscriptExpr(First,
6601 Callee->getLocStart(),
6602 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006603 } else if (Op == OO_Arrow) {
6604 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006605 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6606 } else if (Second == 0 || isPostIncDec) {
6607 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006608 // The argument is not of overloadable type, so try to create a
6609 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006610 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006612
John McCallb268a282010-08-23 23:25:46 +00006613 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006614 }
6615 } else {
John McCallb268a282010-08-23 23:25:46 +00006616 if (!First->getType()->isOverloadableType() &&
6617 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006618 // Neither of the arguments is an overloadable type, so try to
6619 // create a built-in binary operation.
6620 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006621 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006622 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 if (Result.isInvalid())
6624 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 return move(Result);
6627 }
6628 }
Mike Stump11289f42009-09-09 15:08:12 +00006629
6630 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006631 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006632 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006633
John McCallb268a282010-08-23 23:25:46 +00006634 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006635 assert(ULE->requiresADL());
6636
6637 // FIXME: Do we have to check
6638 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006639 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006640 } else {
John McCallb268a282010-08-23 23:25:46 +00006641 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006642 }
Mike Stump11289f42009-09-09 15:08:12 +00006643
Douglas Gregora16548e2009-08-11 05:31:07 +00006644 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006645 Expr *Args[2] = { First, Second };
6646 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006647
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 // Create the overloaded operator invocation for unary operators.
6649 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006650 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006651 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006652 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 }
Mike Stump11289f42009-09-09 15:08:12 +00006654
Sebastian Redladba46e2009-10-29 20:17:01 +00006655 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006656 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006657 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006658 First,
6659 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006660
Douglas Gregora16548e2009-08-11 05:31:07 +00006661 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006662 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006664 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6666 if (Result.isInvalid())
6667 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006668
Mike Stump11289f42009-09-09 15:08:12 +00006669 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006670}
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006673ExprResult
John McCallb268a282010-08-23 23:25:46 +00006674TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006675 SourceLocation OperatorLoc,
6676 bool isArrow,
6677 NestedNameSpecifier *Qualifier,
6678 SourceRange QualifierRange,
6679 TypeSourceInfo *ScopeType,
6680 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006681 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006682 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006683 CXXScopeSpec SS;
6684 if (Qualifier) {
6685 SS.setRange(QualifierRange);
6686 SS.setScopeRep(Qualifier);
6687 }
6688
John McCallb268a282010-08-23 23:25:46 +00006689 QualType BaseType = Base->getType();
6690 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006691 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006692 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006693 !BaseType->getAs<PointerType>()->getPointeeType()
6694 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006695 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006696 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006697 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006698 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006699 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006700 /*FIXME?*/true);
6701 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006702
Douglas Gregor678f90d2010-02-25 01:56:36 +00006703 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006704 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6705 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6706 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6707 NameInfo.setNamedTypeInfo(DestroyedType);
6708
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006709 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006710
John McCallb268a282010-08-23 23:25:46 +00006711 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006712 OperatorLoc, isArrow,
6713 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006714 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006715 /*TemplateArgs*/ 0);
6716}
6717
Douglas Gregord6ff3322009-08-04 16:50:30 +00006718} // end namespace clang
6719
6720#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H