blob: f85d85338043d5105eaa89845ba0b232602d617b [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
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000019#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000020#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000021#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000028#include "clang/AST/TypeLocBuilder.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000033#include <algorithm>
34
35namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000036using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000037
Douglas Gregord6ff3322009-08-04 16:50:30 +000038/// \brief A semantic tree transformation that allows one to transform one
39/// abstract syntax tree into another.
40///
Mike Stump11289f42009-09-09 15:08:12 +000041/// A new tree transformation is defined by creating a new subclass \c X of
42/// \c TreeTransform<X> and then overriding certain operations to provide
43/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// instantiation is implemented as a tree transformation where the
45/// transformation of TemplateTypeParmType nodes involves substituting the
46/// template arguments for their corresponding template parameters; a similar
47/// transformation is performed for non-type template parameters and
48/// template template parameters.
49///
50/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000051/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000052/// override any of the transformation or rebuild operators by providing an
53/// operation with the same signature as the default implementation. The
54/// overridding function should not be virtual.
55///
56/// Semantic tree transformations are split into two stages, either of which
57/// can be replaced by a subclass. The "transform" step transforms an AST node
58/// or the parts of an AST node using the various transformation functions,
59/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60/// node of the appropriate kind from the pieces. The default transformation
61/// routines recursively transform the operands to composite AST nodes (e.g.,
62/// the pointee type of a PointerType node) and, if any of those operand nodes
63/// were changed by the transformation, invokes the rebuild operation to create
64/// a new AST node.
65///
Mike Stump11289f42009-09-09 15:08:12 +000066/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000067/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000068/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70/// new implementations.
71///
72/// For more fine-grained transformations, subclasses can replace any of the
73/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000074/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000076/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// parameters. Additionally, subclasses can override the \c RebuildXXX
78/// functions to control how AST nodes are rebuilt when their operands change.
79/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81/// be able to use more efficient rebuild steps.
82///
83/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000084/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000085/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86/// operands have not changed (\c AlwaysRebuild()), and customize the
87/// default locations and entity names used for type-checking
88/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000089template<typename Derived>
90class TreeTransform {
91protected:
92 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000093
94public:
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,
Douglas Gregora5614c52010-09-08 23:56:00 +0000537 NestedNameSpecifier *Qualifier,
538 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000545 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
546 QualType());
John McCallc392f372010-06-11 00:33:02 +0000547
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000548 if (InstName.isNull())
549 return QualType();
550
John McCallc392f372010-06-11 00:33:02 +0000551 // If it's still dependent, make a dependent specialization.
552 if (InstName.getAsDependentTemplateName())
553 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000554 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000555
556 // Otherwise, make an elaborated type wrapping a non-dependent
557 // specialization.
558 QualType T =
559 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
560 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000561
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000562 // NOTE: NNS is already recorded in template specialization type T.
563 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000564 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
566 /// \brief Build a new typename type that refers to an identifier.
567 ///
568 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000571 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000572 NestedNameSpecifier *NNS,
573 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000574 SourceLocation KeywordLoc,
575 SourceRange NNSRange,
576 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000577 CXXScopeSpec SS;
578 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000579 SS.setRange(NNSRange);
580
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 if (NNS->isDependent()) {
582 // If the name is still dependent, just build a new dependent name type.
583 if (!SemaRef.computeDeclContext(SS))
584 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 }
586
Abramo Bagnara6150c882010-05-11 21:36:43 +0000587 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000588 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
589 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000590
591 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
592
Abramo Bagnarad7548482010-05-19 21:37:53 +0000593 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000594 // into a non-dependent elaborated-type-specifier. Find the tag we're
595 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000596 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000597 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
598 if (!DC)
599 return QualType();
600
John McCallbf8c5192010-05-27 06:40:31 +0000601 if (SemaRef.RequireCompleteDeclContext(SS, DC))
602 return QualType();
603
Douglas Gregore677daf2010-03-31 22:19:08 +0000604 TagDecl *Tag = 0;
605 SemaRef.LookupQualifiedName(Result, DC);
606 switch (Result.getResultKind()) {
607 case LookupResult::NotFound:
608 case LookupResult::NotFoundInCurrentInstantiation:
609 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000610
Douglas Gregore677daf2010-03-31 22:19:08 +0000611 case LookupResult::Found:
612 Tag = Result.getAsSingle<TagDecl>();
613 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000614
Douglas Gregore677daf2010-03-31 22:19:08 +0000615 case LookupResult::FoundOverloaded:
616 case LookupResult::FoundUnresolvedValue:
617 llvm_unreachable("Tag lookup cannot find non-tags");
618 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000619
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 case LookupResult::Ambiguous:
621 // Let the LookupResult structure handle ambiguities.
622 return QualType();
623 }
624
625 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000627 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000628 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000629 return QualType();
630 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000631
Abramo Bagnarad7548482010-05-19 21:37:53 +0000632 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
633 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000634 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
635 return QualType();
636 }
637
638 // Build the elaborated-type-specifier type.
639 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000640 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 }
Mike Stump11289f42009-09-09 15:08:12 +0000642
Douglas Gregor1135c352009-08-06 05:28:30 +0000643 /// \brief Build a new nested-name-specifier given the prefix and an
644 /// identifier that names the next step in the nested-name-specifier.
645 ///
646 /// By default, performs semantic analysis when building the new
647 /// nested-name-specifier. Subclasses may override this routine to provide
648 /// different behavior.
649 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
650 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000651 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000652 QualType ObjectType,
653 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000654
655 /// \brief Build a new nested-name-specifier given the prefix and the
656 /// namespace named in the next step in the nested-name-specifier.
657 ///
658 /// By default, performs semantic analysis when building the new
659 /// nested-name-specifier. Subclasses may override this routine to provide
660 /// different behavior.
661 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
662 SourceRange Range,
663 NamespaceDecl *NS);
664
665 /// \brief Build a new nested-name-specifier given the prefix and the
666 /// type named in the next step in the nested-name-specifier.
667 ///
668 /// By default, performs semantic analysis when building the new
669 /// nested-name-specifier. Subclasses may override this routine to provide
670 /// different behavior.
671 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
672 SourceRange Range,
673 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000674 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000675
676 /// \brief Build a new template name given a nested name specifier, a flag
677 /// indicating whether the "template" keyword was provided, and the template
678 /// that the template name refers to.
679 ///
680 /// By default, builds the new template name directly. Subclasses may override
681 /// this routine to provide different behavior.
682 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
683 bool TemplateKW,
684 TemplateDecl *Template);
685
Douglas Gregor71dc5092009-08-06 06:41:21 +0000686 /// \brief Build a new template name given a nested name specifier and the
687 /// name that is referred to as a template.
688 ///
689 /// By default, performs semantic analysis to determine whether the name can
690 /// be resolved to a specific template, then builds the appropriate kind of
691 /// template name. Subclasses may override this routine to provide different
692 /// behavior.
693 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000694 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000695 const IdentifierInfo &II,
696 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000697
Douglas Gregor71395fa2009-11-04 00:56:37 +0000698 /// \brief Build a new template name given a nested name specifier and the
699 /// overloaded operator name that is referred to as a template.
700 ///
701 /// By default, performs semantic analysis to determine whether the name can
702 /// be resolved to a specific template, then builds the appropriate kind of
703 /// template name. Subclasses may override this routine to provide different
704 /// behavior.
705 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
706 OverloadedOperatorKind Operator,
707 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000708
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 /// \brief Build a new compound statement.
710 ///
711 /// By default, performs semantic analysis to build the new statement.
712 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000713 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000714 MultiStmtArg Statements,
715 SourceLocation RBraceLoc,
716 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000717 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 IsStmtExpr);
719 }
720
721 /// \brief Build a new case statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000725 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000726 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000728 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000730 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 ColonLoc);
732 }
Mike Stump11289f42009-09-09 15:08:12 +0000733
Douglas Gregorebe10102009-08-20 07:17:43 +0000734 /// \brief Attach the body to a new case statement.
735 ///
736 /// By default, performs semantic analysis to build the new statement.
737 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000738 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000739 getSema().ActOnCaseStmtBody(S, Body);
740 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 }
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /// \brief Build a new default statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000747 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000749 Stmt *SubStmt) {
750 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 /*CurScope=*/0);
752 }
Mike Stump11289f42009-09-09 15:08:12 +0000753
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 /// \brief Build a new label statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000758 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 IdentifierInfo *Id,
760 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000761 Stmt *SubStmt) {
762 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Build a new "if" statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000769 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000770 VarDecl *CondVar, Stmt *Then,
771 SourceLocation ElseLoc, Stmt *Else) {
772 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 }
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 /// \brief Start building a new switch statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000779 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000780 Expr *Cond, VarDecl *CondVar) {
781 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000782 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 }
Mike Stump11289f42009-09-09 15:08:12 +0000784
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 /// \brief Attach the body to the switch statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000789 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000790 Stmt *Switch, Stmt *Body) {
791 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000792 }
793
794 /// \brief Build a new while statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000798 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000799 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000800 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000801 Stmt *Body) {
802 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000803 }
Mike Stump11289f42009-09-09 15:08:12 +0000804
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 /// \brief Build a new do-while statement.
806 ///
807 /// By default, performs semantic analysis to build the new statement.
808 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000809 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 SourceLocation WhileLoc,
811 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000812 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000814 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
815 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 }
817
818 /// \brief Build a new for statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000822 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000823 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000824 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000825 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000826 SourceLocation RParenLoc, Stmt *Body) {
827 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000828 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000829 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 }
Mike Stump11289f42009-09-09 15:08:12 +0000831
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 /// \brief Build a new goto statement.
833 ///
834 /// By default, performs semantic analysis to build the new statement.
835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000836 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000837 SourceLocation LabelLoc,
838 LabelStmt *Label) {
839 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
840 }
841
842 /// \brief Build a new indirect goto statement.
843 ///
844 /// By default, performs semantic analysis to build the new statement.
845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000846 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000848 Expr *Target) {
849 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 }
Mike Stump11289f42009-09-09 15:08:12 +0000851
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 /// \brief Build a new return statement.
853 ///
854 /// By default, performs semantic analysis to build the new statement.
855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000856 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000857 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000858
John McCallb268a282010-08-23 23:25:46 +0000859 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000860 }
Mike Stump11289f42009-09-09 15:08:12 +0000861
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 /// \brief Build a new declaration statement.
863 ///
864 /// By default, performs semantic analysis to build the new statement.
865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000866 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000867 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000868 SourceLocation EndLoc) {
869 return getSema().Owned(
870 new (getSema().Context) DeclStmt(
871 DeclGroupRef::Create(getSema().Context,
872 Decls, NumDecls),
873 StartLoc, EndLoc));
874 }
Mike Stump11289f42009-09-09 15:08:12 +0000875
Anders Carlssonaaeef072010-01-24 05:50:09 +0000876 /// \brief Build a new inline asm statement.
877 ///
878 /// By default, performs semantic analysis to build the new statement.
879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000880 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 bool IsSimple,
882 bool IsVolatile,
883 unsigned NumOutputs,
884 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000885 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 MultiExprArg Constraints,
887 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000888 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000889 MultiExprArg Clobbers,
890 SourceLocation RParenLoc,
891 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000892 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000893 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000894 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000895 RParenLoc, MSAsm);
896 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000897
898 /// \brief Build a new Objective-C @try statement.
899 ///
900 /// By default, performs semantic analysis to build the new statement.
901 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000902 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000903 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000904 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000905 Stmt *Finally) {
906 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
907 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000908 }
909
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000910 /// \brief Rebuild an Objective-C exception declaration.
911 ///
912 /// By default, performs semantic analysis to build the new declaration.
913 /// Subclasses may override this routine to provide different behavior.
914 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
915 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000916 return getSema().BuildObjCExceptionDecl(TInfo, T,
917 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000918 ExceptionDecl->getLocation());
919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000920
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000921 /// \brief Build a new Objective-C @catch statement.
922 ///
923 /// By default, performs semantic analysis to build the new statement.
924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000925 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 SourceLocation RParenLoc,
927 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000928 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000929 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000930 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000931 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000932
Douglas Gregor306de2f2010-04-22 23:59:56 +0000933 /// \brief Build a new Objective-C @finally statement.
934 ///
935 /// By default, performs semantic analysis to build the new statement.
936 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000937 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000938 Stmt *Body) {
939 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000940 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000941
Douglas Gregor6148de72010-04-22 22:01:21 +0000942 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000943 ///
944 /// By default, performs semantic analysis to build the new statement.
945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000946 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000947 Expr *Operand) {
948 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000949 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000950
Douglas Gregor6148de72010-04-22 22:01:21 +0000951 /// \brief Build a new Objective-C @synchronized statement.
952 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000955 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000956 Expr *Object,
957 Stmt *Body) {
958 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
959 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000960 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000961
962 /// \brief Build a new Objective-C fast enumeration statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000966 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000967 SourceLocation LParenLoc,
968 Stmt *Element,
969 Expr *Collection,
970 SourceLocation RParenLoc,
971 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000972 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000973 Element,
974 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000975 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000976 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000977 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000978
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 /// \brief Build a new C++ exception declaration.
980 ///
981 /// By default, performs semantic analysis to build the new decaration.
982 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000983 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000984 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 IdentifierInfo *Name,
986 SourceLocation Loc,
987 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000988 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 TypeRange);
990 }
991
992 /// \brief Build a new C++ catch statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000996 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000997 VarDecl *ExceptionDecl,
998 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +0000999 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1000 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /// \brief Build a new C++ try statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001007 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001008 Stmt *TryBlock,
1009 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001010 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 }
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 /// \brief Build a new expression that references a declaration.
1014 ///
1015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001017 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001018 LookupResult &R,
1019 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001020 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 }
1022
1023
1024 /// \brief Build a new expression that references a declaration.
1025 ///
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001028 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001029 SourceRange QualifierRange,
1030 ValueDecl *VD,
1031 const DeclarationNameInfo &NameInfo,
1032 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001033 CXXScopeSpec SS;
1034 SS.setScopeRep(Qualifier);
1035 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001036
1037 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001038
1039 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001048 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 }
1050
Douglas Gregorad8a3362009-09-04 17:36:40 +00001051 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001052 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001056 SourceLocation OperatorLoc,
1057 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001058 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001059 SourceRange QualifierRange,
1060 TypeSourceInfo *ScopeType,
1061 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001062 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001063 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001064
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001066 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001067 /// By default, performs semantic analysis to build the new expression.
1068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001069 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001070 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001071 Expr *SubExpr) {
1072 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregor882211c2010-04-28 22:16:22 +00001075 /// \brief Build a new builtin offsetof expression.
1076 ///
1077 /// By default, performs semantic analysis to build the new expression.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001080 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001081 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001082 unsigned NumComponents,
1083 SourceLocation RParenLoc) {
1084 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1085 NumComponents, RParenLoc);
1086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001087
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001089 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001092 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001093 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001095 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 }
1097
Mike Stump11289f42009-09-09 15:08:12 +00001098 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001103 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001105 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001106 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 return move(Result);
1111 }
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001114 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001117 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001118 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001119 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001121 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1122 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 RBracketLoc);
1124 }
1125
1126 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001131 MultiExprArg Args,
1132 SourceLocation *CommaLocs,
1133 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001134 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 move(Args), CommaLocs, RParenLoc);
1136 }
1137
1138 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001139 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001140 /// By default, performs semantic analysis to build the new expression.
1141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001142 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001143 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001144 NestedNameSpecifier *Qualifier,
1145 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001146 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001147 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001148 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001149 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001150 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001151 if (!Member->getDeclName()) {
1152 // We have a reference to an unnamed field.
1153 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001154
John McCallb268a282010-08-23 23:25:46 +00001155 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001156 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001157 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001158
Mike Stump11289f42009-09-09 15:08:12 +00001159 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001160 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001161 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001162 cast<FieldDecl>(Member)->getType());
1163 return getSema().Owned(ME);
1164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001166 CXXScopeSpec SS;
1167 if (Qualifier) {
1168 SS.setRange(QualifierRange);
1169 SS.setScopeRep(Qualifier);
1170 }
1171
John McCallb268a282010-08-23 23:25:46 +00001172 getSema().DefaultFunctionArrayConversion(Base);
1173 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001174
John McCall16df1e52010-03-30 21:47:33 +00001175 // FIXME: this involves duplicating earlier analysis in a lot of
1176 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001177 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001178 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001179 R.resolveKind();
1180
John McCallb268a282010-08-23 23:25:46 +00001181 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001182 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001183 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001184 }
Mike Stump11289f42009-09-09 15:08:12 +00001185
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001187 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 /// By default, performs semantic analysis to build the new expression.
1189 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001190 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001191 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001192 Expr *LHS, Expr *RHS) {
1193 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 }
1195
1196 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001200 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001202 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001204 Expr *RHS) {
1205 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1206 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 }
1208
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001210 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001213 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001214 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001216 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001217 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001218 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001226 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001228 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001229 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001230 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001234 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001237 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 SourceLocation OpLoc,
1239 SourceLocation AccessorLoc,
1240 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001241
John McCall10eae182009-11-30 22:42:35 +00001242 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001243 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001244 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001245 OpLoc, /*IsArrow*/ false,
1246 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001247 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001248 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001252 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 /// By default, performs semantic analysis to build the new expression.
1254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001255 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001257 SourceLocation RBraceLoc,
1258 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001259 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001260 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1261 if (Result.isInvalid() || ResultTy->isDependentType())
1262 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001263
Douglas Gregord3d93062009-11-09 17:16:50 +00001264 // Patch in the result type we were given, which may have been computed
1265 // when the initial InitListExpr was built.
1266 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1267 ILE->setType(ResultTy);
1268 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001269 }
Mike Stump11289f42009-09-09 15:08:12 +00001270
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001272 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// By default, performs semantic analysis to build the new expression.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001276 MultiExprArg ArrayExprs,
1277 SourceLocation EqualOrColonLoc,
1278 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001279 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001280 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001282 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001285
Douglas Gregora16548e2009-08-11 05:31:07 +00001286 ArrayExprs.release();
1287 return move(Result);
1288 }
Mike Stump11289f42009-09-09 15:08:12 +00001289
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001291 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 /// By default, builds the implicit value initialization without performing
1293 /// any semantic analysis. Subclasses may override this routine to provide
1294 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001295 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1297 }
Mike Stump11289f42009-09-09 15:08:12 +00001298
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001300 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001304 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001305 SourceLocation RParenLoc) {
1306 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001307 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001308 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 }
1310
1311 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001315 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 MultiExprArg SubExprs,
1317 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001318 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001319 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 }
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001323 ///
1324 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// rather than attempting to map the label statement itself.
1326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001327 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 SourceLocation LabelLoc,
1329 LabelStmt *Label) {
1330 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1331 }
Mike Stump11289f42009-09-09 15:08:12 +00001332
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001334 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// By default, performs semantic analysis to build the new expression.
1336 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001337 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001338 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001340 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 }
Mike Stump11289f42009-09-09 15:08:12 +00001342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new __builtin_types_compatible_p expression.
1344 ///
1345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001347 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001348 TypeSourceInfo *TInfo1,
1349 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001351 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1352 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 RParenLoc);
1354 }
Mike Stump11289f42009-09-09 15:08:12 +00001355
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 /// \brief Build a new __builtin_choose_expr expression.
1357 ///
1358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001360 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001361 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 SourceLocation RParenLoc) {
1363 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 RParenLoc);
1366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 /// \brief Build a new overloaded operator call expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// The semantic analysis provides the behavior of template instantiation,
1372 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001373 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// argument-dependent lookup, etc. Subclasses may override this routine to
1375 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001376 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001378 Expr *Callee,
1379 Expr *First,
1380 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001381
1382 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 /// reinterpret_cast.
1384 ///
1385 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001386 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001388 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 Stmt::StmtClass Class,
1390 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001391 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation RAngleLoc,
1393 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001394 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 SourceLocation RParenLoc) {
1396 switch (Class) {
1397 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001398 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001399 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001400 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001401
1402 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001403 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001404 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001405 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001406
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001408 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001409 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001410 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001412
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001414 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001415 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001416 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 default:
1419 assert(false && "Invalid C++ named cast");
1420 break;
1421 }
Mike Stump11289f42009-09-09 15:08:12 +00001422
John McCallfaf5fb42010-08-26 23:41:50 +00001423 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// \brief Build a new C++ static_cast expression.
1427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001430 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001432 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RAngleLoc,
1434 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001435 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001437 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001438 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001439 SourceRange(LAngleLoc, RAngleLoc),
1440 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 }
1442
1443 /// \brief Build a new C++ dynamic_cast expression.
1444 ///
1445 /// By default, performs semantic analysis to build the new expression.
1446 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001447 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001449 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RAngleLoc,
1451 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001452 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001454 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001455 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001456 SourceRange(LAngleLoc, RAngleLoc),
1457 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 }
1459
1460 /// \brief Build a new C++ reinterpret_cast expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001464 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001466 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RAngleLoc,
1468 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001469 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001471 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001472 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001473 SourceRange(LAngleLoc, RAngleLoc),
1474 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 }
1476
1477 /// \brief Build a new C++ const_cast expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001481 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001483 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation RAngleLoc,
1485 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001486 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001488 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001489 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001490 SourceRange(LAngleLoc, RAngleLoc),
1491 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 }
Mike Stump11289f42009-09-09 15:08:12 +00001493
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 /// \brief Build a new C++ functional-style cast expression.
1495 ///
1496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001498 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1499 SourceLocation LParenLoc,
1500 Expr *Sub,
1501 SourceLocation RParenLoc) {
1502 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001503 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 RParenLoc);
1505 }
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 /// \brief Build a new C++ typeid(type) expression.
1508 ///
1509 /// By default, performs semantic analysis to build the new expression.
1510 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001511 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001512 SourceLocation TypeidLoc,
1513 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001515 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001516 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 }
Mike Stump11289f42009-09-09 15:08:12 +00001518
Francois Pichet9f4f2072010-09-08 12:20:18 +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
Francois Pichet9f4f2072010-09-08 12:20:18 +00001532 /// \brief Build a new C++ __uuidof(type) expression.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
1536 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1537 SourceLocation TypeidLoc,
1538 TypeSourceInfo *Operand,
1539 SourceLocation RParenLoc) {
1540 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1541 RParenLoc);
1542 }
1543
1544 /// \brief Build a new C++ __uuidof(expr) expression.
1545 ///
1546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
1548 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1549 SourceLocation TypeidLoc,
1550 Expr *Operand,
1551 SourceLocation RParenLoc) {
1552 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1553 RParenLoc);
1554 }
1555
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// \brief Build a new C++ "this" expression.
1557 ///
1558 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001559 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001561 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001562 QualType ThisType,
1563 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001565 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1566 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 }
1568
1569 /// \brief Build a new C++ throw expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001573 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001574 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new C++ default-argument expression.
1578 ///
1579 /// By default, builds a new default-argument expression, which does not
1580 /// require any semantic analysis. Subclasses may override this routine to
1581 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001582 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001583 ParmVarDecl *Param) {
1584 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1585 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 }
1587
1588 /// \brief Build a new C++ zero-initialization expression.
1589 ///
1590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001592 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1593 SourceLocation LParenLoc,
1594 SourceLocation RParenLoc) {
1595 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001596 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001597 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new C++ "new" expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001604 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001605 bool UseGlobal,
1606 SourceLocation PlacementLParen,
1607 MultiExprArg PlacementArgs,
1608 SourceLocation PlacementRParen,
1609 SourceRange TypeIdParens,
1610 QualType AllocatedType,
1611 TypeSourceInfo *AllocatedTypeInfo,
1612 Expr *ArraySize,
1613 SourceLocation ConstructorLParen,
1614 MultiExprArg ConstructorArgs,
1615 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001616 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 PlacementLParen,
1618 move(PlacementArgs),
1619 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001620 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001621 AllocatedType,
1622 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001623 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 ConstructorLParen,
1625 move(ConstructorArgs),
1626 ConstructorRParen);
1627 }
Mike Stump11289f42009-09-09 15:08:12 +00001628
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 /// \brief Build a new C++ "delete" expression.
1630 ///
1631 /// By default, performs semantic analysis to build the new expression.
1632 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001633 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 bool IsGlobalDelete,
1635 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001636 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001638 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 }
Mike Stump11289f42009-09-09 15:08:12 +00001640
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// \brief Build a new unary type trait expression.
1642 ///
1643 /// By default, performs semantic analysis to build the new expression.
1644 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001645 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001646 SourceLocation StartLoc,
1647 TypeSourceInfo *T,
1648 SourceLocation RParenLoc) {
1649 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 }
1651
Mike Stump11289f42009-09-09 15:08:12 +00001652 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 /// expression.
1654 ///
1655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001657 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001659 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001660 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 CXXScopeSpec SS;
1662 SS.setRange(QualifierRange);
1663 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001664
1665 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001666 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001667 *TemplateArgs);
1668
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001669 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 }
1671
1672 /// \brief Build a new template-id expression.
1673 ///
1674 /// By default, performs semantic analysis to build the new expression.
1675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001677 LookupResult &R,
1678 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001679 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001680 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 }
1682
1683 /// \brief Build a new object-construction expression.
1684 ///
1685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001687 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001688 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 CXXConstructorDecl *Constructor,
1690 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001691 MultiExprArg Args,
1692 bool RequiresZeroInit,
1693 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001694 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001695 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001696 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001697 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001698
Douglas Gregordb121ba2009-12-14 16:27:04 +00001699 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001700 move_arg(ConvertedArgs),
1701 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 }
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.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001708 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1709 SourceLocation LParenLoc,
1710 MultiExprArg Args,
1711 SourceLocation RParenLoc) {
1712 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 LParenLoc,
1714 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 RParenLoc);
1716 }
1717
1718 /// \brief Build a new object-construction expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001722 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1723 SourceLocation LParenLoc,
1724 MultiExprArg Args,
1725 SourceLocation RParenLoc) {
1726 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 LParenLoc,
1728 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 RParenLoc);
1730 }
Mike Stump11289f42009-09-09 15:08:12 +00001731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new member reference expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001736 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001737 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 bool IsArrow,
1739 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001740 NestedNameSpecifier *Qualifier,
1741 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001742 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001743 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001744 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001746 SS.setRange(QualifierRange);
1747 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001748
John McCallb268a282010-08-23 23:25:46 +00001749 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001750 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001751 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001752 MemberNameInfo,
1753 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
1755
John McCall10eae182009-11-30 22:42:35 +00001756 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001761 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001762 SourceLocation OperatorLoc,
1763 bool IsArrow,
1764 NestedNameSpecifier *Qualifier,
1765 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001766 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001767 LookupResult &R,
1768 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001769 CXXScopeSpec SS;
1770 SS.setRange(QualifierRange);
1771 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001772
John McCallb268a282010-08-23 23:25:46 +00001773 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001774 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001775 SS, FirstQualifierInScope,
1776 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001777 }
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 /// \brief Build a new Objective-C @encode expression.
1780 ///
1781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001783 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001784 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001786 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001788 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001789
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001790 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001791 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001792 Selector Sel,
1793 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001794 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001795 MultiExprArg Args,
1796 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001797 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1798 ReceiverTypeInfo->getType(),
1799 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001800 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001801 move(Args));
1802 }
1803
1804 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001805 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 Selector Sel,
1807 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001808 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001809 MultiExprArg Args,
1810 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001811 return SemaRef.BuildInstanceMessage(Receiver,
1812 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001813 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001814 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001815 move(Args));
1816 }
1817
Douglas Gregord51d90d2010-04-26 20:11:03 +00001818 /// \brief Build a new Objective-C ivar reference expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 SourceLocation IvarLoc,
1824 bool IsArrow, bool IsFreeIvar) {
1825 // FIXME: We lose track of the IsFreeIvar bit.
1826 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001827 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001828 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1829 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001831 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001832 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001833 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001834 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001835 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001836
Douglas Gregord51d90d2010-04-26 20:11:03 +00001837 if (Result.get())
1838 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001839
John McCallb268a282010-08-23 23:25:46 +00001840 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001841 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001842 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001843 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001844 /*TemplateArgs=*/0);
1845 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001846
1847 /// \brief Build a new Objective-C property reference expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001851 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001852 ObjCPropertyDecl *Property,
1853 SourceLocation PropertyLoc) {
1854 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001855 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001856 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1857 Sema::LookupMemberName);
1858 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001859 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001860 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001861 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001862 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001863 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001864
Douglas Gregor9faee212010-04-26 20:47:02 +00001865 if (Result.get())
1866 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001867
John McCallb268a282010-08-23 23:25:46 +00001868 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001869 /*FIXME:*/PropertyLoc, IsArrow,
1870 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001871 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001872 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 /*TemplateArgs=*/0);
1874 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001875
1876 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001877 /// expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001881 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001882 ObjCMethodDecl *Getter,
1883 QualType T,
1884 ObjCMethodDecl *Setter,
1885 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001886 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001887 // Since these expressions can only be value-dependent, we do not need to
1888 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001889 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001890 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1891 Setter,
1892 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001893 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001894 }
1895
Douglas Gregord51d90d2010-04-26 20:11:03 +00001896 /// \brief Build a new Objective-C "isa" expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001901 bool IsArrow) {
1902 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001903 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001904 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1905 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001907 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001908 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001909 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001910 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001911
Douglas Gregord51d90d2010-04-26 20:11:03 +00001912 if (Result.get())
1913 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001914
John McCallb268a282010-08-23 23:25:46 +00001915 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001916 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001917 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001918 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001919 /*TemplateArgs=*/0);
1920 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001921
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 /// \brief Build a new shuffle vector expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 MultiExprArg SubExprs,
1928 SourceLocation RParenLoc) {
1929 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001930 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1932 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1933 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1934 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001935
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 // Build a reference to the __builtin_shufflevector builtin
1937 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001938 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001940 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001942
1943 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 unsigned NumSubExprs = SubExprs.size();
1945 Expr **Subs = (Expr **)SubExprs.release();
1946 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1947 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001948 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001950 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001953 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001958 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001960};
Douglas Gregora16548e2009-08-11 05:31:07 +00001961
Douglas Gregorebe10102009-08-20 07:17:43 +00001962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001963StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001964 if (!S)
1965 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregorebe10102009-08-20 07:17:43 +00001967 switch (S->getStmtClass()) {
1968 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001969
Douglas Gregorebe10102009-08-20 07:17:43 +00001970 // Transform individual statement nodes
1971#define STMT(Node, Parent) \
1972 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1973#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001974#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregorebe10102009-08-20 07:17:43 +00001976 // Transform expressions by calling TransformExpr.
1977#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001978#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001979#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001980#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001981 {
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001983 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001984 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001985
John McCallb268a282010-08-23 23:25:46 +00001986 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001987 }
Mike Stump11289f42009-09-09 15:08:12 +00001988 }
1989
Douglas Gregorebe10102009-08-20 07:17:43 +00001990 return SemaRef.Owned(S->Retain());
1991}
Mike Stump11289f42009-09-09 15:08:12 +00001992
1993
Douglas Gregore922c772009-08-04 22:27:00 +00001994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001995ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 if (!E)
1997 return SemaRef.Owned(E);
1998
1999 switch (E->getStmtClass()) {
2000 case Stmt::NoStmtClass: break;
2001#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002002#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002003#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002004 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002005#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002006 }
2007
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002009}
2010
2011template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002012NestedNameSpecifier *
2013TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002014 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002015 QualType ObjectType,
2016 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002017 if (!NNS)
2018 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregorebe10102009-08-20 07:17:43 +00002020 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002021 NestedNameSpecifier *Prefix = NNS->getPrefix();
2022 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002023 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002024 ObjectType,
2025 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 if (!Prefix)
2027 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002028
2029 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002030 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002031 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002032 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002033 }
Mike Stump11289f42009-09-09 15:08:12 +00002034
Douglas Gregor1135c352009-08-06 05:28:30 +00002035 switch (NNS->getKind()) {
2036 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002037 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002038 "Identifier nested-name-specifier with no prefix or object type");
2039 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2040 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002042
2043 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002044 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002045 ObjectType,
2046 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregor1135c352009-08-06 05:28:30 +00002048 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002049 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002050 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002051 getDerived().TransformDecl(Range.getBegin(),
2052 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002053 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002054 Prefix == NNS->getPrefix() &&
2055 NS == NNS->getAsNamespace())
2056 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregor1135c352009-08-06 05:28:30 +00002058 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2059 }
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 case NestedNameSpecifier::Global:
2062 // There is no meaningful transformation that one could perform on the
2063 // global scope.
2064 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002065
Douglas Gregor1135c352009-08-06 05:28:30 +00002066 case NestedNameSpecifier::TypeSpecWithTemplate:
2067 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002068 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002069 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2070 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002071 if (T.isNull())
2072 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002073
Douglas Gregor1135c352009-08-06 05:28:30 +00002074 if (!getDerived().AlwaysRebuild() &&
2075 Prefix == NNS->getPrefix() &&
2076 T == QualType(NNS->getAsType(), 0))
2077 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002078
2079 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2080 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002081 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002082 }
2083 }
Mike Stump11289f42009-09-09 15:08:12 +00002084
Douglas Gregor1135c352009-08-06 05:28:30 +00002085 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002086 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002087}
2088
2089template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002090DeclarationNameInfo
2091TreeTransform<Derived>
2092::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2093 QualType ObjectType) {
2094 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002095 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002096 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002097
2098 switch (Name.getNameKind()) {
2099 case DeclarationName::Identifier:
2100 case DeclarationName::ObjCZeroArgSelector:
2101 case DeclarationName::ObjCOneArgSelector:
2102 case DeclarationName::ObjCMultiArgSelector:
2103 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002104 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002105 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002106 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002107
Douglas Gregorf816bd72009-09-03 22:13:48 +00002108 case DeclarationName::CXXConstructorName:
2109 case DeclarationName::CXXDestructorName:
2110 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002111 TypeSourceInfo *NewTInfo;
2112 CanQualType NewCanTy;
2113 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2114 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2115 if (!NewTInfo)
2116 return DeclarationNameInfo();
2117 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2118 }
2119 else {
2120 NewTInfo = 0;
2121 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2122 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2123 ObjectType);
2124 if (NewT.isNull())
2125 return DeclarationNameInfo();
2126 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002129 DeclarationName NewName
2130 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2131 NewCanTy);
2132 DeclarationNameInfo NewNameInfo(NameInfo);
2133 NewNameInfo.setName(NewName);
2134 NewNameInfo.setNamedTypeInfo(NewTInfo);
2135 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002136 }
Mike Stump11289f42009-09-09 15:08:12 +00002137 }
2138
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002139 assert(0 && "Unknown name kind.");
2140 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002141}
2142
2143template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002144TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002145TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2146 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002147 SourceLocation Loc = getDerived().getBaseLocation();
2148
Douglas Gregor71dc5092009-08-06 06:41:21 +00002149 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002150 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002152 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2153 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 if (!NNS)
2155 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregor71dc5092009-08-06 06:41:21 +00002157 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002158 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002159 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 if (!TransTemplate)
2161 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregor71dc5092009-08-06 06:41:21 +00002163 if (!getDerived().AlwaysRebuild() &&
2164 NNS == QTN->getQualifier() &&
2165 TransTemplate == Template)
2166 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor71dc5092009-08-06 06:41:21 +00002168 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2169 TransTemplate);
2170 }
Mike Stump11289f42009-09-09 15:08:12 +00002171
John McCalle66edc12009-11-24 19:00:30 +00002172 // These should be getting filtered out before they make it into the AST.
2173 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002174 }
Mike Stump11289f42009-09-09 15:08:12 +00002175
Douglas Gregor71dc5092009-08-06 06:41:21 +00002176 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002177 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002179 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2180 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002181 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002182 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002185 NNS == DTN->getQualifier() &&
2186 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregora5614c52010-09-08 23:56:00 +00002189 if (DTN->isIdentifier()) {
2190 // FIXME: Bad range
2191 SourceRange QualifierRange(getDerived().getBaseLocation());
2192 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2193 *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002194 ObjectType);
Douglas Gregora5614c52010-09-08 23:56:00 +00002195 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002196
2197 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002198 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
Douglas Gregor71dc5092009-08-06 06:41:21 +00002201 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002202 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002203 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204 if (!TransTemplate)
2205 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002206
Douglas Gregor71dc5092009-08-06 06:41:21 +00002207 if (!getDerived().AlwaysRebuild() &&
2208 TransTemplate == Template)
2209 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregor71dc5092009-08-06 06:41:21 +00002211 return TemplateName(TransTemplate);
2212 }
Mike Stump11289f42009-09-09 15:08:12 +00002213
John McCalle66edc12009-11-24 19:00:30 +00002214 // These should be getting filtered out before they reach the AST.
2215 assert(false && "overloaded function decl survived to here");
2216 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002217}
2218
2219template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002220void TreeTransform<Derived>::InventTemplateArgumentLoc(
2221 const TemplateArgument &Arg,
2222 TemplateArgumentLoc &Output) {
2223 SourceLocation Loc = getDerived().getBaseLocation();
2224 switch (Arg.getKind()) {
2225 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002226 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002227 break;
2228
2229 case TemplateArgument::Type:
2230 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002231 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002232
John McCall0ad16662009-10-29 08:12:44 +00002233 break;
2234
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002235 case TemplateArgument::Template:
2236 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2237 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002238
John McCall0ad16662009-10-29 08:12:44 +00002239 case TemplateArgument::Expression:
2240 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2241 break;
2242
2243 case TemplateArgument::Declaration:
2244 case TemplateArgument::Integral:
2245 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002246 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002247 break;
2248 }
2249}
2250
2251template<typename Derived>
2252bool TreeTransform<Derived>::TransformTemplateArgument(
2253 const TemplateArgumentLoc &Input,
2254 TemplateArgumentLoc &Output) {
2255 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002256 switch (Arg.getKind()) {
2257 case TemplateArgument::Null:
2258 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002259 Output = Input;
2260 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002261
Douglas Gregore922c772009-08-04 22:27:00 +00002262 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002263 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002264 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002265 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002266
2267 DI = getDerived().TransformType(DI);
2268 if (!DI) return true;
2269
2270 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2271 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002272 }
Mike Stump11289f42009-09-09 15:08:12 +00002273
Douglas Gregore922c772009-08-04 22:27:00 +00002274 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002275 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002276 DeclarationName Name;
2277 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2278 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002279 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002280 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002281 if (!D) return true;
2282
John McCall0d07eb32009-10-29 18:45:58 +00002283 Expr *SourceExpr = Input.getSourceDeclExpression();
2284 if (SourceExpr) {
2285 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002286 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002287 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002288 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002289 }
2290
2291 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002292 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002293 }
Mike Stump11289f42009-09-09 15:08:12 +00002294
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002295 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002296 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002297 TemplateName Template
2298 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2299 if (Template.isNull())
2300 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002301
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002302 Output = TemplateArgumentLoc(TemplateArgument(Template),
2303 Input.getTemplateQualifierRange(),
2304 Input.getTemplateNameLoc());
2305 return false;
2306 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002307
Douglas Gregore922c772009-08-04 22:27:00 +00002308 case TemplateArgument::Expression: {
2309 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002310 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002311 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002312
John McCall0ad16662009-10-29 08:12:44 +00002313 Expr *InputExpr = Input.getSourceExpression();
2314 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2315
John McCalldadc5752010-08-24 06:29:42 +00002316 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002317 = getDerived().TransformExpr(InputExpr);
2318 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002319 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002320 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002321 }
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregore922c772009-08-04 22:27:00 +00002323 case TemplateArgument::Pack: {
2324 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2325 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002326 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002327 AEnd = Arg.pack_end();
2328 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002329
John McCall0ad16662009-10-29 08:12:44 +00002330 // FIXME: preserve source information here when we start
2331 // caring about parameter packs.
2332
John McCall0d07eb32009-10-29 18:45:58 +00002333 TemplateArgumentLoc InputArg;
2334 TemplateArgumentLoc OutputArg;
2335 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2336 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002337 return true;
2338
John McCall0d07eb32009-10-29 18:45:58 +00002339 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002340 }
2341 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002342 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002343 true);
John McCall0d07eb32009-10-29 18:45:58 +00002344 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002345 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002346 }
2347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregore922c772009-08-04 22:27:00 +00002349 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002350 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002351}
2352
Douglas Gregord6ff3322009-08-04 16:50:30 +00002353//===----------------------------------------------------------------------===//
2354// Type transformation
2355//===----------------------------------------------------------------------===//
2356
2357template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002358QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002359 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002360 if (getDerived().AlreadyTransformed(T))
2361 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002362
John McCall550e0c22009-10-21 00:40:46 +00002363 // Temporary workaround. All of these transformations should
2364 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002365 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002366 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002367
Douglas Gregorfe17d252010-02-16 19:09:40 +00002368 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002369
John McCall550e0c22009-10-21 00:40:46 +00002370 if (!NewDI)
2371 return QualType();
2372
2373 return NewDI->getType();
2374}
2375
2376template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002377TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2378 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002379 if (getDerived().AlreadyTransformed(DI->getType()))
2380 return DI;
2381
2382 TypeLocBuilder TLB;
2383
2384 TypeLoc TL = DI->getTypeLoc();
2385 TLB.reserve(TL.getFullDataSize());
2386
Douglas Gregorfe17d252010-02-16 19:09:40 +00002387 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002388 if (Result.isNull())
2389 return 0;
2390
John McCallbcd03502009-12-07 02:54:59 +00002391 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002392}
2393
2394template<typename Derived>
2395QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002396TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2397 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002398 switch (T.getTypeLocClass()) {
2399#define ABSTRACT_TYPELOC(CLASS, PARENT)
2400#define TYPELOC(CLASS, PARENT) \
2401 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002402 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2403 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002404#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002405 }
Mike Stump11289f42009-09-09 15:08:12 +00002406
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002407 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002408 return QualType();
2409}
2410
2411/// FIXME: By default, this routine adds type qualifiers only to types
2412/// that can have qualifiers, and silently suppresses those qualifiers
2413/// that are not permitted (e.g., qualifiers on reference or function
2414/// types). This is the right thing for template instantiation, but
2415/// probably not for other clients.
2416template<typename Derived>
2417QualType
2418TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002419 QualifiedTypeLoc T,
2420 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002421 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002422
Douglas Gregorfe17d252010-02-16 19:09:40 +00002423 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2424 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002425 if (Result.isNull())
2426 return QualType();
2427
2428 // Silently suppress qualifiers if the result type can't be qualified.
2429 // FIXME: this is the right thing for template instantiation, but
2430 // probably not for other clients.
2431 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002432 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002433
John McCallcb0f89a2010-06-05 06:41:15 +00002434 if (!Quals.empty()) {
2435 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2436 TLB.push<QualifiedTypeLoc>(Result);
2437 // No location information to preserve.
2438 }
John McCall550e0c22009-10-21 00:40:46 +00002439
2440 return Result;
2441}
2442
2443template <class TyLoc> static inline
2444QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2445 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2446 NewT.setNameLoc(T.getNameLoc());
2447 return T.getType();
2448}
2449
John McCall550e0c22009-10-21 00:40:46 +00002450template<typename Derived>
2451QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002452 BuiltinTypeLoc T,
2453 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002454 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2455 NewT.setBuiltinLoc(T.getBuiltinLoc());
2456 if (T.needsExtraLocalData())
2457 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2458 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002459}
Mike Stump11289f42009-09-09 15:08:12 +00002460
Douglas Gregord6ff3322009-08-04 16:50:30 +00002461template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002462QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002463 ComplexTypeLoc T,
2464 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002465 // FIXME: recurse?
2466 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002467}
Mike Stump11289f42009-09-09 15:08:12 +00002468
Douglas Gregord6ff3322009-08-04 16:50:30 +00002469template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002470QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002471 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002472 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002473 QualType PointeeType
2474 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002475 if (PointeeType.isNull())
2476 return QualType();
2477
2478 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002479 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002480 // A dependent pointer type 'T *' has is being transformed such
2481 // that an Objective-C class type is being replaced for 'T'. The
2482 // resulting pointer type is an ObjCObjectPointerType, not a
2483 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002484 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485
John McCall8b07ec22010-05-15 11:32:37 +00002486 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2487 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002488 return Result;
2489 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002490
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002491 if (getDerived().AlwaysRebuild() ||
2492 PointeeType != TL.getPointeeLoc().getType()) {
2493 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2494 if (Result.isNull())
2495 return QualType();
2496 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002497
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002498 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2499 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002500 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002501}
Mike Stump11289f42009-09-09 15:08:12 +00002502
2503template<typename Derived>
2504QualType
John McCall550e0c22009-10-21 00:40:46 +00002505TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002506 BlockPointerTypeLoc TL,
2507 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002508 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002509 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2510 if (PointeeType.isNull())
2511 return QualType();
2512
2513 QualType Result = TL.getType();
2514 if (getDerived().AlwaysRebuild() ||
2515 PointeeType != TL.getPointeeLoc().getType()) {
2516 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002517 TL.getSigilLoc());
2518 if (Result.isNull())
2519 return QualType();
2520 }
2521
Douglas Gregor049211a2010-04-22 16:50:51 +00002522 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002523 NewT.setSigilLoc(TL.getSigilLoc());
2524 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002525}
2526
John McCall70dd5f62009-10-30 00:06:24 +00002527/// Transforms a reference type. Note that somewhat paradoxically we
2528/// don't care whether the type itself is an l-value type or an r-value
2529/// type; we only care if the type was *written* as an l-value type
2530/// or an r-value type.
2531template<typename Derived>
2532QualType
2533TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002534 ReferenceTypeLoc TL,
2535 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002536 const ReferenceType *T = TL.getTypePtr();
2537
2538 // Note that this works with the pointee-as-written.
2539 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2540 if (PointeeType.isNull())
2541 return QualType();
2542
2543 QualType Result = TL.getType();
2544 if (getDerived().AlwaysRebuild() ||
2545 PointeeType != T->getPointeeTypeAsWritten()) {
2546 Result = getDerived().RebuildReferenceType(PointeeType,
2547 T->isSpelledAsLValue(),
2548 TL.getSigilLoc());
2549 if (Result.isNull())
2550 return QualType();
2551 }
2552
2553 // r-value references can be rebuilt as l-value references.
2554 ReferenceTypeLoc NewTL;
2555 if (isa<LValueReferenceType>(Result))
2556 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2557 else
2558 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2559 NewTL.setSigilLoc(TL.getSigilLoc());
2560
2561 return Result;
2562}
2563
Mike Stump11289f42009-09-09 15:08:12 +00002564template<typename Derived>
2565QualType
John McCall550e0c22009-10-21 00:40:46 +00002566TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002567 LValueReferenceTypeLoc TL,
2568 QualType ObjectType) {
2569 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002570}
2571
Mike Stump11289f42009-09-09 15:08:12 +00002572template<typename Derived>
2573QualType
John McCall550e0c22009-10-21 00:40:46 +00002574TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002575 RValueReferenceTypeLoc TL,
2576 QualType ObjectType) {
2577 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002578}
Mike Stump11289f42009-09-09 15:08:12 +00002579
Douglas Gregord6ff3322009-08-04 16:50:30 +00002580template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002581QualType
John McCall550e0c22009-10-21 00:40:46 +00002582TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002583 MemberPointerTypeLoc TL,
2584 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002585 MemberPointerType *T = TL.getTypePtr();
2586
2587 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002588 if (PointeeType.isNull())
2589 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002590
John McCall550e0c22009-10-21 00:40:46 +00002591 // TODO: preserve source information for this.
2592 QualType ClassType
2593 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594 if (ClassType.isNull())
2595 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002596
John McCall550e0c22009-10-21 00:40:46 +00002597 QualType Result = TL.getType();
2598 if (getDerived().AlwaysRebuild() ||
2599 PointeeType != T->getPointeeType() ||
2600 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002601 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2602 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002603 if (Result.isNull())
2604 return QualType();
2605 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002606
John McCall550e0c22009-10-21 00:40:46 +00002607 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2608 NewTL.setSigilLoc(TL.getSigilLoc());
2609
2610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002611}
2612
Mike Stump11289f42009-09-09 15:08:12 +00002613template<typename Derived>
2614QualType
John McCall550e0c22009-10-21 00:40:46 +00002615TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002616 ConstantArrayTypeLoc TL,
2617 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002618 ConstantArrayType *T = TL.getTypePtr();
2619 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002620 if (ElementType.isNull())
2621 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002622
John McCall550e0c22009-10-21 00:40:46 +00002623 QualType Result = TL.getType();
2624 if (getDerived().AlwaysRebuild() ||
2625 ElementType != T->getElementType()) {
2626 Result = getDerived().RebuildConstantArrayType(ElementType,
2627 T->getSizeModifier(),
2628 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002629 T->getIndexTypeCVRQualifiers(),
2630 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002631 if (Result.isNull())
2632 return QualType();
2633 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002634
John McCall550e0c22009-10-21 00:40:46 +00002635 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2636 NewTL.setLBracketLoc(TL.getLBracketLoc());
2637 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002638
John McCall550e0c22009-10-21 00:40:46 +00002639 Expr *Size = TL.getSizeExpr();
2640 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002641 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002642 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2643 }
2644 NewTL.setSizeExpr(Size);
2645
2646 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002647}
Mike Stump11289f42009-09-09 15:08:12 +00002648
Douglas Gregord6ff3322009-08-04 16:50:30 +00002649template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002651 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002652 IncompleteArrayTypeLoc TL,
2653 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002654 IncompleteArrayType *T = TL.getTypePtr();
2655 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002656 if (ElementType.isNull())
2657 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002658
John McCall550e0c22009-10-21 00:40:46 +00002659 QualType Result = TL.getType();
2660 if (getDerived().AlwaysRebuild() ||
2661 ElementType != T->getElementType()) {
2662 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002663 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002664 T->getIndexTypeCVRQualifiers(),
2665 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002666 if (Result.isNull())
2667 return QualType();
2668 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002669
John McCall550e0c22009-10-21 00:40:46 +00002670 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2671 NewTL.setLBracketLoc(TL.getLBracketLoc());
2672 NewTL.setRBracketLoc(TL.getRBracketLoc());
2673 NewTL.setSizeExpr(0);
2674
2675 return Result;
2676}
2677
2678template<typename Derived>
2679QualType
2680TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002681 VariableArrayTypeLoc TL,
2682 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002683 VariableArrayType *T = TL.getTypePtr();
2684 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2685 if (ElementType.isNull())
2686 return QualType();
2687
2688 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002689 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002690
John McCalldadc5752010-08-24 06:29:42 +00002691 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002692 = getDerived().TransformExpr(T->getSizeExpr());
2693 if (SizeResult.isInvalid())
2694 return QualType();
2695
John McCallb268a282010-08-23 23:25:46 +00002696 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002697
2698 QualType Result = TL.getType();
2699 if (getDerived().AlwaysRebuild() ||
2700 ElementType != T->getElementType() ||
2701 Size != T->getSizeExpr()) {
2702 Result = getDerived().RebuildVariableArrayType(ElementType,
2703 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002704 Size,
John McCall550e0c22009-10-21 00:40:46 +00002705 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002706 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002707 if (Result.isNull())
2708 return QualType();
2709 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002710
John McCall550e0c22009-10-21 00:40:46 +00002711 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2712 NewTL.setLBracketLoc(TL.getLBracketLoc());
2713 NewTL.setRBracketLoc(TL.getRBracketLoc());
2714 NewTL.setSizeExpr(Size);
2715
2716 return Result;
2717}
2718
2719template<typename Derived>
2720QualType
2721TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002722 DependentSizedArrayTypeLoc TL,
2723 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002724 DependentSizedArrayType *T = TL.getTypePtr();
2725 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2726 if (ElementType.isNull())
2727 return QualType();
2728
2729 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002730 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002731
John McCalldadc5752010-08-24 06:29:42 +00002732 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002733 = getDerived().TransformExpr(T->getSizeExpr());
2734 if (SizeResult.isInvalid())
2735 return QualType();
2736
2737 Expr *Size = static_cast<Expr*>(SizeResult.get());
2738
2739 QualType Result = TL.getType();
2740 if (getDerived().AlwaysRebuild() ||
2741 ElementType != T->getElementType() ||
2742 Size != T->getSizeExpr()) {
2743 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2744 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002745 Size,
John McCall550e0c22009-10-21 00:40:46 +00002746 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002747 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002748 if (Result.isNull())
2749 return QualType();
2750 }
2751 else SizeResult.take();
2752
2753 // We might have any sort of array type now, but fortunately they
2754 // all have the same location layout.
2755 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2756 NewTL.setLBracketLoc(TL.getLBracketLoc());
2757 NewTL.setRBracketLoc(TL.getRBracketLoc());
2758 NewTL.setSizeExpr(Size);
2759
2760 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761}
Mike Stump11289f42009-09-09 15:08:12 +00002762
2763template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002765 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002766 DependentSizedExtVectorTypeLoc TL,
2767 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002768 DependentSizedExtVectorType *T = TL.getTypePtr();
2769
2770 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002771 QualType ElementType = getDerived().TransformType(T->getElementType());
2772 if (ElementType.isNull())
2773 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002774
Douglas Gregore922c772009-08-04 22:27:00 +00002775 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002776 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002777
John McCalldadc5752010-08-24 06:29:42 +00002778 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002779 if (Size.isInvalid())
2780 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002781
John McCall550e0c22009-10-21 00:40:46 +00002782 QualType Result = TL.getType();
2783 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002784 ElementType != T->getElementType() ||
2785 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002786 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002787 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002788 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002789 if (Result.isNull())
2790 return QualType();
2791 }
John McCall550e0c22009-10-21 00:40:46 +00002792
2793 // Result might be dependent or not.
2794 if (isa<DependentSizedExtVectorType>(Result)) {
2795 DependentSizedExtVectorTypeLoc NewTL
2796 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2797 NewTL.setNameLoc(TL.getNameLoc());
2798 } else {
2799 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2800 NewTL.setNameLoc(TL.getNameLoc());
2801 }
2802
2803 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002804}
Mike Stump11289f42009-09-09 15:08:12 +00002805
2806template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002807QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002808 VectorTypeLoc TL,
2809 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002810 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002811 QualType ElementType = getDerived().TransformType(T->getElementType());
2812 if (ElementType.isNull())
2813 return QualType();
2814
John McCall550e0c22009-10-21 00:40:46 +00002815 QualType Result = TL.getType();
2816 if (getDerived().AlwaysRebuild() ||
2817 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002818 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002819 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002820 if (Result.isNull())
2821 return QualType();
2822 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002823
John McCall550e0c22009-10-21 00:40:46 +00002824 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2825 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002826
John McCall550e0c22009-10-21 00:40:46 +00002827 return Result;
2828}
2829
2830template<typename Derived>
2831QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002832 ExtVectorTypeLoc TL,
2833 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002834 VectorType *T = TL.getTypePtr();
2835 QualType ElementType = getDerived().TransformType(T->getElementType());
2836 if (ElementType.isNull())
2837 return QualType();
2838
2839 QualType Result = TL.getType();
2840 if (getDerived().AlwaysRebuild() ||
2841 ElementType != T->getElementType()) {
2842 Result = getDerived().RebuildExtVectorType(ElementType,
2843 T->getNumElements(),
2844 /*FIXME*/ SourceLocation());
2845 if (Result.isNull())
2846 return QualType();
2847 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002848
John McCall550e0c22009-10-21 00:40:46 +00002849 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2850 NewTL.setNameLoc(TL.getNameLoc());
2851
2852 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002853}
Mike Stump11289f42009-09-09 15:08:12 +00002854
2855template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002856ParmVarDecl *
2857TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2858 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2859 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2860 if (!NewDI)
2861 return 0;
2862
2863 if (NewDI == OldDI)
2864 return OldParm;
2865 else
2866 return ParmVarDecl::Create(SemaRef.Context,
2867 OldParm->getDeclContext(),
2868 OldParm->getLocation(),
2869 OldParm->getIdentifier(),
2870 NewDI->getType(),
2871 NewDI,
2872 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002873 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002874 /* DefArg */ NULL);
2875}
2876
2877template<typename Derived>
2878bool TreeTransform<Derived>::
2879 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2880 llvm::SmallVectorImpl<QualType> &PTypes,
2881 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2882 FunctionProtoType *T = TL.getTypePtr();
2883
2884 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2885 ParmVarDecl *OldParm = TL.getArg(i);
2886
2887 QualType NewType;
2888 ParmVarDecl *NewParm;
2889
2890 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002891 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2892 if (!NewParm)
2893 return true;
2894 NewType = NewParm->getType();
2895
2896 // Deal with the possibility that we don't have a parameter
2897 // declaration for this parameter.
2898 } else {
2899 NewParm = 0;
2900
2901 QualType OldType = T->getArgType(i);
2902 NewType = getDerived().TransformType(OldType);
2903 if (NewType.isNull())
2904 return true;
2905 }
2906
2907 PTypes.push_back(NewType);
2908 PVars.push_back(NewParm);
2909 }
2910
2911 return false;
2912}
2913
2914template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002915QualType
John McCall550e0c22009-10-21 00:40:46 +00002916TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002917 FunctionProtoTypeLoc TL,
2918 QualType ObjectType) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00002919 // Transform the parameters and return type.
2920 //
2921 // We instantiate in source order, with the return type first followed by
2922 // the parameters, because users tend to expect this (even if they shouldn't
2923 // rely on it!).
2924 //
2925 // FIXME: When we implement late-specified return types, we'll need to
2926 // instantiate the return tpe *after* the parameter types in that case,
2927 // since the return type can then refer to the parameters themselves (via
2928 // decltype, sizeof, etc.).
Douglas Gregord6ff3322009-08-04 16:50:30 +00002929 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002930 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00002931 FunctionProtoType *T = TL.getTypePtr();
2932 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2933 if (ResultType.isNull())
2934 return QualType();
Douglas Gregor4afc2362010-08-31 00:26:14 +00002935
2936 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2937 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002938
John McCall550e0c22009-10-21 00:40:46 +00002939 QualType Result = TL.getType();
2940 if (getDerived().AlwaysRebuild() ||
2941 ResultType != T->getResultType() ||
2942 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2943 Result = getDerived().RebuildFunctionProtoType(ResultType,
2944 ParamTypes.data(),
2945 ParamTypes.size(),
2946 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002947 T->getTypeQuals(),
2948 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002949 if (Result.isNull())
2950 return QualType();
2951 }
Mike Stump11289f42009-09-09 15:08:12 +00002952
John McCall550e0c22009-10-21 00:40:46 +00002953 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2954 NewTL.setLParenLoc(TL.getLParenLoc());
2955 NewTL.setRParenLoc(TL.getRParenLoc());
2956 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2957 NewTL.setArg(i, ParamDecls[i]);
2958
2959 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002960}
Mike Stump11289f42009-09-09 15:08:12 +00002961
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962template<typename Derived>
2963QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002964 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002965 FunctionNoProtoTypeLoc TL,
2966 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002967 FunctionNoProtoType *T = TL.getTypePtr();
2968 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2969 if (ResultType.isNull())
2970 return QualType();
2971
2972 QualType Result = TL.getType();
2973 if (getDerived().AlwaysRebuild() ||
2974 ResultType != T->getResultType())
2975 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2976
2977 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2978 NewTL.setLParenLoc(TL.getLParenLoc());
2979 NewTL.setRParenLoc(TL.getRParenLoc());
2980
2981 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002982}
Mike Stump11289f42009-09-09 15:08:12 +00002983
John McCallb96ec562009-12-04 22:46:56 +00002984template<typename Derived> QualType
2985TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002986 UnresolvedUsingTypeLoc TL,
2987 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002988 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002989 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002990 if (!D)
2991 return QualType();
2992
2993 QualType Result = TL.getType();
2994 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2995 Result = getDerived().RebuildUnresolvedUsingType(D);
2996 if (Result.isNull())
2997 return QualType();
2998 }
2999
3000 // We might get an arbitrary type spec type back. We should at
3001 // least always get a type spec type, though.
3002 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3003 NewTL.setNameLoc(TL.getNameLoc());
3004
3005 return Result;
3006}
3007
Douglas Gregord6ff3322009-08-04 16:50:30 +00003008template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003009QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003010 TypedefTypeLoc TL,
3011 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003012 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003014 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3015 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003016 if (!Typedef)
3017 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003018
John McCall550e0c22009-10-21 00:40:46 +00003019 QualType Result = TL.getType();
3020 if (getDerived().AlwaysRebuild() ||
3021 Typedef != T->getDecl()) {
3022 Result = getDerived().RebuildTypedefType(Typedef);
3023 if (Result.isNull())
3024 return QualType();
3025 }
Mike Stump11289f42009-09-09 15:08:12 +00003026
John McCall550e0c22009-10-21 00:40:46 +00003027 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3028 NewTL.setNameLoc(TL.getNameLoc());
3029
3030 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003031}
Mike Stump11289f42009-09-09 15:08:12 +00003032
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003034QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003035 TypeOfExprTypeLoc TL,
3036 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003037 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003038 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003039
John McCalldadc5752010-08-24 06:29:42 +00003040 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003041 if (E.isInvalid())
3042 return QualType();
3043
John McCall550e0c22009-10-21 00:40:46 +00003044 QualType Result = TL.getType();
3045 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003046 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003047 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003048 if (Result.isNull())
3049 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003050 }
John McCall550e0c22009-10-21 00:40:46 +00003051 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003052
John McCall550e0c22009-10-21 00:40:46 +00003053 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003054 NewTL.setTypeofLoc(TL.getTypeofLoc());
3055 NewTL.setLParenLoc(TL.getLParenLoc());
3056 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003057
3058 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003059}
Mike Stump11289f42009-09-09 15:08:12 +00003060
3061template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003062QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003063 TypeOfTypeLoc TL,
3064 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003065 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3066 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3067 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003068 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003069
John McCall550e0c22009-10-21 00:40:46 +00003070 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003071 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3072 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003073 if (Result.isNull())
3074 return QualType();
3075 }
Mike Stump11289f42009-09-09 15:08:12 +00003076
John McCall550e0c22009-10-21 00:40:46 +00003077 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003078 NewTL.setTypeofLoc(TL.getTypeofLoc());
3079 NewTL.setLParenLoc(TL.getLParenLoc());
3080 NewTL.setRParenLoc(TL.getRParenLoc());
3081 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003082
3083 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084}
Mike Stump11289f42009-09-09 15:08:12 +00003085
3086template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003087QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003088 DecltypeTypeLoc TL,
3089 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003090 DecltypeType *T = TL.getTypePtr();
3091
Douglas Gregore922c772009-08-04 22:27:00 +00003092 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003093 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCalldadc5752010-08-24 06:29:42 +00003095 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003096 if (E.isInvalid())
3097 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003098
John McCall550e0c22009-10-21 00:40:46 +00003099 QualType Result = TL.getType();
3100 if (getDerived().AlwaysRebuild() ||
3101 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003102 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003103 if (Result.isNull())
3104 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 }
John McCall550e0c22009-10-21 00:40:46 +00003106 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003107
John McCall550e0c22009-10-21 00:40:46 +00003108 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3109 NewTL.setNameLoc(TL.getNameLoc());
3110
3111 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112}
3113
3114template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003115QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003116 RecordTypeLoc TL,
3117 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003118 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003119 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003120 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3121 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003122 if (!Record)
3123 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003124
John McCall550e0c22009-10-21 00:40:46 +00003125 QualType Result = TL.getType();
3126 if (getDerived().AlwaysRebuild() ||
3127 Record != T->getDecl()) {
3128 Result = getDerived().RebuildRecordType(Record);
3129 if (Result.isNull())
3130 return QualType();
3131 }
Mike Stump11289f42009-09-09 15:08:12 +00003132
John McCall550e0c22009-10-21 00:40:46 +00003133 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3134 NewTL.setNameLoc(TL.getNameLoc());
3135
3136 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003137}
Mike Stump11289f42009-09-09 15:08:12 +00003138
3139template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003140QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003141 EnumTypeLoc TL,
3142 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003143 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003145 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3146 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147 if (!Enum)
3148 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003149
John McCall550e0c22009-10-21 00:40:46 +00003150 QualType Result = TL.getType();
3151 if (getDerived().AlwaysRebuild() ||
3152 Enum != T->getDecl()) {
3153 Result = getDerived().RebuildEnumType(Enum);
3154 if (Result.isNull())
3155 return QualType();
3156 }
Mike Stump11289f42009-09-09 15:08:12 +00003157
John McCall550e0c22009-10-21 00:40:46 +00003158 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3159 NewTL.setNameLoc(TL.getNameLoc());
3160
3161 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003162}
John McCallfcc33b02009-09-05 00:15:47 +00003163
John McCalle78aac42010-03-10 03:28:59 +00003164template<typename Derived>
3165QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3166 TypeLocBuilder &TLB,
3167 InjectedClassNameTypeLoc TL,
3168 QualType ObjectType) {
3169 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3170 TL.getTypePtr()->getDecl());
3171 if (!D) return QualType();
3172
3173 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3174 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3175 return T;
3176}
3177
Mike Stump11289f42009-09-09 15:08:12 +00003178
Douglas Gregord6ff3322009-08-04 16:50:30 +00003179template<typename Derived>
3180QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003181 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003182 TemplateTypeParmTypeLoc TL,
3183 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003184 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003185}
3186
Mike Stump11289f42009-09-09 15:08:12 +00003187template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003188QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003189 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003190 SubstTemplateTypeParmTypeLoc TL,
3191 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003192 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003193}
3194
3195template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003196QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3197 const TemplateSpecializationType *TST,
3198 QualType ObjectType) {
3199 // FIXME: this entire method is a temporary workaround; callers
3200 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003201
John McCall0ad16662009-10-29 08:12:44 +00003202 // Fake up a TemplateSpecializationTypeLoc.
3203 TypeLocBuilder TLB;
3204 TemplateSpecializationTypeLoc TL
3205 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3206
John McCall0d07eb32009-10-29 18:45:58 +00003207 SourceLocation BaseLoc = getDerived().getBaseLocation();
3208
3209 TL.setTemplateNameLoc(BaseLoc);
3210 TL.setLAngleLoc(BaseLoc);
3211 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003212 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3213 const TemplateArgument &TA = TST->getArg(i);
3214 TemplateArgumentLoc TAL;
3215 getDerived().InventTemplateArgumentLoc(TA, TAL);
3216 TL.setArgLocInfo(i, TAL.getLocInfo());
3217 }
3218
3219 TypeLocBuilder IgnoredTLB;
3220 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003221}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003222
Douglas Gregorc59e5612009-10-19 22:04:39 +00003223template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003224QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003225 TypeLocBuilder &TLB,
3226 TemplateSpecializationTypeLoc TL,
3227 QualType ObjectType) {
3228 const TemplateSpecializationType *T = TL.getTypePtr();
3229
Mike Stump11289f42009-09-09 15:08:12 +00003230 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003231 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003232 if (Template.isNull())
3233 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003234
John McCall6b51f282009-11-23 01:53:49 +00003235 TemplateArgumentListInfo NewTemplateArgs;
3236 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3237 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3238
3239 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3240 TemplateArgumentLoc Loc;
3241 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003242 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003243 NewTemplateArgs.addArgument(Loc);
3244 }
Mike Stump11289f42009-09-09 15:08:12 +00003245
John McCall0ad16662009-10-29 08:12:44 +00003246 // FIXME: maybe don't rebuild if all the template arguments are the same.
3247
3248 QualType Result =
3249 getDerived().RebuildTemplateSpecializationType(Template,
3250 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003251 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003252
3253 if (!Result.isNull()) {
3254 TemplateSpecializationTypeLoc NewTL
3255 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3256 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3257 NewTL.setLAngleLoc(TL.getLAngleLoc());
3258 NewTL.setRAngleLoc(TL.getRAngleLoc());
3259 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3260 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003261 }
Mike Stump11289f42009-09-09 15:08:12 +00003262
John McCall0ad16662009-10-29 08:12:44 +00003263 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003264}
Mike Stump11289f42009-09-09 15:08:12 +00003265
3266template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003267QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003268TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3269 ElaboratedTypeLoc TL,
3270 QualType ObjectType) {
3271 ElaboratedType *T = TL.getTypePtr();
3272
3273 NestedNameSpecifier *NNS = 0;
3274 // NOTE: the qualifier in an ElaboratedType is optional.
3275 if (T->getQualifier() != 0) {
3276 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003277 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003278 ObjectType);
3279 if (!NNS)
3280 return QualType();
3281 }
Mike Stump11289f42009-09-09 15:08:12 +00003282
Abramo Bagnarad7548482010-05-19 21:37:53 +00003283 QualType NamedT;
3284 // FIXME: this test is meant to workaround a problem (failing assertion)
3285 // occurring if directly executing the code in the else branch.
3286 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3287 TemplateSpecializationTypeLoc OldNamedTL
3288 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3289 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003290 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003291 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3292 if (NamedT.isNull())
3293 return QualType();
3294 TemplateSpecializationTypeLoc NewNamedTL
3295 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3296 NewNamedTL.copy(OldNamedTL);
3297 }
3298 else {
3299 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3300 if (NamedT.isNull())
3301 return QualType();
3302 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003303
John McCall550e0c22009-10-21 00:40:46 +00003304 QualType Result = TL.getType();
3305 if (getDerived().AlwaysRebuild() ||
3306 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003307 NamedT != T->getNamedType()) {
3308 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003309 if (Result.isNull())
3310 return QualType();
3311 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003312
Abramo Bagnara6150c882010-05-11 21:36:43 +00003313 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003314 NewTL.setKeywordLoc(TL.getKeywordLoc());
3315 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003316
3317 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003318}
Mike Stump11289f42009-09-09 15:08:12 +00003319
3320template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003321QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3322 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003323 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003324 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003325
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003327 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3328 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003329 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003330 if (!NNS)
3331 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003332
John McCallc392f372010-06-11 00:33:02 +00003333 QualType Result
3334 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3335 T->getIdentifier(),
3336 TL.getKeywordLoc(),
3337 TL.getQualifierRange(),
3338 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003339 if (Result.isNull())
3340 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341
Abramo Bagnarad7548482010-05-19 21:37:53 +00003342 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3343 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003344 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3345
Abramo Bagnarad7548482010-05-19 21:37:53 +00003346 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3347 NewTL.setKeywordLoc(TL.getKeywordLoc());
3348 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003349 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003350 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3351 NewTL.setKeywordLoc(TL.getKeywordLoc());
3352 NewTL.setQualifierRange(TL.getQualifierRange());
3353 NewTL.setNameLoc(TL.getNameLoc());
3354 }
John McCall550e0c22009-10-21 00:40:46 +00003355 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003356}
Mike Stump11289f42009-09-09 15:08:12 +00003357
Douglas Gregord6ff3322009-08-04 16:50:30 +00003358template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003359QualType TreeTransform<Derived>::
3360 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3361 DependentTemplateSpecializationTypeLoc TL,
3362 QualType ObjectType) {
3363 DependentTemplateSpecializationType *T = TL.getTypePtr();
3364
3365 NestedNameSpecifier *NNS
3366 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3367 TL.getQualifierRange(),
3368 ObjectType);
3369 if (!NNS)
3370 return QualType();
3371
3372 TemplateArgumentListInfo NewTemplateArgs;
3373 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3374 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3375
3376 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3377 TemplateArgumentLoc Loc;
3378 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3379 return QualType();
3380 NewTemplateArgs.addArgument(Loc);
3381 }
3382
Douglas Gregora5614c52010-09-08 23:56:00 +00003383 QualType Result
3384 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3385 NNS,
3386 TL.getQualifierRange(),
3387 T->getIdentifier(),
3388 TL.getNameLoc(),
3389 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003390 if (Result.isNull())
3391 return QualType();
3392
3393 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3394 QualType NamedT = ElabT->getNamedType();
3395
3396 // Copy information relevant to the template specialization.
3397 TemplateSpecializationTypeLoc NamedTL
3398 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3399 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3400 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3401 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3402 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3403
3404 // Copy information relevant to the elaborated type.
3405 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3406 NewTL.setKeywordLoc(TL.getKeywordLoc());
3407 NewTL.setQualifierRange(TL.getQualifierRange());
3408 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003409 TypeLoc NewTL(Result, TL.getOpaqueData());
3410 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003411 }
3412 return Result;
3413}
3414
3415template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003416QualType
3417TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003418 ObjCInterfaceTypeLoc TL,
3419 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003420 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003421 TLB.pushFullCopy(TL);
3422 return TL.getType();
3423}
3424
3425template<typename Derived>
3426QualType
3427TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3428 ObjCObjectTypeLoc TL,
3429 QualType ObjectType) {
3430 // ObjCObjectType is never dependent.
3431 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003432 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003433}
Mike Stump11289f42009-09-09 15:08:12 +00003434
3435template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003436QualType
3437TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003438 ObjCObjectPointerTypeLoc TL,
3439 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003440 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003441 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003442 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003443}
3444
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003446// Statement transformation
3447//===----------------------------------------------------------------------===//
3448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003449StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003450TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3451 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003452}
3453
3454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003455StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003456TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3457 return getDerived().TransformCompoundStmt(S, false);
3458}
3459
3460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003461StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003462TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003463 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003464 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003465 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003466 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3468 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003469 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003470 if (Result.isInvalid()) {
3471 // Immediately fail if this was a DeclStmt, since it's very
3472 // likely that this will cause problems for future statements.
3473 if (isa<DeclStmt>(*B))
3474 return StmtError();
3475
3476 // Otherwise, just keep processing substatements and fail later.
3477 SubStmtInvalid = true;
3478 continue;
3479 }
Mike Stump11289f42009-09-09 15:08:12 +00003480
Douglas Gregorebe10102009-08-20 07:17:43 +00003481 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3482 Statements.push_back(Result.takeAs<Stmt>());
3483 }
Mike Stump11289f42009-09-09 15:08:12 +00003484
John McCall1ababa62010-08-27 19:56:05 +00003485 if (SubStmtInvalid)
3486 return StmtError();
3487
Douglas Gregorebe10102009-08-20 07:17:43 +00003488 if (!getDerived().AlwaysRebuild() &&
3489 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003490 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003491
3492 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3493 move_arg(Statements),
3494 S->getRBracLoc(),
3495 IsStmtExpr);
3496}
Mike Stump11289f42009-09-09 15:08:12 +00003497
Douglas Gregorebe10102009-08-20 07:17:43 +00003498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003499StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003500TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003501 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003502 {
3503 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003504 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003505
Eli Friedman06577382009-11-19 03:14:00 +00003506 // Transform the left-hand case value.
3507 LHS = getDerived().TransformExpr(S->getLHS());
3508 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003509 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003510
Eli Friedman06577382009-11-19 03:14:00 +00003511 // Transform the right-hand case value (for the GNU case-range extension).
3512 RHS = getDerived().TransformExpr(S->getRHS());
3513 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003514 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003515 }
Mike Stump11289f42009-09-09 15:08:12 +00003516
Douglas Gregorebe10102009-08-20 07:17:43 +00003517 // Build the case statement.
3518 // Case statements are always rebuilt so that they will attached to their
3519 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003520 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003521 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003523 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 S->getColonLoc());
3525 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003526 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregorebe10102009-08-20 07:17:43 +00003528 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003529 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003530 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003531 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003534 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003535}
3536
3537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003538StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003539TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003540 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003541 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003542 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003543 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Default statements are always rebuilt
3546 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003547 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003548}
Mike Stump11289f42009-09-09 15:08:12 +00003549
Douglas Gregorebe10102009-08-20 07:17:43 +00003550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003551StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003552TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003553 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003554 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003555 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregorebe10102009-08-20 07:17:43 +00003557 // FIXME: Pass the real colon location in.
3558 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3559 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003560 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003561}
Mike Stump11289f42009-09-09 15:08:12 +00003562
Douglas Gregorebe10102009-08-20 07:17:43 +00003563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003564StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003565TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003566 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003567 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003568 VarDecl *ConditionVar = 0;
3569 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003570 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003571 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003572 getDerived().TransformDefinition(
3573 S->getConditionVariable()->getLocation(),
3574 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003575 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003576 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003577 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003578 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003579
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003580 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003581 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003582
3583 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003584 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003585 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003586 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003587 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003588 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003589 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003590
John McCallb268a282010-08-23 23:25:46 +00003591 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003592 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003593 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003594
John McCallb268a282010-08-23 23:25:46 +00003595 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3596 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003597 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003598
Douglas Gregorebe10102009-08-20 07:17:43 +00003599 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003600 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003602 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003605 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003607 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregorebe10102009-08-20 07:17:43 +00003609 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003610 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003611 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003612 Then.get() == S->getThen() &&
3613 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003614 return SemaRef.Owned(S->Retain());
3615
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003616 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003617 Then.get(),
3618 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003619}
3620
3621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003622StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003623TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003625 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003626 VarDecl *ConditionVar = 0;
3627 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003628 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003629 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003630 getDerived().TransformDefinition(
3631 S->getConditionVariable()->getLocation(),
3632 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003633 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003634 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003635 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003636 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003637
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003638 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003639 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003640 }
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003643 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003644 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003645 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003646 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003647 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregorebe10102009-08-20 07:17:43 +00003649 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003650 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003651 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003652 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorebe10102009-08-20 07:17:43 +00003654 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003655 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3656 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003657}
Mike Stump11289f42009-09-09 15:08:12 +00003658
Douglas Gregorebe10102009-08-20 07:17:43 +00003659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003660StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003661TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003662 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003663 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003664 VarDecl *ConditionVar = 0;
3665 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003666 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003667 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003668 getDerived().TransformDefinition(
3669 S->getConditionVariable()->getLocation(),
3670 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003671 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003672 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003673 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003674 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003675
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003676 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003677 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003678
3679 if (S->getCond()) {
3680 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003681 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003682 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003683 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003684 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003685 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003686 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003687 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003688 }
Mike Stump11289f42009-09-09 15:08:12 +00003689
John McCallb268a282010-08-23 23:25:46 +00003690 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3691 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003692 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003693
Douglas Gregorebe10102009-08-20 07:17:43 +00003694 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003695 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003696 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003697 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregorebe10102009-08-20 07:17:43 +00003699 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003700 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003701 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003702 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003703 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003704
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003705 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003706 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003707}
Mike Stump11289f42009-09-09 15:08:12 +00003708
Douglas Gregorebe10102009-08-20 07:17:43 +00003709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003710StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003711TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003712 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003713 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003715 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003716
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003717 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003718 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003719 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003720 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003721
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 if (!getDerived().AlwaysRebuild() &&
3723 Cond.get() == S->getCond() &&
3724 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003725 return SemaRef.Owned(S->Retain());
3726
John McCallb268a282010-08-23 23:25:46 +00003727 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3728 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003729 S->getRParenLoc());
3730}
Mike Stump11289f42009-09-09 15:08:12 +00003731
Douglas Gregorebe10102009-08-20 07:17:43 +00003732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003733StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003734TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003735 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003736 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003737 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003738 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003741 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003742 VarDecl *ConditionVar = 0;
3743 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003744 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003745 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003746 getDerived().TransformDefinition(
3747 S->getConditionVariable()->getLocation(),
3748 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003749 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003750 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003751 } else {
3752 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003753
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003754 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003756
3757 if (S->getCond()) {
3758 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003759 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003760 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003761 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003762 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003763 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003764
John McCallb268a282010-08-23 23:25:46 +00003765 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003766 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003767 }
Mike Stump11289f42009-09-09 15:08:12 +00003768
John McCallb268a282010-08-23 23:25:46 +00003769 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3770 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003771 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003772
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003774 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003775 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003776 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003777
John McCallb268a282010-08-23 23:25:46 +00003778 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3779 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003780 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003781
Douglas Gregorebe10102009-08-20 07:17:43 +00003782 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003783 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003784 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003785 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregorebe10102009-08-20 07:17:43 +00003787 if (!getDerived().AlwaysRebuild() &&
3788 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003789 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 Inc.get() == S->getInc() &&
3791 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003792 return SemaRef.Owned(S->Retain());
3793
Douglas Gregorebe10102009-08-20 07:17:43 +00003794 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003795 Init.get(), FullCond, ConditionVar,
3796 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003797}
3798
3799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003800StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003801TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003802 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003803 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003804 S->getLabel());
3805}
3806
3807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003808StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003809TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003810 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003811 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003812 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregorebe10102009-08-20 07:17:43 +00003814 if (!getDerived().AlwaysRebuild() &&
3815 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003816 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003817
3818 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003819 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003820}
3821
3822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003824TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3825 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003826}
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregorebe10102009-08-20 07:17:43 +00003828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003829StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003830TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3831 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003832}
Mike Stump11289f42009-09-09 15:08:12 +00003833
Douglas Gregorebe10102009-08-20 07:17:43 +00003834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003836TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003837 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003838 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003839 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003840
Mike Stump11289f42009-09-09 15:08:12 +00003841 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003842 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003843 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003844}
Mike Stump11289f42009-09-09 15:08:12 +00003845
Douglas Gregorebe10102009-08-20 07:17:43 +00003846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003848TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003849 bool DeclChanged = false;
3850 llvm::SmallVector<Decl *, 4> Decls;
3851 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3852 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003853 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3854 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003855 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003856 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregorebe10102009-08-20 07:17:43 +00003858 if (Transformed != *D)
3859 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003860
Douglas Gregorebe10102009-08-20 07:17:43 +00003861 Decls.push_back(Transformed);
3862 }
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregorebe10102009-08-20 07:17:43 +00003864 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003865 return SemaRef.Owned(S->Retain());
3866
3867 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003868 S->getStartLoc(), S->getEndLoc());
3869}
Mike Stump11289f42009-09-09 15:08:12 +00003870
Douglas Gregorebe10102009-08-20 07:17:43 +00003871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003872StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003873TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003874 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003875 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003876}
3877
3878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003879StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003880TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003881
John McCall37ad5512010-08-23 06:44:23 +00003882 ASTOwningVector<Expr*> Constraints(getSema());
3883 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003884 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003885
John McCalldadc5752010-08-24 06:29:42 +00003886 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003887 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003888
3889 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003890
Anders Carlssonaaeef072010-01-24 05:50:09 +00003891 // Go through the outputs.
3892 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003893 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003894
Anders Carlssonaaeef072010-01-24 05:50:09 +00003895 // No need to transform the constraint literal.
3896 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003897
Anders Carlssonaaeef072010-01-24 05:50:09 +00003898 // Transform the output expr.
3899 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003900 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003902 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003903
Anders Carlssonaaeef072010-01-24 05:50:09 +00003904 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003905
John McCallb268a282010-08-23 23:25:46 +00003906 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003907 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003908
Anders Carlssonaaeef072010-01-24 05:50:09 +00003909 // Go through the inputs.
3910 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003911 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003912
Anders Carlssonaaeef072010-01-24 05:50:09 +00003913 // No need to transform the constraint literal.
3914 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003915
Anders Carlssonaaeef072010-01-24 05:50:09 +00003916 // Transform the input expr.
3917 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003918 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003919 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003920 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003921
Anders Carlssonaaeef072010-01-24 05:50:09 +00003922 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003923
John McCallb268a282010-08-23 23:25:46 +00003924 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003925 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003926
Anders Carlssonaaeef072010-01-24 05:50:09 +00003927 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3928 return SemaRef.Owned(S->Retain());
3929
3930 // Go through the clobbers.
3931 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3932 Clobbers.push_back(S->getClobber(I)->Retain());
3933
3934 // No need to transform the asm string literal.
3935 AsmString = SemaRef.Owned(S->getAsmString());
3936
3937 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3938 S->isSimple(),
3939 S->isVolatile(),
3940 S->getNumOutputs(),
3941 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003942 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003943 move_arg(Constraints),
3944 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003945 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003946 move_arg(Clobbers),
3947 S->getRParenLoc(),
3948 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003949}
3950
3951
3952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003953StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003954TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003955 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003956 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003957 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003958 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003959
Douglas Gregor96c79492010-04-23 22:50:49 +00003960 // Transform the @catch statements (if present).
3961 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003962 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003963 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003964 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003965 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003966 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003967 if (Catch.get() != S->getCatchStmt(I))
3968 AnyCatchChanged = true;
3969 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003970 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003971
Douglas Gregor306de2f2010-04-22 23:59:56 +00003972 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00003973 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003974 if (S->getFinallyStmt()) {
3975 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3976 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003977 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00003978 }
3979
3980 // If nothing changed, just retain this statement.
3981 if (!getDerived().AlwaysRebuild() &&
3982 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003983 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003984 Finally.get() == S->getFinallyStmt())
3985 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003986
Douglas Gregor306de2f2010-04-22 23:59:56 +00003987 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003988 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3989 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003990}
Mike Stump11289f42009-09-09 15:08:12 +00003991
Douglas Gregorebe10102009-08-20 07:17:43 +00003992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003993StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003994TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003995 // Transform the @catch parameter, if there is one.
3996 VarDecl *Var = 0;
3997 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3998 TypeSourceInfo *TSInfo = 0;
3999 if (FromVar->getTypeSourceInfo()) {
4000 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4001 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004002 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004003 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004004
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004005 QualType T;
4006 if (TSInfo)
4007 T = TSInfo->getType();
4008 else {
4009 T = getDerived().TransformType(FromVar->getType());
4010 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004011 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004012 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004013
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004014 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4015 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004016 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004017 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004018
John McCalldadc5752010-08-24 06:29:42 +00004019 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004020 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004021 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004022
4023 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004024 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004025 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004026}
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregorebe10102009-08-20 07:17:43 +00004028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004029StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004030TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004031 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004032 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004033 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004034 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004035
Douglas Gregor306de2f2010-04-22 23:59:56 +00004036 // If nothing changed, just retain this statement.
4037 if (!getDerived().AlwaysRebuild() &&
4038 Body.get() == S->getFinallyBody())
4039 return SemaRef.Owned(S->Retain());
4040
4041 // Build a new statement.
4042 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004043 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004044}
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregorebe10102009-08-20 07:17:43 +00004046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004047StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004048TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004049 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004050 if (S->getThrowExpr()) {
4051 Operand = getDerived().TransformExpr(S->getThrowExpr());
4052 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004053 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004054 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004055
Douglas Gregor2900c162010-04-22 21:44:01 +00004056 if (!getDerived().AlwaysRebuild() &&
4057 Operand.get() == S->getThrowExpr())
4058 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004059
John McCallb268a282010-08-23 23:25:46 +00004060 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregorebe10102009-08-20 07:17:43 +00004063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004064StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004065TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004066 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004067 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004068 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004069 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004070 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004071
Douglas Gregor6148de72010-04-22 22:01:21 +00004072 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004073 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004074 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004075 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004076
Douglas Gregor6148de72010-04-22 22:01:21 +00004077 // If nothing change, just retain the current statement.
4078 if (!getDerived().AlwaysRebuild() &&
4079 Object.get() == S->getSynchExpr() &&
4080 Body.get() == S->getSynchBody())
4081 return SemaRef.Owned(S->Retain());
4082
4083 // Build a new statement.
4084 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004085 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004086}
4087
4088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004089StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004090TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004091 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004092 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004093 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004094 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004095 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004096
Douglas Gregorf68a5082010-04-22 23:10:45 +00004097 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004098 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004099 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004100 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004101
Douglas Gregorf68a5082010-04-22 23:10:45 +00004102 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004103 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004104 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004105 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004106
Douglas Gregorf68a5082010-04-22 23:10:45 +00004107 // If nothing changed, just retain this statement.
4108 if (!getDerived().AlwaysRebuild() &&
4109 Element.get() == S->getElement() &&
4110 Collection.get() == S->getCollection() &&
4111 Body.get() == S->getBody())
4112 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004113
Douglas Gregorf68a5082010-04-22 23:10:45 +00004114 // Build a new statement.
4115 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4116 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004117 Element.get(),
4118 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004119 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004120 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004121}
4122
4123
4124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004125StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004126TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4127 // Transform the exception declaration, if any.
4128 VarDecl *Var = 0;
4129 if (S->getExceptionDecl()) {
4130 VarDecl *ExceptionDecl = S->getExceptionDecl();
4131 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4132 ExceptionDecl->getDeclName());
4133
4134 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4135 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004136 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregorebe10102009-08-20 07:17:43 +00004138 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4139 T,
John McCallbcd03502009-12-07 02:54:59 +00004140 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004141 ExceptionDecl->getIdentifier(),
4142 ExceptionDecl->getLocation(),
4143 /*FIXME: Inaccurate*/
4144 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004145 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004146 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004147 }
Mike Stump11289f42009-09-09 15:08:12 +00004148
Douglas Gregorebe10102009-08-20 07:17:43 +00004149 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004150 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004151 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004152 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004153
Douglas Gregorebe10102009-08-20 07:17:43 +00004154 if (!getDerived().AlwaysRebuild() &&
4155 !Var &&
4156 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004157 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004158
4159 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4160 Var,
John McCallb268a282010-08-23 23:25:46 +00004161 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004162}
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregorebe10102009-08-20 07:17:43 +00004164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004165StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004166TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4167 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004168 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004169 = getDerived().TransformCompoundStmt(S->getTryBlock());
4170 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004171 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregorebe10102009-08-20 07:17:43 +00004173 // Transform the handlers.
4174 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004175 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004176 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004177 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004178 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4179 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004180 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregorebe10102009-08-20 07:17:43 +00004182 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4183 Handlers.push_back(Handler.takeAs<Stmt>());
4184 }
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregorebe10102009-08-20 07:17:43 +00004186 if (!getDerived().AlwaysRebuild() &&
4187 TryBlock.get() == S->getTryBlock() &&
4188 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004189 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004190
John McCallb268a282010-08-23 23:25:46 +00004191 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004192 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004193}
Mike Stump11289f42009-09-09 15:08:12 +00004194
Douglas Gregorebe10102009-08-20 07:17:43 +00004195//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004196// Expression transformation
4197//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004200TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004201 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004202}
Mike Stump11289f42009-09-09 15:08:12 +00004203
4204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004206TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004207 NestedNameSpecifier *Qualifier = 0;
4208 if (E->getQualifier()) {
4209 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004210 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004211 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004212 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004213 }
John McCallce546572009-12-08 09:08:17 +00004214
4215 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004216 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4217 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004218 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004220
John McCall815039a2010-08-17 21:27:17 +00004221 DeclarationNameInfo NameInfo = E->getNameInfo();
4222 if (NameInfo.getName()) {
4223 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4224 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004225 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004226 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004227
4228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004229 Qualifier == E->getQualifier() &&
4230 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004231 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004232 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004233
4234 // Mark it referenced in the new context regardless.
4235 // FIXME: this is a bit instantiation-specific.
4236 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4237
Mike Stump11289f42009-09-09 15:08:12 +00004238 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004239 }
John McCallce546572009-12-08 09:08:17 +00004240
4241 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004242 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004243 TemplateArgs = &TransArgs;
4244 TransArgs.setLAngleLoc(E->getLAngleLoc());
4245 TransArgs.setRAngleLoc(E->getRAngleLoc());
4246 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4247 TemplateArgumentLoc Loc;
4248 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004249 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004250 TransArgs.addArgument(Loc);
4251 }
4252 }
4253
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004254 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004255 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004256}
Mike Stump11289f42009-09-09 15:08:12 +00004257
Douglas Gregora16548e2009-08-11 05:31:07 +00004258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004261 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004262}
Mike Stump11289f42009-09-09 15:08:12 +00004263
Douglas Gregora16548e2009-08-11 05:31:07 +00004264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004266TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004267 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004268}
Mike Stump11289f42009-09-09 15:08:12 +00004269
Douglas Gregora16548e2009-08-11 05:31:07 +00004270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004273 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004274}
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004277ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004278TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004279 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004280}
Mike Stump11289f42009-09-09 15:08:12 +00004281
Douglas Gregora16548e2009-08-11 05:31:07 +00004282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004284TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004285 return SemaRef.Owned(E->Retain());
4286}
4287
4288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004291 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004292 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004296 return SemaRef.Owned(E->Retain());
4297
John McCallb268a282010-08-23 23:25:46 +00004298 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 E->getRParen());
4300}
4301
Mike Stump11289f42009-09-09 15:08:12 +00004302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004304TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004305 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004308
Douglas Gregora16548e2009-08-11 05:31:07 +00004309 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004310 return SemaRef.Owned(E->Retain());
4311
Douglas Gregora16548e2009-08-11 05:31:07 +00004312 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4313 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004314 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004315}
Mike Stump11289f42009-09-09 15:08:12 +00004316
Douglas Gregora16548e2009-08-11 05:31:07 +00004317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004318ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004319TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4320 // Transform the type.
4321 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4322 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004323 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004324
Douglas Gregor882211c2010-04-28 22:16:22 +00004325 // Transform all of the components into components similar to what the
4326 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004327 // FIXME: It would be slightly more efficient in the non-dependent case to
4328 // just map FieldDecls, rather than requiring the rebuilder to look for
4329 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004330 // template code that we don't care.
4331 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004332 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004333 typedef OffsetOfExpr::OffsetOfNode Node;
4334 llvm::SmallVector<Component, 4> Components;
4335 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4336 const Node &ON = E->getComponent(I);
4337 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004338 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004339 Comp.LocStart = ON.getRange().getBegin();
4340 Comp.LocEnd = ON.getRange().getEnd();
4341 switch (ON.getKind()) {
4342 case Node::Array: {
4343 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004344 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004345 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004346 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004347
Douglas Gregor882211c2010-04-28 22:16:22 +00004348 ExprChanged = ExprChanged || Index.get() != FromIndex;
4349 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004350 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004351 break;
4352 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004353
Douglas Gregor882211c2010-04-28 22:16:22 +00004354 case Node::Field:
4355 case Node::Identifier:
4356 Comp.isBrackets = false;
4357 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004358 if (!Comp.U.IdentInfo)
4359 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004360
Douglas Gregor882211c2010-04-28 22:16:22 +00004361 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004362
Douglas Gregord1702062010-04-29 00:18:15 +00004363 case Node::Base:
4364 // Will be recomputed during the rebuild.
4365 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004366 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004367
Douglas Gregor882211c2010-04-28 22:16:22 +00004368 Components.push_back(Comp);
4369 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004370
Douglas Gregor882211c2010-04-28 22:16:22 +00004371 // If nothing changed, retain the existing expression.
4372 if (!getDerived().AlwaysRebuild() &&
4373 Type == E->getTypeSourceInfo() &&
4374 !ExprChanged)
4375 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004376
Douglas Gregor882211c2010-04-28 22:16:22 +00004377 // Build a new offsetof expression.
4378 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4379 Components.data(), Components.size(),
4380 E->getRParenLoc());
4381}
4382
4383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004385TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004387 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004388
John McCallbcd03502009-12-07 02:54:59 +00004389 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004390 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004391 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004392
John McCall4c98fd82009-11-04 07:28:41 +00004393 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004395
John McCall4c98fd82009-11-04 07:28:41 +00004396 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004397 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 E->getSourceRange());
4399 }
Mike Stump11289f42009-09-09 15:08:12 +00004400
John McCalldadc5752010-08-24 06:29:42 +00004401 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004402 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 // C++0x [expr.sizeof]p1:
4404 // The operand is either an expression, which is an unevaluated operand
4405 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004406 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4409 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004411
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4413 return SemaRef.Owned(E->Retain());
4414 }
Mike Stump11289f42009-09-09 15:08:12 +00004415
John McCallb268a282010-08-23 23:25:46 +00004416 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 E->isSizeOf(),
4418 E->getSourceRange());
4419}
Mike Stump11289f42009-09-09 15:08:12 +00004420
Douglas Gregora16548e2009-08-11 05:31:07 +00004421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004423TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004424 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004427
John McCalldadc5752010-08-24 06:29:42 +00004428 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004431
4432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 if (!getDerived().AlwaysRebuild() &&
4434 LHS.get() == E->getLHS() &&
4435 RHS.get() == E->getRHS())
4436 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004437
John McCallb268a282010-08-23 23:25:46 +00004438 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004440 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 E->getRBracketLoc());
4442}
Mike Stump11289f42009-09-09 15:08:12 +00004443
4444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004446TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004448 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004450 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004451
4452 // Transform arguments.
4453 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004454 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4456 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004457 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004459 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004460
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 // FIXME: Wrong source location information for the ','.
4462 FakeCommaLocs.push_back(
4463 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004464
4465 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004466 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 }
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregora16548e2009-08-11 05:31:07 +00004469 if (!getDerived().AlwaysRebuild() &&
4470 Callee.get() == E->getCallee() &&
4471 !ArgChanged)
4472 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004475 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004477 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 move_arg(Args),
4479 FakeCommaLocs.data(),
4480 E->getRParenLoc());
4481}
Mike Stump11289f42009-09-09 15:08:12 +00004482
4483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004485TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004486 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004490 NestedNameSpecifier *Qualifier = 0;
4491 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004492 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004493 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004494 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004495 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004496 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004497 }
Mike Stump11289f42009-09-09 15:08:12 +00004498
Eli Friedman2cfcef62009-12-04 06:40:45 +00004499 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004500 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4501 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004504
John McCall16df1e52010-03-30 21:47:33 +00004505 NamedDecl *FoundDecl = E->getFoundDecl();
4506 if (FoundDecl == E->getMemberDecl()) {
4507 FoundDecl = Member;
4508 } else {
4509 FoundDecl = cast_or_null<NamedDecl>(
4510 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4511 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004512 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004513 }
4514
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 if (!getDerived().AlwaysRebuild() &&
4516 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004517 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004518 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004519 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004520 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004521
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004522 // Mark it referenced in the new context regardless.
4523 // FIXME: this is a bit instantiation-specific.
4524 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004525 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004526 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004527
John McCall6b51f282009-11-23 01:53:49 +00004528 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004529 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004530 TransArgs.setLAngleLoc(E->getLAngleLoc());
4531 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004532 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004533 TemplateArgumentLoc Loc;
4534 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004535 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004536 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004537 }
4538 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004539
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 // FIXME: Bogus source location for the operator
4541 SourceLocation FakeOperatorLoc
4542 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4543
John McCall38836f02010-01-15 08:34:02 +00004544 // FIXME: to do this check properly, we will need to preserve the
4545 // first-qualifier-in-scope here, just in case we had a dependent
4546 // base (and therefore couldn't do the check) and a
4547 // nested-name-qualifier (and therefore could do the lookup).
4548 NamedDecl *FirstQualifierInScope = 0;
4549
John McCallb268a282010-08-23 23:25:46 +00004550 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004552 Qualifier,
4553 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004554 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004555 Member,
John McCall16df1e52010-03-30 21:47:33 +00004556 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004557 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004558 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004559 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004560}
Mike Stump11289f42009-09-09 15:08:12 +00004561
Douglas Gregora16548e2009-08-11 05:31:07 +00004562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004563ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004564TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004565 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004568
John McCalldadc5752010-08-24 06:29:42 +00004569 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004572
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 if (!getDerived().AlwaysRebuild() &&
4574 LHS.get() == E->getLHS() &&
4575 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004576 return SemaRef.Owned(E->Retain());
4577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004579 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004580}
4581
Mike Stump11289f42009-09-09 15:08:12 +00004582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004583ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004584TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004585 CompoundAssignOperator *E) {
4586 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004587}
Mike Stump11289f42009-09-09 15:08:12 +00004588
Douglas Gregora16548e2009-08-11 05:31:07 +00004589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004591TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004592 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004593 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
John McCalldadc5752010-08-24 06:29:42 +00004596 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004599
John McCalldadc5752010-08-24 06:29:42 +00004600 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 if (!getDerived().AlwaysRebuild() &&
4605 Cond.get() == E->getCond() &&
4606 LHS.get() == E->getLHS() &&
4607 RHS.get() == E->getRHS())
4608 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004609
John McCallb268a282010-08-23 23:25:46 +00004610 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004611 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004612 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004613 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004614 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004615}
Mike Stump11289f42009-09-09 15:08:12 +00004616
4617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004619TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004620 // Implicit casts are eliminated during transformation, since they
4621 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004622 return getDerived().TransformExpr(E->getSubExprAsWritten());
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>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004628 TypeSourceInfo *OldT;
4629 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 {
4631 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004632 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4634 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004635
John McCall97513962010-01-15 18:39:57 +00004636 OldT = E->getTypeInfoAsWritten();
4637 NewT = getDerived().TransformType(OldT);
4638 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004639 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004640 }
Mike Stump11289f42009-09-09 15:08:12 +00004641
John McCalldadc5752010-08-24 06:29:42 +00004642 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004643 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004644 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004648 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004650 return SemaRef.Owned(E->Retain());
4651
John McCall97513962010-01-15 18:39:57 +00004652 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4653 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004655 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004656}
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004659ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004660TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004661 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4662 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4663 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004664 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCalldadc5752010-08-24 06:29:42 +00004666 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregora16548e2009-08-11 05:31:07 +00004670 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004671 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004673 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004674
John McCall5d7aa7f2010-01-19 22:33:45 +00004675 // Note: the expression type doesn't necessarily match the
4676 // type-as-written, but that's okay, because it should always be
4677 // derivable from the initializer.
4678
John McCalle15bbff2010-01-18 19:35:47 +00004679 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004681 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004682}
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004685ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004686TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004687 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004690
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 if (!getDerived().AlwaysRebuild() &&
4692 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004693 return SemaRef.Owned(E->Retain());
4694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004696 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004698 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 E->getAccessorLoc(),
4700 E->getAccessor());
4701}
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregora16548e2009-08-11 05:31:07 +00004703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004704ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004705TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004706 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004707
John McCall37ad5512010-08-23 06:44:23 +00004708 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004710 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004715 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 }
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004719 return SemaRef.Owned(E->Retain());
4720
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004722 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004723}
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregora16548e2009-08-11 05:31:07 +00004725template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004726ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004727TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregorebe10102009-08-20 07:17:43 +00004730 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004731 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregorebe10102009-08-20 07:17:43 +00004735 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004736 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 bool ExprChanged = false;
4738 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4739 DEnd = E->designators_end();
4740 D != DEnd; ++D) {
4741 if (D->isFieldDesignator()) {
4742 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4743 D->getDotLoc(),
4744 D->getFieldLoc()));
4745 continue;
4746 }
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004749 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004752
4753 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4757 ArrayExprs.push_back(Index.release());
4758 continue;
4759 }
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004762 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004763 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4764 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004766
John McCalldadc5752010-08-24 06:29:42 +00004767 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
4771 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004772 End.get(),
4773 D->getLBracketLoc(),
4774 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4777 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 ArrayExprs.push_back(Start.release());
4780 ArrayExprs.push_back(End.release());
4781 }
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 if (!getDerived().AlwaysRebuild() &&
4784 Init.get() == E->getInit() &&
4785 !ExprChanged)
4786 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4789 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004790 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004791}
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregora16548e2009-08-11 05:31:07 +00004793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004794ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004795TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004796 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004797 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004798
Douglas Gregor3da3c062009-10-28 00:29:27 +00004799 // FIXME: Will we ever have proper type location here? Will we actually
4800 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 QualType T = getDerived().TransformType(E->getType());
4802 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 if (!getDerived().AlwaysRebuild() &&
4806 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004807 return SemaRef.Owned(E->Retain());
4808
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 return getDerived().RebuildImplicitValueInitExpr(T);
4810}
Mike Stump11289f42009-09-09 15:08:12 +00004811
Douglas Gregora16548e2009-08-11 05:31:07 +00004812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004813ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004814TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004815 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4816 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004817 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004818
John McCalldadc5752010-08-24 06:29:42 +00004819 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004824 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 SubExpr.get() == E->getSubExpr())
4826 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004827
John McCallb268a282010-08-23 23:25:46 +00004828 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004829 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004830}
4831
4832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004833ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004834TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004836 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004838 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004839 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004843 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 }
Mike Stump11289f42009-09-09 15:08:12 +00004845
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4847 move_arg(Inits),
4848 E->getRParenLoc());
4849}
Mike Stump11289f42009-09-09 15:08:12 +00004850
Douglas Gregora16548e2009-08-11 05:31:07 +00004851/// \brief Transform an address-of-label expression.
4852///
4853/// By default, the transformation of an address-of-label expression always
4854/// rebuilds the expression, so that the label identifier can be resolved to
4855/// the corresponding label statement by semantic analysis.
4856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4860 E->getLabel());
4861}
Mike Stump11289f42009-09-09 15:08:12 +00004862
4863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004865TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004866 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4868 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 if (!getDerived().AlwaysRebuild() &&
4872 SubStmt.get() == E->getSubStmt())
4873 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004874
4875 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004876 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 E->getRParenLoc());
4878}
Mike Stump11289f42009-09-09 15:08:12 +00004879
Douglas Gregora16548e2009-08-11 05:31:07 +00004880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004881ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004882TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004883 TypeSourceInfo *TInfo1;
4884 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004885
4886 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4887 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregor7058c262010-08-10 14:27:00 +00004890 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4891 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004892 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004893
4894 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004895 TInfo1 == E->getArgTInfo1() &&
4896 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004897 return SemaRef.Owned(E->Retain());
4898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004900 TInfo1, TInfo2,
4901 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004902}
Mike Stump11289f42009-09-09 15:08:12 +00004903
Douglas Gregora16548e2009-08-11 05:31:07 +00004904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004906TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004907 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
John McCalldadc5752010-08-24 06:29:42 +00004911 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004912 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004914
John McCalldadc5752010-08-24 06:29:42 +00004915 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004916 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004917 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004918
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 if (!getDerived().AlwaysRebuild() &&
4920 Cond.get() == E->getCond() &&
4921 LHS.get() == E->getLHS() &&
4922 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004923 return SemaRef.Owned(E->Retain());
4924
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004926 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004927 E->getRParenLoc());
4928}
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregora16548e2009-08-11 05:31:07 +00004930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004932TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004933 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004934}
4935
4936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004938TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004939 switch (E->getOperator()) {
4940 case OO_New:
4941 case OO_Delete:
4942 case OO_Array_New:
4943 case OO_Array_Delete:
4944 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004945 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004946
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004947 case OO_Call: {
4948 // This is a call to an object's operator().
4949 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4950
4951 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004952 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004953 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004954 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004955
4956 // FIXME: Poor location information
4957 SourceLocation FakeLParenLoc
4958 = SemaRef.PP.getLocForEndOfToken(
4959 static_cast<Expr *>(Object.get())->getLocEnd());
4960
4961 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004962 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004963 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4964 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004965 if (getDerived().DropCallArgument(E->getArg(I)))
4966 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004967
John McCalldadc5752010-08-24 06:29:42 +00004968 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004969 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004970 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004971
4972 // FIXME: Poor source location information.
4973 SourceLocation FakeCommaLoc
4974 = SemaRef.PP.getLocForEndOfToken(
4975 static_cast<Expr *>(Arg.get())->getLocEnd());
4976 FakeCommaLocs.push_back(FakeCommaLoc);
4977 Args.push_back(Arg.release());
4978 }
4979
John McCallb268a282010-08-23 23:25:46 +00004980 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004981 move_arg(Args),
4982 FakeCommaLocs.data(),
4983 E->getLocEnd());
4984 }
4985
4986#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4987 case OO_##Name:
4988#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4989#include "clang/Basic/OperatorKinds.def"
4990 case OO_Subscript:
4991 // Handled below.
4992 break;
4993
4994 case OO_Conditional:
4995 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00004996 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004997
4998 case OO_None:
4999 case NUM_OVERLOADED_OPERATORS:
5000 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005001 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005002 }
5003
John McCalldadc5752010-08-24 06:29:42 +00005004 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005006 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005007
John McCalldadc5752010-08-24 06:29:42 +00005008 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005009 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005010 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005011
John McCalldadc5752010-08-24 06:29:42 +00005012 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 if (E->getNumArgs() == 2) {
5014 Second = getDerived().TransformExpr(E->getArg(1));
5015 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005016 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 }
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 if (!getDerived().AlwaysRebuild() &&
5020 Callee.get() == E->getCallee() &&
5021 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005022 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5023 return SemaRef.Owned(E->Retain());
5024
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5026 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005027 Callee.get(),
5028 First.get(),
5029 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005030}
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregora16548e2009-08-11 05:31:07 +00005032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005033ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005034TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5035 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005036}
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregora16548e2009-08-11 05:31:07 +00005038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005040TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005041 TypeSourceInfo *OldT;
5042 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 {
5044 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005045 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5047 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005048
John McCall97513962010-01-15 18:39:57 +00005049 OldT = E->getTypeInfoAsWritten();
5050 NewT = getDerived().TransformType(OldT);
5051 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005052 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 }
Mike Stump11289f42009-09-09 15:08:12 +00005054
John McCalldadc5752010-08-24 06:29:42 +00005055 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005056 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005057 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005058 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005061 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005063 return SemaRef.Owned(E->Retain());
5064
Douglas Gregora16548e2009-08-11 05:31:07 +00005065 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005066 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5068 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5069 SourceLocation FakeRParenLoc
5070 = SemaRef.PP.getLocForEndOfToken(
5071 E->getSubExpr()->getSourceRange().getEnd());
5072 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005073 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005075 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 FakeRAngleLoc,
5077 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005078 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005079 FakeRParenLoc);
5080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005083ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5085 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005086}
Mike Stump11289f42009-09-09 15:08:12 +00005087
5088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005089ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005090TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5091 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005092}
5093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005095ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005096TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005097 CXXReinterpretCastExpr *E) {
5098 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005099}
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005103TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5104 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005105}
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005108ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005109TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005110 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005111 TypeSourceInfo *OldT;
5112 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 {
5114 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005115
John McCall97513962010-01-15 18:39:57 +00005116 OldT = E->getTypeInfoAsWritten();
5117 NewT = getDerived().TransformType(OldT);
5118 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 }
Mike Stump11289f42009-09-09 15:08:12 +00005121
John McCalldadc5752010-08-24 06:29:42 +00005122 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005123 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005128 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005130 return SemaRef.Owned(E->Retain());
5131
Douglas Gregor2b88c112010-09-08 00:15:04 +00005132 return getDerived().RebuildCXXFunctionalCastExpr(NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005134 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 E->getRParenLoc());
5136}
Mike Stump11289f42009-09-09 15:08:12 +00005137
Douglas Gregora16548e2009-08-11 05:31:07 +00005138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005140TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005142 TypeSourceInfo *TInfo
5143 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5144 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregora16548e2009-08-11 05:31:07 +00005147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005148 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregor9da64192010-04-26 22:37:10 +00005151 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5152 E->getLocStart(),
5153 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005154 E->getLocEnd());
5155 }
Mike Stump11289f42009-09-09 15:08:12 +00005156
Douglas Gregora16548e2009-08-11 05:31:07 +00005157 // We don't know whether the expression is potentially evaluated until
5158 // after we perform semantic analysis, so the expression is potentially
5159 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005160 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005161 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005162
John McCalldadc5752010-08-24 06:29:42 +00005163 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005165 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (!getDerived().AlwaysRebuild() &&
5168 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005169 return SemaRef.Owned(E->Retain());
5170
Douglas Gregor9da64192010-04-26 22:37:10 +00005171 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5172 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005173 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 E->getLocEnd());
5175}
5176
5177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005178ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005179TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5180 if (E->isTypeOperand()) {
5181 TypeSourceInfo *TInfo
5182 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5183 if (!TInfo)
5184 return ExprError();
5185
5186 if (!getDerived().AlwaysRebuild() &&
5187 TInfo == E->getTypeOperandSourceInfo())
5188 return SemaRef.Owned(E->Retain());
5189
5190 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5191 E->getLocStart(),
5192 TInfo,
5193 E->getLocEnd());
5194 }
5195
5196 // We don't know whether the expression is potentially evaluated until
5197 // after we perform semantic analysis, so the expression is potentially
5198 // potentially evaluated.
5199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5200
5201 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5202 if (SubExpr.isInvalid())
5203 return ExprError();
5204
5205 if (!getDerived().AlwaysRebuild() &&
5206 SubExpr.get() == E->getExprOperand())
5207 return SemaRef.Owned(E->Retain());
5208
5209 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5210 E->getLocStart(),
5211 SubExpr.get(),
5212 E->getLocEnd());
5213}
5214
5215template<typename Derived>
5216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005218 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregora16548e2009-08-11 05:31:07 +00005221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005222ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005223TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005224 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005225 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005226}
Mike Stump11289f42009-09-09 15:08:12 +00005227
Douglas Gregora16548e2009-08-11 05:31:07 +00005228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005230TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005231 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregora16548e2009-08-11 05:31:07 +00005233 QualType T = getDerived().TransformType(E->getType());
5234 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 if (!getDerived().AlwaysRebuild() &&
5238 T == E->getType())
5239 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005240
Douglas Gregorb15af892010-01-07 23:12:05 +00005241 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005242}
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005246TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005247 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregora16548e2009-08-11 05:31:07 +00005251 if (!getDerived().AlwaysRebuild() &&
5252 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005253 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005254
John McCallb268a282010-08-23 23:25:46 +00005255 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005256}
Mike Stump11289f42009-09-09 15:08:12 +00005257
Douglas Gregora16548e2009-08-11 05:31:07 +00005258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005260TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005261 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005262 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5263 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005264 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005265 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005266
Chandler Carruth794da4c2010-02-08 06:42:49 +00005267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 Param == E->getParam())
5269 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregor033f6752009-12-23 23:03:06 +00005271 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005272}
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005275ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005276TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5277 CXXScalarValueInitExpr *E) {
5278 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5279 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005280 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005281
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005283 T == E->getTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005284 return SemaRef.Owned(E->Retain());
5285
Douglas Gregor2b88c112010-09-08 00:15:04 +00005286 return getDerived().RebuildCXXScalarValueInitExpr(T,
5287 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005288 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005289}
Mike Stump11289f42009-09-09 15:08:12 +00005290
Douglas Gregora16548e2009-08-11 05:31:07 +00005291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005293TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005295 TypeSourceInfo *AllocTypeInfo
5296 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5297 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005299
Douglas Gregora16548e2009-08-11 05:31:07 +00005300 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005301 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 // Transform the placement arguments (if any).
5306 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005307 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005308 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005309 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5314 PlacementArgs.push_back(Arg.take());
5315 }
Mike Stump11289f42009-09-09 15:08:12 +00005316
Douglas Gregorebe10102009-08-20 07:17:43 +00005317 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005318 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005319 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005320 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5321 break;
5322
John McCalldadc5752010-08-24 06:29:42 +00005323 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregora16548e2009-08-11 05:31:07 +00005327 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5328 ConstructorArgs.push_back(Arg.take());
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
Douglas Gregord2d9da02010-02-26 00:38:10 +00005331 // Transform constructor, new operator, and delete operator.
5332 CXXConstructorDecl *Constructor = 0;
5333 if (E->getConstructor()) {
5334 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005335 getDerived().TransformDecl(E->getLocStart(),
5336 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005337 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005339 }
5340
5341 FunctionDecl *OperatorNew = 0;
5342 if (E->getOperatorNew()) {
5343 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005344 getDerived().TransformDecl(E->getLocStart(),
5345 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005346 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005347 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005348 }
5349
5350 FunctionDecl *OperatorDelete = 0;
5351 if (E->getOperatorDelete()) {
5352 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005353 getDerived().TransformDecl(E->getLocStart(),
5354 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005355 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005356 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005357 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005360 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005362 Constructor == E->getConstructor() &&
5363 OperatorNew == E->getOperatorNew() &&
5364 OperatorDelete == E->getOperatorDelete() &&
5365 !ArgumentChanged) {
5366 // Mark any declarations we need as referenced.
5367 // FIXME: instantiation-specific.
5368 if (Constructor)
5369 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5370 if (OperatorNew)
5371 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5372 if (OperatorDelete)
5373 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005374 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005375 }
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregor0744ef62010-09-07 21:49:58 +00005377 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005378 if (!ArraySize.get()) {
5379 // If no array size was specified, but the new expression was
5380 // instantiated with an array type (e.g., "new T" where T is
5381 // instantiated with "int[4]"), extract the outer bound from the
5382 // array type as our array size. We do this with constant and
5383 // dependently-sized array types.
5384 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5385 if (!ArrayT) {
5386 // Do nothing
5387 } else if (const ConstantArrayType *ConsArrayT
5388 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005389 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005390 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5391 ConsArrayT->getSize(),
5392 SemaRef.Context.getSizeType(),
5393 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005394 AllocType = ConsArrayT->getElementType();
5395 } else if (const DependentSizedArrayType *DepArrayT
5396 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5397 if (DepArrayT->getSizeExpr()) {
5398 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5399 AllocType = DepArrayT->getElementType();
5400 }
5401 }
5402 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005403
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5405 E->isGlobalNew(),
5406 /*FIXME:*/E->getLocStart(),
5407 move_arg(PlacementArgs),
5408 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005409 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005410 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005411 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005412 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 /*FIXME:*/E->getLocStart(),
5414 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005415 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005416}
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregora16548e2009-08-11 05:31:07 +00005418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005420TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005421 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005422 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005424
Douglas Gregord2d9da02010-02-26 00:38:10 +00005425 // Transform the delete operator, if known.
5426 FunctionDecl *OperatorDelete = 0;
5427 if (E->getOperatorDelete()) {
5428 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005429 getDerived().TransformDecl(E->getLocStart(),
5430 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005431 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005432 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005433 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005434
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005436 Operand.get() == E->getArgument() &&
5437 OperatorDelete == E->getOperatorDelete()) {
5438 // Mark any declarations we need as referenced.
5439 // FIXME: instantiation-specific.
5440 if (OperatorDelete)
5441 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005442 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005443 }
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregora16548e2009-08-11 05:31:07 +00005445 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5446 E->isGlobalDelete(),
5447 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005448 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005449}
Mike Stump11289f42009-09-09 15:08:12 +00005450
Douglas Gregora16548e2009-08-11 05:31:07 +00005451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005452ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005453TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005454 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005455 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005456 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005458
John McCallba7bf592010-08-24 05:47:05 +00005459 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005460 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005461 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005462 E->getOperatorLoc(),
5463 E->isArrow()? tok::arrow : tok::period,
5464 ObjectTypePtr,
5465 MayBePseudoDestructor);
5466 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005468
John McCallba7bf592010-08-24 05:47:05 +00005469 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005470 NestedNameSpecifier *Qualifier
5471 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005472 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005473 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005474 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005475 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005476
Douglas Gregor678f90d2010-02-25 01:56:36 +00005477 PseudoDestructorTypeStorage Destroyed;
5478 if (E->getDestroyedTypeInfo()) {
5479 TypeSourceInfo *DestroyedTypeInfo
5480 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5481 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005483 Destroyed = DestroyedTypeInfo;
5484 } else if (ObjectType->isDependentType()) {
5485 // We aren't likely to be able to resolve the identifier down to a type
5486 // now anyway, so just retain the identifier.
5487 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5488 E->getDestroyedTypeLoc());
5489 } else {
5490 // Look for a destructor known with the given name.
5491 CXXScopeSpec SS;
5492 if (Qualifier) {
5493 SS.setScopeRep(Qualifier);
5494 SS.setRange(E->getQualifierRange());
5495 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005496
John McCallba7bf592010-08-24 05:47:05 +00005497 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005498 *E->getDestroyedTypeIdentifier(),
5499 E->getDestroyedTypeLoc(),
5500 /*Scope=*/0,
5501 SS, ObjectTypePtr,
5502 false);
5503 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005505
Douglas Gregor678f90d2010-02-25 01:56:36 +00005506 Destroyed
5507 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5508 E->getDestroyedTypeLoc());
5509 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005510
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005511 TypeSourceInfo *ScopeTypeInfo = 0;
5512 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005513 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005514 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005515 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005516 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005517 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005518
John McCallb268a282010-08-23 23:25:46 +00005519 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005520 E->getOperatorLoc(),
5521 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005522 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005523 E->getQualifierRange(),
5524 ScopeTypeInfo,
5525 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005526 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005527 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005528}
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregorad8a3362009-09-04 17:36:40 +00005530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005531ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005532TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005533 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005534 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5535
5536 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5537 Sema::LookupOrdinaryName);
5538
5539 // Transform all the decls.
5540 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5541 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005542 NamedDecl *InstD = static_cast<NamedDecl*>(
5543 getDerived().TransformDecl(Old->getNameLoc(),
5544 *I));
John McCall84d87672009-12-10 09:41:52 +00005545 if (!InstD) {
5546 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5547 // This can happen because of dependent hiding.
5548 if (isa<UsingShadowDecl>(*I))
5549 continue;
5550 else
John McCallfaf5fb42010-08-26 23:41:50 +00005551 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005552 }
John McCalle66edc12009-11-24 19:00:30 +00005553
5554 // Expand using declarations.
5555 if (isa<UsingDecl>(InstD)) {
5556 UsingDecl *UD = cast<UsingDecl>(InstD);
5557 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5558 E = UD->shadow_end(); I != E; ++I)
5559 R.addDecl(*I);
5560 continue;
5561 }
5562
5563 R.addDecl(InstD);
5564 }
5565
5566 // Resolve a kind, but don't do any further analysis. If it's
5567 // ambiguous, the callee needs to deal with it.
5568 R.resolveKind();
5569
5570 // Rebuild the nested-name qualifier, if present.
5571 CXXScopeSpec SS;
5572 NestedNameSpecifier *Qualifier = 0;
5573 if (Old->getQualifier()) {
5574 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005575 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005576 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005577 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005578
John McCalle66edc12009-11-24 19:00:30 +00005579 SS.setScopeRep(Qualifier);
5580 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005581 }
5582
Douglas Gregor9262f472010-04-27 18:19:34 +00005583 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005584 CXXRecordDecl *NamingClass
5585 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5586 Old->getNameLoc(),
5587 Old->getNamingClass()));
5588 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005589 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005590
Douglas Gregorda7be082010-04-27 16:10:10 +00005591 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005592 }
5593
5594 // If we have no template arguments, it's a normal declaration name.
5595 if (!Old->hasExplicitTemplateArgs())
5596 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5597
5598 // If we have template arguments, rebuild them, then rebuild the
5599 // templateid expression.
5600 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5601 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5602 TemplateArgumentLoc Loc;
5603 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005605 TransArgs.addArgument(Loc);
5606 }
5607
5608 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5609 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005610}
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregora16548e2009-08-11 05:31:07 +00005612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005614TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005615 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5616 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005620 T == E->getQueriedTypeSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005621 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005622
Mike Stump11289f42009-09-09 15:08:12 +00005623 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 T,
5626 E->getLocEnd());
5627}
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregora16548e2009-08-11 05:31:07 +00005629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005630ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005631TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005632 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005634 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005635 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005638
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005639 DeclarationNameInfo NameInfo
5640 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5641 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005642 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005643
John McCalle66edc12009-11-24 19:00:30 +00005644 if (!E->hasExplicitTemplateArgs()) {
5645 if (!getDerived().AlwaysRebuild() &&
5646 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005647 // Note: it is sufficient to compare the Name component of NameInfo:
5648 // if name has not changed, DNLoc has not changed either.
5649 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005650 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005651
John McCalle66edc12009-11-24 19:00:30 +00005652 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5653 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005654 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005655 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005656 }
John McCall6b51f282009-11-23 01:53:49 +00005657
5658 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005660 TemplateArgumentLoc Loc;
5661 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005663 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 }
5665
John McCalle66edc12009-11-24 19:00:30 +00005666 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5667 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005668 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005669 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005670}
5671
5672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005673ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005674TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005675 // CXXConstructExprs are always implicit, so when we have a
5676 // 1-argument construction we just transform that argument.
5677 if (E->getNumArgs() == 1 ||
5678 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5679 return getDerived().TransformExpr(E->getArg(0));
5680
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5682
5683 QualType T = getDerived().TransformType(E->getType());
5684 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005685 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005686
5687 CXXConstructorDecl *Constructor
5688 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005689 getDerived().TransformDecl(E->getLocStart(),
5690 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregora16548e2009-08-11 05:31:07 +00005694 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005695 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005696 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 ArgEnd = E->arg_end();
5698 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005699 if (getDerived().DropCallArgument(*Arg)) {
5700 ArgumentChanged = true;
5701 break;
5702 }
5703
John McCalldadc5752010-08-24 06:29:42 +00005704 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005707
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005709 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 }
5711
5712 if (!getDerived().AlwaysRebuild() &&
5713 T == E->getType() &&
5714 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005715 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005716 // Mark the constructor as referenced.
5717 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005718 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005720 }
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregordb121ba2009-12-14 16:27:04 +00005722 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5723 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005724 move_arg(Args),
5725 E->requiresZeroInitialization(),
5726 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005727}
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregora16548e2009-08-11 05:31:07 +00005729/// \brief Transform a C++ temporary-binding expression.
5730///
Douglas Gregor363b1512009-12-24 18:51:59 +00005731/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5732/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005735TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005736 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005737}
Mike Stump11289f42009-09-09 15:08:12 +00005738
5739/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005740/// be destroyed after the expression is evaluated.
5741///
Douglas Gregor363b1512009-12-24 18:51:59 +00005742/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5743/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005745ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005746TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005747 CXXExprWithTemporaries *E) {
5748 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005749}
Mike Stump11289f42009-09-09 15:08:12 +00005750
Douglas Gregora16548e2009-08-11 05:31:07 +00005751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005752ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005753TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005754 CXXTemporaryObjectExpr *E) {
5755 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5756 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005757 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 CXXConstructorDecl *Constructor
5760 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005761 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005762 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005763 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005764 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005765
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005767 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005769 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 ArgEnd = E->arg_end();
5771 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005772 if (getDerived().DropCallArgument(*Arg)) {
5773 ArgumentChanged = true;
5774 break;
5775 }
5776
John McCalldadc5752010-08-24 06:29:42 +00005777 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005780
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5782 Args.push_back((Expr *)TransArg.release());
5783 }
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005786 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005788 !ArgumentChanged) {
5789 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005790 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005791 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005792 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005793
5794 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5795 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005796 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 E->getLocEnd());
5798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005802TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005803 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005804 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5805 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005809 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5811 ArgEnd = E->arg_end();
5812 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005813 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005818 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005819 }
Mike Stump11289f42009-09-09 15:08:12 +00005820
Douglas Gregora16548e2009-08-11 05:31:07 +00005821 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005822 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005824 return SemaRef.Owned(E->Retain());
5825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005827 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 E->getLParenLoc(),
5829 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 E->getRParenLoc());
5831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregora16548e2009-08-11 05:31:07 +00005833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005835TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005836 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005838 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005839 Expr *OldBase;
5840 QualType BaseType;
5841 QualType ObjectType;
5842 if (!E->isImplicitAccess()) {
5843 OldBase = E->getBase();
5844 Base = getDerived().TransformExpr(OldBase);
5845 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005846 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005847
John McCall2d74de92009-12-01 22:10:20 +00005848 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005849 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005850 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005851 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005852 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005853 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005854 ObjectTy,
5855 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005856 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005858
John McCallba7bf592010-08-24 05:47:05 +00005859 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005860 BaseType = ((Expr*) Base.get())->getType();
5861 } else {
5862 OldBase = 0;
5863 BaseType = getDerived().TransformType(E->getBaseType());
5864 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5865 }
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005867 // Transform the first part of the nested-name-specifier that qualifies
5868 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005869 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005870 = getDerived().TransformFirstQualifierInScope(
5871 E->getFirstQualifierFoundInScope(),
5872 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005874 NestedNameSpecifier *Qualifier = 0;
5875 if (E->getQualifier()) {
5876 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5877 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005878 ObjectType,
5879 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005880 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005881 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005882 }
Mike Stump11289f42009-09-09 15:08:12 +00005883
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005884 DeclarationNameInfo NameInfo
5885 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5886 ObjectType);
5887 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
John McCall2d74de92009-12-01 22:10:20 +00005890 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005891 // This is a reference to a member without an explicitly-specified
5892 // template argument list. Optimize for this common case.
5893 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005894 Base.get() == OldBase &&
5895 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005896 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005897 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005898 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005899 return SemaRef.Owned(E->Retain());
5900
John McCallb268a282010-08-23 23:25:46 +00005901 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005902 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005903 E->isArrow(),
5904 E->getOperatorLoc(),
5905 Qualifier,
5906 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005907 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005908 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005909 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005910 }
5911
John McCall6b51f282009-11-23 01:53:49 +00005912 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005913 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005914 TemplateArgumentLoc Loc;
5915 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005917 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005918 }
Mike Stump11289f42009-09-09 15:08:12 +00005919
John McCallb268a282010-08-23 23:25:46 +00005920 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005921 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 E->isArrow(),
5923 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005924 Qualifier,
5925 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005926 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005927 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005928 &TransArgs);
5929}
5930
5931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005932ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005933TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005934 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005935 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005936 QualType BaseType;
5937 if (!Old->isImplicitAccess()) {
5938 Base = getDerived().TransformExpr(Old->getBase());
5939 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005940 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005941 BaseType = ((Expr*) Base.get())->getType();
5942 } else {
5943 BaseType = getDerived().TransformType(Old->getBaseType());
5944 }
John McCall10eae182009-11-30 22:42:35 +00005945
5946 NestedNameSpecifier *Qualifier = 0;
5947 if (Old->getQualifier()) {
5948 Qualifier
5949 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005950 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005951 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005953 }
5954
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005955 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005956 Sema::LookupOrdinaryName);
5957
5958 // Transform all the decls.
5959 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5960 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005961 NamedDecl *InstD = static_cast<NamedDecl*>(
5962 getDerived().TransformDecl(Old->getMemberLoc(),
5963 *I));
John McCall84d87672009-12-10 09:41:52 +00005964 if (!InstD) {
5965 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5966 // This can happen because of dependent hiding.
5967 if (isa<UsingShadowDecl>(*I))
5968 continue;
5969 else
John McCallfaf5fb42010-08-26 23:41:50 +00005970 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005971 }
John McCall10eae182009-11-30 22:42:35 +00005972
5973 // Expand using declarations.
5974 if (isa<UsingDecl>(InstD)) {
5975 UsingDecl *UD = cast<UsingDecl>(InstD);
5976 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5977 E = UD->shadow_end(); I != E; ++I)
5978 R.addDecl(*I);
5979 continue;
5980 }
5981
5982 R.addDecl(InstD);
5983 }
5984
5985 R.resolveKind();
5986
Douglas Gregor9262f472010-04-27 18:19:34 +00005987 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005988 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005989 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005990 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005991 Old->getMemberLoc(),
5992 Old->getNamingClass()));
5993 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005995
Douglas Gregorda7be082010-04-27 16:10:10 +00005996 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005997 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005998
John McCall10eae182009-11-30 22:42:35 +00005999 TemplateArgumentListInfo TransArgs;
6000 if (Old->hasExplicitTemplateArgs()) {
6001 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6002 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6003 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6004 TemplateArgumentLoc Loc;
6005 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6006 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006008 TransArgs.addArgument(Loc);
6009 }
6010 }
John McCall38836f02010-01-15 08:34:02 +00006011
6012 // FIXME: to do this check properly, we will need to preserve the
6013 // first-qualifier-in-scope here, just in case we had a dependent
6014 // base (and therefore couldn't do the check) and a
6015 // nested-name-qualifier (and therefore could do the lookup).
6016 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006017
John McCallb268a282010-08-23 23:25:46 +00006018 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006019 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006020 Old->getOperatorLoc(),
6021 Old->isArrow(),
6022 Qualifier,
6023 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006024 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006025 R,
6026 (Old->hasExplicitTemplateArgs()
6027 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006028}
6029
6030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006031ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006032TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006033 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006034}
6035
Mike Stump11289f42009-09-09 15:08:12 +00006036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006038TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006039 TypeSourceInfo *EncodedTypeInfo
6040 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6041 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006045 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006046 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006047
6048 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006049 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006050 E->getRParenLoc());
6051}
Mike Stump11289f42009-09-09 15:08:12 +00006052
Douglas Gregora16548e2009-08-11 05:31:07 +00006053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006054ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006055TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006056 // Transform arguments.
6057 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006058 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006059 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006060 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006061 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006063
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006064 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006065 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006066 }
6067
6068 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6069 // Class message: transform the receiver type.
6070 TypeSourceInfo *ReceiverTypeInfo
6071 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6072 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006074
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006075 // If nothing changed, just retain the existing message send.
6076 if (!getDerived().AlwaysRebuild() &&
6077 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6078 return SemaRef.Owned(E->Retain());
6079
6080 // Build a new class message send.
6081 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6082 E->getSelector(),
6083 E->getMethodDecl(),
6084 E->getLeftLoc(),
6085 move_arg(Args),
6086 E->getRightLoc());
6087 }
6088
6089 // Instance message: transform the receiver
6090 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6091 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006092 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006093 = getDerived().TransformExpr(E->getInstanceReceiver());
6094 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006096
6097 // If nothing changed, just retain the existing message send.
6098 if (!getDerived().AlwaysRebuild() &&
6099 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6100 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006101
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006102 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006103 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006104 E->getSelector(),
6105 E->getMethodDecl(),
6106 E->getLeftLoc(),
6107 move_arg(Args),
6108 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006109}
6110
Mike Stump11289f42009-09-09 15:08:12 +00006111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006114 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006115}
6116
Mike Stump11289f42009-09-09 15:08:12 +00006117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006118ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006120 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006121}
6122
Mike Stump11289f42009-09-09 15:08:12 +00006123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006125TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006126 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006127 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006128 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006130
6131 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006132
Douglas Gregord51d90d2010-04-26 20:11:03 +00006133 // If nothing changed, just retain the existing expression.
6134 if (!getDerived().AlwaysRebuild() &&
6135 Base.get() == E->getBase())
6136 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006137
John McCallb268a282010-08-23 23:25:46 +00006138 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006139 E->getLocation(),
6140 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006141}
6142
Mike Stump11289f42009-09-09 15:08:12 +00006143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006144ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006145TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006146 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006147 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006148 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006150
Douglas Gregor9faee212010-04-26 20:47:02 +00006151 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006152
Douglas Gregor9faee212010-04-26 20:47:02 +00006153 // If nothing changed, just retain the existing expression.
6154 if (!getDerived().AlwaysRebuild() &&
6155 Base.get() == E->getBase())
6156 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006157
John McCallb268a282010-08-23 23:25:46 +00006158 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006159 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006160}
6161
Mike Stump11289f42009-09-09 15:08:12 +00006162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006163ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006164TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006165 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006166 // If this implicit setter/getter refers to class methods, it cannot have any
6167 // dependent parts. Just retain the existing declaration.
6168 if (E->getInterfaceDecl())
6169 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006170
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006171 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006172 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006173 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006175
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006176 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006177
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006178 // If nothing changed, just retain the existing expression.
6179 if (!getDerived().AlwaysRebuild() &&
6180 Base.get() == E->getBase())
6181 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006182
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006183 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6184 E->getGetterMethod(),
6185 E->getType(),
6186 E->getSetterMethod(),
6187 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006188 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006189
Douglas Gregora16548e2009-08-11 05:31:07 +00006190}
6191
Mike Stump11289f42009-09-09 15:08:12 +00006192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006195 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006196 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006197}
6198
Mike Stump11289f42009-09-09 15:08:12 +00006199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006200ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006201TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006202 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006203 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006204 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006206
Douglas Gregord51d90d2010-04-26 20:11:03 +00006207 // If nothing changed, just retain the existing expression.
6208 if (!getDerived().AlwaysRebuild() &&
6209 Base.get() == E->getBase())
6210 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006211
John McCallb268a282010-08-23 23:25:46 +00006212 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006213 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006214}
6215
Mike Stump11289f42009-09-09 15:08:12 +00006216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006218TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006219 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006220 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006222 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregora16548e2009-08-11 05:31:07 +00006226 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006227 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 }
Mike Stump11289f42009-09-09 15:08:12 +00006229
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 if (!getDerived().AlwaysRebuild() &&
6231 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006232 return SemaRef.Owned(E->Retain());
6233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6235 move_arg(SubExprs),
6236 E->getRParenLoc());
6237}
6238
Mike Stump11289f42009-09-09 15:08:12 +00006239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006241TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006242 SourceLocation CaretLoc(E->getExprLoc());
6243
6244 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6245 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6246 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6247 llvm::SmallVector<ParmVarDecl*, 4> Params;
6248 llvm::SmallVector<QualType, 4> ParamTypes;
6249
6250 // Parameter substitution.
6251 const BlockDecl *BD = E->getBlockDecl();
6252 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6253 EN = BD->param_end(); P != EN; ++P) {
6254 ParmVarDecl *OldParm = (*P);
6255 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6256 QualType NewType = NewParm->getType();
6257 Params.push_back(NewParm);
6258 ParamTypes.push_back(NewParm->getType());
6259 }
6260
6261 const FunctionType *BExprFunctionType = E->getFunctionType();
6262 QualType BExprResultType = BExprFunctionType->getResultType();
6263 if (!BExprResultType.isNull()) {
6264 if (!BExprResultType->isDependentType())
6265 CurBlock->ReturnType = BExprResultType;
6266 else if (BExprResultType != SemaRef.Context.DependentTy)
6267 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6268 }
6269
6270 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006271 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006272 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006273 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006274 // Set the parameters on the block decl.
6275 if (!Params.empty())
6276 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6277
6278 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6279 CurBlock->ReturnType,
6280 ParamTypes.data(),
6281 ParamTypes.size(),
6282 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006283 0,
6284 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006285
6286 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006287 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006288}
6289
Mike Stump11289f42009-09-09 15:08:12 +00006290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006292TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006293 NestedNameSpecifier *Qualifier = 0;
6294
6295 ValueDecl *ND
6296 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6297 E->getDecl()));
6298 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006300
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006301 if (!getDerived().AlwaysRebuild() &&
6302 ND == E->getDecl()) {
6303 // Mark it referenced in the new context regardless.
6304 // FIXME: this is a bit instantiation-specific.
6305 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6306
6307 return SemaRef.Owned(E->Retain());
6308 }
6309
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006310 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006311 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006312 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006313}
Mike Stump11289f42009-09-09 15:08:12 +00006314
Douglas Gregora16548e2009-08-11 05:31:07 +00006315//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006316// Type reconstruction
6317//===----------------------------------------------------------------------===//
6318
Mike Stump11289f42009-09-09 15:08:12 +00006319template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006320QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6321 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006322 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006323 getDerived().getBaseEntity());
6324}
6325
Mike Stump11289f42009-09-09 15:08:12 +00006326template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006327QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6328 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006329 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006330 getDerived().getBaseEntity());
6331}
6332
Mike Stump11289f42009-09-09 15:08:12 +00006333template<typename Derived>
6334QualType
John McCall70dd5f62009-10-30 00:06:24 +00006335TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6336 bool WrittenAsLValue,
6337 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006338 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006339 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006340}
6341
6342template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006343QualType
John McCall70dd5f62009-10-30 00:06:24 +00006344TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6345 QualType ClassType,
6346 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006347 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006348 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006349}
6350
6351template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006352QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6354 ArrayType::ArraySizeModifier SizeMod,
6355 const llvm::APInt *Size,
6356 Expr *SizeExpr,
6357 unsigned IndexTypeQuals,
6358 SourceRange BracketsRange) {
6359 if (SizeExpr || !Size)
6360 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6361 IndexTypeQuals, BracketsRange,
6362 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006363
6364 QualType Types[] = {
6365 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6366 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6367 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006368 };
6369 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6370 QualType SizeType;
6371 for (unsigned I = 0; I != NumTypes; ++I)
6372 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6373 SizeType = Types[I];
6374 break;
6375 }
Mike Stump11289f42009-09-09 15:08:12 +00006376
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006377 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6378 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006379 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006380 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006381 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006382}
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregord6ff3322009-08-04 16:50:30 +00006384template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006385QualType
6386TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006387 ArrayType::ArraySizeModifier SizeMod,
6388 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006389 unsigned IndexTypeQuals,
6390 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006391 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006392 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006393}
6394
6395template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006396QualType
Mike Stump11289f42009-09-09 15:08:12 +00006397TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006398 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006399 unsigned IndexTypeQuals,
6400 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006401 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006402 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006403}
Mike Stump11289f42009-09-09 15:08:12 +00006404
Douglas Gregord6ff3322009-08-04 16:50:30 +00006405template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006406QualType
6407TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006408 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006409 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410 unsigned IndexTypeQuals,
6411 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006412 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006413 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414 IndexTypeQuals, BracketsRange);
6415}
6416
6417template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006418QualType
6419TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006420 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006421 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006422 unsigned IndexTypeQuals,
6423 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006424 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006425 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426 IndexTypeQuals, BracketsRange);
6427}
6428
6429template<typename Derived>
6430QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006431 unsigned NumElements,
6432 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006433 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006434 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregord6ff3322009-08-04 16:50:30 +00006437template<typename Derived>
6438QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6439 unsigned NumElements,
6440 SourceLocation AttributeLoc) {
6441 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6442 NumElements, true);
6443 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006444 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6445 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006446 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregord6ff3322009-08-04 16:50:30 +00006449template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006450QualType
6451TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006452 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006453 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006454 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006455}
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregord6ff3322009-08-04 16:50:30 +00006457template<typename Derived>
6458QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006459 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006460 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006461 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006462 unsigned Quals,
6463 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006464 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006465 Quals,
6466 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006467 getDerived().getBaseEntity(),
6468 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006469}
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregord6ff3322009-08-04 16:50:30 +00006471template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006472QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6473 return SemaRef.Context.getFunctionNoProtoType(T);
6474}
6475
6476template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006477QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6478 assert(D && "no decl found");
6479 if (D->isInvalidDecl()) return QualType();
6480
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006481 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006482 TypeDecl *Ty;
6483 if (isa<UsingDecl>(D)) {
6484 UsingDecl *Using = cast<UsingDecl>(D);
6485 assert(Using->isTypeName() &&
6486 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6487
6488 // A valid resolved using typename decl points to exactly one type decl.
6489 assert(++Using->shadow_begin() == Using->shadow_end());
6490 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006491
John McCallb96ec562009-12-04 22:46:56 +00006492 } else {
6493 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6494 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6495 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6496 }
6497
6498 return SemaRef.Context.getTypeDeclType(Ty);
6499}
6500
6501template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006502QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6503 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006504}
6505
6506template<typename Derived>
6507QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6508 return SemaRef.Context.getTypeOfType(Underlying);
6509}
6510
6511template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006512QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6513 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006514}
6515
6516template<typename Derived>
6517QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006518 TemplateName Template,
6519 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006520 const TemplateArgumentListInfo &TemplateArgs) {
6521 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006522}
Mike Stump11289f42009-09-09 15:08:12 +00006523
Douglas Gregor1135c352009-08-06 05:28:30 +00006524template<typename Derived>
6525NestedNameSpecifier *
6526TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6527 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006528 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006529 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006530 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006531 CXXScopeSpec SS;
6532 // FIXME: The source location information is all wrong.
6533 SS.setRange(Range);
6534 SS.setScopeRep(Prefix);
6535 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006536 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006537 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006538 ObjectType,
6539 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006540 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006541}
6542
6543template<typename Derived>
6544NestedNameSpecifier *
6545TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6546 SourceRange Range,
6547 NamespaceDecl *NS) {
6548 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6549}
6550
6551template<typename Derived>
6552NestedNameSpecifier *
6553TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6554 SourceRange Range,
6555 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006556 QualType T) {
6557 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006558 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006559 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006560 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6561 T.getTypePtr());
6562 }
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregor1135c352009-08-06 05:28:30 +00006564 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6565 return 0;
6566}
Mike Stump11289f42009-09-09 15:08:12 +00006567
Douglas Gregor71dc5092009-08-06 06:41:21 +00006568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006569TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006570TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6571 bool TemplateKW,
6572 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006573 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006574 Template);
6575}
6576
6577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006578TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006579TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006580 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006581 const IdentifierInfo &II,
6582 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006583 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006584 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006585 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006586 UnqualifiedId Name;
6587 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006588 Sema::TemplateTy Template;
6589 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6590 /*FIXME:*/getDerived().getBaseLocation(),
6591 SS,
6592 Name,
John McCallba7bf592010-08-24 05:47:05 +00006593 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006594 /*EnteringContext=*/false,
6595 Template);
6596 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006597}
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregora16548e2009-08-11 05:31:07 +00006599template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006600TemplateName
6601TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6602 OverloadedOperatorKind Operator,
6603 QualType ObjectType) {
6604 CXXScopeSpec SS;
6605 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6606 SS.setScopeRep(Qualifier);
6607 UnqualifiedId Name;
6608 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6609 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6610 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006611 Sema::TemplateTy Template;
6612 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006613 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006614 SS,
6615 Name,
John McCallba7bf592010-08-24 05:47:05 +00006616 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006617 /*EnteringContext=*/false,
6618 Template);
6619 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006620}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006621
Douglas Gregor71395fa2009-11-04 00:56:37 +00006622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006624TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6625 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006626 Expr *OrigCallee,
6627 Expr *First,
6628 Expr *Second) {
6629 Expr *Callee = OrigCallee->IgnoreParenCasts();
6630 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006631
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006633 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006634 if (!First->getType()->isOverloadableType() &&
6635 !Second->getType()->isOverloadableType())
6636 return getSema().CreateBuiltinArraySubscriptExpr(First,
6637 Callee->getLocStart(),
6638 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006639 } else if (Op == OO_Arrow) {
6640 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006641 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6642 } else if (Second == 0 || isPostIncDec) {
6643 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006644 // The argument is not of overloadable type, so try to create a
6645 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006646 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006647 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006648
John McCallb268a282010-08-23 23:25:46 +00006649 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006650 }
6651 } else {
John McCallb268a282010-08-23 23:25:46 +00006652 if (!First->getType()->isOverloadableType() &&
6653 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 // Neither of the arguments is an overloadable type, so try to
6655 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006656 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006657 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006658 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006661
Douglas Gregora16548e2009-08-11 05:31:07 +00006662 return move(Result);
6663 }
6664 }
Mike Stump11289f42009-09-09 15:08:12 +00006665
6666 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006668 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006669
John McCallb268a282010-08-23 23:25:46 +00006670 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006671 assert(ULE->requiresADL());
6672
6673 // FIXME: Do we have to check
6674 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006675 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006676 } else {
John McCallb268a282010-08-23 23:25:46 +00006677 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006678 }
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006681 Expr *Args[2] = { First, Second };
6682 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006683
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 // Create the overloaded operator invocation for unary operators.
6685 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006686 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006688 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 }
Mike Stump11289f42009-09-09 15:08:12 +00006690
Sebastian Redladba46e2009-10-29 20:17:01 +00006691 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006692 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006693 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006694 First,
6695 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006698 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006699 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6701 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006703
Mike Stump11289f42009-09-09 15:08:12 +00006704 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006705}
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006708ExprResult
John McCallb268a282010-08-23 23:25:46 +00006709TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006710 SourceLocation OperatorLoc,
6711 bool isArrow,
6712 NestedNameSpecifier *Qualifier,
6713 SourceRange QualifierRange,
6714 TypeSourceInfo *ScopeType,
6715 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006716 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006717 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006718 CXXScopeSpec SS;
6719 if (Qualifier) {
6720 SS.setRange(QualifierRange);
6721 SS.setScopeRep(Qualifier);
6722 }
6723
John McCallb268a282010-08-23 23:25:46 +00006724 QualType BaseType = Base->getType();
6725 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006726 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006727 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006728 !BaseType->getAs<PointerType>()->getPointeeType()
6729 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006730 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006731 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006732 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006733 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006734 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006735 /*FIXME?*/true);
6736 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006737
Douglas Gregor678f90d2010-02-25 01:56:36 +00006738 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006739 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6740 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6741 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6742 NameInfo.setNamedTypeInfo(DestroyedType);
6743
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006744 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006745
John McCallb268a282010-08-23 23:25:46 +00006746 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006747 OperatorLoc, isArrow,
6748 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006749 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006750 /*TemplateArgs*/ 0);
6751}
6752
Douglas Gregord6ff3322009-08-04 16:50:30 +00006753} // end namespace clang
6754
6755#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H