blob: 746d6ca04cc8ada9bdb89cbeddc1a1d6304d284f [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,
537 NestedNameSpecifier *NNS,
538 const IdentifierInfo *Name,
539 SourceLocation NameLoc,
540 const TemplateArgumentListInfo &Args) {
541 // Rebuild the template name.
542 // TODO: avoid TemplateName abstraction
543 TemplateName InstName =
544 getDerived().RebuildTemplateName(NNS, *Name, QualType());
545
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000546 if (InstName.isNull())
547 return QualType();
548
John McCallc392f372010-06-11 00:33:02 +0000549 // If it's still dependent, make a dependent specialization.
550 if (InstName.getAsDependentTemplateName())
551 return SemaRef.Context.getDependentTemplateSpecializationType(
552 Keyword, NNS, Name, Args);
553
554 // Otherwise, make an elaborated type wrapping a non-dependent
555 // specialization.
556 QualType T =
557 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
558 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000559
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000560 // NOTE: NNS is already recorded in template specialization type T.
561 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000562 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563
564 /// \brief Build a new typename type that refers to an identifier.
565 ///
566 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000567 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000575 CXXScopeSpec SS;
576 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SS.setRange(NNSRange);
578
Douglas Gregore677daf2010-03-31 22:19:08 +0000579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
583 }
584
Abramo Bagnara6150c882010-05-11 21:36:43 +0000585 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000588
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
590
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
John McCallbf8c5192010-05-27 06:40:31 +0000599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
600 return QualType();
601
Douglas Gregore677daf2010-03-31 22:19:08 +0000602 TagDecl *Tag = 0;
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
607 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000608
Douglas Gregore677daf2010-03-31 22:19:08 +0000609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
611 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000612
Douglas Gregore677daf2010-03-31 22:19:08 +0000613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
616 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
620 return QualType();
621 }
622
623 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000624 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000627 return QualType();
628 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000629
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
633 return QualType();
634 }
635
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
643 ///
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
648 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000649 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000650 QualType ObjectType,
651 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000652
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
655 ///
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
660 SourceRange Range,
661 NamespaceDecl *NS);
662
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
665 ///
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
670 SourceRange Range,
671 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000672 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000673
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
677 ///
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
681 bool TemplateKW,
682 TemplateDecl *Template);
683
Douglas Gregor71dc5092009-08-06 06:41:21 +0000684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
686 ///
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
690 /// behavior.
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000692 const IdentifierInfo &II,
693 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Douglas Gregor71395fa2009-11-04 00:56:37 +0000695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
697 ///
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
701 /// behavior.
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000705
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 /// \brief Build a new compound statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000710 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
713 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000715 IsStmtExpr);
716 }
717
718 /// \brief Build a new case statement.
719 ///
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000722 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000723 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000725 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000727 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 ColonLoc);
729 }
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 /// \brief Attach the body to a new case statement.
732 ///
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000735 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000736 getSema().ActOnCaseStmtBody(S, Body);
737 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000738 }
Mike Stump11289f42009-09-09 15:08:12 +0000739
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 /// \brief Build a new default statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000744 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000746 Stmt *SubStmt) {
747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 /*CurScope=*/0);
749 }
Mike Stump11289f42009-09-09 15:08:12 +0000750
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 /// \brief Build a new label statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000755 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 IdentifierInfo *Id,
757 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000758 Stmt *SubStmt) {
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new "if" statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000766 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
John McCallb268a282010-08-23 23:25:46 +0000767 VarDecl *CondVar, Stmt *Then,
768 SourceLocation ElseLoc, Stmt *Else) {
769 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 /// \brief Start building a new switch statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000776 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000777 Expr *Cond, VarDecl *CondVar) {
778 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000779 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 }
Mike Stump11289f42009-09-09 15:08:12 +0000781
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 /// \brief Attach the body to the switch statement.
783 ///
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000786 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000787 Stmt *Switch, Stmt *Body) {
788 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 }
790
791 /// \brief Build a new while statement.
792 ///
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000795 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000796 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000797 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000798 Stmt *Body) {
799 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000800 }
Mike Stump11289f42009-09-09 15:08:12 +0000801
Douglas Gregorebe10102009-08-20 07:17:43 +0000802 /// \brief Build a new do-while statement.
803 ///
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000806 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 SourceLocation WhileLoc,
808 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000809 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000811 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
812 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 }
814
815 /// \brief Build a new for statement.
816 ///
817 /// By default, performs semantic analysis to build the new statement.
818 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000819 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000820 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000821 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000822 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000823 SourceLocation RParenLoc, Stmt *Body) {
824 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000825 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000826 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 }
Mike Stump11289f42009-09-09 15:08:12 +0000828
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 /// \brief Build a new goto statement.
830 ///
831 /// By default, performs semantic analysis to build the new statement.
832 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000833 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 SourceLocation LabelLoc,
835 LabelStmt *Label) {
836 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
837 }
838
839 /// \brief Build a new indirect goto statement.
840 ///
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000843 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000845 Expr *Target) {
846 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 }
Mike Stump11289f42009-09-09 15:08:12 +0000848
Douglas Gregorebe10102009-08-20 07:17:43 +0000849 /// \brief Build a new return statement.
850 ///
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000853 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000854 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000855
John McCallb268a282010-08-23 23:25:46 +0000856 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 }
Mike Stump11289f42009-09-09 15:08:12 +0000858
Douglas Gregorebe10102009-08-20 07:17:43 +0000859 /// \brief Build a new declaration statement.
860 ///
861 /// By default, performs semantic analysis to build the new statement.
862 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000863 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000864 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 SourceLocation EndLoc) {
866 return getSema().Owned(
867 new (getSema().Context) DeclStmt(
868 DeclGroupRef::Create(getSema().Context,
869 Decls, NumDecls),
870 StartLoc, EndLoc));
871 }
Mike Stump11289f42009-09-09 15:08:12 +0000872
Anders Carlssonaaeef072010-01-24 05:50:09 +0000873 /// \brief Build a new inline asm statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000877 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000878 bool IsSimple,
879 bool IsVolatile,
880 unsigned NumOutputs,
881 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000882 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000883 MultiExprArg Constraints,
884 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000885 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000886 MultiExprArg Clobbers,
887 SourceLocation RParenLoc,
888 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000889 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000890 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000891 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000892 RParenLoc, MSAsm);
893 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000894
895 /// \brief Build a new Objective-C @try statement.
896 ///
897 /// By default, performs semantic analysis to build the new statement.
898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000899 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000900 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000901 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +0000902 Stmt *Finally) {
903 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
904 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000905 }
906
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000907 /// \brief Rebuild an Objective-C exception declaration.
908 ///
909 /// By default, performs semantic analysis to build the new declaration.
910 /// Subclasses may override this routine to provide different behavior.
911 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
912 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000913 return getSema().BuildObjCExceptionDecl(TInfo, T,
914 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000915 ExceptionDecl->getLocation());
916 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000917
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000918 /// \brief Build a new Objective-C @catch statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000922 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000923 SourceLocation RParenLoc,
924 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +0000925 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000926 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000927 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000928 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000929
Douglas Gregor306de2f2010-04-22 23:59:56 +0000930 /// \brief Build a new Objective-C @finally statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000934 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000935 Stmt *Body) {
936 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +0000937 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000938
Douglas Gregor6148de72010-04-22 22:01:21 +0000939 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000940 ///
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000943 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000944 Expr *Operand) {
945 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +0000946 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000947
Douglas Gregor6148de72010-04-22 22:01:21 +0000948 /// \brief Build a new Objective-C @synchronized statement.
949 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000950 /// By default, performs semantic analysis to build the new statement.
951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000952 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +0000953 Expr *Object,
954 Stmt *Body) {
955 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
956 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +0000957 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000958
959 /// \brief Build a new Objective-C fast enumeration statement.
960 ///
961 /// By default, performs semantic analysis to build the new statement.
962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000963 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000964 SourceLocation LParenLoc,
965 Stmt *Element,
966 Expr *Collection,
967 SourceLocation RParenLoc,
968 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +0000969 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000970 Element,
971 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +0000972 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000973 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +0000974 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000975
Douglas Gregorebe10102009-08-20 07:17:43 +0000976 /// \brief Build a new C++ exception declaration.
977 ///
978 /// By default, performs semantic analysis to build the new decaration.
979 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000980 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000981 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 IdentifierInfo *Name,
983 SourceLocation Loc,
984 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000985 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 TypeRange);
987 }
988
989 /// \brief Build a new C++ catch statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +0000994 VarDecl *ExceptionDecl,
995 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +0000996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
997 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +0000998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new C++ try statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001005 Stmt *TryBlock,
1006 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001007 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// \brief Build a new expression that references a declaration.
1011 ///
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001014 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001015 LookupResult &R,
1016 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001017 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1018 }
1019
1020
1021 /// \brief Build a new expression that references a declaration.
1022 ///
1023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001025 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001026 SourceRange QualifierRange,
1027 ValueDecl *VD,
1028 const DeclarationNameInfo &NameInfo,
1029 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001030 CXXScopeSpec SS;
1031 SS.setScopeRep(Qualifier);
1032 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001033
1034 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001035
1036 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 }
Mike Stump11289f42009-09-09 15:08:12 +00001038
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001040 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001045 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 }
1047
Douglas Gregorad8a3362009-09-04 17:36:40 +00001048 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001052 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001053 SourceLocation OperatorLoc,
1054 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001055 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001056 SourceRange QualifierRange,
1057 TypeSourceInfo *ScopeType,
1058 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001059 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001060 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001061
Douglas Gregora16548e2009-08-11 05:31:07 +00001062 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001063 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001066 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001067 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001068 Expr *SubExpr) {
1069 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor882211c2010-04-28 22:16:22 +00001072 /// \brief Build a new builtin offsetof expression.
1073 ///
1074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001077 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001078 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001079 unsigned NumComponents,
1080 SourceLocation RParenLoc) {
1081 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1082 NumComponents, RParenLoc);
1083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001084
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001086 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// By default, performs semantic analysis to build the new expression.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001090 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001092 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001093 }
1094
Mike Stump11289f42009-09-09 15:08:12 +00001095 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// By default, performs semantic analysis to build the new expression.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001102 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001103 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 return move(Result);
1108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001111 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001116 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1119 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 RBracketLoc);
1121 }
1122
1123 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001127 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 MultiExprArg Args,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 move(Args), CommaLocs, RParenLoc);
1133 }
1134
1135 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001140 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001143 const DeclarationNameInfo &MemberNameInfo,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001144 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001145 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001147 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001151
John McCallb268a282010-08-23 23:25:46 +00001152 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001153 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001154 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001155
Mike Stump11289f42009-09-09 15:08:12 +00001156 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001157 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001158 Member, MemberNameInfo,
Anders Carlsson5da84842009-09-01 04:26:58 +00001159 cast<FieldDecl>(Member)->getType());
1160 return getSema().Owned(ME);
1161 }
Mike Stump11289f42009-09-09 15:08:12 +00001162
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001163 CXXScopeSpec SS;
1164 if (Qualifier) {
1165 SS.setRange(QualifierRange);
1166 SS.setScopeRep(Qualifier);
1167 }
1168
John McCallb268a282010-08-23 23:25:46 +00001169 getSema().DefaultFunctionArrayConversion(Base);
1170 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001171
John McCall16df1e52010-03-30 21:47:33 +00001172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001174 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001175 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001176 R.resolveKind();
1177
John McCallb268a282010-08-23 23:25:46 +00001178 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001179 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001180 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 }
Mike Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregora16548e2009-08-11 05:31:07 +00001183 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001188 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *LHS, Expr *RHS) {
1190 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 }
1192
1193 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001194 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 /// By default, performs semantic analysis to build the new expression.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001201 Expr *RHS) {
1202 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1203 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 }
1205
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001207 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001210 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001211 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001213 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001214 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001219 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001222 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001225 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001226 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001227 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 SourceLocation OpLoc,
1236 SourceLocation AccessorLoc,
1237 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001238
John McCall10eae182009-11-30 22:42:35 +00001239 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001240 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001241 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001242 OpLoc, /*IsArrow*/ false,
1243 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001244 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001245 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001252 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001254 SourceLocation RBraceLoc,
1255 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001256 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001257 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1258 if (Result.isInvalid() || ResultTy->isDependentType())
1259 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001260
Douglas Gregord3d93062009-11-09 17:16:50 +00001261 // Patch in the result type we were given, which may have been computed
1262 // when the initial InitListExpr was built.
1263 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1264 ILE->setType(ResultTy);
1265 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 }
Mike Stump11289f42009-09-09 15:08:12 +00001267
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001269 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001272 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 MultiExprArg ArrayExprs,
1274 SourceLocation EqualOrColonLoc,
1275 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001276 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001279 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 ArrayExprs.release();
1284 return move(Result);
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001288 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 /// By default, builds the implicit value initialization without performing
1290 /// any semantic analysis. Subclasses may override this routine to provide
1291 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1294 }
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001301 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001302 SourceLocation RParenLoc) {
1303 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001304 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001305 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 }
1307
1308 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001309 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001312 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 MultiExprArg SubExprs,
1314 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001315 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001316 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
1321 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// rather than attempting to map the label statement itself.
1323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001324 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 SourceLocation LabelLoc,
1326 LabelStmt *Label) {
1327 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001337 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 }
Mike Stump11289f42009-09-09 15:08:12 +00001339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// \brief Build a new __builtin_types_compatible_p expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001344 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
Abramo Bagnara092990a2010-08-10 08:50:03 +00001345 TypeSourceInfo *TInfo1,
1346 TypeSourceInfo *TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParenLoc) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00001348 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1349 TInfo1, TInfo2,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 RParenLoc);
1351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new __builtin_choose_expr expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 SourceLocation RParenLoc) {
1360 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001361 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 RParenLoc);
1363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// \brief Build a new overloaded operator call expression.
1366 ///
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// The semantic analysis provides the behavior of template instantiation,
1369 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001370 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// argument-dependent lookup, etc. Subclasses may override this routine to
1372 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001373 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *Callee,
1376 Expr *First,
1377 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001378
1379 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 /// reinterpret_cast.
1381 ///
1382 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001383 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001385 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 Stmt::StmtClass Class,
1387 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001388 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001391 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation RParenLoc) {
1393 switch (Class) {
1394 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001397 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001398
1399 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001400 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001401 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001402 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001405 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001406 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 default:
1416 assert(false && "Invalid C++ named cast");
1417 break;
1418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
John McCallfaf5fb42010-08-26 23:41:50 +00001420 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 }
Mike Stump11289f42009-09-09 15:08:12 +00001422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new C++ static_cast expression.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001429 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001435 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new C++ dynamic_cast expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001444 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001446 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001452 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 }
1456
1457 /// \brief Build a new C++ reinterpret_cast expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001463 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 SourceLocation RAngleLoc,
1465 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001466 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001469 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001470 SourceRange(LAngleLoc, RAngleLoc),
1471 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new C++ const_cast expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001480 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001483 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001485 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001486 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001487 SourceRange(LAngleLoc, RAngleLoc),
1488 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
Mike Stump11289f42009-09-09 15:08:12 +00001490
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// \brief Build a new C++ functional-style cast expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001495 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1496 SourceLocation LParenLoc,
1497 Expr *Sub,
1498 SourceLocation RParenLoc) {
1499 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001500 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 RParenLoc);
1502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// \brief Build a new C++ typeid(type) expression.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001508 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001509 SourceLocation TypeidLoc,
1510 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001512 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001513 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Francois Pichet9f4f2072010-09-08 12:20:18 +00001516
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// \brief Build a new C++ typeid(expr) expression.
1518 ///
1519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001521 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001522 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001523 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001525 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001526 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001527 }
1528
Francois Pichet9f4f2072010-09-08 12:20:18 +00001529 /// \brief Build a new C++ __uuidof(type) expression.
1530 ///
1531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
1533 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1534 SourceLocation TypeidLoc,
1535 TypeSourceInfo *Operand,
1536 SourceLocation RParenLoc) {
1537 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1538 RParenLoc);
1539 }
1540
1541 /// \brief Build a new C++ __uuidof(expr) expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
1545 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1546 SourceLocation TypeidLoc,
1547 Expr *Operand,
1548 SourceLocation RParenLoc) {
1549 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1550 RParenLoc);
1551 }
1552
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// \brief Build a new C++ "this" expression.
1554 ///
1555 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001556 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001559 QualType ThisType,
1560 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001562 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1563 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 }
1565
1566 /// \brief Build a new C++ throw expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001570 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001571 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 }
1573
1574 /// \brief Build a new C++ default-argument expression.
1575 ///
1576 /// By default, builds a new default-argument expression, which does not
1577 /// require any semantic analysis. Subclasses may override this routine to
1578 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001579 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001580 ParmVarDecl *Param) {
1581 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1582 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
1584
1585 /// \brief Build a new C++ zero-initialization expression.
1586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001589 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1590 SourceLocation LParenLoc,
1591 SourceLocation RParenLoc) {
1592 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001593 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001594 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 }
Mike Stump11289f42009-09-09 15:08:12 +00001596
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 /// \brief Build a new C++ "new" expression.
1598 ///
1599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001601 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001602 bool UseGlobal,
1603 SourceLocation PlacementLParen,
1604 MultiExprArg PlacementArgs,
1605 SourceLocation PlacementRParen,
1606 SourceRange TypeIdParens,
1607 QualType AllocatedType,
1608 TypeSourceInfo *AllocatedTypeInfo,
1609 Expr *ArraySize,
1610 SourceLocation ConstructorLParen,
1611 MultiExprArg ConstructorArgs,
1612 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001613 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 PlacementLParen,
1615 move(PlacementArgs),
1616 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001617 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001618 AllocatedType,
1619 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001620 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 ConstructorLParen,
1622 move(ConstructorArgs),
1623 ConstructorRParen);
1624 }
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// \brief Build a new C++ "delete" expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 bool IsGlobalDelete,
1632 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001633 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001635 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new unary type trait expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001642 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceLocation StartLoc,
1644 SourceLocation LParenLoc,
1645 QualType T,
1646 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001647 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallba7bf592010-08-24 05:47:05 +00001648 ParsedType::make(T), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
1650
Mike Stump11289f42009-09-09 15:08:12 +00001651 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// expression.
1653 ///
1654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001656 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001658 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001659 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 CXXScopeSpec SS;
1661 SS.setRange(QualifierRange);
1662 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001663
1664 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001665 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001666 *TemplateArgs);
1667
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001668 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new template-id expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001676 LookupResult &R,
1677 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001678 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001679 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new object-construction expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001686 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001687 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 CXXConstructorDecl *Constructor,
1689 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001690 MultiExprArg Args,
1691 bool RequiresZeroInit,
1692 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001693 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001694 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001695 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001696 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001697
Douglas Gregordb121ba2009-12-14 16:27:04 +00001698 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001699 move_arg(ConvertedArgs),
1700 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 }
1702
1703 /// \brief Build a new object-construction expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001707 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1708 SourceLocation LParenLoc,
1709 MultiExprArg Args,
1710 SourceLocation RParenLoc) {
1711 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 LParenLoc,
1713 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 RParenLoc);
1715 }
1716
1717 /// \brief Build a new object-construction expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001721 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1722 SourceLocation LParenLoc,
1723 MultiExprArg Args,
1724 SourceLocation RParenLoc) {
1725 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 LParenLoc,
1727 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 RParenLoc);
1729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// \brief Build a new member reference expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001735 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001736 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 bool IsArrow,
1738 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001739 NestedNameSpecifier *Qualifier,
1740 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001741 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001742 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001743 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 SS.setRange(QualifierRange);
1746 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001747
John McCallb268a282010-08-23 23:25:46 +00001748 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001749 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001750 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001751 MemberNameInfo,
1752 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 }
1754
John McCall10eae182009-11-30 22:42:35 +00001755 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001759 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001760 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001761 SourceLocation OperatorLoc,
1762 bool IsArrow,
1763 NestedNameSpecifier *Qualifier,
1764 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001765 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001766 LookupResult &R,
1767 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001768 CXXScopeSpec SS;
1769 SS.setRange(QualifierRange);
1770 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001771
John McCallb268a282010-08-23 23:25:46 +00001772 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001773 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001774 SS, FirstQualifierInScope,
1775 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001776 }
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 /// \brief Build a new Objective-C @encode expression.
1779 ///
1780 /// By default, performs semantic analysis to build the new expression.
1781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001783 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001785 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001787 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001788
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001790 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001791 Selector Sel,
1792 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001793 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001794 MultiExprArg Args,
1795 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001796 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1797 ReceiverTypeInfo->getType(),
1798 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001799 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 move(Args));
1801 }
1802
1803 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001805 Selector Sel,
1806 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001807 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001808 MultiExprArg Args,
1809 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001810 return SemaRef.BuildInstanceMessage(Receiver,
1811 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001812 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001813 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001814 move(Args));
1815 }
1816
Douglas Gregord51d90d2010-04-26 20:11:03 +00001817 /// \brief Build a new Objective-C ivar reference expression.
1818 ///
1819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001822 SourceLocation IvarLoc,
1823 bool IsArrow, bool IsFreeIvar) {
1824 // FIXME: We lose track of the IsFreeIvar bit.
1825 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001826 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001827 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1828 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001830 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001831 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001832 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001833 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001834 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001835
Douglas Gregord51d90d2010-04-26 20:11:03 +00001836 if (Result.get())
1837 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001838
John McCallb268a282010-08-23 23:25:46 +00001839 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001840 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001841 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001842 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 /*TemplateArgs=*/0);
1844 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001845
1846 /// \brief Build a new Objective-C property reference expression.
1847 ///
1848 /// By default, performs semantic analysis to build the new expression.
1849 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001850 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001851 ObjCPropertyDecl *Property,
1852 SourceLocation PropertyLoc) {
1853 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001854 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001855 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1856 Sema::LookupMemberName);
1857 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001858 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001859 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001860 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001861 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001862 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001863
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 if (Result.get())
1865 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001866
John McCallb268a282010-08-23 23:25:46 +00001867 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001868 /*FIXME:*/PropertyLoc, IsArrow,
1869 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001870 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001872 /*TemplateArgs=*/0);
1873 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001874
1875 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001876 /// expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001881 ObjCMethodDecl *Getter,
1882 QualType T,
1883 ObjCMethodDecl *Setter,
1884 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001885 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001886 // Since these expressions can only be value-dependent, we do not need to
1887 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001888 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001889 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1890 Setter,
1891 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001892 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001893 }
1894
Douglas Gregord51d90d2010-04-26 20:11:03 +00001895 /// \brief Build a new Objective-C "isa" expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 bool IsArrow) {
1901 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001902 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001903 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1904 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001905 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001906 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001907 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001908 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001909 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001910
Douglas Gregord51d90d2010-04-26 20:11:03 +00001911 if (Result.get())
1912 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001913
John McCallb268a282010-08-23 23:25:46 +00001914 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001915 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001916 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001917 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001918 /*TemplateArgs=*/0);
1919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001920
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// \brief Build a new shuffle vector expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001925 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 MultiExprArg SubExprs,
1927 SourceLocation RParenLoc) {
1928 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001929 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1931 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1932 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1933 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 // Build a reference to the __builtin_shufflevector builtin
1936 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001937 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001939 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001941
1942 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 unsigned NumSubExprs = SubExprs.size();
1944 Expr **Subs = (Expr **)SubExprs.release();
1945 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1946 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001947 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001949 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001950
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001954 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001955
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001957 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001959};
Douglas Gregora16548e2009-08-11 05:31:07 +00001960
Douglas Gregorebe10102009-08-20 07:17:43 +00001961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001962StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001963 if (!S)
1964 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregorebe10102009-08-20 07:17:43 +00001966 switch (S->getStmtClass()) {
1967 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001968
Douglas Gregorebe10102009-08-20 07:17:43 +00001969 // Transform individual statement nodes
1970#define STMT(Node, Parent) \
1971 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1972#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001973#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001974
Douglas Gregorebe10102009-08-20 07:17:43 +00001975 // Transform expressions by calling TransformExpr.
1976#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001977#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001978#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001979#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001980 {
John McCalldadc5752010-08-24 06:29:42 +00001981 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001982 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001983 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001984
John McCallb268a282010-08-23 23:25:46 +00001985 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987 }
1988
Douglas Gregorebe10102009-08-20 07:17:43 +00001989 return SemaRef.Owned(S->Retain());
1990}
Mike Stump11289f42009-09-09 15:08:12 +00001991
1992
Douglas Gregore922c772009-08-04 22:27:00 +00001993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001994ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 if (!E)
1996 return SemaRef.Owned(E);
1997
1998 switch (E->getStmtClass()) {
1999 case Stmt::NoStmtClass: break;
2000#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002001#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002002#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002003 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002004#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002005 }
2006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002008}
2009
2010template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002011NestedNameSpecifier *
2012TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002013 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002014 QualType ObjectType,
2015 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002016 if (!NNS)
2017 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002018
Douglas Gregorebe10102009-08-20 07:17:43 +00002019 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002020 NestedNameSpecifier *Prefix = NNS->getPrefix();
2021 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002022 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002023 ObjectType,
2024 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002025 if (!Prefix)
2026 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002027
2028 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002029 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002030 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002031 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 }
Mike Stump11289f42009-09-09 15:08:12 +00002033
Douglas Gregor1135c352009-08-06 05:28:30 +00002034 switch (NNS->getKind()) {
2035 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002036 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002037 "Identifier nested-name-specifier with no prefix or object type");
2038 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2039 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002040 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002041
2042 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002043 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002044 ObjectType,
2045 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregor1135c352009-08-06 05:28:30 +00002047 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002048 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002050 getDerived().TransformDecl(Range.getBegin(),
2051 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002052 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002053 Prefix == NNS->getPrefix() &&
2054 NS == NNS->getAsNamespace())
2055 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2058 }
Mike Stump11289f42009-09-09 15:08:12 +00002059
Douglas Gregor1135c352009-08-06 05:28:30 +00002060 case NestedNameSpecifier::Global:
2061 // There is no meaningful transformation that one could perform on the
2062 // global scope.
2063 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002064
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 case NestedNameSpecifier::TypeSpecWithTemplate:
2066 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002067 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002068 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2069 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002070 if (T.isNull())
2071 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002072
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 if (!getDerived().AlwaysRebuild() &&
2074 Prefix == NNS->getPrefix() &&
2075 T == QualType(NNS->getAsType(), 0))
2076 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002077
2078 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2079 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002080 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002081 }
2082 }
Mike Stump11289f42009-09-09 15:08:12 +00002083
Douglas Gregor1135c352009-08-06 05:28:30 +00002084 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002085 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002086}
2087
2088template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002089DeclarationNameInfo
2090TreeTransform<Derived>
2091::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2092 QualType ObjectType) {
2093 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002094 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002095 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002096
2097 switch (Name.getNameKind()) {
2098 case DeclarationName::Identifier:
2099 case DeclarationName::ObjCZeroArgSelector:
2100 case DeclarationName::ObjCOneArgSelector:
2101 case DeclarationName::ObjCMultiArgSelector:
2102 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002103 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002104 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002105 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002106
Douglas Gregorf816bd72009-09-03 22:13:48 +00002107 case DeclarationName::CXXConstructorName:
2108 case DeclarationName::CXXDestructorName:
2109 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002110 TypeSourceInfo *NewTInfo;
2111 CanQualType NewCanTy;
2112 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2113 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2114 if (!NewTInfo)
2115 return DeclarationNameInfo();
2116 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2117 }
2118 else {
2119 NewTInfo = 0;
2120 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2121 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2122 ObjectType);
2123 if (NewT.isNull())
2124 return DeclarationNameInfo();
2125 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002128 DeclarationName NewName
2129 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2130 NewCanTy);
2131 DeclarationNameInfo NewNameInfo(NameInfo);
2132 NewNameInfo.setName(NewName);
2133 NewNameInfo.setNamedTypeInfo(NewTInfo);
2134 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002135 }
Mike Stump11289f42009-09-09 15:08:12 +00002136 }
2137
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002138 assert(0 && "Unknown name kind.");
2139 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002140}
2141
2142template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002143TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002144TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2145 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002146 SourceLocation Loc = getDerived().getBaseLocation();
2147
Douglas Gregor71dc5092009-08-06 06:41:21 +00002148 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002149 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002150 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002151 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2152 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002153 if (!NNS)
2154 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002155
Douglas Gregor71dc5092009-08-06 06:41:21 +00002156 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002157 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002158 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 if (!TransTemplate)
2160 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregor71dc5092009-08-06 06:41:21 +00002162 if (!getDerived().AlwaysRebuild() &&
2163 NNS == QTN->getQualifier() &&
2164 TransTemplate == Template)
2165 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2168 TransTemplate);
2169 }
Mike Stump11289f42009-09-09 15:08:12 +00002170
John McCalle66edc12009-11-24 19:00:30 +00002171 // These should be getting filtered out before they make it into the AST.
2172 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002176 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002178 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2179 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002180 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregor71dc5092009-08-06 06:41:21 +00002183 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002184 NNS == DTN->getQualifier() &&
2185 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002186 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregor71395fa2009-11-04 00:56:37 +00002188 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002189 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002190 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002191
2192 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002193 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregor71dc5092009-08-06 06:41:21 +00002196 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002197 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002198 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002199 if (!TransTemplate)
2200 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregor71dc5092009-08-06 06:41:21 +00002202 if (!getDerived().AlwaysRebuild() &&
2203 TransTemplate == Template)
2204 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206 return TemplateName(TransTemplate);
2207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
John McCalle66edc12009-11-24 19:00:30 +00002209 // These should be getting filtered out before they reach the AST.
2210 assert(false && "overloaded function decl survived to here");
2211 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002212}
2213
2214template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002215void TreeTransform<Derived>::InventTemplateArgumentLoc(
2216 const TemplateArgument &Arg,
2217 TemplateArgumentLoc &Output) {
2218 SourceLocation Loc = getDerived().getBaseLocation();
2219 switch (Arg.getKind()) {
2220 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002221 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002222 break;
2223
2224 case TemplateArgument::Type:
2225 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002226 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002227
John McCall0ad16662009-10-29 08:12:44 +00002228 break;
2229
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002230 case TemplateArgument::Template:
2231 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2232 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002233
John McCall0ad16662009-10-29 08:12:44 +00002234 case TemplateArgument::Expression:
2235 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2236 break;
2237
2238 case TemplateArgument::Declaration:
2239 case TemplateArgument::Integral:
2240 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002241 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002242 break;
2243 }
2244}
2245
2246template<typename Derived>
2247bool TreeTransform<Derived>::TransformTemplateArgument(
2248 const TemplateArgumentLoc &Input,
2249 TemplateArgumentLoc &Output) {
2250 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002251 switch (Arg.getKind()) {
2252 case TemplateArgument::Null:
2253 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002254 Output = Input;
2255 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002256
Douglas Gregore922c772009-08-04 22:27:00 +00002257 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002258 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002259 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002260 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002261
2262 DI = getDerived().TransformType(DI);
2263 if (!DI) return true;
2264
2265 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2266 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002267 }
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregore922c772009-08-04 22:27:00 +00002269 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002270 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002271 DeclarationName Name;
2272 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2273 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002274 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002275 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002276 if (!D) return true;
2277
John McCall0d07eb32009-10-29 18:45:58 +00002278 Expr *SourceExpr = Input.getSourceDeclExpression();
2279 if (SourceExpr) {
2280 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002281 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002283 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002284 }
2285
2286 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002287 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002288 }
Mike Stump11289f42009-09-09 15:08:12 +00002289
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002290 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002291 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002292 TemplateName Template
2293 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2294 if (Template.isNull())
2295 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002296
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002297 Output = TemplateArgumentLoc(TemplateArgument(Template),
2298 Input.getTemplateQualifierRange(),
2299 Input.getTemplateNameLoc());
2300 return false;
2301 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002302
Douglas Gregore922c772009-08-04 22:27:00 +00002303 case TemplateArgument::Expression: {
2304 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002305 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002306 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002307
John McCall0ad16662009-10-29 08:12:44 +00002308 Expr *InputExpr = Input.getSourceExpression();
2309 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2310
John McCalldadc5752010-08-24 06:29:42 +00002311 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002312 = getDerived().TransformExpr(InputExpr);
2313 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002314 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002315 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002316 }
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregore922c772009-08-04 22:27:00 +00002318 case TemplateArgument::Pack: {
2319 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2320 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002321 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002322 AEnd = Arg.pack_end();
2323 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002324
John McCall0ad16662009-10-29 08:12:44 +00002325 // FIXME: preserve source information here when we start
2326 // caring about parameter packs.
2327
John McCall0d07eb32009-10-29 18:45:58 +00002328 TemplateArgumentLoc InputArg;
2329 TemplateArgumentLoc OutputArg;
2330 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2331 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002332 return true;
2333
John McCall0d07eb32009-10-29 18:45:58 +00002334 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002335 }
2336 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002337 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002338 true);
John McCall0d07eb32009-10-29 18:45:58 +00002339 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002340 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002341 }
2342 }
Mike Stump11289f42009-09-09 15:08:12 +00002343
Douglas Gregore922c772009-08-04 22:27:00 +00002344 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002345 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002346}
2347
Douglas Gregord6ff3322009-08-04 16:50:30 +00002348//===----------------------------------------------------------------------===//
2349// Type transformation
2350//===----------------------------------------------------------------------===//
2351
2352template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002353QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002354 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002355 if (getDerived().AlreadyTransformed(T))
2356 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002357
John McCall550e0c22009-10-21 00:40:46 +00002358 // Temporary workaround. All of these transformations should
2359 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002360 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002361 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002362
Douglas Gregorfe17d252010-02-16 19:09:40 +00002363 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002364
John McCall550e0c22009-10-21 00:40:46 +00002365 if (!NewDI)
2366 return QualType();
2367
2368 return NewDI->getType();
2369}
2370
2371template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002372TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2373 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002374 if (getDerived().AlreadyTransformed(DI->getType()))
2375 return DI;
2376
2377 TypeLocBuilder TLB;
2378
2379 TypeLoc TL = DI->getTypeLoc();
2380 TLB.reserve(TL.getFullDataSize());
2381
Douglas Gregorfe17d252010-02-16 19:09:40 +00002382 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002383 if (Result.isNull())
2384 return 0;
2385
John McCallbcd03502009-12-07 02:54:59 +00002386 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002387}
2388
2389template<typename Derived>
2390QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002391TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2392 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002393 switch (T.getTypeLocClass()) {
2394#define ABSTRACT_TYPELOC(CLASS, PARENT)
2395#define TYPELOC(CLASS, PARENT) \
2396 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002397 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2398 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002399#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002400 }
Mike Stump11289f42009-09-09 15:08:12 +00002401
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002402 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002403 return QualType();
2404}
2405
2406/// FIXME: By default, this routine adds type qualifiers only to types
2407/// that can have qualifiers, and silently suppresses those qualifiers
2408/// that are not permitted (e.g., qualifiers on reference or function
2409/// types). This is the right thing for template instantiation, but
2410/// probably not for other clients.
2411template<typename Derived>
2412QualType
2413TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002414 QualifiedTypeLoc T,
2415 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002416 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002417
Douglas Gregorfe17d252010-02-16 19:09:40 +00002418 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2419 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002420 if (Result.isNull())
2421 return QualType();
2422
2423 // Silently suppress qualifiers if the result type can't be qualified.
2424 // FIXME: this is the right thing for template instantiation, but
2425 // probably not for other clients.
2426 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002427 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002428
John McCallcb0f89a2010-06-05 06:41:15 +00002429 if (!Quals.empty()) {
2430 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2431 TLB.push<QualifiedTypeLoc>(Result);
2432 // No location information to preserve.
2433 }
John McCall550e0c22009-10-21 00:40:46 +00002434
2435 return Result;
2436}
2437
2438template <class TyLoc> static inline
2439QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2440 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2441 NewT.setNameLoc(T.getNameLoc());
2442 return T.getType();
2443}
2444
John McCall550e0c22009-10-21 00:40:46 +00002445template<typename Derived>
2446QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002447 BuiltinTypeLoc T,
2448 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002449 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2450 NewT.setBuiltinLoc(T.getBuiltinLoc());
2451 if (T.needsExtraLocalData())
2452 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2453 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002454}
Mike Stump11289f42009-09-09 15:08:12 +00002455
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002457QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002458 ComplexTypeLoc T,
2459 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002460 // FIXME: recurse?
2461 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002462}
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002465QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002466 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002467 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002468 QualType PointeeType
2469 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002470 if (PointeeType.isNull())
2471 return QualType();
2472
2473 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002474 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002475 // A dependent pointer type 'T *' has is being transformed such
2476 // that an Objective-C class type is being replaced for 'T'. The
2477 // resulting pointer type is an ObjCObjectPointerType, not a
2478 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002479 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002480
John McCall8b07ec22010-05-15 11:32:37 +00002481 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2482 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002483 return Result;
2484 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002486 if (getDerived().AlwaysRebuild() ||
2487 PointeeType != TL.getPointeeLoc().getType()) {
2488 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2489 if (Result.isNull())
2490 return QualType();
2491 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002492
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002493 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2494 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002495 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002496}
Mike Stump11289f42009-09-09 15:08:12 +00002497
2498template<typename Derived>
2499QualType
John McCall550e0c22009-10-21 00:40:46 +00002500TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002501 BlockPointerTypeLoc TL,
2502 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002503 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002504 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2505 if (PointeeType.isNull())
2506 return QualType();
2507
2508 QualType Result = TL.getType();
2509 if (getDerived().AlwaysRebuild() ||
2510 PointeeType != TL.getPointeeLoc().getType()) {
2511 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002512 TL.getSigilLoc());
2513 if (Result.isNull())
2514 return QualType();
2515 }
2516
Douglas Gregor049211a2010-04-22 16:50:51 +00002517 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002518 NewT.setSigilLoc(TL.getSigilLoc());
2519 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002520}
2521
John McCall70dd5f62009-10-30 00:06:24 +00002522/// Transforms a reference type. Note that somewhat paradoxically we
2523/// don't care whether the type itself is an l-value type or an r-value
2524/// type; we only care if the type was *written* as an l-value type
2525/// or an r-value type.
2526template<typename Derived>
2527QualType
2528TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002529 ReferenceTypeLoc TL,
2530 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002531 const ReferenceType *T = TL.getTypePtr();
2532
2533 // Note that this works with the pointee-as-written.
2534 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2535 if (PointeeType.isNull())
2536 return QualType();
2537
2538 QualType Result = TL.getType();
2539 if (getDerived().AlwaysRebuild() ||
2540 PointeeType != T->getPointeeTypeAsWritten()) {
2541 Result = getDerived().RebuildReferenceType(PointeeType,
2542 T->isSpelledAsLValue(),
2543 TL.getSigilLoc());
2544 if (Result.isNull())
2545 return QualType();
2546 }
2547
2548 // r-value references can be rebuilt as l-value references.
2549 ReferenceTypeLoc NewTL;
2550 if (isa<LValueReferenceType>(Result))
2551 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2552 else
2553 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2554 NewTL.setSigilLoc(TL.getSigilLoc());
2555
2556 return Result;
2557}
2558
Mike Stump11289f42009-09-09 15:08:12 +00002559template<typename Derived>
2560QualType
John McCall550e0c22009-10-21 00:40:46 +00002561TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002562 LValueReferenceTypeLoc TL,
2563 QualType ObjectType) {
2564 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565}
2566
Mike Stump11289f42009-09-09 15:08:12 +00002567template<typename Derived>
2568QualType
John McCall550e0c22009-10-21 00:40:46 +00002569TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002570 RValueReferenceTypeLoc TL,
2571 QualType ObjectType) {
2572 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002573}
Mike Stump11289f42009-09-09 15:08:12 +00002574
Douglas Gregord6ff3322009-08-04 16:50:30 +00002575template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002576QualType
John McCall550e0c22009-10-21 00:40:46 +00002577TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002578 MemberPointerTypeLoc TL,
2579 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002580 MemberPointerType *T = TL.getTypePtr();
2581
2582 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583 if (PointeeType.isNull())
2584 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002585
John McCall550e0c22009-10-21 00:40:46 +00002586 // TODO: preserve source information for this.
2587 QualType ClassType
2588 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002589 if (ClassType.isNull())
2590 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002591
John McCall550e0c22009-10-21 00:40:46 +00002592 QualType Result = TL.getType();
2593 if (getDerived().AlwaysRebuild() ||
2594 PointeeType != T->getPointeeType() ||
2595 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002596 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2597 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002598 if (Result.isNull())
2599 return QualType();
2600 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002601
John McCall550e0c22009-10-21 00:40:46 +00002602 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2603 NewTL.setSigilLoc(TL.getSigilLoc());
2604
2605 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002606}
2607
Mike Stump11289f42009-09-09 15:08:12 +00002608template<typename Derived>
2609QualType
John McCall550e0c22009-10-21 00:40:46 +00002610TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002611 ConstantArrayTypeLoc TL,
2612 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002613 ConstantArrayType *T = TL.getTypePtr();
2614 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002615 if (ElementType.isNull())
2616 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002617
John McCall550e0c22009-10-21 00:40:46 +00002618 QualType Result = TL.getType();
2619 if (getDerived().AlwaysRebuild() ||
2620 ElementType != T->getElementType()) {
2621 Result = getDerived().RebuildConstantArrayType(ElementType,
2622 T->getSizeModifier(),
2623 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002624 T->getIndexTypeCVRQualifiers(),
2625 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002626 if (Result.isNull())
2627 return QualType();
2628 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002629
John McCall550e0c22009-10-21 00:40:46 +00002630 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2631 NewTL.setLBracketLoc(TL.getLBracketLoc());
2632 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002633
John McCall550e0c22009-10-21 00:40:46 +00002634 Expr *Size = TL.getSizeExpr();
2635 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002636 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002637 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2638 }
2639 NewTL.setSizeExpr(Size);
2640
2641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002642}
Mike Stump11289f42009-09-09 15:08:12 +00002643
Douglas Gregord6ff3322009-08-04 16:50:30 +00002644template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002646 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002647 IncompleteArrayTypeLoc TL,
2648 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002649 IncompleteArrayType *T = TL.getTypePtr();
2650 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651 if (ElementType.isNull())
2652 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002653
John McCall550e0c22009-10-21 00:40:46 +00002654 QualType Result = TL.getType();
2655 if (getDerived().AlwaysRebuild() ||
2656 ElementType != T->getElementType()) {
2657 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002658 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002659 T->getIndexTypeCVRQualifiers(),
2660 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002661 if (Result.isNull())
2662 return QualType();
2663 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002664
John McCall550e0c22009-10-21 00:40:46 +00002665 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2666 NewTL.setLBracketLoc(TL.getLBracketLoc());
2667 NewTL.setRBracketLoc(TL.getRBracketLoc());
2668 NewTL.setSizeExpr(0);
2669
2670 return Result;
2671}
2672
2673template<typename Derived>
2674QualType
2675TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002676 VariableArrayTypeLoc TL,
2677 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002678 VariableArrayType *T = TL.getTypePtr();
2679 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2680 if (ElementType.isNull())
2681 return QualType();
2682
2683 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002684 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002685
John McCalldadc5752010-08-24 06:29:42 +00002686 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002687 = getDerived().TransformExpr(T->getSizeExpr());
2688 if (SizeResult.isInvalid())
2689 return QualType();
2690
John McCallb268a282010-08-23 23:25:46 +00002691 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002692
2693 QualType Result = TL.getType();
2694 if (getDerived().AlwaysRebuild() ||
2695 ElementType != T->getElementType() ||
2696 Size != T->getSizeExpr()) {
2697 Result = getDerived().RebuildVariableArrayType(ElementType,
2698 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002699 Size,
John McCall550e0c22009-10-21 00:40:46 +00002700 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002701 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002702 if (Result.isNull())
2703 return QualType();
2704 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002705
John McCall550e0c22009-10-21 00:40:46 +00002706 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2707 NewTL.setLBracketLoc(TL.getLBracketLoc());
2708 NewTL.setRBracketLoc(TL.getRBracketLoc());
2709 NewTL.setSizeExpr(Size);
2710
2711 return Result;
2712}
2713
2714template<typename Derived>
2715QualType
2716TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002717 DependentSizedArrayTypeLoc TL,
2718 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002719 DependentSizedArrayType *T = TL.getTypePtr();
2720 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2721 if (ElementType.isNull())
2722 return QualType();
2723
2724 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002725 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002726
John McCalldadc5752010-08-24 06:29:42 +00002727 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002728 = getDerived().TransformExpr(T->getSizeExpr());
2729 if (SizeResult.isInvalid())
2730 return QualType();
2731
2732 Expr *Size = static_cast<Expr*>(SizeResult.get());
2733
2734 QualType Result = TL.getType();
2735 if (getDerived().AlwaysRebuild() ||
2736 ElementType != T->getElementType() ||
2737 Size != T->getSizeExpr()) {
2738 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2739 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002740 Size,
John McCall550e0c22009-10-21 00:40:46 +00002741 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002742 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002743 if (Result.isNull())
2744 return QualType();
2745 }
2746 else SizeResult.take();
2747
2748 // We might have any sort of array type now, but fortunately they
2749 // all have the same location layout.
2750 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2751 NewTL.setLBracketLoc(TL.getLBracketLoc());
2752 NewTL.setRBracketLoc(TL.getRBracketLoc());
2753 NewTL.setSizeExpr(Size);
2754
2755 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756}
Mike Stump11289f42009-09-09 15:08:12 +00002757
2758template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002760 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002761 DependentSizedExtVectorTypeLoc TL,
2762 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002763 DependentSizedExtVectorType *T = TL.getTypePtr();
2764
2765 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766 QualType ElementType = getDerived().TransformType(T->getElementType());
2767 if (ElementType.isNull())
2768 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002769
Douglas Gregore922c772009-08-04 22:27:00 +00002770 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002771 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002772
John McCalldadc5752010-08-24 06:29:42 +00002773 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002774 if (Size.isInvalid())
2775 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002776
John McCall550e0c22009-10-21 00:40:46 +00002777 QualType Result = TL.getType();
2778 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002779 ElementType != T->getElementType() ||
2780 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002781 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002782 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002783 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002784 if (Result.isNull())
2785 return QualType();
2786 }
John McCall550e0c22009-10-21 00:40:46 +00002787
2788 // Result might be dependent or not.
2789 if (isa<DependentSizedExtVectorType>(Result)) {
2790 DependentSizedExtVectorTypeLoc NewTL
2791 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2792 NewTL.setNameLoc(TL.getNameLoc());
2793 } else {
2794 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2795 NewTL.setNameLoc(TL.getNameLoc());
2796 }
2797
2798 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799}
Mike Stump11289f42009-09-09 15:08:12 +00002800
2801template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002802QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002803 VectorTypeLoc TL,
2804 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002805 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002806 QualType ElementType = getDerived().TransformType(T->getElementType());
2807 if (ElementType.isNull())
2808 return QualType();
2809
John McCall550e0c22009-10-21 00:40:46 +00002810 QualType Result = TL.getType();
2811 if (getDerived().AlwaysRebuild() ||
2812 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002813 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002814 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002815 if (Result.isNull())
2816 return QualType();
2817 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002818
John McCall550e0c22009-10-21 00:40:46 +00002819 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2820 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002821
John McCall550e0c22009-10-21 00:40:46 +00002822 return Result;
2823}
2824
2825template<typename Derived>
2826QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002827 ExtVectorTypeLoc TL,
2828 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002829 VectorType *T = TL.getTypePtr();
2830 QualType ElementType = getDerived().TransformType(T->getElementType());
2831 if (ElementType.isNull())
2832 return QualType();
2833
2834 QualType Result = TL.getType();
2835 if (getDerived().AlwaysRebuild() ||
2836 ElementType != T->getElementType()) {
2837 Result = getDerived().RebuildExtVectorType(ElementType,
2838 T->getNumElements(),
2839 /*FIXME*/ SourceLocation());
2840 if (Result.isNull())
2841 return QualType();
2842 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002843
John McCall550e0c22009-10-21 00:40:46 +00002844 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2845 NewTL.setNameLoc(TL.getNameLoc());
2846
2847 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002848}
Mike Stump11289f42009-09-09 15:08:12 +00002849
2850template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002851ParmVarDecl *
2852TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2853 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2854 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2855 if (!NewDI)
2856 return 0;
2857
2858 if (NewDI == OldDI)
2859 return OldParm;
2860 else
2861 return ParmVarDecl::Create(SemaRef.Context,
2862 OldParm->getDeclContext(),
2863 OldParm->getLocation(),
2864 OldParm->getIdentifier(),
2865 NewDI->getType(),
2866 NewDI,
2867 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002868 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002869 /* DefArg */ NULL);
2870}
2871
2872template<typename Derived>
2873bool TreeTransform<Derived>::
2874 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2875 llvm::SmallVectorImpl<QualType> &PTypes,
2876 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2877 FunctionProtoType *T = TL.getTypePtr();
2878
2879 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2880 ParmVarDecl *OldParm = TL.getArg(i);
2881
2882 QualType NewType;
2883 ParmVarDecl *NewParm;
2884
2885 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002886 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2887 if (!NewParm)
2888 return true;
2889 NewType = NewParm->getType();
2890
2891 // Deal with the possibility that we don't have a parameter
2892 // declaration for this parameter.
2893 } else {
2894 NewParm = 0;
2895
2896 QualType OldType = T->getArgType(i);
2897 NewType = getDerived().TransformType(OldType);
2898 if (NewType.isNull())
2899 return true;
2900 }
2901
2902 PTypes.push_back(NewType);
2903 PVars.push_back(NewParm);
2904 }
2905
2906 return false;
2907}
2908
2909template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002910QualType
John McCall550e0c22009-10-21 00:40:46 +00002911TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002912 FunctionProtoTypeLoc TL,
2913 QualType ObjectType) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00002914 // Transform the parameters and return type.
2915 //
2916 // We instantiate in source order, with the return type first followed by
2917 // the parameters, because users tend to expect this (even if they shouldn't
2918 // rely on it!).
2919 //
2920 // FIXME: When we implement late-specified return types, we'll need to
2921 // instantiate the return tpe *after* the parameter types in that case,
2922 // since the return type can then refer to the parameters themselves (via
2923 // decltype, sizeof, etc.).
Douglas Gregord6ff3322009-08-04 16:50:30 +00002924 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002925 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00002926 FunctionProtoType *T = TL.getTypePtr();
2927 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2928 if (ResultType.isNull())
2929 return QualType();
Douglas Gregor4afc2362010-08-31 00:26:14 +00002930
2931 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2932 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002933
John McCall550e0c22009-10-21 00:40:46 +00002934 QualType Result = TL.getType();
2935 if (getDerived().AlwaysRebuild() ||
2936 ResultType != T->getResultType() ||
2937 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2938 Result = getDerived().RebuildFunctionProtoType(ResultType,
2939 ParamTypes.data(),
2940 ParamTypes.size(),
2941 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002942 T->getTypeQuals(),
2943 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002944 if (Result.isNull())
2945 return QualType();
2946 }
Mike Stump11289f42009-09-09 15:08:12 +00002947
John McCall550e0c22009-10-21 00:40:46 +00002948 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2949 NewTL.setLParenLoc(TL.getLParenLoc());
2950 NewTL.setRParenLoc(TL.getRParenLoc());
2951 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2952 NewTL.setArg(i, ParamDecls[i]);
2953
2954 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002955}
Mike Stump11289f42009-09-09 15:08:12 +00002956
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957template<typename Derived>
2958QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002959 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002960 FunctionNoProtoTypeLoc TL,
2961 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002962 FunctionNoProtoType *T = TL.getTypePtr();
2963 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2964 if (ResultType.isNull())
2965 return QualType();
2966
2967 QualType Result = TL.getType();
2968 if (getDerived().AlwaysRebuild() ||
2969 ResultType != T->getResultType())
2970 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2971
2972 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2973 NewTL.setLParenLoc(TL.getLParenLoc());
2974 NewTL.setRParenLoc(TL.getRParenLoc());
2975
2976 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977}
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCallb96ec562009-12-04 22:46:56 +00002979template<typename Derived> QualType
2980TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002981 UnresolvedUsingTypeLoc TL,
2982 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002983 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002984 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002985 if (!D)
2986 return QualType();
2987
2988 QualType Result = TL.getType();
2989 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2990 Result = getDerived().RebuildUnresolvedUsingType(D);
2991 if (Result.isNull())
2992 return QualType();
2993 }
2994
2995 // We might get an arbitrary type spec type back. We should at
2996 // least always get a type spec type, though.
2997 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2998 NewTL.setNameLoc(TL.getNameLoc());
2999
3000 return Result;
3001}
3002
Douglas Gregord6ff3322009-08-04 16:50:30 +00003003template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003004QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003005 TypedefTypeLoc TL,
3006 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003007 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003008 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003009 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3010 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003011 if (!Typedef)
3012 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003013
John McCall550e0c22009-10-21 00:40:46 +00003014 QualType Result = TL.getType();
3015 if (getDerived().AlwaysRebuild() ||
3016 Typedef != T->getDecl()) {
3017 Result = getDerived().RebuildTypedefType(Typedef);
3018 if (Result.isNull())
3019 return QualType();
3020 }
Mike Stump11289f42009-09-09 15:08:12 +00003021
John McCall550e0c22009-10-21 00:40:46 +00003022 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3023 NewTL.setNameLoc(TL.getNameLoc());
3024
3025 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003026}
Mike Stump11289f42009-09-09 15:08:12 +00003027
Douglas Gregord6ff3322009-08-04 16:50:30 +00003028template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003029QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003030 TypeOfExprTypeLoc TL,
3031 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003032 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003033 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003034
John McCalldadc5752010-08-24 06:29:42 +00003035 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036 if (E.isInvalid())
3037 return QualType();
3038
John McCall550e0c22009-10-21 00:40:46 +00003039 QualType Result = TL.getType();
3040 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003041 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003042 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003043 if (Result.isNull())
3044 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003045 }
John McCall550e0c22009-10-21 00:40:46 +00003046 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003047
John McCall550e0c22009-10-21 00:40:46 +00003048 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003049 NewTL.setTypeofLoc(TL.getTypeofLoc());
3050 NewTL.setLParenLoc(TL.getLParenLoc());
3051 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003052
3053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003054}
Mike Stump11289f42009-09-09 15:08:12 +00003055
3056template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003057QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003058 TypeOfTypeLoc TL,
3059 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003060 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3061 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3062 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003064
John McCall550e0c22009-10-21 00:40:46 +00003065 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003066 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3067 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003068 if (Result.isNull())
3069 return QualType();
3070 }
Mike Stump11289f42009-09-09 15:08:12 +00003071
John McCall550e0c22009-10-21 00:40:46 +00003072 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003073 NewTL.setTypeofLoc(TL.getTypeofLoc());
3074 NewTL.setLParenLoc(TL.getLParenLoc());
3075 NewTL.setRParenLoc(TL.getRParenLoc());
3076 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003077
3078 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003079}
Mike Stump11289f42009-09-09 15:08:12 +00003080
3081template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003082QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003083 DecltypeTypeLoc TL,
3084 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003085 DecltypeType *T = TL.getTypePtr();
3086
Douglas Gregore922c772009-08-04 22:27:00 +00003087 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003088 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003089
John McCalldadc5752010-08-24 06:29:42 +00003090 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091 if (E.isInvalid())
3092 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003093
John McCall550e0c22009-10-21 00:40:46 +00003094 QualType Result = TL.getType();
3095 if (getDerived().AlwaysRebuild() ||
3096 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003097 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003098 if (Result.isNull())
3099 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100 }
John McCall550e0c22009-10-21 00:40:46 +00003101 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003102
John McCall550e0c22009-10-21 00:40:46 +00003103 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3104 NewTL.setNameLoc(TL.getNameLoc());
3105
3106 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003107}
3108
3109template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003110QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003111 RecordTypeLoc TL,
3112 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003113 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003114 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003115 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3116 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117 if (!Record)
3118 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003119
John McCall550e0c22009-10-21 00:40:46 +00003120 QualType Result = TL.getType();
3121 if (getDerived().AlwaysRebuild() ||
3122 Record != T->getDecl()) {
3123 Result = getDerived().RebuildRecordType(Record);
3124 if (Result.isNull())
3125 return QualType();
3126 }
Mike Stump11289f42009-09-09 15:08:12 +00003127
John McCall550e0c22009-10-21 00:40:46 +00003128 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3129 NewTL.setNameLoc(TL.getNameLoc());
3130
3131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132}
Mike Stump11289f42009-09-09 15:08:12 +00003133
3134template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003135QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003136 EnumTypeLoc TL,
3137 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003138 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003140 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3141 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142 if (!Enum)
3143 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003144
John McCall550e0c22009-10-21 00:40:46 +00003145 QualType Result = TL.getType();
3146 if (getDerived().AlwaysRebuild() ||
3147 Enum != T->getDecl()) {
3148 Result = getDerived().RebuildEnumType(Enum);
3149 if (Result.isNull())
3150 return QualType();
3151 }
Mike Stump11289f42009-09-09 15:08:12 +00003152
John McCall550e0c22009-10-21 00:40:46 +00003153 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3154 NewTL.setNameLoc(TL.getNameLoc());
3155
3156 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003157}
John McCallfcc33b02009-09-05 00:15:47 +00003158
John McCalle78aac42010-03-10 03:28:59 +00003159template<typename Derived>
3160QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3161 TypeLocBuilder &TLB,
3162 InjectedClassNameTypeLoc TL,
3163 QualType ObjectType) {
3164 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3165 TL.getTypePtr()->getDecl());
3166 if (!D) return QualType();
3167
3168 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3169 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3170 return T;
3171}
3172
Mike Stump11289f42009-09-09 15:08:12 +00003173
Douglas Gregord6ff3322009-08-04 16:50:30 +00003174template<typename Derived>
3175QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003176 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003177 TemplateTypeParmTypeLoc TL,
3178 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003179 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003180}
3181
Mike Stump11289f42009-09-09 15:08:12 +00003182template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003183QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003184 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003185 SubstTemplateTypeParmTypeLoc TL,
3186 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003187 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003188}
3189
3190template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003191QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3192 const TemplateSpecializationType *TST,
3193 QualType ObjectType) {
3194 // FIXME: this entire method is a temporary workaround; callers
3195 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003196
John McCall0ad16662009-10-29 08:12:44 +00003197 // Fake up a TemplateSpecializationTypeLoc.
3198 TypeLocBuilder TLB;
3199 TemplateSpecializationTypeLoc TL
3200 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3201
John McCall0d07eb32009-10-29 18:45:58 +00003202 SourceLocation BaseLoc = getDerived().getBaseLocation();
3203
3204 TL.setTemplateNameLoc(BaseLoc);
3205 TL.setLAngleLoc(BaseLoc);
3206 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003207 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3208 const TemplateArgument &TA = TST->getArg(i);
3209 TemplateArgumentLoc TAL;
3210 getDerived().InventTemplateArgumentLoc(TA, TAL);
3211 TL.setArgLocInfo(i, TAL.getLocInfo());
3212 }
3213
3214 TypeLocBuilder IgnoredTLB;
3215 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003216}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003217
Douglas Gregorc59e5612009-10-19 22:04:39 +00003218template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003219QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003220 TypeLocBuilder &TLB,
3221 TemplateSpecializationTypeLoc TL,
3222 QualType ObjectType) {
3223 const TemplateSpecializationType *T = TL.getTypePtr();
3224
Mike Stump11289f42009-09-09 15:08:12 +00003225 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003226 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003227 if (Template.isNull())
3228 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003229
John McCall6b51f282009-11-23 01:53:49 +00003230 TemplateArgumentListInfo NewTemplateArgs;
3231 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3232 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3233
3234 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3235 TemplateArgumentLoc Loc;
3236 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003237 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003238 NewTemplateArgs.addArgument(Loc);
3239 }
Mike Stump11289f42009-09-09 15:08:12 +00003240
John McCall0ad16662009-10-29 08:12:44 +00003241 // FIXME: maybe don't rebuild if all the template arguments are the same.
3242
3243 QualType Result =
3244 getDerived().RebuildTemplateSpecializationType(Template,
3245 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003246 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003247
3248 if (!Result.isNull()) {
3249 TemplateSpecializationTypeLoc NewTL
3250 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3251 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3252 NewTL.setLAngleLoc(TL.getLAngleLoc());
3253 NewTL.setRAngleLoc(TL.getRAngleLoc());
3254 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3255 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003256 }
Mike Stump11289f42009-09-09 15:08:12 +00003257
John McCall0ad16662009-10-29 08:12:44 +00003258 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003259}
Mike Stump11289f42009-09-09 15:08:12 +00003260
3261template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003262QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003263TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3264 ElaboratedTypeLoc TL,
3265 QualType ObjectType) {
3266 ElaboratedType *T = TL.getTypePtr();
3267
3268 NestedNameSpecifier *NNS = 0;
3269 // NOTE: the qualifier in an ElaboratedType is optional.
3270 if (T->getQualifier() != 0) {
3271 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003272 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003273 ObjectType);
3274 if (!NNS)
3275 return QualType();
3276 }
Mike Stump11289f42009-09-09 15:08:12 +00003277
Abramo Bagnarad7548482010-05-19 21:37:53 +00003278 QualType NamedT;
3279 // FIXME: this test is meant to workaround a problem (failing assertion)
3280 // occurring if directly executing the code in the else branch.
3281 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3282 TemplateSpecializationTypeLoc OldNamedTL
3283 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3284 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003285 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003286 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3287 if (NamedT.isNull())
3288 return QualType();
3289 TemplateSpecializationTypeLoc NewNamedTL
3290 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3291 NewNamedTL.copy(OldNamedTL);
3292 }
3293 else {
3294 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3295 if (NamedT.isNull())
3296 return QualType();
3297 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003298
John McCall550e0c22009-10-21 00:40:46 +00003299 QualType Result = TL.getType();
3300 if (getDerived().AlwaysRebuild() ||
3301 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003302 NamedT != T->getNamedType()) {
3303 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003304 if (Result.isNull())
3305 return QualType();
3306 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003307
Abramo Bagnara6150c882010-05-11 21:36:43 +00003308 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003309 NewTL.setKeywordLoc(TL.getKeywordLoc());
3310 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003311
3312 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313}
Mike Stump11289f42009-09-09 15:08:12 +00003314
3315template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003316QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3317 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003318 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003319 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003320
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003322 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3323 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003324 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325 if (!NNS)
3326 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003327
John McCallc392f372010-06-11 00:33:02 +00003328 QualType Result
3329 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3330 T->getIdentifier(),
3331 TL.getKeywordLoc(),
3332 TL.getQualifierRange(),
3333 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003334 if (Result.isNull())
3335 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003336
Abramo Bagnarad7548482010-05-19 21:37:53 +00003337 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3338 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003339 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3340
Abramo Bagnarad7548482010-05-19 21:37:53 +00003341 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3342 NewTL.setKeywordLoc(TL.getKeywordLoc());
3343 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003344 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003345 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3346 NewTL.setKeywordLoc(TL.getKeywordLoc());
3347 NewTL.setQualifierRange(TL.getQualifierRange());
3348 NewTL.setNameLoc(TL.getNameLoc());
3349 }
John McCall550e0c22009-10-21 00:40:46 +00003350 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003351}
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregord6ff3322009-08-04 16:50:30 +00003353template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003354QualType TreeTransform<Derived>::
3355 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3356 DependentTemplateSpecializationTypeLoc TL,
3357 QualType ObjectType) {
3358 DependentTemplateSpecializationType *T = TL.getTypePtr();
3359
3360 NestedNameSpecifier *NNS
3361 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3362 TL.getQualifierRange(),
3363 ObjectType);
3364 if (!NNS)
3365 return QualType();
3366
3367 TemplateArgumentListInfo NewTemplateArgs;
3368 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3369 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3370
3371 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3372 TemplateArgumentLoc Loc;
3373 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3374 return QualType();
3375 NewTemplateArgs.addArgument(Loc);
3376 }
3377
3378 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3379 T->getKeyword(),
3380 NNS,
3381 T->getIdentifier(),
3382 TL.getNameLoc(),
3383 NewTemplateArgs);
3384 if (Result.isNull())
3385 return QualType();
3386
3387 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3388 QualType NamedT = ElabT->getNamedType();
3389
3390 // Copy information relevant to the template specialization.
3391 TemplateSpecializationTypeLoc NamedTL
3392 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3393 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3394 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3395 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3396 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3397
3398 // Copy information relevant to the elaborated type.
3399 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3400 NewTL.setKeywordLoc(TL.getKeywordLoc());
3401 NewTL.setQualifierRange(TL.getQualifierRange());
3402 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003403 TypeLoc NewTL(Result, TL.getOpaqueData());
3404 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003405 }
3406 return Result;
3407}
3408
3409template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003410QualType
3411TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003412 ObjCInterfaceTypeLoc TL,
3413 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003414 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003415 TLB.pushFullCopy(TL);
3416 return TL.getType();
3417}
3418
3419template<typename Derived>
3420QualType
3421TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3422 ObjCObjectTypeLoc TL,
3423 QualType ObjectType) {
3424 // ObjCObjectType is never dependent.
3425 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003426 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003427}
Mike Stump11289f42009-09-09 15:08:12 +00003428
3429template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003430QualType
3431TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003432 ObjCObjectPointerTypeLoc TL,
3433 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003434 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003435 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003436 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003437}
3438
Douglas Gregord6ff3322009-08-04 16:50:30 +00003439//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003440// Statement transformation
3441//===----------------------------------------------------------------------===//
3442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003443StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003444TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3445 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003446}
3447
3448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003449StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003450TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3451 return getDerived().TransformCompoundStmt(S, false);
3452}
3453
3454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003455StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003456TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003457 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003458 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003459 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003460 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3462 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003463 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003464 if (Result.isInvalid()) {
3465 // Immediately fail if this was a DeclStmt, since it's very
3466 // likely that this will cause problems for future statements.
3467 if (isa<DeclStmt>(*B))
3468 return StmtError();
3469
3470 // Otherwise, just keep processing substatements and fail later.
3471 SubStmtInvalid = true;
3472 continue;
3473 }
Mike Stump11289f42009-09-09 15:08:12 +00003474
Douglas Gregorebe10102009-08-20 07:17:43 +00003475 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3476 Statements.push_back(Result.takeAs<Stmt>());
3477 }
Mike Stump11289f42009-09-09 15:08:12 +00003478
John McCall1ababa62010-08-27 19:56:05 +00003479 if (SubStmtInvalid)
3480 return StmtError();
3481
Douglas Gregorebe10102009-08-20 07:17:43 +00003482 if (!getDerived().AlwaysRebuild() &&
3483 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003484 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003485
3486 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3487 move_arg(Statements),
3488 S->getRBracLoc(),
3489 IsStmtExpr);
3490}
Mike Stump11289f42009-09-09 15:08:12 +00003491
Douglas Gregorebe10102009-08-20 07:17:43 +00003492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003493StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003494TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003495 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003496 {
3497 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003498 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003499
Eli Friedman06577382009-11-19 03:14:00 +00003500 // Transform the left-hand case value.
3501 LHS = getDerived().TransformExpr(S->getLHS());
3502 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003503 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003504
Eli Friedman06577382009-11-19 03:14:00 +00003505 // Transform the right-hand case value (for the GNU case-range extension).
3506 RHS = getDerived().TransformExpr(S->getRHS());
3507 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003508 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003509 }
Mike Stump11289f42009-09-09 15:08:12 +00003510
Douglas Gregorebe10102009-08-20 07:17:43 +00003511 // Build the case statement.
3512 // Case statements are always rebuilt so that they will attached to their
3513 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003514 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003515 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003516 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003517 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003518 S->getColonLoc());
3519 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003520 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorebe10102009-08-20 07:17:43 +00003522 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003523 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003525 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003526
Douglas Gregorebe10102009-08-20 07:17:43 +00003527 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003528 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003529}
3530
3531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003532StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003533TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003535 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003537 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 // Default statements are always rebuilt
3540 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003541 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003542}
Mike Stump11289f42009-09-09 15:08:12 +00003543
Douglas Gregorebe10102009-08-20 07:17:43 +00003544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003545StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003546TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003547 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003548 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003549 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003550
Douglas Gregorebe10102009-08-20 07:17:43 +00003551 // FIXME: Pass the real colon location in.
3552 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3553 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003554 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003555}
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregorebe10102009-08-20 07:17:43 +00003557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003558StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003559TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003560 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003561 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003562 VarDecl *ConditionVar = 0;
3563 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003564 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003565 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003566 getDerived().TransformDefinition(
3567 S->getConditionVariable()->getLocation(),
3568 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003569 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003570 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003571 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003572 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003573
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003574 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003575 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003576
3577 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003578 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003579 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003580 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003581 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003582 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003583 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003584
John McCallb268a282010-08-23 23:25:46 +00003585 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003586 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003587 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003588
John McCallb268a282010-08-23 23:25:46 +00003589 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3590 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003591 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003592
Douglas Gregorebe10102009-08-20 07:17:43 +00003593 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003594 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003595 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003596 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003599 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003600 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003602
Douglas Gregorebe10102009-08-20 07:17:43 +00003603 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003604 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003605 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 Then.get() == S->getThen() &&
3607 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003608 return SemaRef.Owned(S->Retain());
3609
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003610 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003611 Then.get(),
3612 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003613}
3614
3615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003616StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003617TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003618 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003619 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003620 VarDecl *ConditionVar = 0;
3621 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003622 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003623 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003624 getDerived().TransformDefinition(
3625 S->getConditionVariable()->getLocation(),
3626 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003627 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003628 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003629 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003630 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003631
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003632 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003633 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003634 }
Mike Stump11289f42009-09-09 15:08:12 +00003635
Douglas Gregorebe10102009-08-20 07:17:43 +00003636 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003637 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003638 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003639 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003640 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003641 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003642
Douglas Gregorebe10102009-08-20 07:17:43 +00003643 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003644 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003645 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003646 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003647
Douglas Gregorebe10102009-08-20 07:17:43 +00003648 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003649 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3650 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003651}
Mike Stump11289f42009-09-09 15:08:12 +00003652
Douglas Gregorebe10102009-08-20 07:17:43 +00003653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003654StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003655TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003656 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003657 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003658 VarDecl *ConditionVar = 0;
3659 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003660 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003661 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003662 getDerived().TransformDefinition(
3663 S->getConditionVariable()->getLocation(),
3664 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003665 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003666 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003667 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003668 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003669
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003670 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003671 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003672
3673 if (S->getCond()) {
3674 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003675 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003676 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003677 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003678 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003679 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003680 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003681 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003682 }
Mike Stump11289f42009-09-09 15:08:12 +00003683
John McCallb268a282010-08-23 23:25:46 +00003684 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3685 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003686 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003687
Douglas Gregorebe10102009-08-20 07:17:43 +00003688 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003689 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003690 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003691 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003692
Douglas Gregorebe10102009-08-20 07:17:43 +00003693 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003694 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003695 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003696 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003697 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003699 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003700 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003701}
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregorebe10102009-08-20 07:17:43 +00003703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003704StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003705TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003706 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003707 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003709 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003711 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003712 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003713 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003714 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003715
Douglas Gregorebe10102009-08-20 07:17:43 +00003716 if (!getDerived().AlwaysRebuild() &&
3717 Cond.get() == S->getCond() &&
3718 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003719 return SemaRef.Owned(S->Retain());
3720
John McCallb268a282010-08-23 23:25:46 +00003721 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3722 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003723 S->getRParenLoc());
3724}
Mike Stump11289f42009-09-09 15:08:12 +00003725
Douglas Gregorebe10102009-08-20 07:17:43 +00003726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003727StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003728TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003729 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003730 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003732 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003733
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003735 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003736 VarDecl *ConditionVar = 0;
3737 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003738 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003739 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003740 getDerived().TransformDefinition(
3741 S->getConditionVariable()->getLocation(),
3742 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003743 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003744 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003745 } else {
3746 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003747
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003748 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003749 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003750
3751 if (S->getCond()) {
3752 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003753 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003754 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003755 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003756 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003757 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003758
John McCallb268a282010-08-23 23:25:46 +00003759 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003760 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003761 }
Mike Stump11289f42009-09-09 15:08:12 +00003762
John McCallb268a282010-08-23 23:25:46 +00003763 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3764 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003765 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003766
Douglas Gregorebe10102009-08-20 07:17:43 +00003767 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003768 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003769 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003770 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003771
John McCallb268a282010-08-23 23:25:46 +00003772 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3773 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003774 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003775
Douglas Gregorebe10102009-08-20 07:17:43 +00003776 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003777 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003779 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003780
Douglas Gregorebe10102009-08-20 07:17:43 +00003781 if (!getDerived().AlwaysRebuild() &&
3782 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003783 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003784 Inc.get() == S->getInc() &&
3785 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003786 return SemaRef.Owned(S->Retain());
3787
Douglas Gregorebe10102009-08-20 07:17:43 +00003788 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003789 Init.get(), FullCond, ConditionVar,
3790 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003791}
3792
3793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003794StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003795TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003796 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003797 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003798 S->getLabel());
3799}
3800
3801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003803TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003804 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003805 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003806 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregorebe10102009-08-20 07:17:43 +00003808 if (!getDerived().AlwaysRebuild() &&
3809 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003810 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003811
3812 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003813 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003814}
3815
3816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003817StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003818TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3819 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003820}
Mike Stump11289f42009-09-09 15:08:12 +00003821
Douglas Gregorebe10102009-08-20 07:17:43 +00003822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003824TreeTransform<Derived>::TransformBreakStmt(BreakStmt *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>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003831 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003833 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003834
Mike Stump11289f42009-09-09 15:08:12 +00003835 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003836 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003837 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003838}
Mike Stump11289f42009-09-09 15:08:12 +00003839
Douglas Gregorebe10102009-08-20 07:17:43 +00003840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003842TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 bool DeclChanged = false;
3844 llvm::SmallVector<Decl *, 4> Decls;
3845 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3846 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003847 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3848 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003849 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003850 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003851
Douglas Gregorebe10102009-08-20 07:17:43 +00003852 if (Transformed != *D)
3853 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003854
Douglas Gregorebe10102009-08-20 07:17:43 +00003855 Decls.push_back(Transformed);
3856 }
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregorebe10102009-08-20 07:17:43 +00003858 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003859 return SemaRef.Owned(S->Retain());
3860
3861 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003862 S->getStartLoc(), S->getEndLoc());
3863}
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregorebe10102009-08-20 07:17:43 +00003865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003866StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003867TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003868 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003869 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003870}
3871
3872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003873StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003874TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003875
John McCall37ad5512010-08-23 06:44:23 +00003876 ASTOwningVector<Expr*> Constraints(getSema());
3877 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003878 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003879
John McCalldadc5752010-08-24 06:29:42 +00003880 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003881 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003882
3883 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003884
Anders Carlssonaaeef072010-01-24 05:50:09 +00003885 // Go through the outputs.
3886 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003887 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003888
Anders Carlssonaaeef072010-01-24 05:50:09 +00003889 // No need to transform the constraint literal.
3890 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003891
Anders Carlssonaaeef072010-01-24 05:50:09 +00003892 // Transform the output expr.
3893 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003894 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003895 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003896 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003897
Anders Carlssonaaeef072010-01-24 05:50:09 +00003898 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003899
John McCallb268a282010-08-23 23:25:46 +00003900 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003902
Anders Carlssonaaeef072010-01-24 05:50:09 +00003903 // Go through the inputs.
3904 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003905 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003906
Anders Carlssonaaeef072010-01-24 05:50:09 +00003907 // No need to transform the constraint literal.
3908 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003909
Anders Carlssonaaeef072010-01-24 05:50:09 +00003910 // Transform the input expr.
3911 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003912 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003913 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003914 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003915
Anders Carlssonaaeef072010-01-24 05:50:09 +00003916 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003917
John McCallb268a282010-08-23 23:25:46 +00003918 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003920
Anders Carlssonaaeef072010-01-24 05:50:09 +00003921 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3922 return SemaRef.Owned(S->Retain());
3923
3924 // Go through the clobbers.
3925 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3926 Clobbers.push_back(S->getClobber(I)->Retain());
3927
3928 // No need to transform the asm string literal.
3929 AsmString = SemaRef.Owned(S->getAsmString());
3930
3931 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3932 S->isSimple(),
3933 S->isVolatile(),
3934 S->getNumOutputs(),
3935 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003936 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003937 move_arg(Constraints),
3938 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003939 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003940 move_arg(Clobbers),
3941 S->getRParenLoc(),
3942 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003943}
3944
3945
3946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003947StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003948TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003949 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003950 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003951 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003952 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003953
Douglas Gregor96c79492010-04-23 22:50:49 +00003954 // Transform the @catch statements (if present).
3955 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003956 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003957 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003958 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003959 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003960 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003961 if (Catch.get() != S->getCatchStmt(I))
3962 AnyCatchChanged = true;
3963 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003964 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003965
Douglas Gregor306de2f2010-04-22 23:59:56 +00003966 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00003967 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003968 if (S->getFinallyStmt()) {
3969 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3970 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003971 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00003972 }
3973
3974 // If nothing changed, just retain this statement.
3975 if (!getDerived().AlwaysRebuild() &&
3976 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003977 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003978 Finally.get() == S->getFinallyStmt())
3979 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003980
Douglas Gregor306de2f2010-04-22 23:59:56 +00003981 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003982 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3983 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003984}
Mike Stump11289f42009-09-09 15:08:12 +00003985
Douglas Gregorebe10102009-08-20 07:17:43 +00003986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003987StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003988TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003989 // Transform the @catch parameter, if there is one.
3990 VarDecl *Var = 0;
3991 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3992 TypeSourceInfo *TSInfo = 0;
3993 if (FromVar->getTypeSourceInfo()) {
3994 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3995 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00003996 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003997 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003998
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003999 QualType T;
4000 if (TSInfo)
4001 T = TSInfo->getType();
4002 else {
4003 T = getDerived().TransformType(FromVar->getType());
4004 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004005 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004006 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004007
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004008 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4009 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004010 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004011 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004012
John McCalldadc5752010-08-24 06:29:42 +00004013 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004014 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004015 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004016
4017 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004018 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004019 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004020}
Mike Stump11289f42009-09-09 15:08:12 +00004021
Douglas Gregorebe10102009-08-20 07:17:43 +00004022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004023StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004024TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004025 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004026 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004027 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004028 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004029
Douglas Gregor306de2f2010-04-22 23:59:56 +00004030 // If nothing changed, just retain this statement.
4031 if (!getDerived().AlwaysRebuild() &&
4032 Body.get() == S->getFinallyBody())
4033 return SemaRef.Owned(S->Retain());
4034
4035 // Build a new statement.
4036 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004037 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004038}
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregorebe10102009-08-20 07:17:43 +00004040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004041StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004042TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004043 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004044 if (S->getThrowExpr()) {
4045 Operand = getDerived().TransformExpr(S->getThrowExpr());
4046 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004047 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004048 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004049
Douglas Gregor2900c162010-04-22 21:44:01 +00004050 if (!getDerived().AlwaysRebuild() &&
4051 Operand.get() == S->getThrowExpr())
4052 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004053
John McCallb268a282010-08-23 23:25:46 +00004054 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004055}
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregorebe10102009-08-20 07:17:43 +00004057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004058StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004059TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004060 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004061 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004062 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004063 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004064 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004065
Douglas Gregor6148de72010-04-22 22:01:21 +00004066 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004067 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004068 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004069 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004070
Douglas Gregor6148de72010-04-22 22:01:21 +00004071 // If nothing change, just retain the current statement.
4072 if (!getDerived().AlwaysRebuild() &&
4073 Object.get() == S->getSynchExpr() &&
4074 Body.get() == S->getSynchBody())
4075 return SemaRef.Owned(S->Retain());
4076
4077 // Build a new statement.
4078 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004079 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004080}
4081
4082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004083StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004084TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004085 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004086 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004087 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004088 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004089 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004090
Douglas Gregorf68a5082010-04-22 23:10:45 +00004091 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004092 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004093 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004094 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004095
Douglas Gregorf68a5082010-04-22 23:10:45 +00004096 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004097 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004098 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004099 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004100
Douglas Gregorf68a5082010-04-22 23:10:45 +00004101 // If nothing changed, just retain this statement.
4102 if (!getDerived().AlwaysRebuild() &&
4103 Element.get() == S->getElement() &&
4104 Collection.get() == S->getCollection() &&
4105 Body.get() == S->getBody())
4106 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004107
Douglas Gregorf68a5082010-04-22 23:10:45 +00004108 // Build a new statement.
4109 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4110 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004111 Element.get(),
4112 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004113 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004114 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004115}
4116
4117
4118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004119StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004120TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4121 // Transform the exception declaration, if any.
4122 VarDecl *Var = 0;
4123 if (S->getExceptionDecl()) {
4124 VarDecl *ExceptionDecl = S->getExceptionDecl();
4125 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4126 ExceptionDecl->getDeclName());
4127
4128 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4129 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregorebe10102009-08-20 07:17:43 +00004132 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4133 T,
John McCallbcd03502009-12-07 02:54:59 +00004134 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004135 ExceptionDecl->getIdentifier(),
4136 ExceptionDecl->getLocation(),
4137 /*FIXME: Inaccurate*/
4138 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004139 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004140 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004141 }
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregorebe10102009-08-20 07:17:43 +00004143 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004144 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004145 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004146 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004147
Douglas Gregorebe10102009-08-20 07:17:43 +00004148 if (!getDerived().AlwaysRebuild() &&
4149 !Var &&
4150 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004151 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004152
4153 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4154 Var,
John McCallb268a282010-08-23 23:25:46 +00004155 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004156}
Mike Stump11289f42009-09-09 15:08:12 +00004157
Douglas Gregorebe10102009-08-20 07:17:43 +00004158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004159StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004160TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4161 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004162 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004163 = getDerived().TransformCompoundStmt(S->getTryBlock());
4164 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004165 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004166
Douglas Gregorebe10102009-08-20 07:17:43 +00004167 // Transform the handlers.
4168 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004169 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004170 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004171 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004172 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4173 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004174 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004175
Douglas Gregorebe10102009-08-20 07:17:43 +00004176 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4177 Handlers.push_back(Handler.takeAs<Stmt>());
4178 }
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregorebe10102009-08-20 07:17:43 +00004180 if (!getDerived().AlwaysRebuild() &&
4181 TryBlock.get() == S->getTryBlock() &&
4182 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004183 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004184
John McCallb268a282010-08-23 23:25:46 +00004185 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004186 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004187}
Mike Stump11289f42009-09-09 15:08:12 +00004188
Douglas Gregorebe10102009-08-20 07:17:43 +00004189//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004190// Expression transformation
4191//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004194TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004195 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004196}
Mike Stump11289f42009-09-09 15:08:12 +00004197
4198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004200TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004201 NestedNameSpecifier *Qualifier = 0;
4202 if (E->getQualifier()) {
4203 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004204 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004205 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004206 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004207 }
John McCallce546572009-12-08 09:08:17 +00004208
4209 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004210 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4211 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall815039a2010-08-17 21:27:17 +00004215 DeclarationNameInfo NameInfo = E->getNameInfo();
4216 if (NameInfo.getName()) {
4217 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4218 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004219 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004220 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004221
4222 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004223 Qualifier == E->getQualifier() &&
4224 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004225 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004226 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004227
4228 // Mark it referenced in the new context regardless.
4229 // FIXME: this is a bit instantiation-specific.
4230 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4231
Mike Stump11289f42009-09-09 15:08:12 +00004232 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004233 }
John McCallce546572009-12-08 09:08:17 +00004234
4235 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004236 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004237 TemplateArgs = &TransArgs;
4238 TransArgs.setLAngleLoc(E->getLAngleLoc());
4239 TransArgs.setRAngleLoc(E->getRAngleLoc());
4240 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4241 TemplateArgumentLoc Loc;
4242 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004243 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004244 TransArgs.addArgument(Loc);
4245 }
4246 }
4247
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004248 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004249 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004250}
Mike Stump11289f42009-09-09 15:08:12 +00004251
Douglas Gregora16548e2009-08-11 05:31:07 +00004252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004254TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004255 return SemaRef.Owned(E->Retain());
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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004279 return SemaRef.Owned(E->Retain());
4280}
4281
4282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004284TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004285 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregora16548e2009-08-11 05:31:07 +00004289 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004290 return SemaRef.Owned(E->Retain());
4291
John McCallb268a282010-08-23 23:25:46 +00004292 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 E->getRParen());
4294}
4295
Mike Stump11289f42009-09-09 15:08:12 +00004296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004297ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004298TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004299 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004301 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004302
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004304 return SemaRef.Owned(E->Retain());
4305
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4307 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004308 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004312ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004313TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4314 // Transform the type.
4315 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4316 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004317 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004318
Douglas Gregor882211c2010-04-28 22:16:22 +00004319 // Transform all of the components into components similar to what the
4320 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004321 // FIXME: It would be slightly more efficient in the non-dependent case to
4322 // just map FieldDecls, rather than requiring the rebuilder to look for
4323 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004324 // template code that we don't care.
4325 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004326 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004327 typedef OffsetOfExpr::OffsetOfNode Node;
4328 llvm::SmallVector<Component, 4> Components;
4329 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4330 const Node &ON = E->getComponent(I);
4331 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004332 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004333 Comp.LocStart = ON.getRange().getBegin();
4334 Comp.LocEnd = ON.getRange().getEnd();
4335 switch (ON.getKind()) {
4336 case Node::Array: {
4337 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004338 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004339 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004340 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004341
Douglas Gregor882211c2010-04-28 22:16:22 +00004342 ExprChanged = ExprChanged || Index.get() != FromIndex;
4343 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004344 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004345 break;
4346 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004347
Douglas Gregor882211c2010-04-28 22:16:22 +00004348 case Node::Field:
4349 case Node::Identifier:
4350 Comp.isBrackets = false;
4351 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004352 if (!Comp.U.IdentInfo)
4353 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004354
Douglas Gregor882211c2010-04-28 22:16:22 +00004355 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004356
Douglas Gregord1702062010-04-29 00:18:15 +00004357 case Node::Base:
4358 // Will be recomputed during the rebuild.
4359 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004360 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004361
Douglas Gregor882211c2010-04-28 22:16:22 +00004362 Components.push_back(Comp);
4363 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004364
Douglas Gregor882211c2010-04-28 22:16:22 +00004365 // If nothing changed, retain the existing expression.
4366 if (!getDerived().AlwaysRebuild() &&
4367 Type == E->getTypeSourceInfo() &&
4368 !ExprChanged)
4369 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004370
Douglas Gregor882211c2010-04-28 22:16:22 +00004371 // Build a new offsetof expression.
4372 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4373 Components.data(), Components.size(),
4374 E->getRParenLoc());
4375}
4376
4377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004379TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004380 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004381 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004382
John McCallbcd03502009-12-07 02:54:59 +00004383 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004384 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004386
John McCall4c98fd82009-11-04 07:28:41 +00004387 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004389
John McCall4c98fd82009-11-04 07:28:41 +00004390 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004391 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 E->getSourceRange());
4393 }
Mike Stump11289f42009-09-09 15:08:12 +00004394
John McCalldadc5752010-08-24 06:29:42 +00004395 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004396 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 // C++0x [expr.sizeof]p1:
4398 // The operand is either an expression, which is an unevaluated operand
4399 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4403 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4407 return SemaRef.Owned(E->Retain());
4408 }
Mike Stump11289f42009-09-09 15:08:12 +00004409
John McCallb268a282010-08-23 23:25:46 +00004410 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 E->isSizeOf(),
4412 E->getSourceRange());
4413}
Mike Stump11289f42009-09-09 15:08:12 +00004414
Douglas Gregora16548e2009-08-11 05:31:07 +00004415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004417TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004418 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004420 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004421
John McCalldadc5752010-08-24 06:29:42 +00004422 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004424 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004425
4426
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 if (!getDerived().AlwaysRebuild() &&
4428 LHS.get() == E->getLHS() &&
4429 RHS.get() == E->getRHS())
4430 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004431
John McCallb268a282010-08-23 23:25:46 +00004432 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004434 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 E->getRBracketLoc());
4436}
Mike Stump11289f42009-09-09 15:08:12 +00004437
4438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004440TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004442 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004444 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004445
4446 // Transform arguments.
4447 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004448 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4450 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004451 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 // FIXME: Wrong source location information for the ','.
4456 FakeCommaLocs.push_back(
4457 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004458
4459 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004460 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 }
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 if (!getDerived().AlwaysRebuild() &&
4464 Callee.get() == E->getCallee() &&
4465 !ArgChanged)
4466 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004469 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004471 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 move_arg(Args),
4473 FakeCommaLocs.data(),
4474 E->getRParenLoc());
4475}
Mike Stump11289f42009-09-09 15:08:12 +00004476
4477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004478ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004479TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004480 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004483
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004484 NestedNameSpecifier *Qualifier = 0;
4485 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004486 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004487 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004488 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004489 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004490 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004491 }
Mike Stump11289f42009-09-09 15:08:12 +00004492
Eli Friedman2cfcef62009-12-04 06:40:45 +00004493 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004494 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4495 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004496 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004498
John McCall16df1e52010-03-30 21:47:33 +00004499 NamedDecl *FoundDecl = E->getFoundDecl();
4500 if (FoundDecl == E->getMemberDecl()) {
4501 FoundDecl = Member;
4502 } else {
4503 FoundDecl = cast_or_null<NamedDecl>(
4504 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4505 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004506 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004507 }
4508
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 if (!getDerived().AlwaysRebuild() &&
4510 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004511 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004512 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004513 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004514 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004515
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004516 // Mark it referenced in the new context regardless.
4517 // FIXME: this is a bit instantiation-specific.
4518 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004519 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004520 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004521
John McCall6b51f282009-11-23 01:53:49 +00004522 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004523 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004524 TransArgs.setLAngleLoc(E->getLAngleLoc());
4525 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004526 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004527 TemplateArgumentLoc Loc;
4528 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004529 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004530 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004531 }
4532 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 // FIXME: Bogus source location for the operator
4535 SourceLocation FakeOperatorLoc
4536 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4537
John McCall38836f02010-01-15 08:34:02 +00004538 // FIXME: to do this check properly, we will need to preserve the
4539 // first-qualifier-in-scope here, just in case we had a dependent
4540 // base (and therefore couldn't do the check) and a
4541 // nested-name-qualifier (and therefore could do the lookup).
4542 NamedDecl *FirstQualifierInScope = 0;
4543
John McCallb268a282010-08-23 23:25:46 +00004544 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004546 Qualifier,
4547 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004548 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004549 Member,
John McCall16df1e52010-03-30 21:47:33 +00004550 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004551 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004552 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004553 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004554}
Mike Stump11289f42009-09-09 15:08:12 +00004555
Douglas Gregora16548e2009-08-11 05:31:07 +00004556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004558TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004559 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
John McCalldadc5752010-08-24 06:29:42 +00004563 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004566
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 if (!getDerived().AlwaysRebuild() &&
4568 LHS.get() == E->getLHS() &&
4569 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004570 return SemaRef.Owned(E->Retain());
4571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004573 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004574}
4575
Mike Stump11289f42009-09-09 15:08:12 +00004576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004577ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004578TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004579 CompoundAssignOperator *E) {
4580 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004581}
Mike Stump11289f42009-09-09 15:08:12 +00004582
Douglas Gregora16548e2009-08-11 05:31:07 +00004583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004585TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004586 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004589
John McCalldadc5752010-08-24 06:29:42 +00004590 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004593
John McCalldadc5752010-08-24 06:29:42 +00004594 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004597
Douglas Gregora16548e2009-08-11 05:31:07 +00004598 if (!getDerived().AlwaysRebuild() &&
4599 Cond.get() == E->getCond() &&
4600 LHS.get() == E->getLHS() &&
4601 RHS.get() == E->getRHS())
4602 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004603
John McCallb268a282010-08-23 23:25:46 +00004604 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004605 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004606 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004607 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004608 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004609}
Mike Stump11289f42009-09-09 15:08:12 +00004610
4611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004613TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004614 // Implicit casts are eliminated during transformation, since they
4615 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004616 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregora16548e2009-08-11 05:31:07 +00004619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004622 TypeSourceInfo *OldT;
4623 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 {
4625 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004626 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4628 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004629
John McCall97513962010-01-15 18:39:57 +00004630 OldT = E->getTypeInfoAsWritten();
4631 NewT = getDerived().TransformType(OldT);
4632 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004633 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004634 }
Mike Stump11289f42009-09-09 15:08:12 +00004635
John McCalldadc5752010-08-24 06:29:42 +00004636 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004637 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004639 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004642 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004644 return SemaRef.Owned(E->Retain());
4645
John McCall97513962010-01-15 18:39:57 +00004646 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4647 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004649 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004650}
Mike Stump11289f42009-09-09 15:08:12 +00004651
Douglas Gregora16548e2009-08-11 05:31:07 +00004652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004654TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004655 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4656 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4657 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
John McCalldadc5752010-08-24 06:29:42 +00004660 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004661 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004665 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004667 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004668
John McCall5d7aa7f2010-01-19 22:33:45 +00004669 // Note: the expression type doesn't necessarily match the
4670 // type-as-written, but that's okay, because it should always be
4671 // derivable from the initializer.
4672
John McCalle15bbff2010-01-18 19:35:47 +00004673 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004675 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004676}
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregora16548e2009-08-11 05:31:07 +00004678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004680TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004681 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004684
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 if (!getDerived().AlwaysRebuild() &&
4686 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004687 return SemaRef.Owned(E->Retain());
4688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004690 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004692 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 E->getAccessorLoc(),
4694 E->getAccessor());
4695}
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004699TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004701
John McCall37ad5512010-08-23 06:44:23 +00004702 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004703 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004704 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004709 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 }
Mike Stump11289f42009-09-09 15:08:12 +00004711
Douglas Gregora16548e2009-08-11 05:31:07 +00004712 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004713 return SemaRef.Owned(E->Retain());
4714
Douglas Gregora16548e2009-08-11 05:31:07 +00004715 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004716 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004717}
Mike Stump11289f42009-09-09 15:08:12 +00004718
Douglas Gregora16548e2009-08-11 05:31:07 +00004719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004721TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004723
Douglas Gregorebe10102009-08-20 07:17:43 +00004724 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004725 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregorebe10102009-08-20 07:17:43 +00004729 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004730 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 bool ExprChanged = false;
4732 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4733 DEnd = E->designators_end();
4734 D != DEnd; ++D) {
4735 if (D->isFieldDesignator()) {
4736 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4737 D->getDotLoc(),
4738 D->getFieldLoc()));
4739 continue;
4740 }
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004743 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004746
4747 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregora16548e2009-08-11 05:31:07 +00004750 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4751 ArrayExprs.push_back(Index.release());
4752 continue;
4753 }
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004756 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4758 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004759 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004760
John McCalldadc5752010-08-24 06:29:42 +00004761 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004764
4765 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 End.get(),
4767 D->getLBracketLoc(),
4768 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4771 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 ArrayExprs.push_back(Start.release());
4774 ArrayExprs.push_back(End.release());
4775 }
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregora16548e2009-08-11 05:31:07 +00004777 if (!getDerived().AlwaysRebuild() &&
4778 Init.get() == E->getInit() &&
4779 !ExprChanged)
4780 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4783 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004784 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004785}
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004788ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004789TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004790 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004791 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004792
Douglas Gregor3da3c062009-10-28 00:29:27 +00004793 // FIXME: Will we ever have proper type location here? Will we actually
4794 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 QualType T = getDerived().TransformType(E->getType());
4796 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004797 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 if (!getDerived().AlwaysRebuild() &&
4800 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004801 return SemaRef.Owned(E->Retain());
4802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 return getDerived().RebuildImplicitValueInitExpr(T);
4804}
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004808TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004809 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4810 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004812
John McCalldadc5752010-08-24 06:29:42 +00004813 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004818 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 SubExpr.get() == E->getSubExpr())
4820 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004821
John McCallb268a282010-08-23 23:25:46 +00004822 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004823 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004824}
4825
4826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004828TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004830 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004832 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregora16548e2009-08-11 05:31:07 +00004836 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004837 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 }
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4841 move_arg(Inits),
4842 E->getRParenLoc());
4843}
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregora16548e2009-08-11 05:31:07 +00004845/// \brief Transform an address-of-label expression.
4846///
4847/// By default, the transformation of an address-of-label expression always
4848/// rebuilds the expression, so that the label identifier can be resolved to
4849/// the corresponding label statement by semantic analysis.
4850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004852TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004853 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4854 E->getLabel());
4855}
Mike Stump11289f42009-09-09 15:08:12 +00004856
4857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004859TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004860 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4862 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004864
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 if (!getDerived().AlwaysRebuild() &&
4866 SubStmt.get() == E->getSubStmt())
4867 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004868
4869 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004870 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 E->getRParenLoc());
4872}
Mike Stump11289f42009-09-09 15:08:12 +00004873
Douglas Gregora16548e2009-08-11 05:31:07 +00004874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004875ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004876TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004877 TypeSourceInfo *TInfo1;
4878 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004879
4880 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4881 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregor7058c262010-08-10 14:27:00 +00004884 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4885 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004886 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004887
4888 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004889 TInfo1 == E->getArgTInfo1() &&
4890 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004891 return SemaRef.Owned(E->Retain());
4892
Douglas Gregora16548e2009-08-11 05:31:07 +00004893 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004894 TInfo1, TInfo2,
4895 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004896}
Mike Stump11289f42009-09-09 15:08:12 +00004897
Douglas Gregora16548e2009-08-11 05:31:07 +00004898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004900TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004901 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004902 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004903 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004904
John McCalldadc5752010-08-24 06:29:42 +00004905 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004906 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004908
John McCalldadc5752010-08-24 06:29:42 +00004909 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004912
Douglas Gregora16548e2009-08-11 05:31:07 +00004913 if (!getDerived().AlwaysRebuild() &&
4914 Cond.get() == E->getCond() &&
4915 LHS.get() == E->getLHS() &&
4916 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004917 return SemaRef.Owned(E->Retain());
4918
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004920 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 E->getRParenLoc());
4922}
Mike Stump11289f42009-09-09 15:08:12 +00004923
Douglas Gregora16548e2009-08-11 05:31:07 +00004924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004926TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004927 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004928}
4929
4930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004932TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004933 switch (E->getOperator()) {
4934 case OO_New:
4935 case OO_Delete:
4936 case OO_Array_New:
4937 case OO_Array_Delete:
4938 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004939 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004940
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004941 case OO_Call: {
4942 // This is a call to an object's operator().
4943 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4944
4945 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004946 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004947 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004948 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004949
4950 // FIXME: Poor location information
4951 SourceLocation FakeLParenLoc
4952 = SemaRef.PP.getLocForEndOfToken(
4953 static_cast<Expr *>(Object.get())->getLocEnd());
4954
4955 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004956 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004957 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4958 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004959 if (getDerived().DropCallArgument(E->getArg(I)))
4960 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004961
John McCalldadc5752010-08-24 06:29:42 +00004962 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004963 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004964 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004965
4966 // FIXME: Poor source location information.
4967 SourceLocation FakeCommaLoc
4968 = SemaRef.PP.getLocForEndOfToken(
4969 static_cast<Expr *>(Arg.get())->getLocEnd());
4970 FakeCommaLocs.push_back(FakeCommaLoc);
4971 Args.push_back(Arg.release());
4972 }
4973
John McCallb268a282010-08-23 23:25:46 +00004974 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004975 move_arg(Args),
4976 FakeCommaLocs.data(),
4977 E->getLocEnd());
4978 }
4979
4980#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4981 case OO_##Name:
4982#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4983#include "clang/Basic/OperatorKinds.def"
4984 case OO_Subscript:
4985 // Handled below.
4986 break;
4987
4988 case OO_Conditional:
4989 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004991
4992 case OO_None:
4993 case NUM_OVERLOADED_OPERATORS:
4994 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004996 }
4997
John McCalldadc5752010-08-24 06:29:42 +00004998 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005001
John McCalldadc5752010-08-24 06:29:42 +00005002 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005005
John McCalldadc5752010-08-24 06:29:42 +00005006 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 if (E->getNumArgs() == 2) {
5008 Second = getDerived().TransformExpr(E->getArg(1));
5009 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005010 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 }
Mike Stump11289f42009-09-09 15:08:12 +00005012
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 if (!getDerived().AlwaysRebuild() &&
5014 Callee.get() == E->getCallee() &&
5015 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005016 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5017 return SemaRef.Owned(E->Retain());
5018
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5020 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005021 Callee.get(),
5022 First.get(),
5023 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005024}
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregora16548e2009-08-11 05:31:07 +00005026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005027ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005028TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5029 return getDerived().TransformCallExpr(E);
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>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005035 TypeSourceInfo *OldT;
5036 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 {
5038 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005039 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5041 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005042
John McCall97513962010-01-15 18:39:57 +00005043 OldT = E->getTypeInfoAsWritten();
5044 NewT = getDerived().TransformType(OldT);
5045 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005046 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 }
Mike Stump11289f42009-09-09 15:08:12 +00005048
John McCalldadc5752010-08-24 06:29:42 +00005049 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005050 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005051 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005052 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005053
Douglas Gregora16548e2009-08-11 05:31:07 +00005054 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005055 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005057 return SemaRef.Owned(E->Retain());
5058
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005060 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5062 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5063 SourceLocation FakeRParenLoc
5064 = SemaRef.PP.getLocForEndOfToken(
5065 E->getSubExpr()->getSourceRange().getEnd());
5066 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005067 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005068 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005069 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 FakeRAngleLoc,
5071 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005072 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 FakeRParenLoc);
5074}
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregora16548e2009-08-11 05:31:07 +00005076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5079 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
5082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005083ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5085 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005086}
5087
Douglas Gregora16548e2009-08-11 05:31:07 +00005088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005089ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005090TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005091 CXXReinterpretCastExpr *E) {
5092 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005093}
Mike Stump11289f42009-09-09 15:08:12 +00005094
Douglas Gregora16548e2009-08-11 05:31:07 +00005095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005097TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *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
Douglas Gregora16548e2009-08-11 05:31:07 +00005103TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005104 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005105 TypeSourceInfo *OldT;
5106 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005107 {
5108 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005109
John McCall97513962010-01-15 18:39:57 +00005110 OldT = E->getTypeInfoAsWritten();
5111 NewT = getDerived().TransformType(OldT);
5112 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005113 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 }
Mike Stump11289f42009-09-09 15:08:12 +00005115
John McCalldadc5752010-08-24 06:29:42 +00005116 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005117 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005122 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005124 return SemaRef.Owned(E->Retain());
5125
Douglas Gregor2b88c112010-09-08 00:15:04 +00005126 return getDerived().RebuildCXXFunctionalCastExpr(NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005128 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 E->getRParenLoc());
5130}
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregora16548e2009-08-11 05:31:07 +00005132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005134TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005136 TypeSourceInfo *TInfo
5137 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5138 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005142 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005143 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregor9da64192010-04-26 22:37:10 +00005145 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5146 E->getLocStart(),
5147 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 E->getLocEnd());
5149 }
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 // We don't know whether the expression is potentially evaluated until
5152 // after we perform semantic analysis, so the expression is potentially
5153 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005154 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005155 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005156
John McCalldadc5752010-08-24 06:29:42 +00005157 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005158 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005160
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 if (!getDerived().AlwaysRebuild() &&
5162 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005163 return SemaRef.Owned(E->Retain());
5164
Douglas Gregor9da64192010-04-26 22:37:10 +00005165 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5166 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005167 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 E->getLocEnd());
5169}
5170
5171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005172ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005173TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5174 if (E->isTypeOperand()) {
5175 TypeSourceInfo *TInfo
5176 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5177 if (!TInfo)
5178 return ExprError();
5179
5180 if (!getDerived().AlwaysRebuild() &&
5181 TInfo == E->getTypeOperandSourceInfo())
5182 return SemaRef.Owned(E->Retain());
5183
5184 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5185 E->getLocStart(),
5186 TInfo,
5187 E->getLocEnd());
5188 }
5189
5190 // We don't know whether the expression is potentially evaluated until
5191 // after we perform semantic analysis, so the expression is potentially
5192 // potentially evaluated.
5193 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5194
5195 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5196 if (SubExpr.isInvalid())
5197 return ExprError();
5198
5199 if (!getDerived().AlwaysRebuild() &&
5200 SubExpr.get() == E->getExprOperand())
5201 return SemaRef.Owned(E->Retain());
5202
5203 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5204 E->getLocStart(),
5205 SubExpr.get(),
5206 E->getLocEnd());
5207}
5208
5209template<typename Derived>
5210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005211TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005212 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005213}
Mike Stump11289f42009-09-09 15:08:12 +00005214
Douglas Gregora16548e2009-08-11 05:31:07 +00005215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005216ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005217TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005218 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005219 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005220}
Mike Stump11289f42009-09-09 15:08:12 +00005221
Douglas Gregora16548e2009-08-11 05:31:07 +00005222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005224TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregora16548e2009-08-11 05:31:07 +00005227 QualType T = getDerived().TransformType(E->getType());
5228 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregora16548e2009-08-11 05:31:07 +00005231 if (!getDerived().AlwaysRebuild() &&
5232 T == E->getType())
5233 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregorb15af892010-01-07 23:12:05 +00005235 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005236}
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregora16548e2009-08-11 05:31:07 +00005238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005240TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005241 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005243 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005244
Douglas Gregora16548e2009-08-11 05:31:07 +00005245 if (!getDerived().AlwaysRebuild() &&
5246 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005247 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248
John McCallb268a282010-08-23 23:25:46 +00005249 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005250}
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregora16548e2009-08-11 05:31:07 +00005252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005255 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005256 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5257 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005260
Chandler Carruth794da4c2010-02-08 06:42:49 +00005261 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005262 Param == E->getParam())
5263 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregor033f6752009-12-23 23:03:06 +00005265 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005266}
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregora16548e2009-08-11 05:31:07 +00005268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005269ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005270TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5271 CXXScalarValueInitExpr *E) {
5272 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5273 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005274 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005275
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005277 T == E->getTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005278 return SemaRef.Owned(E->Retain());
5279
Douglas Gregor2b88c112010-09-08 00:15:04 +00005280 return getDerived().RebuildCXXScalarValueInitExpr(T,
5281 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005282 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005283}
Mike Stump11289f42009-09-09 15:08:12 +00005284
Douglas Gregora16548e2009-08-11 05:31:07 +00005285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005287TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005289 TypeSourceInfo *AllocTypeInfo
5290 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5291 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005292 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005295 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005296 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005298
Douglas Gregora16548e2009-08-11 05:31:07 +00005299 // Transform the placement arguments (if any).
5300 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005301 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005303 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005304 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005305 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregora16548e2009-08-11 05:31:07 +00005307 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5308 PlacementArgs.push_back(Arg.take());
5309 }
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregorebe10102009-08-20 07:17:43 +00005311 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005312 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005314 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5315 break;
5316
John McCalldadc5752010-08-24 06:29:42 +00005317 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005318 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005320
Douglas Gregora16548e2009-08-11 05:31:07 +00005321 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5322 ConstructorArgs.push_back(Arg.take());
5323 }
Mike Stump11289f42009-09-09 15:08:12 +00005324
Douglas Gregord2d9da02010-02-26 00:38:10 +00005325 // Transform constructor, new operator, and delete operator.
5326 CXXConstructorDecl *Constructor = 0;
5327 if (E->getConstructor()) {
5328 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005329 getDerived().TransformDecl(E->getLocStart(),
5330 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005331 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005332 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005333 }
5334
5335 FunctionDecl *OperatorNew = 0;
5336 if (E->getOperatorNew()) {
5337 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005338 getDerived().TransformDecl(E->getLocStart(),
5339 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005340 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005341 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005342 }
5343
5344 FunctionDecl *OperatorDelete = 0;
5345 if (E->getOperatorDelete()) {
5346 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005347 getDerived().TransformDecl(E->getLocStart(),
5348 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005349 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005350 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005351 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005352
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005354 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005356 Constructor == E->getConstructor() &&
5357 OperatorNew == E->getOperatorNew() &&
5358 OperatorDelete == E->getOperatorDelete() &&
5359 !ArgumentChanged) {
5360 // Mark any declarations we need as referenced.
5361 // FIXME: instantiation-specific.
5362 if (Constructor)
5363 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5364 if (OperatorNew)
5365 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5366 if (OperatorDelete)
5367 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005368 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005369 }
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregor0744ef62010-09-07 21:49:58 +00005371 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005372 if (!ArraySize.get()) {
5373 // If no array size was specified, but the new expression was
5374 // instantiated with an array type (e.g., "new T" where T is
5375 // instantiated with "int[4]"), extract the outer bound from the
5376 // array type as our array size. We do this with constant and
5377 // dependently-sized array types.
5378 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5379 if (!ArrayT) {
5380 // Do nothing
5381 } else if (const ConstantArrayType *ConsArrayT
5382 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005383 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005384 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5385 ConsArrayT->getSize(),
5386 SemaRef.Context.getSizeType(),
5387 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005388 AllocType = ConsArrayT->getElementType();
5389 } else if (const DependentSizedArrayType *DepArrayT
5390 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5391 if (DepArrayT->getSizeExpr()) {
5392 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5393 AllocType = DepArrayT->getElementType();
5394 }
5395 }
5396 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005397
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5399 E->isGlobalNew(),
5400 /*FIXME:*/E->getLocStart(),
5401 move_arg(PlacementArgs),
5402 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005403 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005405 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005406 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005407 /*FIXME:*/E->getLocStart(),
5408 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005409 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005410}
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregora16548e2009-08-11 05:31:07 +00005412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005414TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005415 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005416 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregord2d9da02010-02-26 00:38:10 +00005419 // Transform the delete operator, if known.
5420 FunctionDecl *OperatorDelete = 0;
5421 if (E->getOperatorDelete()) {
5422 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005423 getDerived().TransformDecl(E->getLocStart(),
5424 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005425 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005427 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005428
Douglas Gregora16548e2009-08-11 05:31:07 +00005429 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005430 Operand.get() == E->getArgument() &&
5431 OperatorDelete == E->getOperatorDelete()) {
5432 // Mark any declarations we need as referenced.
5433 // FIXME: instantiation-specific.
5434 if (OperatorDelete)
5435 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005436 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005437 }
Mike Stump11289f42009-09-09 15:08:12 +00005438
Douglas Gregora16548e2009-08-11 05:31:07 +00005439 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5440 E->isGlobalDelete(),
5441 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005442 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005443}
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregora16548e2009-08-11 05:31:07 +00005445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005446ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005447TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005448 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005449 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005450 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
John McCallba7bf592010-08-24 05:47:05 +00005453 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005454 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005455 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005456 E->getOperatorLoc(),
5457 E->isArrow()? tok::arrow : tok::period,
5458 ObjectTypePtr,
5459 MayBePseudoDestructor);
5460 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005462
John McCallba7bf592010-08-24 05:47:05 +00005463 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005464 NestedNameSpecifier *Qualifier
5465 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005466 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005467 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005468 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregor678f90d2010-02-25 01:56:36 +00005471 PseudoDestructorTypeStorage Destroyed;
5472 if (E->getDestroyedTypeInfo()) {
5473 TypeSourceInfo *DestroyedTypeInfo
5474 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5475 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005477 Destroyed = DestroyedTypeInfo;
5478 } else if (ObjectType->isDependentType()) {
5479 // We aren't likely to be able to resolve the identifier down to a type
5480 // now anyway, so just retain the identifier.
5481 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5482 E->getDestroyedTypeLoc());
5483 } else {
5484 // Look for a destructor known with the given name.
5485 CXXScopeSpec SS;
5486 if (Qualifier) {
5487 SS.setScopeRep(Qualifier);
5488 SS.setRange(E->getQualifierRange());
5489 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005490
John McCallba7bf592010-08-24 05:47:05 +00005491 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005492 *E->getDestroyedTypeIdentifier(),
5493 E->getDestroyedTypeLoc(),
5494 /*Scope=*/0,
5495 SS, ObjectTypePtr,
5496 false);
5497 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005498 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005499
Douglas Gregor678f90d2010-02-25 01:56:36 +00005500 Destroyed
5501 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5502 E->getDestroyedTypeLoc());
5503 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005504
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005505 TypeSourceInfo *ScopeTypeInfo = 0;
5506 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005507 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005508 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005509 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005511 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005512
John McCallb268a282010-08-23 23:25:46 +00005513 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005514 E->getOperatorLoc(),
5515 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005516 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005517 E->getQualifierRange(),
5518 ScopeTypeInfo,
5519 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005520 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005521 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005522}
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregorad8a3362009-09-04 17:36:40 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005526TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005527 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005528 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5529
5530 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5531 Sema::LookupOrdinaryName);
5532
5533 // Transform all the decls.
5534 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5535 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005536 NamedDecl *InstD = static_cast<NamedDecl*>(
5537 getDerived().TransformDecl(Old->getNameLoc(),
5538 *I));
John McCall84d87672009-12-10 09:41:52 +00005539 if (!InstD) {
5540 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5541 // This can happen because of dependent hiding.
5542 if (isa<UsingShadowDecl>(*I))
5543 continue;
5544 else
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005546 }
John McCalle66edc12009-11-24 19:00:30 +00005547
5548 // Expand using declarations.
5549 if (isa<UsingDecl>(InstD)) {
5550 UsingDecl *UD = cast<UsingDecl>(InstD);
5551 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5552 E = UD->shadow_end(); I != E; ++I)
5553 R.addDecl(*I);
5554 continue;
5555 }
5556
5557 R.addDecl(InstD);
5558 }
5559
5560 // Resolve a kind, but don't do any further analysis. If it's
5561 // ambiguous, the callee needs to deal with it.
5562 R.resolveKind();
5563
5564 // Rebuild the nested-name qualifier, if present.
5565 CXXScopeSpec SS;
5566 NestedNameSpecifier *Qualifier = 0;
5567 if (Old->getQualifier()) {
5568 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005569 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005570 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005571 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005572
John McCalle66edc12009-11-24 19:00:30 +00005573 SS.setScopeRep(Qualifier);
5574 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005575 }
5576
Douglas Gregor9262f472010-04-27 18:19:34 +00005577 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005578 CXXRecordDecl *NamingClass
5579 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5580 Old->getNameLoc(),
5581 Old->getNamingClass()));
5582 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005584
Douglas Gregorda7be082010-04-27 16:10:10 +00005585 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005586 }
5587
5588 // If we have no template arguments, it's a normal declaration name.
5589 if (!Old->hasExplicitTemplateArgs())
5590 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5591
5592 // If we have template arguments, rebuild them, then rebuild the
5593 // templateid expression.
5594 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5595 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5596 TemplateArgumentLoc Loc;
5597 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005599 TransArgs.addArgument(Loc);
5600 }
5601
5602 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5603 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005604}
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregora16548e2009-08-11 05:31:07 +00005606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005607ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005608TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 QualType T = getDerived().TransformType(E->getQueriedType());
5612 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 if (!getDerived().AlwaysRebuild() &&
5616 T == E->getQueriedType())
5617 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 // FIXME: Bad location information
5620 SourceLocation FakeLParenLoc
5621 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005622
5623 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 E->getLocStart(),
5625 /*FIXME:*/FakeLParenLoc,
5626 T,
5627 E->getLocEnd());
5628}
Mike Stump11289f42009-09-09 15:08:12 +00005629
Douglas Gregora16548e2009-08-11 05:31:07 +00005630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005631ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005632TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005633 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005635 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005636 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005639
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005640 DeclarationNameInfo NameInfo
5641 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5642 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005644
John McCalle66edc12009-11-24 19:00:30 +00005645 if (!E->hasExplicitTemplateArgs()) {
5646 if (!getDerived().AlwaysRebuild() &&
5647 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005648 // Note: it is sufficient to compare the Name component of NameInfo:
5649 // if name has not changed, DNLoc has not changed either.
5650 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005651 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCalle66edc12009-11-24 19:00:30 +00005653 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5654 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005655 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005656 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005657 }
John McCall6b51f282009-11-23 01:53:49 +00005658
5659 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005661 TemplateArgumentLoc Loc;
5662 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005663 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005664 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 }
5666
John McCalle66edc12009-11-24 19:00:30 +00005667 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5668 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005669 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005670 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005671}
5672
5673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005675TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005676 // CXXConstructExprs are always implicit, so when we have a
5677 // 1-argument construction we just transform that argument.
5678 if (E->getNumArgs() == 1 ||
5679 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5680 return getDerived().TransformExpr(E->getArg(0));
5681
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5683
5684 QualType T = getDerived().TransformType(E->getType());
5685 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005686 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005687
5688 CXXConstructorDecl *Constructor
5689 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005690 getDerived().TransformDecl(E->getLocStart(),
5691 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005694
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005696 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005697 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 ArgEnd = E->arg_end();
5699 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005700 if (getDerived().DropCallArgument(*Arg)) {
5701 ArgumentChanged = true;
5702 break;
5703 }
5704
John McCalldadc5752010-08-24 06:29:42 +00005705 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005710 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 }
5712
5713 if (!getDerived().AlwaysRebuild() &&
5714 T == E->getType() &&
5715 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005716 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005717 // Mark the constructor as referenced.
5718 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005719 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005720 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005721 }
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregordb121ba2009-12-14 16:27:04 +00005723 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5724 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005725 move_arg(Args),
5726 E->requiresZeroInitialization(),
5727 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005728}
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730/// \brief Transform a C++ temporary-binding expression.
5731///
Douglas Gregor363b1512009-12-24 18:51:59 +00005732/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5733/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005736TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005737 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005738}
Mike Stump11289f42009-09-09 15:08:12 +00005739
5740/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005741/// be destroyed after the expression is evaluated.
5742///
Douglas Gregor363b1512009-12-24 18:51:59 +00005743/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5744/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005746ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005747TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005748 CXXExprWithTemporaries *E) {
5749 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005750}
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregora16548e2009-08-11 05:31:07 +00005752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005753ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005754TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00005755 CXXTemporaryObjectExpr *E) {
5756 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5757 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 CXXConstructorDecl *Constructor
5761 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005762 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005763 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005766
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005768 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005770 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005771 ArgEnd = E->arg_end();
5772 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005773 if (getDerived().DropCallArgument(*Arg)) {
5774 ArgumentChanged = true;
5775 break;
5776 }
5777
John McCalldadc5752010-08-24 06:29:42 +00005778 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005781
Douglas Gregora16548e2009-08-11 05:31:07 +00005782 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5783 Args.push_back((Expr *)TransArg.release());
5784 }
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005787 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005789 !ArgumentChanged) {
5790 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00005791 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005792 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005793 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00005794
5795 return getDerived().RebuildCXXTemporaryObjectExpr(T,
5796 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005798 E->getLocEnd());
5799}
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregora16548e2009-08-11 05:31:07 +00005801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005802ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005803TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005804 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00005805 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5806 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005808
Douglas Gregora16548e2009-08-11 05:31:07 +00005809 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005810 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005811 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5812 ArgEnd = E->arg_end();
5813 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005814 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005817
Douglas Gregora16548e2009-08-11 05:31:07 +00005818 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005819 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 }
Mike Stump11289f42009-09-09 15:08:12 +00005821
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005823 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005825 return SemaRef.Owned(E->Retain());
5826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00005828 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00005829 E->getLParenLoc(),
5830 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005831 E->getRParenLoc());
5832}
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregora16548e2009-08-11 05:31:07 +00005834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005836TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005837 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005838 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005839 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005840 Expr *OldBase;
5841 QualType BaseType;
5842 QualType ObjectType;
5843 if (!E->isImplicitAccess()) {
5844 OldBase = E->getBase();
5845 Base = getDerived().TransformExpr(OldBase);
5846 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005848
John McCall2d74de92009-12-01 22:10:20 +00005849 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005850 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005851 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005852 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005853 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005854 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005855 ObjectTy,
5856 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005857 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005858 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005859
John McCallba7bf592010-08-24 05:47:05 +00005860 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005861 BaseType = ((Expr*) Base.get())->getType();
5862 } else {
5863 OldBase = 0;
5864 BaseType = getDerived().TransformType(E->getBaseType());
5865 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5866 }
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005868 // Transform the first part of the nested-name-specifier that qualifies
5869 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005870 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005871 = getDerived().TransformFirstQualifierInScope(
5872 E->getFirstQualifierFoundInScope(),
5873 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005875 NestedNameSpecifier *Qualifier = 0;
5876 if (E->getQualifier()) {
5877 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5878 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005879 ObjectType,
5880 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005881 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005883 }
Mike Stump11289f42009-09-09 15:08:12 +00005884
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005885 DeclarationNameInfo NameInfo
5886 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5887 ObjectType);
5888 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005889 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005890
John McCall2d74de92009-12-01 22:10:20 +00005891 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005892 // This is a reference to a member without an explicitly-specified
5893 // template argument list. Optimize for this common case.
5894 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005895 Base.get() == OldBase &&
5896 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005897 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005898 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005899 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005900 return SemaRef.Owned(E->Retain());
5901
John McCallb268a282010-08-23 23:25:46 +00005902 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005903 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005904 E->isArrow(),
5905 E->getOperatorLoc(),
5906 Qualifier,
5907 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005908 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005909 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005910 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005911 }
5912
John McCall6b51f282009-11-23 01:53:49 +00005913 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005914 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005915 TemplateArgumentLoc Loc;
5916 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005917 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005918 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005919 }
Mike Stump11289f42009-09-09 15:08:12 +00005920
John McCallb268a282010-08-23 23:25:46 +00005921 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005922 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 E->isArrow(),
5924 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005925 Qualifier,
5926 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005927 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005928 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005929 &TransArgs);
5930}
5931
5932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005933ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005934TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005935 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005936 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005937 QualType BaseType;
5938 if (!Old->isImplicitAccess()) {
5939 Base = getDerived().TransformExpr(Old->getBase());
5940 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005941 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005942 BaseType = ((Expr*) Base.get())->getType();
5943 } else {
5944 BaseType = getDerived().TransformType(Old->getBaseType());
5945 }
John McCall10eae182009-11-30 22:42:35 +00005946
5947 NestedNameSpecifier *Qualifier = 0;
5948 if (Old->getQualifier()) {
5949 Qualifier
5950 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005951 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005952 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005953 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005954 }
5955
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005956 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005957 Sema::LookupOrdinaryName);
5958
5959 // Transform all the decls.
5960 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5961 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005962 NamedDecl *InstD = static_cast<NamedDecl*>(
5963 getDerived().TransformDecl(Old->getMemberLoc(),
5964 *I));
John McCall84d87672009-12-10 09:41:52 +00005965 if (!InstD) {
5966 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5967 // This can happen because of dependent hiding.
5968 if (isa<UsingShadowDecl>(*I))
5969 continue;
5970 else
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005972 }
John McCall10eae182009-11-30 22:42:35 +00005973
5974 // Expand using declarations.
5975 if (isa<UsingDecl>(InstD)) {
5976 UsingDecl *UD = cast<UsingDecl>(InstD);
5977 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5978 E = UD->shadow_end(); I != E; ++I)
5979 R.addDecl(*I);
5980 continue;
5981 }
5982
5983 R.addDecl(InstD);
5984 }
5985
5986 R.resolveKind();
5987
Douglas Gregor9262f472010-04-27 18:19:34 +00005988 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005989 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005990 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005991 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005992 Old->getMemberLoc(),
5993 Old->getNamingClass()));
5994 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005996
Douglas Gregorda7be082010-04-27 16:10:10 +00005997 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005998 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005999
John McCall10eae182009-11-30 22:42:35 +00006000 TemplateArgumentListInfo TransArgs;
6001 if (Old->hasExplicitTemplateArgs()) {
6002 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6003 TransArgs.setRAngleLoc(Old->getRAngleLoc());
6004 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6005 TemplateArgumentLoc Loc;
6006 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6007 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00006008 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006009 TransArgs.addArgument(Loc);
6010 }
6011 }
John McCall38836f02010-01-15 08:34:02 +00006012
6013 // FIXME: to do this check properly, we will need to preserve the
6014 // first-qualifier-in-scope here, just in case we had a dependent
6015 // base (and therefore couldn't do the check) and a
6016 // nested-name-qualifier (and therefore could do the lookup).
6017 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006018
John McCallb268a282010-08-23 23:25:46 +00006019 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006020 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006021 Old->getOperatorLoc(),
6022 Old->isArrow(),
6023 Qualifier,
6024 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006025 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006026 R,
6027 (Old->hasExplicitTemplateArgs()
6028 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006029}
6030
6031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006033TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006034 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006035}
6036
Mike Stump11289f42009-09-09 15:08:12 +00006037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006039TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006040 TypeSourceInfo *EncodedTypeInfo
6041 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6042 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006046 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006047 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006048
6049 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006050 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006051 E->getRParenLoc());
6052}
Mike Stump11289f42009-09-09 15:08:12 +00006053
Douglas Gregora16548e2009-08-11 05:31:07 +00006054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006056TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006057 // Transform arguments.
6058 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006059 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006060 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006061 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006062 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006063 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006064
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006065 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006066 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006067 }
6068
6069 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6070 // Class message: transform the receiver type.
6071 TypeSourceInfo *ReceiverTypeInfo
6072 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6073 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006075
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006076 // If nothing changed, just retain the existing message send.
6077 if (!getDerived().AlwaysRebuild() &&
6078 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6079 return SemaRef.Owned(E->Retain());
6080
6081 // Build a new class message send.
6082 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6083 E->getSelector(),
6084 E->getMethodDecl(),
6085 E->getLeftLoc(),
6086 move_arg(Args),
6087 E->getRightLoc());
6088 }
6089
6090 // Instance message: transform the receiver
6091 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6092 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006093 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006094 = getDerived().TransformExpr(E->getInstanceReceiver());
6095 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006096 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006097
6098 // If nothing changed, just retain the existing message send.
6099 if (!getDerived().AlwaysRebuild() &&
6100 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6101 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006102
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006103 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006104 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006105 E->getSelector(),
6106 E->getMethodDecl(),
6107 E->getLeftLoc(),
6108 move_arg(Args),
6109 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110}
6111
Mike Stump11289f42009-09-09 15:08:12 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006115 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006116}
6117
Mike Stump11289f42009-09-09 15:08:12 +00006118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006121 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006122}
6123
Mike Stump11289f42009-09-09 15:08:12 +00006124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006127 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006128 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006129 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006131
6132 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006133
Douglas Gregord51d90d2010-04-26 20:11:03 +00006134 // If nothing changed, just retain the existing expression.
6135 if (!getDerived().AlwaysRebuild() &&
6136 Base.get() == E->getBase())
6137 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006138
John McCallb268a282010-08-23 23:25:46 +00006139 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006140 E->getLocation(),
6141 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006142}
6143
Mike Stump11289f42009-09-09 15:08:12 +00006144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006146TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006147 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006148 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006149 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006150 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006151
Douglas Gregor9faee212010-04-26 20:47:02 +00006152 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006153
Douglas Gregor9faee212010-04-26 20:47:02 +00006154 // If nothing changed, just retain the existing expression.
6155 if (!getDerived().AlwaysRebuild() &&
6156 Base.get() == E->getBase())
6157 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006158
John McCallb268a282010-08-23 23:25:46 +00006159 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006160 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006161}
6162
Mike Stump11289f42009-09-09 15:08:12 +00006163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006164ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006165TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006166 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006167 // If this implicit setter/getter refers to class methods, it cannot have any
6168 // dependent parts. Just retain the existing declaration.
6169 if (E->getInterfaceDecl())
6170 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006171
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006172 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006173 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006174 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006176
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006177 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006178
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006179 // If nothing changed, just retain the existing expression.
6180 if (!getDerived().AlwaysRebuild() &&
6181 Base.get() == E->getBase())
6182 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006183
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006184 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6185 E->getGetterMethod(),
6186 E->getType(),
6187 E->getSetterMethod(),
6188 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006189 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006190
Douglas Gregora16548e2009-08-11 05:31:07 +00006191}
6192
Mike Stump11289f42009-09-09 15:08:12 +00006193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006194ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006196 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006197 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006198}
6199
Mike Stump11289f42009-09-09 15:08:12 +00006200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006202TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006203 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006204 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006205 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006207
Douglas Gregord51d90d2010-04-26 20:11:03 +00006208 // If nothing changed, just retain the existing expression.
6209 if (!getDerived().AlwaysRebuild() &&
6210 Base.get() == E->getBase())
6211 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006212
John McCallb268a282010-08-23 23:25:46 +00006213 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006214 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006215}
6216
Mike Stump11289f42009-09-09 15:08:12 +00006217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006221 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006223 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006224 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006226
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006228 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 }
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 if (!getDerived().AlwaysRebuild() &&
6232 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006233 return SemaRef.Owned(E->Retain());
6234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6236 move_arg(SubExprs),
6237 E->getRParenLoc());
6238}
6239
Mike Stump11289f42009-09-09 15:08:12 +00006240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006242TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006243 SourceLocation CaretLoc(E->getExprLoc());
6244
6245 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6246 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6247 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6248 llvm::SmallVector<ParmVarDecl*, 4> Params;
6249 llvm::SmallVector<QualType, 4> ParamTypes;
6250
6251 // Parameter substitution.
6252 const BlockDecl *BD = E->getBlockDecl();
6253 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6254 EN = BD->param_end(); P != EN; ++P) {
6255 ParmVarDecl *OldParm = (*P);
6256 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6257 QualType NewType = NewParm->getType();
6258 Params.push_back(NewParm);
6259 ParamTypes.push_back(NewParm->getType());
6260 }
6261
6262 const FunctionType *BExprFunctionType = E->getFunctionType();
6263 QualType BExprResultType = BExprFunctionType->getResultType();
6264 if (!BExprResultType.isNull()) {
6265 if (!BExprResultType->isDependentType())
6266 CurBlock->ReturnType = BExprResultType;
6267 else if (BExprResultType != SemaRef.Context.DependentTy)
6268 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6269 }
6270
6271 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006272 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006273 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006275 // Set the parameters on the block decl.
6276 if (!Params.empty())
6277 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6278
6279 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6280 CurBlock->ReturnType,
6281 ParamTypes.data(),
6282 ParamTypes.size(),
6283 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006284 0,
6285 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006286
6287 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006288 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006289}
6290
Mike Stump11289f42009-09-09 15:08:12 +00006291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006293TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006294 NestedNameSpecifier *Qualifier = 0;
6295
6296 ValueDecl *ND
6297 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6298 E->getDecl()));
6299 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006300 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006301
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006302 if (!getDerived().AlwaysRebuild() &&
6303 ND == E->getDecl()) {
6304 // Mark it referenced in the new context regardless.
6305 // FIXME: this is a bit instantiation-specific.
6306 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6307
6308 return SemaRef.Owned(E->Retain());
6309 }
6310
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006311 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006312 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006313 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006314}
Mike Stump11289f42009-09-09 15:08:12 +00006315
Douglas Gregora16548e2009-08-11 05:31:07 +00006316//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006317// Type reconstruction
6318//===----------------------------------------------------------------------===//
6319
Mike Stump11289f42009-09-09 15:08:12 +00006320template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006321QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6322 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006323 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006324 getDerived().getBaseEntity());
6325}
6326
Mike Stump11289f42009-09-09 15:08:12 +00006327template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006328QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6329 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006330 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006331 getDerived().getBaseEntity());
6332}
6333
Mike Stump11289f42009-09-09 15:08:12 +00006334template<typename Derived>
6335QualType
John McCall70dd5f62009-10-30 00:06:24 +00006336TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6337 bool WrittenAsLValue,
6338 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006339 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006340 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006341}
6342
6343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006344QualType
John McCall70dd5f62009-10-30 00:06:24 +00006345TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6346 QualType ClassType,
6347 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006348 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006349 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006350}
6351
6352template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006353QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006354TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6355 ArrayType::ArraySizeModifier SizeMod,
6356 const llvm::APInt *Size,
6357 Expr *SizeExpr,
6358 unsigned IndexTypeQuals,
6359 SourceRange BracketsRange) {
6360 if (SizeExpr || !Size)
6361 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6362 IndexTypeQuals, BracketsRange,
6363 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006364
6365 QualType Types[] = {
6366 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6367 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6368 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006369 };
6370 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6371 QualType SizeType;
6372 for (unsigned I = 0; I != NumTypes; ++I)
6373 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6374 SizeType = Types[I];
6375 break;
6376 }
Mike Stump11289f42009-09-09 15:08:12 +00006377
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006378 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6379 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006380 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006381 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006382 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006383}
Mike Stump11289f42009-09-09 15:08:12 +00006384
Douglas Gregord6ff3322009-08-04 16:50:30 +00006385template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006386QualType
6387TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006388 ArrayType::ArraySizeModifier SizeMod,
6389 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006390 unsigned IndexTypeQuals,
6391 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006392 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006393 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006394}
6395
6396template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006397QualType
Mike Stump11289f42009-09-09 15:08:12 +00006398TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006399 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006400 unsigned IndexTypeQuals,
6401 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006402 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006403 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006404}
Mike Stump11289f42009-09-09 15:08:12 +00006405
Douglas Gregord6ff3322009-08-04 16:50:30 +00006406template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006407QualType
6408TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006409 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006410 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006411 unsigned IndexTypeQuals,
6412 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006413 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006414 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006415 IndexTypeQuals, BracketsRange);
6416}
6417
6418template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006419QualType
6420TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006421 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006422 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006423 unsigned IndexTypeQuals,
6424 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006425 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006426 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006427 IndexTypeQuals, BracketsRange);
6428}
6429
6430template<typename Derived>
6431QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006432 unsigned NumElements,
6433 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006435 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006436}
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregord6ff3322009-08-04 16:50:30 +00006438template<typename Derived>
6439QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6440 unsigned NumElements,
6441 SourceLocation AttributeLoc) {
6442 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6443 NumElements, true);
6444 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006445 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6446 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006447 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006448}
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregord6ff3322009-08-04 16:50:30 +00006450template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006451QualType
6452TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006453 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006454 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006455 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006456}
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregord6ff3322009-08-04 16:50:30 +00006458template<typename Derived>
6459QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006460 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006461 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006462 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006463 unsigned Quals,
6464 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006465 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006466 Quals,
6467 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006468 getDerived().getBaseEntity(),
6469 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006470}
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregord6ff3322009-08-04 16:50:30 +00006472template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006473QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6474 return SemaRef.Context.getFunctionNoProtoType(T);
6475}
6476
6477template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006478QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6479 assert(D && "no decl found");
6480 if (D->isInvalidDecl()) return QualType();
6481
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006482 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006483 TypeDecl *Ty;
6484 if (isa<UsingDecl>(D)) {
6485 UsingDecl *Using = cast<UsingDecl>(D);
6486 assert(Using->isTypeName() &&
6487 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6488
6489 // A valid resolved using typename decl points to exactly one type decl.
6490 assert(++Using->shadow_begin() == Using->shadow_end());
6491 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006492
John McCallb96ec562009-12-04 22:46:56 +00006493 } else {
6494 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6495 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6496 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6497 }
6498
6499 return SemaRef.Context.getTypeDeclType(Ty);
6500}
6501
6502template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006503QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6504 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006505}
6506
6507template<typename Derived>
6508QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6509 return SemaRef.Context.getTypeOfType(Underlying);
6510}
6511
6512template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006513QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6514 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006515}
6516
6517template<typename Derived>
6518QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006519 TemplateName Template,
6520 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006521 const TemplateArgumentListInfo &TemplateArgs) {
6522 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006523}
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregor1135c352009-08-06 05:28:30 +00006525template<typename Derived>
6526NestedNameSpecifier *
6527TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6528 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006529 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006530 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006531 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006532 CXXScopeSpec SS;
6533 // FIXME: The source location information is all wrong.
6534 SS.setRange(Range);
6535 SS.setScopeRep(Prefix);
6536 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006537 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006538 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006539 ObjectType,
6540 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006541 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006542}
6543
6544template<typename Derived>
6545NestedNameSpecifier *
6546TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6547 SourceRange Range,
6548 NamespaceDecl *NS) {
6549 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6550}
6551
6552template<typename Derived>
6553NestedNameSpecifier *
6554TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6555 SourceRange Range,
6556 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006557 QualType T) {
6558 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006559 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006560 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006561 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6562 T.getTypePtr());
6563 }
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregor1135c352009-08-06 05:28:30 +00006565 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6566 return 0;
6567}
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregor71dc5092009-08-06 06:41:21 +00006569template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006570TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006571TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6572 bool TemplateKW,
6573 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006574 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006575 Template);
6576}
6577
6578template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006579TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006580TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006581 const IdentifierInfo &II,
6582 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006583 CXXScopeSpec SS;
6584 SS.setRange(SourceRange(getDerived().getBaseLocation()));
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