blob: dbc02d8727207823013af573cfdd1f06f42f3e35 [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.
John McCalldadc5752010-08-24 06:29:42 +00001495 ExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001496 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001498 Expr *Sub,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCallba7bf592010-08-24 05:47:05 +00001501 ParsedType::make(TInfo->getType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001503 MultiExprArg(&Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001504 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 RParenLoc);
1506 }
Mike Stump11289f42009-09-09 15:08:12 +00001507
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// \brief Build a new C++ typeid(type) expression.
1509 ///
1510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001512 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001513 SourceLocation TypeidLoc,
1514 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001516 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001517 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new C++ typeid(expr) expression.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001525 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001526 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001528 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001529 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001530 }
1531
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// \brief Build a new C++ "this" expression.
1533 ///
1534 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001535 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001537 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001538 QualType ThisType,
1539 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001541 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1542 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
1544
1545 /// \brief Build a new C++ throw expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001549 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001550 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 }
1552
1553 /// \brief Build a new C++ default-argument expression.
1554 ///
1555 /// By default, builds a new default-argument expression, which does not
1556 /// require any semantic analysis. Subclasses may override this routine to
1557 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001559 ParmVarDecl *Param) {
1560 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1561 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 }
1563
1564 /// \brief Build a new C++ zero-initialization expression.
1565 ///
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001568 ExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 SourceLocation LParenLoc,
1570 QualType T,
1571 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001572 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
John McCallba7bf592010-08-24 05:47:05 +00001573 ParsedType::make(T), LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001574 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 0, RParenLoc);
1576 }
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// \brief Build a new C++ "new" expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001582 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 bool UseGlobal,
1584 SourceLocation PlacementLParen,
1585 MultiExprArg PlacementArgs,
1586 SourceLocation PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001587 SourceRange TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 QualType AllocType,
1589 SourceLocation TypeLoc,
1590 SourceRange TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001591 Expr *ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 SourceLocation ConstructorLParen,
1593 MultiExprArg ConstructorArgs,
1594 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001595 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 PlacementLParen,
1597 move(PlacementArgs),
1598 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001599 TypeIdParens,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 AllocType,
1601 TypeLoc,
1602 TypeRange,
John McCallb268a282010-08-23 23:25:46 +00001603 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 ConstructorLParen,
1605 move(ConstructorArgs),
1606 ConstructorRParen);
1607 }
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new C++ "delete" expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 bool IsGlobalDelete,
1615 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001616 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001618 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// \brief Build a new unary type trait expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1628 QualType T,
1629 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001630 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
John McCallba7bf592010-08-24 05:47:05 +00001631 ParsedType::make(T), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
1633
Mike Stump11289f42009-09-09 15:08:12 +00001634 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001639 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001641 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001642 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 CXXScopeSpec SS;
1644 SS.setRange(QualifierRange);
1645 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001646
1647 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001648 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001649 *TemplateArgs);
1650
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001651 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 }
1653
1654 /// \brief Build a new template-id expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001658 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001659 LookupResult &R,
1660 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001661 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001662 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 }
1664
1665 /// \brief Build a new object-construction expression.
1666 ///
1667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001669 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001670 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 CXXConstructorDecl *Constructor,
1672 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001673 MultiExprArg Args,
1674 bool RequiresZeroInit,
1675 CXXConstructExpr::ConstructionKind ConstructKind) {
John McCall37ad5512010-08-23 06:44:23 +00001676 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001677 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001678 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001679 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001680
Douglas Gregordb121ba2009-12-14 16:27:04 +00001681 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001682 move_arg(ConvertedArgs),
1683 RequiresZeroInit, ConstructKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 }
1685
1686 /// \brief Build a new object-construction expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001690 ExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 QualType T,
1692 SourceLocation LParenLoc,
1693 MultiExprArg Args,
1694 SourceLocation *Commas,
1695 SourceLocation RParenLoc) {
1696 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
John McCallba7bf592010-08-24 05:47:05 +00001697 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 LParenLoc,
1699 move(Args),
1700 Commas,
1701 RParenLoc);
1702 }
1703
1704 /// \brief Build a new object-construction expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001708 ExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 QualType T,
1710 SourceLocation LParenLoc,
1711 MultiExprArg Args,
1712 SourceLocation *Commas,
1713 SourceLocation RParenLoc) {
1714 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1715 /*FIXME*/LParenLoc),
John McCallba7bf592010-08-24 05:47:05 +00001716 ParsedType::make(T),
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 LParenLoc,
1718 move(Args),
1719 Commas,
1720 RParenLoc);
1721 }
Mike Stump11289f42009-09-09 15:08:12 +00001722
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// \brief Build a new member reference expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001727 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001728 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 bool IsArrow,
1730 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001731 NestedNameSpecifier *Qualifier,
1732 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001733 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001734 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001735 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001737 SS.setRange(QualifierRange);
1738 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001739
John McCallb268a282010-08-23 23:25:46 +00001740 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001741 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001742 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001743 MemberNameInfo,
1744 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 }
1746
John McCall10eae182009-11-30 22:42:35 +00001747 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001748 ///
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001751 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001752 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001753 SourceLocation OperatorLoc,
1754 bool IsArrow,
1755 NestedNameSpecifier *Qualifier,
1756 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001757 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001758 LookupResult &R,
1759 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001760 CXXScopeSpec SS;
1761 SS.setRange(QualifierRange);
1762 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001763
John McCallb268a282010-08-23 23:25:46 +00001764 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001765 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001766 SS, FirstQualifierInScope,
1767 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001768 }
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 /// \brief Build a new Objective-C @encode expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001774 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001775 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001777 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001779 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001780
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001781 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001783 Selector Sel,
1784 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001785 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001786 MultiExprArg Args,
1787 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001788 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1789 ReceiverTypeInfo->getType(),
1790 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001791 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001792 move(Args));
1793 }
1794
1795 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001796 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001797 Selector Sel,
1798 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001799 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001800 MultiExprArg Args,
1801 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001802 return SemaRef.BuildInstanceMessage(Receiver,
1803 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001804 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001805 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001806 move(Args));
1807 }
1808
Douglas Gregord51d90d2010-04-26 20:11:03 +00001809 /// \brief Build a new Objective-C ivar reference expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001813 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001814 SourceLocation IvarLoc,
1815 bool IsArrow, bool IsFreeIvar) {
1816 // FIXME: We lose track of the IsFreeIvar bit.
1817 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001818 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001819 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1820 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001822 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001823 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001824 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001825 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001826 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001827
Douglas Gregord51d90d2010-04-26 20:11:03 +00001828 if (Result.get())
1829 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001830
John McCallb268a282010-08-23 23:25:46 +00001831 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001833 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001834 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001835 /*TemplateArgs=*/0);
1836 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001837
1838 /// \brief Build a new Objective-C property reference expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001843 ObjCPropertyDecl *Property,
1844 SourceLocation PropertyLoc) {
1845 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001846 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001847 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1848 Sema::LookupMemberName);
1849 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001850 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001851 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001852 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001853 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001854 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001855
Douglas Gregor9faee212010-04-26 20:47:02 +00001856 if (Result.get())
1857 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001858
John McCallb268a282010-08-23 23:25:46 +00001859 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001860 /*FIXME:*/PropertyLoc, IsArrow,
1861 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001862 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001863 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001864 /*TemplateArgs=*/0);
1865 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001866
1867 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001868 /// expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001872 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001873 ObjCMethodDecl *Getter,
1874 QualType T,
1875 ObjCMethodDecl *Setter,
1876 SourceLocation NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001877 Expr *Base) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001878 // Since these expressions can only be value-dependent, we do not need to
1879 // perform semantic analysis again.
John McCallb268a282010-08-23 23:25:46 +00001880 return Owned(
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001881 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1882 Setter,
1883 NameLoc,
John McCallb268a282010-08-23 23:25:46 +00001884 Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001885 }
1886
Douglas Gregord51d90d2010-04-26 20:11:03 +00001887 /// \brief Build a new Objective-C "isa" expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001891 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001892 bool IsArrow) {
1893 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001894 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001895 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1896 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001897 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001898 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00001899 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001901 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001902
Douglas Gregord51d90d2010-04-26 20:11:03 +00001903 if (Result.get())
1904 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001905
John McCallb268a282010-08-23 23:25:46 +00001906 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001907 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001908 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001909 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001910 /*TemplateArgs=*/0);
1911 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001912
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 /// \brief Build a new shuffle vector expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001917 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 MultiExprArg SubExprs,
1919 SourceLocation RParenLoc) {
1920 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001921 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1923 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1924 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1925 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 // Build a reference to the __builtin_shufflevector builtin
1928 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001929 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001931 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001933
1934 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 unsigned NumSubExprs = SubExprs.size();
1936 Expr **Subs = (Expr **)SubExprs.release();
1937 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1938 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001939 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00001944 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001949 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001951};
Douglas Gregora16548e2009-08-11 05:31:07 +00001952
Douglas Gregorebe10102009-08-20 07:17:43 +00001953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001954StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 if (!S)
1956 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregorebe10102009-08-20 07:17:43 +00001958 switch (S->getStmtClass()) {
1959 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregorebe10102009-08-20 07:17:43 +00001961 // Transform individual statement nodes
1962#define STMT(Node, Parent) \
1963 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1964#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001965#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregorebe10102009-08-20 07:17:43 +00001967 // Transform expressions by calling TransformExpr.
1968#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001969#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001970#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001971#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 {
John McCalldadc5752010-08-24 06:29:42 +00001973 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00001974 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001975 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001976
John McCallb268a282010-08-23 23:25:46 +00001977 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00001978 }
Mike Stump11289f42009-09-09 15:08:12 +00001979 }
1980
Douglas Gregorebe10102009-08-20 07:17:43 +00001981 return SemaRef.Owned(S->Retain());
1982}
Mike Stump11289f42009-09-09 15:08:12 +00001983
1984
Douglas Gregore922c772009-08-04 22:27:00 +00001985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00001986ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 if (!E)
1988 return SemaRef.Owned(E);
1989
1990 switch (E->getStmtClass()) {
1991 case Stmt::NoStmtClass: break;
1992#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00001993#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001994#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001995 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001996#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001997 }
1998
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002000}
2001
2002template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002003NestedNameSpecifier *
2004TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002005 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002006 QualType ObjectType,
2007 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002008 if (!NNS)
2009 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002010
Douglas Gregorebe10102009-08-20 07:17:43 +00002011 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002012 NestedNameSpecifier *Prefix = NNS->getPrefix();
2013 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002014 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002015 ObjectType,
2016 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002017 if (!Prefix)
2018 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002019
2020 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002021 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002022 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002023 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002024 }
Mike Stump11289f42009-09-09 15:08:12 +00002025
Douglas Gregor1135c352009-08-06 05:28:30 +00002026 switch (NNS->getKind()) {
2027 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002028 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002029 "Identifier nested-name-specifier with no prefix or object type");
2030 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2031 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002032 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002033
2034 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002035 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002036 ObjectType,
2037 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002038
Douglas Gregor1135c352009-08-06 05:28:30 +00002039 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002040 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002042 getDerived().TransformDecl(Range.getBegin(),
2043 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002045 Prefix == NNS->getPrefix() &&
2046 NS == NNS->getAsNamespace())
2047 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2050 }
Mike Stump11289f42009-09-09 15:08:12 +00002051
Douglas Gregor1135c352009-08-06 05:28:30 +00002052 case NestedNameSpecifier::Global:
2053 // There is no meaningful transformation that one could perform on the
2054 // global scope.
2055 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 case NestedNameSpecifier::TypeSpecWithTemplate:
2058 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002059 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002060 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2061 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002062 if (T.isNull())
2063 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002064
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 if (!getDerived().AlwaysRebuild() &&
2066 Prefix == NNS->getPrefix() &&
2067 T == QualType(NNS->getAsType(), 0))
2068 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002069
2070 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2071 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002072 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 }
2074 }
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregor1135c352009-08-06 05:28:30 +00002076 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002077 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002078}
2079
2080template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002081DeclarationNameInfo
2082TreeTransform<Derived>
2083::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2084 QualType ObjectType) {
2085 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002086 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002087 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002088
2089 switch (Name.getNameKind()) {
2090 case DeclarationName::Identifier:
2091 case DeclarationName::ObjCZeroArgSelector:
2092 case DeclarationName::ObjCOneArgSelector:
2093 case DeclarationName::ObjCMultiArgSelector:
2094 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002095 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002096 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002097 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregorf816bd72009-09-03 22:13:48 +00002099 case DeclarationName::CXXConstructorName:
2100 case DeclarationName::CXXDestructorName:
2101 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002102 TypeSourceInfo *NewTInfo;
2103 CanQualType NewCanTy;
2104 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2105 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2106 if (!NewTInfo)
2107 return DeclarationNameInfo();
2108 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2109 }
2110 else {
2111 NewTInfo = 0;
2112 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2113 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2114 ObjectType);
2115 if (NewT.isNull())
2116 return DeclarationNameInfo();
2117 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2118 }
Mike Stump11289f42009-09-09 15:08:12 +00002119
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002120 DeclarationName NewName
2121 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2122 NewCanTy);
2123 DeclarationNameInfo NewNameInfo(NameInfo);
2124 NewNameInfo.setName(NewName);
2125 NewNameInfo.setNamedTypeInfo(NewTInfo);
2126 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128 }
2129
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002130 assert(0 && "Unknown name kind.");
2131 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002132}
2133
2134template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002135TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002136TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2137 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002138 SourceLocation Loc = getDerived().getBaseLocation();
2139
Douglas Gregor71dc5092009-08-06 06:41:21 +00002140 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002141 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002142 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002143 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2144 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002145 if (!NNS)
2146 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002147
Douglas Gregor71dc5092009-08-06 06:41:21 +00002148 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002149 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002150 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002151 if (!TransTemplate)
2152 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 if (!getDerived().AlwaysRebuild() &&
2155 NNS == QTN->getQualifier() &&
2156 TransTemplate == Template)
2157 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002158
Douglas Gregor71dc5092009-08-06 06:41:21 +00002159 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2160 TransTemplate);
2161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162
John McCalle66edc12009-11-24 19:00:30 +00002163 // These should be getting filtered out before they make it into the AST.
2164 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002168 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002169 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002170 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2171 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002172 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002173 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002174
Douglas Gregor71dc5092009-08-06 06:41:21 +00002175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002176 NNS == DTN->getQualifier() &&
2177 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregor71395fa2009-11-04 00:56:37 +00002180 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002181 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002182 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002183
2184 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002185 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002186 }
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregor71dc5092009-08-06 06:41:21 +00002188 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002189 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002190 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002191 if (!TransTemplate)
2192 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregor71dc5092009-08-06 06:41:21 +00002194 if (!getDerived().AlwaysRebuild() &&
2195 TransTemplate == Template)
2196 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002197
Douglas Gregor71dc5092009-08-06 06:41:21 +00002198 return TemplateName(TransTemplate);
2199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
John McCalle66edc12009-11-24 19:00:30 +00002201 // These should be getting filtered out before they reach the AST.
2202 assert(false && "overloaded function decl survived to here");
2203 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002204}
2205
2206template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002207void TreeTransform<Derived>::InventTemplateArgumentLoc(
2208 const TemplateArgument &Arg,
2209 TemplateArgumentLoc &Output) {
2210 SourceLocation Loc = getDerived().getBaseLocation();
2211 switch (Arg.getKind()) {
2212 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002213 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002214 break;
2215
2216 case TemplateArgument::Type:
2217 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002218 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002219
John McCall0ad16662009-10-29 08:12:44 +00002220 break;
2221
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002222 case TemplateArgument::Template:
2223 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2224 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002225
John McCall0ad16662009-10-29 08:12:44 +00002226 case TemplateArgument::Expression:
2227 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2228 break;
2229
2230 case TemplateArgument::Declaration:
2231 case TemplateArgument::Integral:
2232 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002233 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002234 break;
2235 }
2236}
2237
2238template<typename Derived>
2239bool TreeTransform<Derived>::TransformTemplateArgument(
2240 const TemplateArgumentLoc &Input,
2241 TemplateArgumentLoc &Output) {
2242 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002243 switch (Arg.getKind()) {
2244 case TemplateArgument::Null:
2245 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002246 Output = Input;
2247 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002248
Douglas Gregore922c772009-08-04 22:27:00 +00002249 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002250 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002251 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002252 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002253
2254 DI = getDerived().TransformType(DI);
2255 if (!DI) return true;
2256
2257 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2258 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002259 }
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregore922c772009-08-04 22:27:00 +00002261 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002262 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002263 DeclarationName Name;
2264 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2265 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002266 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002267 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002268 if (!D) return true;
2269
John McCall0d07eb32009-10-29 18:45:58 +00002270 Expr *SourceExpr = Input.getSourceDeclExpression();
2271 if (SourceExpr) {
2272 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002273 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002275 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002276 }
2277
2278 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002279 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002280 }
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002282 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002283 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002284 TemplateName Template
2285 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2286 if (Template.isNull())
2287 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002288
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002289 Output = TemplateArgumentLoc(TemplateArgument(Template),
2290 Input.getTemplateQualifierRange(),
2291 Input.getTemplateNameLoc());
2292 return false;
2293 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002294
Douglas Gregore922c772009-08-04 22:27:00 +00002295 case TemplateArgument::Expression: {
2296 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002297 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002298 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002299
John McCall0ad16662009-10-29 08:12:44 +00002300 Expr *InputExpr = Input.getSourceExpression();
2301 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2302
John McCalldadc5752010-08-24 06:29:42 +00002303 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002304 = getDerived().TransformExpr(InputExpr);
2305 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002306 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002307 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregore922c772009-08-04 22:27:00 +00002310 case TemplateArgument::Pack: {
2311 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2312 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002313 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002314 AEnd = Arg.pack_end();
2315 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002316
John McCall0ad16662009-10-29 08:12:44 +00002317 // FIXME: preserve source information here when we start
2318 // caring about parameter packs.
2319
John McCall0d07eb32009-10-29 18:45:58 +00002320 TemplateArgumentLoc InputArg;
2321 TemplateArgumentLoc OutputArg;
2322 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2323 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002324 return true;
2325
John McCall0d07eb32009-10-29 18:45:58 +00002326 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002327 }
2328 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002329 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002330 true);
John McCall0d07eb32009-10-29 18:45:58 +00002331 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002332 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002333 }
2334 }
Mike Stump11289f42009-09-09 15:08:12 +00002335
Douglas Gregore922c772009-08-04 22:27:00 +00002336 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002337 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002338}
2339
Douglas Gregord6ff3322009-08-04 16:50:30 +00002340//===----------------------------------------------------------------------===//
2341// Type transformation
2342//===----------------------------------------------------------------------===//
2343
2344template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002345QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002346 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002347 if (getDerived().AlreadyTransformed(T))
2348 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002349
John McCall550e0c22009-10-21 00:40:46 +00002350 // Temporary workaround. All of these transformations should
2351 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002352 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002353 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002354
Douglas Gregorfe17d252010-02-16 19:09:40 +00002355 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002356
John McCall550e0c22009-10-21 00:40:46 +00002357 if (!NewDI)
2358 return QualType();
2359
2360 return NewDI->getType();
2361}
2362
2363template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002364TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2365 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002366 if (getDerived().AlreadyTransformed(DI->getType()))
2367 return DI;
2368
2369 TypeLocBuilder TLB;
2370
2371 TypeLoc TL = DI->getTypeLoc();
2372 TLB.reserve(TL.getFullDataSize());
2373
Douglas Gregorfe17d252010-02-16 19:09:40 +00002374 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002375 if (Result.isNull())
2376 return 0;
2377
John McCallbcd03502009-12-07 02:54:59 +00002378 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002379}
2380
2381template<typename Derived>
2382QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002383TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2384 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002385 switch (T.getTypeLocClass()) {
2386#define ABSTRACT_TYPELOC(CLASS, PARENT)
2387#define TYPELOC(CLASS, PARENT) \
2388 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002389 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2390 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002391#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002392 }
Mike Stump11289f42009-09-09 15:08:12 +00002393
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002394 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002395 return QualType();
2396}
2397
2398/// FIXME: By default, this routine adds type qualifiers only to types
2399/// that can have qualifiers, and silently suppresses those qualifiers
2400/// that are not permitted (e.g., qualifiers on reference or function
2401/// types). This is the right thing for template instantiation, but
2402/// probably not for other clients.
2403template<typename Derived>
2404QualType
2405TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002406 QualifiedTypeLoc T,
2407 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002408 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002409
Douglas Gregorfe17d252010-02-16 19:09:40 +00002410 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2411 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002412 if (Result.isNull())
2413 return QualType();
2414
2415 // Silently suppress qualifiers if the result type can't be qualified.
2416 // FIXME: this is the right thing for template instantiation, but
2417 // probably not for other clients.
2418 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002419 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002420
John McCallcb0f89a2010-06-05 06:41:15 +00002421 if (!Quals.empty()) {
2422 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2423 TLB.push<QualifiedTypeLoc>(Result);
2424 // No location information to preserve.
2425 }
John McCall550e0c22009-10-21 00:40:46 +00002426
2427 return Result;
2428}
2429
2430template <class TyLoc> static inline
2431QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2432 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2433 NewT.setNameLoc(T.getNameLoc());
2434 return T.getType();
2435}
2436
John McCall550e0c22009-10-21 00:40:46 +00002437template<typename Derived>
2438QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002439 BuiltinTypeLoc T,
2440 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002441 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2442 NewT.setBuiltinLoc(T.getBuiltinLoc());
2443 if (T.needsExtraLocalData())
2444 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2445 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002446}
Mike Stump11289f42009-09-09 15:08:12 +00002447
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002449QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002450 ComplexTypeLoc T,
2451 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002452 // FIXME: recurse?
2453 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002454}
Mike Stump11289f42009-09-09 15:08:12 +00002455
Douglas Gregord6ff3322009-08-04 16:50:30 +00002456template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002457QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002458 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002459 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002460 QualType PointeeType
2461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002462 if (PointeeType.isNull())
2463 return QualType();
2464
2465 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002466 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002467 // A dependent pointer type 'T *' has is being transformed such
2468 // that an Objective-C class type is being replaced for 'T'. The
2469 // resulting pointer type is an ObjCObjectPointerType, not a
2470 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002471 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002472
John McCall8b07ec22010-05-15 11:32:37 +00002473 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2474 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002475 return Result;
2476 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002477
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002478 if (getDerived().AlwaysRebuild() ||
2479 PointeeType != TL.getPointeeLoc().getType()) {
2480 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2481 if (Result.isNull())
2482 return QualType();
2483 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002484
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002485 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2486 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002487 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002488}
Mike Stump11289f42009-09-09 15:08:12 +00002489
2490template<typename Derived>
2491QualType
John McCall550e0c22009-10-21 00:40:46 +00002492TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002493 BlockPointerTypeLoc TL,
2494 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002495 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002496 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2497 if (PointeeType.isNull())
2498 return QualType();
2499
2500 QualType Result = TL.getType();
2501 if (getDerived().AlwaysRebuild() ||
2502 PointeeType != TL.getPointeeLoc().getType()) {
2503 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002504 TL.getSigilLoc());
2505 if (Result.isNull())
2506 return QualType();
2507 }
2508
Douglas Gregor049211a2010-04-22 16:50:51 +00002509 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002510 NewT.setSigilLoc(TL.getSigilLoc());
2511 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002512}
2513
John McCall70dd5f62009-10-30 00:06:24 +00002514/// Transforms a reference type. Note that somewhat paradoxically we
2515/// don't care whether the type itself is an l-value type or an r-value
2516/// type; we only care if the type was *written* as an l-value type
2517/// or an r-value type.
2518template<typename Derived>
2519QualType
2520TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002521 ReferenceTypeLoc TL,
2522 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002523 const ReferenceType *T = TL.getTypePtr();
2524
2525 // Note that this works with the pointee-as-written.
2526 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2527 if (PointeeType.isNull())
2528 return QualType();
2529
2530 QualType Result = TL.getType();
2531 if (getDerived().AlwaysRebuild() ||
2532 PointeeType != T->getPointeeTypeAsWritten()) {
2533 Result = getDerived().RebuildReferenceType(PointeeType,
2534 T->isSpelledAsLValue(),
2535 TL.getSigilLoc());
2536 if (Result.isNull())
2537 return QualType();
2538 }
2539
2540 // r-value references can be rebuilt as l-value references.
2541 ReferenceTypeLoc NewTL;
2542 if (isa<LValueReferenceType>(Result))
2543 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2544 else
2545 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2546 NewTL.setSigilLoc(TL.getSigilLoc());
2547
2548 return Result;
2549}
2550
Mike Stump11289f42009-09-09 15:08:12 +00002551template<typename Derived>
2552QualType
John McCall550e0c22009-10-21 00:40:46 +00002553TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002554 LValueReferenceTypeLoc TL,
2555 QualType ObjectType) {
2556 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002557}
2558
Mike Stump11289f42009-09-09 15:08:12 +00002559template<typename Derived>
2560QualType
John McCall550e0c22009-10-21 00:40:46 +00002561TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002562 RValueReferenceTypeLoc TL,
2563 QualType ObjectType) {
2564 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565}
Mike Stump11289f42009-09-09 15:08:12 +00002566
Douglas Gregord6ff3322009-08-04 16:50:30 +00002567template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002568QualType
John McCall550e0c22009-10-21 00:40:46 +00002569TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002570 MemberPointerTypeLoc TL,
2571 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002572 MemberPointerType *T = TL.getTypePtr();
2573
2574 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002575 if (PointeeType.isNull())
2576 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002577
John McCall550e0c22009-10-21 00:40:46 +00002578 // TODO: preserve source information for this.
2579 QualType ClassType
2580 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581 if (ClassType.isNull())
2582 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002583
John McCall550e0c22009-10-21 00:40:46 +00002584 QualType Result = TL.getType();
2585 if (getDerived().AlwaysRebuild() ||
2586 PointeeType != T->getPointeeType() ||
2587 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002588 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2589 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002590 if (Result.isNull())
2591 return QualType();
2592 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002593
John McCall550e0c22009-10-21 00:40:46 +00002594 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2595 NewTL.setSigilLoc(TL.getSigilLoc());
2596
2597 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002598}
2599
Mike Stump11289f42009-09-09 15:08:12 +00002600template<typename Derived>
2601QualType
John McCall550e0c22009-10-21 00:40:46 +00002602TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002603 ConstantArrayTypeLoc TL,
2604 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002605 ConstantArrayType *T = TL.getTypePtr();
2606 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002607 if (ElementType.isNull())
2608 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002609
John McCall550e0c22009-10-21 00:40:46 +00002610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 ElementType != T->getElementType()) {
2613 Result = getDerived().RebuildConstantArrayType(ElementType,
2614 T->getSizeModifier(),
2615 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002616 T->getIndexTypeCVRQualifiers(),
2617 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002618 if (Result.isNull())
2619 return QualType();
2620 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002621
John McCall550e0c22009-10-21 00:40:46 +00002622 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2623 NewTL.setLBracketLoc(TL.getLBracketLoc());
2624 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002625
John McCall550e0c22009-10-21 00:40:46 +00002626 Expr *Size = TL.getSizeExpr();
2627 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00002628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002629 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2630 }
2631 NewTL.setSizeExpr(Size);
2632
2633 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634}
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002638 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002639 IncompleteArrayTypeLoc TL,
2640 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002641 IncompleteArrayType *T = TL.getTypePtr();
2642 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002643 if (ElementType.isNull())
2644 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002645
John McCall550e0c22009-10-21 00:40:46 +00002646 QualType Result = TL.getType();
2647 if (getDerived().AlwaysRebuild() ||
2648 ElementType != T->getElementType()) {
2649 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002651 T->getIndexTypeCVRQualifiers(),
2652 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002653 if (Result.isNull())
2654 return QualType();
2655 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002656
John McCall550e0c22009-10-21 00:40:46 +00002657 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2658 NewTL.setLBracketLoc(TL.getLBracketLoc());
2659 NewTL.setRBracketLoc(TL.getRBracketLoc());
2660 NewTL.setSizeExpr(0);
2661
2662 return Result;
2663}
2664
2665template<typename Derived>
2666QualType
2667TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002668 VariableArrayTypeLoc TL,
2669 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002670 VariableArrayType *T = TL.getTypePtr();
2671 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2672 if (ElementType.isNull())
2673 return QualType();
2674
2675 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002676 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002677
John McCalldadc5752010-08-24 06:29:42 +00002678 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002679 = getDerived().TransformExpr(T->getSizeExpr());
2680 if (SizeResult.isInvalid())
2681 return QualType();
2682
John McCallb268a282010-08-23 23:25:46 +00002683 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00002684
2685 QualType Result = TL.getType();
2686 if (getDerived().AlwaysRebuild() ||
2687 ElementType != T->getElementType() ||
2688 Size != T->getSizeExpr()) {
2689 Result = getDerived().RebuildVariableArrayType(ElementType,
2690 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002691 Size,
John McCall550e0c22009-10-21 00:40:46 +00002692 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002693 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002694 if (Result.isNull())
2695 return QualType();
2696 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002697
John McCall550e0c22009-10-21 00:40:46 +00002698 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2699 NewTL.setLBracketLoc(TL.getLBracketLoc());
2700 NewTL.setRBracketLoc(TL.getRBracketLoc());
2701 NewTL.setSizeExpr(Size);
2702
2703 return Result;
2704}
2705
2706template<typename Derived>
2707QualType
2708TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002709 DependentSizedArrayTypeLoc TL,
2710 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002711 DependentSizedArrayType *T = TL.getTypePtr();
2712 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2713 if (ElementType.isNull())
2714 return QualType();
2715
2716 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00002718
John McCalldadc5752010-08-24 06:29:42 +00002719 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00002720 = getDerived().TransformExpr(T->getSizeExpr());
2721 if (SizeResult.isInvalid())
2722 return QualType();
2723
2724 Expr *Size = static_cast<Expr*>(SizeResult.get());
2725
2726 QualType Result = TL.getType();
2727 if (getDerived().AlwaysRebuild() ||
2728 ElementType != T->getElementType() ||
2729 Size != T->getSizeExpr()) {
2730 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2731 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00002732 Size,
John McCall550e0c22009-10-21 00:40:46 +00002733 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002734 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002735 if (Result.isNull())
2736 return QualType();
2737 }
2738 else SizeResult.take();
2739
2740 // We might have any sort of array type now, but fortunately they
2741 // all have the same location layout.
2742 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2743 NewTL.setLBracketLoc(TL.getLBracketLoc());
2744 NewTL.setRBracketLoc(TL.getRBracketLoc());
2745 NewTL.setSizeExpr(Size);
2746
2747 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002748}
Mike Stump11289f42009-09-09 15:08:12 +00002749
2750template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002752 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002753 DependentSizedExtVectorTypeLoc TL,
2754 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002755 DependentSizedExtVectorType *T = TL.getTypePtr();
2756
2757 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 QualType ElementType = getDerived().TransformType(T->getElementType());
2759 if (ElementType.isNull())
2760 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002761
Douglas Gregore922c772009-08-04 22:27:00 +00002762 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00002763 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00002764
John McCalldadc5752010-08-24 06:29:42 +00002765 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766 if (Size.isInvalid())
2767 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002768
John McCall550e0c22009-10-21 00:40:46 +00002769 QualType Result = TL.getType();
2770 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002771 ElementType != T->getElementType() ||
2772 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002773 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00002774 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002776 if (Result.isNull())
2777 return QualType();
2778 }
John McCall550e0c22009-10-21 00:40:46 +00002779
2780 // Result might be dependent or not.
2781 if (isa<DependentSizedExtVectorType>(Result)) {
2782 DependentSizedExtVectorTypeLoc NewTL
2783 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785 } else {
2786 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 }
2789
2790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791}
Mike Stump11289f42009-09-09 15:08:12 +00002792
2793template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002795 VectorTypeLoc TL,
2796 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002797 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002798 QualType ElementType = getDerived().TransformType(T->getElementType());
2799 if (ElementType.isNull())
2800 return QualType();
2801
John McCall550e0c22009-10-21 00:40:46 +00002802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
2804 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002805 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002806 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002810
John McCall550e0c22009-10-21 00:40:46 +00002811 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002813
John McCall550e0c22009-10-21 00:40:46 +00002814 return Result;
2815}
2816
2817template<typename Derived>
2818QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002819 ExtVectorTypeLoc TL,
2820 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002821 VectorType *T = TL.getTypePtr();
2822 QualType ElementType = getDerived().TransformType(T->getElementType());
2823 if (ElementType.isNull())
2824 return QualType();
2825
2826 QualType Result = TL.getType();
2827 if (getDerived().AlwaysRebuild() ||
2828 ElementType != T->getElementType()) {
2829 Result = getDerived().RebuildExtVectorType(ElementType,
2830 T->getNumElements(),
2831 /*FIXME*/ SourceLocation());
2832 if (Result.isNull())
2833 return QualType();
2834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002835
John McCall550e0c22009-10-21 00:40:46 +00002836 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
2838
2839 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002840}
Mike Stump11289f42009-09-09 15:08:12 +00002841
2842template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002843ParmVarDecl *
2844TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2845 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2846 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2847 if (!NewDI)
2848 return 0;
2849
2850 if (NewDI == OldDI)
2851 return OldParm;
2852 else
2853 return ParmVarDecl::Create(SemaRef.Context,
2854 OldParm->getDeclContext(),
2855 OldParm->getLocation(),
2856 OldParm->getIdentifier(),
2857 NewDI->getType(),
2858 NewDI,
2859 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002860 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002861 /* DefArg */ NULL);
2862}
2863
2864template<typename Derived>
2865bool TreeTransform<Derived>::
2866 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2867 llvm::SmallVectorImpl<QualType> &PTypes,
2868 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2869 FunctionProtoType *T = TL.getTypePtr();
2870
2871 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2872 ParmVarDecl *OldParm = TL.getArg(i);
2873
2874 QualType NewType;
2875 ParmVarDecl *NewParm;
2876
2877 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002878 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2879 if (!NewParm)
2880 return true;
2881 NewType = NewParm->getType();
2882
2883 // Deal with the possibility that we don't have a parameter
2884 // declaration for this parameter.
2885 } else {
2886 NewParm = 0;
2887
2888 QualType OldType = T->getArgType(i);
2889 NewType = getDerived().TransformType(OldType);
2890 if (NewType.isNull())
2891 return true;
2892 }
2893
2894 PTypes.push_back(NewType);
2895 PVars.push_back(NewParm);
2896 }
2897
2898 return false;
2899}
2900
2901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002902QualType
John McCall550e0c22009-10-21 00:40:46 +00002903TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002904 FunctionProtoTypeLoc TL,
2905 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002906 // Transform the parameters. We do this first for the benefit of template
2907 // instantiations, so that the ParmVarDecls get/ placed into the template
2908 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002910 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002911 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2912 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002913
Douglas Gregor14cf7522010-04-30 18:55:50 +00002914 FunctionProtoType *T = TL.getTypePtr();
2915 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2916 if (ResultType.isNull())
2917 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002918
John McCall550e0c22009-10-21 00:40:46 +00002919 QualType Result = TL.getType();
2920 if (getDerived().AlwaysRebuild() ||
2921 ResultType != T->getResultType() ||
2922 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2923 Result = getDerived().RebuildFunctionProtoType(ResultType,
2924 ParamTypes.data(),
2925 ParamTypes.size(),
2926 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00002927 T->getTypeQuals(),
2928 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00002929 if (Result.isNull())
2930 return QualType();
2931 }
Mike Stump11289f42009-09-09 15:08:12 +00002932
John McCall550e0c22009-10-21 00:40:46 +00002933 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2934 NewTL.setLParenLoc(TL.getLParenLoc());
2935 NewTL.setRParenLoc(TL.getRParenLoc());
2936 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2937 NewTL.setArg(i, ParamDecls[i]);
2938
2939 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940}
Mike Stump11289f42009-09-09 15:08:12 +00002941
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942template<typename Derived>
2943QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002944 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002945 FunctionNoProtoTypeLoc TL,
2946 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002947 FunctionNoProtoType *T = TL.getTypePtr();
2948 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2949 if (ResultType.isNull())
2950 return QualType();
2951
2952 QualType Result = TL.getType();
2953 if (getDerived().AlwaysRebuild() ||
2954 ResultType != T->getResultType())
2955 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2956
2957 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2958 NewTL.setLParenLoc(TL.getLParenLoc());
2959 NewTL.setRParenLoc(TL.getRParenLoc());
2960
2961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962}
Mike Stump11289f42009-09-09 15:08:12 +00002963
John McCallb96ec562009-12-04 22:46:56 +00002964template<typename Derived> QualType
2965TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002966 UnresolvedUsingTypeLoc TL,
2967 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002968 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002969 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002970 if (!D)
2971 return QualType();
2972
2973 QualType Result = TL.getType();
2974 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2975 Result = getDerived().RebuildUnresolvedUsingType(D);
2976 if (Result.isNull())
2977 return QualType();
2978 }
2979
2980 // We might get an arbitrary type spec type back. We should at
2981 // least always get a type spec type, though.
2982 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2983 NewTL.setNameLoc(TL.getNameLoc());
2984
2985 return Result;
2986}
2987
Douglas Gregord6ff3322009-08-04 16:50:30 +00002988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002989QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002990 TypedefTypeLoc TL,
2991 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002992 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002993 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002994 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2995 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996 if (!Typedef)
2997 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002998
John McCall550e0c22009-10-21 00:40:46 +00002999 QualType Result = TL.getType();
3000 if (getDerived().AlwaysRebuild() ||
3001 Typedef != T->getDecl()) {
3002 Result = getDerived().RebuildTypedefType(Typedef);
3003 if (Result.isNull())
3004 return QualType();
3005 }
Mike Stump11289f42009-09-09 15:08:12 +00003006
John McCall550e0c22009-10-21 00:40:46 +00003007 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3008 NewTL.setNameLoc(TL.getNameLoc());
3009
3010 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003011}
Mike Stump11289f42009-09-09 15:08:12 +00003012
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003014QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003015 TypeOfExprTypeLoc TL,
3016 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003017 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003018 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003019
John McCalldadc5752010-08-24 06:29:42 +00003020 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 if (E.isInvalid())
3022 return QualType();
3023
John McCall550e0c22009-10-21 00:40:46 +00003024 QualType Result = TL.getType();
3025 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003026 E.get() != TL.getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003027 Result = getDerived().RebuildTypeOfExprType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003028 if (Result.isNull())
3029 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003030 }
John McCall550e0c22009-10-21 00:40:46 +00003031 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003032
John McCall550e0c22009-10-21 00:40:46 +00003033 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003034 NewTL.setTypeofLoc(TL.getTypeofLoc());
3035 NewTL.setLParenLoc(TL.getLParenLoc());
3036 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003037
3038 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003039}
Mike Stump11289f42009-09-09 15:08:12 +00003040
3041template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003042QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003043 TypeOfTypeLoc TL,
3044 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003045 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3046 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3047 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003048 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003049
John McCall550e0c22009-10-21 00:40:46 +00003050 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003051 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3052 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003053 if (Result.isNull())
3054 return QualType();
3055 }
Mike Stump11289f42009-09-09 15:08:12 +00003056
John McCall550e0c22009-10-21 00:40:46 +00003057 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003058 NewTL.setTypeofLoc(TL.getTypeofLoc());
3059 NewTL.setLParenLoc(TL.getLParenLoc());
3060 NewTL.setRParenLoc(TL.getRParenLoc());
3061 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003062
3063 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003064}
Mike Stump11289f42009-09-09 15:08:12 +00003065
3066template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003067QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003068 DecltypeTypeLoc TL,
3069 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003070 DecltypeType *T = TL.getTypePtr();
3071
Douglas Gregore922c772009-08-04 22:27:00 +00003072 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003074
John McCalldadc5752010-08-24 06:29:42 +00003075 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 if (E.isInvalid())
3077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall550e0c22009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
3080 if (getDerived().AlwaysRebuild() ||
3081 E.get() != T->getUnderlyingExpr()) {
John McCallb268a282010-08-23 23:25:46 +00003082 Result = getDerived().RebuildDecltypeType(E.get());
John McCall550e0c22009-10-21 00:40:46 +00003083 if (Result.isNull())
3084 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003085 }
John McCall550e0c22009-10-21 00:40:46 +00003086 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003087
John McCall550e0c22009-10-21 00:40:46 +00003088 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3089 NewTL.setNameLoc(TL.getNameLoc());
3090
3091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003092}
3093
3094template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003095QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003096 RecordTypeLoc TL,
3097 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003098 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003100 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3101 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102 if (!Record)
3103 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003104
John McCall550e0c22009-10-21 00:40:46 +00003105 QualType Result = TL.getType();
3106 if (getDerived().AlwaysRebuild() ||
3107 Record != T->getDecl()) {
3108 Result = getDerived().RebuildRecordType(Record);
3109 if (Result.isNull())
3110 return QualType();
3111 }
Mike Stump11289f42009-09-09 15:08:12 +00003112
John McCall550e0c22009-10-21 00:40:46 +00003113 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3114 NewTL.setNameLoc(TL.getNameLoc());
3115
3116 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117}
Mike Stump11289f42009-09-09 15:08:12 +00003118
3119template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003120QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003121 EnumTypeLoc TL,
3122 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003123 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003125 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3126 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127 if (!Enum)
3128 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003129
John McCall550e0c22009-10-21 00:40:46 +00003130 QualType Result = TL.getType();
3131 if (getDerived().AlwaysRebuild() ||
3132 Enum != T->getDecl()) {
3133 Result = getDerived().RebuildEnumType(Enum);
3134 if (Result.isNull())
3135 return QualType();
3136 }
Mike Stump11289f42009-09-09 15:08:12 +00003137
John McCall550e0c22009-10-21 00:40:46 +00003138 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3139 NewTL.setNameLoc(TL.getNameLoc());
3140
3141 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142}
John McCallfcc33b02009-09-05 00:15:47 +00003143
John McCalle78aac42010-03-10 03:28:59 +00003144template<typename Derived>
3145QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3146 TypeLocBuilder &TLB,
3147 InjectedClassNameTypeLoc TL,
3148 QualType ObjectType) {
3149 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3150 TL.getTypePtr()->getDecl());
3151 if (!D) return QualType();
3152
3153 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3154 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3155 return T;
3156}
3157
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159template<typename Derived>
3160QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003161 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003162 TemplateTypeParmTypeLoc TL,
3163 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003164 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003165}
3166
Mike Stump11289f42009-09-09 15:08:12 +00003167template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003168QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003169 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003170 SubstTemplateTypeParmTypeLoc TL,
3171 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003172 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003173}
3174
3175template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003176QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3177 const TemplateSpecializationType *TST,
3178 QualType ObjectType) {
3179 // FIXME: this entire method is a temporary workaround; callers
3180 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003181
John McCall0ad16662009-10-29 08:12:44 +00003182 // Fake up a TemplateSpecializationTypeLoc.
3183 TypeLocBuilder TLB;
3184 TemplateSpecializationTypeLoc TL
3185 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3186
John McCall0d07eb32009-10-29 18:45:58 +00003187 SourceLocation BaseLoc = getDerived().getBaseLocation();
3188
3189 TL.setTemplateNameLoc(BaseLoc);
3190 TL.setLAngleLoc(BaseLoc);
3191 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003192 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3193 const TemplateArgument &TA = TST->getArg(i);
3194 TemplateArgumentLoc TAL;
3195 getDerived().InventTemplateArgumentLoc(TA, TAL);
3196 TL.setArgLocInfo(i, TAL.getLocInfo());
3197 }
3198
3199 TypeLocBuilder IgnoredTLB;
3200 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003201}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003202
Douglas Gregorc59e5612009-10-19 22:04:39 +00003203template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003204QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003205 TypeLocBuilder &TLB,
3206 TemplateSpecializationTypeLoc TL,
3207 QualType ObjectType) {
3208 const TemplateSpecializationType *T = TL.getTypePtr();
3209
Mike Stump11289f42009-09-09 15:08:12 +00003210 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003211 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003212 if (Template.isNull())
3213 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003214
John McCall6b51f282009-11-23 01:53:49 +00003215 TemplateArgumentListInfo NewTemplateArgs;
3216 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3217 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3218
3219 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3220 TemplateArgumentLoc Loc;
3221 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003222 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003223 NewTemplateArgs.addArgument(Loc);
3224 }
Mike Stump11289f42009-09-09 15:08:12 +00003225
John McCall0ad16662009-10-29 08:12:44 +00003226 // FIXME: maybe don't rebuild if all the template arguments are the same.
3227
3228 QualType Result =
3229 getDerived().RebuildTemplateSpecializationType(Template,
3230 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003231 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003232
3233 if (!Result.isNull()) {
3234 TemplateSpecializationTypeLoc NewTL
3235 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3236 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3237 NewTL.setLAngleLoc(TL.getLAngleLoc());
3238 NewTL.setRAngleLoc(TL.getRAngleLoc());
3239 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3240 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 }
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall0ad16662009-10-29 08:12:44 +00003243 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003244}
Mike Stump11289f42009-09-09 15:08:12 +00003245
3246template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003247QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003248TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3249 ElaboratedTypeLoc TL,
3250 QualType ObjectType) {
3251 ElaboratedType *T = TL.getTypePtr();
3252
3253 NestedNameSpecifier *NNS = 0;
3254 // NOTE: the qualifier in an ElaboratedType is optional.
3255 if (T->getQualifier() != 0) {
3256 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003257 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003258 ObjectType);
3259 if (!NNS)
3260 return QualType();
3261 }
Mike Stump11289f42009-09-09 15:08:12 +00003262
Abramo Bagnarad7548482010-05-19 21:37:53 +00003263 QualType NamedT;
3264 // FIXME: this test is meant to workaround a problem (failing assertion)
3265 // occurring if directly executing the code in the else branch.
3266 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3267 TemplateSpecializationTypeLoc OldNamedTL
3268 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3269 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003270 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003271 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3272 if (NamedT.isNull())
3273 return QualType();
3274 TemplateSpecializationTypeLoc NewNamedTL
3275 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3276 NewNamedTL.copy(OldNamedTL);
3277 }
3278 else {
3279 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3280 if (NamedT.isNull())
3281 return QualType();
3282 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003283
John McCall550e0c22009-10-21 00:40:46 +00003284 QualType Result = TL.getType();
3285 if (getDerived().AlwaysRebuild() ||
3286 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003287 NamedT != T->getNamedType()) {
3288 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003289 if (Result.isNull())
3290 return QualType();
3291 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003292
Abramo Bagnara6150c882010-05-11 21:36:43 +00003293 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003294 NewTL.setKeywordLoc(TL.getKeywordLoc());
3295 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003296
3297 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298}
Mike Stump11289f42009-09-09 15:08:12 +00003299
3300template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003301QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3302 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003303 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003304 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003305
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003307 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3308 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003309 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310 if (!NNS)
3311 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003312
John McCallc392f372010-06-11 00:33:02 +00003313 QualType Result
3314 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3315 T->getIdentifier(),
3316 TL.getKeywordLoc(),
3317 TL.getQualifierRange(),
3318 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003319 if (Result.isNull())
3320 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321
Abramo Bagnarad7548482010-05-19 21:37:53 +00003322 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3323 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003324 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3325
Abramo Bagnarad7548482010-05-19 21:37:53 +00003326 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3327 NewTL.setKeywordLoc(TL.getKeywordLoc());
3328 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003329 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003330 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3331 NewTL.setKeywordLoc(TL.getKeywordLoc());
3332 NewTL.setQualifierRange(TL.getQualifierRange());
3333 NewTL.setNameLoc(TL.getNameLoc());
3334 }
John McCall550e0c22009-10-21 00:40:46 +00003335 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003336}
Mike Stump11289f42009-09-09 15:08:12 +00003337
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003339QualType TreeTransform<Derived>::
3340 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3341 DependentTemplateSpecializationTypeLoc TL,
3342 QualType ObjectType) {
3343 DependentTemplateSpecializationType *T = TL.getTypePtr();
3344
3345 NestedNameSpecifier *NNS
3346 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3347 TL.getQualifierRange(),
3348 ObjectType);
3349 if (!NNS)
3350 return QualType();
3351
3352 TemplateArgumentListInfo NewTemplateArgs;
3353 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3354 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3355
3356 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3357 TemplateArgumentLoc Loc;
3358 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3359 return QualType();
3360 NewTemplateArgs.addArgument(Loc);
3361 }
3362
3363 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3364 T->getKeyword(),
3365 NNS,
3366 T->getIdentifier(),
3367 TL.getNameLoc(),
3368 NewTemplateArgs);
3369 if (Result.isNull())
3370 return QualType();
3371
3372 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3373 QualType NamedT = ElabT->getNamedType();
3374
3375 // Copy information relevant to the template specialization.
3376 TemplateSpecializationTypeLoc NamedTL
3377 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3378 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3379 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3380 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3381 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3382
3383 // Copy information relevant to the elaborated type.
3384 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3385 NewTL.setKeywordLoc(TL.getKeywordLoc());
3386 NewTL.setQualifierRange(TL.getQualifierRange());
3387 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003388 TypeLoc NewTL(Result, TL.getOpaqueData());
3389 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003390 }
3391 return Result;
3392}
3393
3394template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003395QualType
3396TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003397 ObjCInterfaceTypeLoc TL,
3398 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003399 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003400 TLB.pushFullCopy(TL);
3401 return TL.getType();
3402}
3403
3404template<typename Derived>
3405QualType
3406TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3407 ObjCObjectTypeLoc TL,
3408 QualType ObjectType) {
3409 // ObjCObjectType is never dependent.
3410 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003411 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412}
Mike Stump11289f42009-09-09 15:08:12 +00003413
3414template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003415QualType
3416TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003417 ObjCObjectPointerTypeLoc TL,
3418 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003419 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003420 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003421 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003422}
3423
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003425// Statement transformation
3426//===----------------------------------------------------------------------===//
3427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003428StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003429TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3430 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003431}
3432
3433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003434StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003435TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3436 return getDerived().TransformCompoundStmt(S, false);
3437}
3438
3439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003441TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003443 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003444 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003445 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003446 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3447 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003448 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003449 if (Result.isInvalid()) {
3450 // Immediately fail if this was a DeclStmt, since it's very
3451 // likely that this will cause problems for future statements.
3452 if (isa<DeclStmt>(*B))
3453 return StmtError();
3454
3455 // Otherwise, just keep processing substatements and fail later.
3456 SubStmtInvalid = true;
3457 continue;
3458 }
Mike Stump11289f42009-09-09 15:08:12 +00003459
Douglas Gregorebe10102009-08-20 07:17:43 +00003460 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3461 Statements.push_back(Result.takeAs<Stmt>());
3462 }
Mike Stump11289f42009-09-09 15:08:12 +00003463
John McCall1ababa62010-08-27 19:56:05 +00003464 if (SubStmtInvalid)
3465 return StmtError();
3466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 if (!getDerived().AlwaysRebuild() &&
3468 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003469 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003470
3471 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3472 move_arg(Statements),
3473 S->getRBracLoc(),
3474 IsStmtExpr);
3475}
Mike Stump11289f42009-09-09 15:08:12 +00003476
Douglas Gregorebe10102009-08-20 07:17:43 +00003477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003478StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003479TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003480 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003481 {
3482 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003483 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003484
Eli Friedman06577382009-11-19 03:14:00 +00003485 // Transform the left-hand case value.
3486 LHS = getDerived().TransformExpr(S->getLHS());
3487 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003488 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003489
Eli Friedman06577382009-11-19 03:14:00 +00003490 // Transform the right-hand case value (for the GNU case-range extension).
3491 RHS = getDerived().TransformExpr(S->getRHS());
3492 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003493 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003494 }
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregorebe10102009-08-20 07:17:43 +00003496 // Build the case statement.
3497 // Case statements are always rebuilt so that they will attached to their
3498 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003499 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003500 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003501 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003502 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003503 S->getColonLoc());
3504 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003505 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003508 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003510 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003511
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003513 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003514}
3515
3516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003518TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003520 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003522 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 // Default statements are always rebuilt
3525 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003526 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003527}
Mike Stump11289f42009-09-09 15:08:12 +00003528
Douglas Gregorebe10102009-08-20 07:17:43 +00003529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003530StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003531TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003532 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003534 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 // FIXME: Pass the real colon location in.
3537 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3538 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00003539 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregorebe10102009-08-20 07:17:43 +00003542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003543StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003544TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003546 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003547 VarDecl *ConditionVar = 0;
3548 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003549 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003550 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003551 getDerived().TransformDefinition(
3552 S->getConditionVariable()->getLocation(),
3553 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003554 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003555 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003556 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003557 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003558
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003559 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003560 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003561
3562 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003563 if (S->getCond()) {
John McCalldadc5752010-08-24 06:29:42 +00003564 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003565 S->getIfLoc(),
John McCallb268a282010-08-23 23:25:46 +00003566 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003567 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003568 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003569
John McCallb268a282010-08-23 23:25:46 +00003570 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003571 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003572 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003573
John McCallb268a282010-08-23 23:25:46 +00003574 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3575 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003576 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00003579 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00003580 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003581 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00003584 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00003585 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003586 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003589 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003590 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003591 Then.get() == S->getThen() &&
3592 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003593 return SemaRef.Owned(S->Retain());
3594
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003595 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
John McCallb268a282010-08-23 23:25:46 +00003596 Then.get(),
3597 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003598}
3599
3600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003601StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003602TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003603 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00003604 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00003605 VarDecl *ConditionVar = 0;
3606 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003607 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003608 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003609 getDerived().TransformDefinition(
3610 S->getConditionVariable()->getLocation(),
3611 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003612 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003613 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003614 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003615 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003616
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003617 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003618 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003619 }
Mike Stump11289f42009-09-09 15:08:12 +00003620
Douglas Gregorebe10102009-08-20 07:17:43 +00003621 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003622 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00003623 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003624 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003626 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003629 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003630 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003631 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003632
Douglas Gregorebe10102009-08-20 07:17:43 +00003633 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00003634 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3635 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003636}
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregorebe10102009-08-20 07:17:43 +00003638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003639StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003640TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003641 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003642 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00003643 VarDecl *ConditionVar = 0;
3644 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003645 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003646 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003647 getDerived().TransformDefinition(
3648 S->getConditionVariable()->getLocation(),
3649 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003650 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003651 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003652 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003653 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003654
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003655 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003656 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003657
3658 if (S->getCond()) {
3659 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003660 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003661 S->getWhileLoc(),
John McCallb268a282010-08-23 23:25:46 +00003662 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003663 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003664 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00003665 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00003666 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003667 }
Mike Stump11289f42009-09-09 15:08:12 +00003668
John McCallb268a282010-08-23 23:25:46 +00003669 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3670 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003671 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003672
Douglas Gregorebe10102009-08-20 07:17:43 +00003673 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003674 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003675 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003676 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003677
Douglas Gregorebe10102009-08-20 07:17:43 +00003678 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00003679 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003680 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00003682 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003684 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00003685 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003686}
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregorebe10102009-08-20 07:17:43 +00003688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003689StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003690TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003692 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003693 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003694 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003695
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003696 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003697 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003698 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003699 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701 if (!getDerived().AlwaysRebuild() &&
3702 Cond.get() == S->getCond() &&
3703 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003704 return SemaRef.Owned(S->Retain());
3705
John McCallb268a282010-08-23 23:25:46 +00003706 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3707 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003708 S->getRParenLoc());
3709}
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregorebe10102009-08-20 07:17:43 +00003711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003712StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00003715 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00003716 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003717 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003720 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003721 VarDecl *ConditionVar = 0;
3722 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003723 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003724 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003725 getDerived().TransformDefinition(
3726 S->getConditionVariable()->getLocation(),
3727 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003728 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00003729 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003730 } else {
3731 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003732
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003733 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003734 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003735
3736 if (S->getCond()) {
3737 // Convert the condition to a boolean value.
John McCalldadc5752010-08-24 06:29:42 +00003738 ExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregor6d319c62010-05-08 23:34:38 +00003739 S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00003740 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00003741 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003742 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003743
John McCallb268a282010-08-23 23:25:46 +00003744 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003745 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003746 }
Mike Stump11289f42009-09-09 15:08:12 +00003747
John McCallb268a282010-08-23 23:25:46 +00003748 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3749 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003750 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003751
Douglas Gregorebe10102009-08-20 07:17:43 +00003752 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00003753 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00003754 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003755 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003756
John McCallb268a282010-08-23 23:25:46 +00003757 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3758 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00003759 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003760
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00003762 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00003763 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003764 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003765
Douglas Gregorebe10102009-08-20 07:17:43 +00003766 if (!getDerived().AlwaysRebuild() &&
3767 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00003768 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003769 Inc.get() == S->getInc() &&
3770 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003771 return SemaRef.Owned(S->Retain());
3772
Douglas Gregorebe10102009-08-20 07:17:43 +00003773 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00003774 Init.get(), FullCond, ConditionVar,
3775 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003776}
3777
3778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003779StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003780TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003781 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003782 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003783 S->getLabel());
3784}
3785
3786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003788TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003789 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00003790 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003791 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregorebe10102009-08-20 07:17:43 +00003793 if (!getDerived().AlwaysRebuild() &&
3794 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003795 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003796
3797 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00003798 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003799}
3800
3801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003803TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3804 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003805}
Mike Stump11289f42009-09-09 15:08:12 +00003806
Douglas Gregorebe10102009-08-20 07:17:43 +00003807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003808StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003809TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3810 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003811}
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregorebe10102009-08-20 07:17:43 +00003813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003814StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003815TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003816 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00003817 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003818 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00003819
Mike Stump11289f42009-09-09 15:08:12 +00003820 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003821 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00003822 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003823}
Mike Stump11289f42009-09-09 15:08:12 +00003824
Douglas Gregorebe10102009-08-20 07:17:43 +00003825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003826StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003827TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003828 bool DeclChanged = false;
3829 llvm::SmallVector<Decl *, 4> Decls;
3830 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3831 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003832 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3833 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003834 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00003835 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregorebe10102009-08-20 07:17:43 +00003837 if (Transformed != *D)
3838 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003839
Douglas Gregorebe10102009-08-20 07:17:43 +00003840 Decls.push_back(Transformed);
3841 }
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregorebe10102009-08-20 07:17:43 +00003843 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003844 return SemaRef.Owned(S->Retain());
3845
3846 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003847 S->getStartLoc(), S->getEndLoc());
3848}
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregorebe10102009-08-20 07:17:43 +00003850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003851StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003852TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003853 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003854 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003855}
3856
3857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003858StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003859TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003860
John McCall37ad5512010-08-23 06:44:23 +00003861 ASTOwningVector<Expr*> Constraints(getSema());
3862 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003863 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003864
John McCalldadc5752010-08-24 06:29:42 +00003865 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00003866 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003867
3868 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003869
Anders Carlssonaaeef072010-01-24 05:50:09 +00003870 // Go through the outputs.
3871 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003872 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003873
Anders Carlssonaaeef072010-01-24 05:50:09 +00003874 // No need to transform the constraint literal.
3875 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003876
Anders Carlssonaaeef072010-01-24 05:50:09 +00003877 // Transform the output expr.
3878 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003879 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003880 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003881 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003882
Anders Carlssonaaeef072010-01-24 05:50:09 +00003883 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003884
John McCallb268a282010-08-23 23:25:46 +00003885 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003886 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003887
Anders Carlssonaaeef072010-01-24 05:50:09 +00003888 // Go through the inputs.
3889 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003890 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003891
Anders Carlssonaaeef072010-01-24 05:50:09 +00003892 // No need to transform the constraint literal.
3893 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003894
Anders Carlssonaaeef072010-01-24 05:50:09 +00003895 // Transform the input expr.
3896 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00003897 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00003898 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003899 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003900
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003902
John McCallb268a282010-08-23 23:25:46 +00003903 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00003904 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003905
Anders Carlssonaaeef072010-01-24 05:50:09 +00003906 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3907 return SemaRef.Owned(S->Retain());
3908
3909 // Go through the clobbers.
3910 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3911 Clobbers.push_back(S->getClobber(I)->Retain());
3912
3913 // No need to transform the asm string literal.
3914 AsmString = SemaRef.Owned(S->getAsmString());
3915
3916 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3917 S->isSimple(),
3918 S->isVolatile(),
3919 S->getNumOutputs(),
3920 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003921 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003922 move_arg(Constraints),
3923 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00003924 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003925 move_arg(Clobbers),
3926 S->getRParenLoc(),
3927 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003928}
3929
3930
3931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003932StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003933TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003934 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00003935 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003936 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003937 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003938
Douglas Gregor96c79492010-04-23 22:50:49 +00003939 // Transform the @catch statements (if present).
3940 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003941 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00003942 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00003943 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003944 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003945 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003946 if (Catch.get() != S->getCatchStmt(I))
3947 AnyCatchChanged = true;
3948 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003949 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003950
Douglas Gregor306de2f2010-04-22 23:59:56 +00003951 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00003952 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00003953 if (S->getFinallyStmt()) {
3954 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3955 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003956 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00003957 }
3958
3959 // If nothing changed, just retain this statement.
3960 if (!getDerived().AlwaysRebuild() &&
3961 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003962 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003963 Finally.get() == S->getFinallyStmt())
3964 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003965
Douglas Gregor306de2f2010-04-22 23:59:56 +00003966 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00003967 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3968 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003969}
Mike Stump11289f42009-09-09 15:08:12 +00003970
Douglas Gregorebe10102009-08-20 07:17:43 +00003971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003972StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003973TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003974 // Transform the @catch parameter, if there is one.
3975 VarDecl *Var = 0;
3976 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3977 TypeSourceInfo *TSInfo = 0;
3978 if (FromVar->getTypeSourceInfo()) {
3979 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3980 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00003981 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003982 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003984 QualType T;
3985 if (TSInfo)
3986 T = TSInfo->getType();
3987 else {
3988 T = getDerived().TransformType(FromVar->getType());
3989 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00003990 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003991 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003992
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003993 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3994 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00003995 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003996 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003997
John McCalldadc5752010-08-24 06:29:42 +00003998 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003999 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004000 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004001
4002 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004003 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004004 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004005}
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregorebe10102009-08-20 07:17:43 +00004007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004008StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004009TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004010 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004011 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004012 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004013 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004014
Douglas Gregor306de2f2010-04-22 23:59:56 +00004015 // If nothing changed, just retain this statement.
4016 if (!getDerived().AlwaysRebuild() &&
4017 Body.get() == S->getFinallyBody())
4018 return SemaRef.Owned(S->Retain());
4019
4020 // Build a new statement.
4021 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004022 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004023}
Mike Stump11289f42009-09-09 15:08:12 +00004024
Douglas Gregorebe10102009-08-20 07:17:43 +00004025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004026StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004027TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004028 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004029 if (S->getThrowExpr()) {
4030 Operand = getDerived().TransformExpr(S->getThrowExpr());
4031 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004032 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004033 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004034
Douglas Gregor2900c162010-04-22 21:44:01 +00004035 if (!getDerived().AlwaysRebuild() &&
4036 Operand.get() == S->getThrowExpr())
4037 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004038
John McCallb268a282010-08-23 23:25:46 +00004039 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004040}
Mike Stump11289f42009-09-09 15:08:12 +00004041
Douglas Gregorebe10102009-08-20 07:17:43 +00004042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004043StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004044TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004045 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004046 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004047 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004048 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004049 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004050
Douglas Gregor6148de72010-04-22 22:01:21 +00004051 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004052 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004053 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004054 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004055
Douglas Gregor6148de72010-04-22 22:01:21 +00004056 // If nothing change, just retain the current statement.
4057 if (!getDerived().AlwaysRebuild() &&
4058 Object.get() == S->getSynchExpr() &&
4059 Body.get() == S->getSynchBody())
4060 return SemaRef.Owned(S->Retain());
4061
4062 // Build a new statement.
4063 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004064 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004065}
4066
4067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004068StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004069TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004070 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004071 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004072 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004073 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004074 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004075
Douglas Gregorf68a5082010-04-22 23:10:45 +00004076 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004077 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004078 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004079 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004080
Douglas Gregorf68a5082010-04-22 23:10:45 +00004081 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004082 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004083 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004084 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004085
Douglas Gregorf68a5082010-04-22 23:10:45 +00004086 // If nothing changed, just retain this statement.
4087 if (!getDerived().AlwaysRebuild() &&
4088 Element.get() == S->getElement() &&
4089 Collection.get() == S->getCollection() &&
4090 Body.get() == S->getBody())
4091 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004092
Douglas Gregorf68a5082010-04-22 23:10:45 +00004093 // Build a new statement.
4094 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4095 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004096 Element.get(),
4097 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004098 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004099 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004100}
4101
4102
4103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004104StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004105TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4106 // Transform the exception declaration, if any.
4107 VarDecl *Var = 0;
4108 if (S->getExceptionDecl()) {
4109 VarDecl *ExceptionDecl = S->getExceptionDecl();
4110 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4111 ExceptionDecl->getDeclName());
4112
4113 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4114 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004115 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregorebe10102009-08-20 07:17:43 +00004117 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4118 T,
John McCallbcd03502009-12-07 02:54:59 +00004119 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004120 ExceptionDecl->getIdentifier(),
4121 ExceptionDecl->getLocation(),
4122 /*FIXME: Inaccurate*/
4123 SourceRange(ExceptionDecl->getLocation()));
Douglas Gregorb412e172010-07-25 18:17:45 +00004124 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004125 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004126 }
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregorebe10102009-08-20 07:17:43 +00004128 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004129 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004130 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004131 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregorebe10102009-08-20 07:17:43 +00004133 if (!getDerived().AlwaysRebuild() &&
4134 !Var &&
4135 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004136 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004137
4138 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4139 Var,
John McCallb268a282010-08-23 23:25:46 +00004140 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregorebe10102009-08-20 07:17:43 +00004143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004144StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004145TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4146 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004147 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004148 = getDerived().TransformCompoundStmt(S->getTryBlock());
4149 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004150 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregorebe10102009-08-20 07:17:43 +00004152 // Transform the handlers.
4153 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004154 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004155 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004156 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004157 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4158 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004159 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregorebe10102009-08-20 07:17:43 +00004161 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4162 Handlers.push_back(Handler.takeAs<Stmt>());
4163 }
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregorebe10102009-08-20 07:17:43 +00004165 if (!getDerived().AlwaysRebuild() &&
4166 TryBlock.get() == S->getTryBlock() &&
4167 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004168 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004169
John McCallb268a282010-08-23 23:25:46 +00004170 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004171 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregorebe10102009-08-20 07:17:43 +00004174//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004175// Expression transformation
4176//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004179TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004180 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004181}
Mike Stump11289f42009-09-09 15:08:12 +00004182
4183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004185TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004186 NestedNameSpecifier *Qualifier = 0;
4187 if (E->getQualifier()) {
4188 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004189 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004190 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004191 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004192 }
John McCallce546572009-12-08 09:08:17 +00004193
4194 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004195 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4196 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004197 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004199
John McCall815039a2010-08-17 21:27:17 +00004200 DeclarationNameInfo NameInfo = E->getNameInfo();
4201 if (NameInfo.getName()) {
4202 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4203 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004204 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004205 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004206
4207 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004208 Qualifier == E->getQualifier() &&
4209 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004210 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004211 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004212
4213 // Mark it referenced in the new context regardless.
4214 // FIXME: this is a bit instantiation-specific.
4215 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4216
Mike Stump11289f42009-09-09 15:08:12 +00004217 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004218 }
John McCallce546572009-12-08 09:08:17 +00004219
4220 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004221 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004222 TemplateArgs = &TransArgs;
4223 TransArgs.setLAngleLoc(E->getLAngleLoc());
4224 TransArgs.setRAngleLoc(E->getRAngleLoc());
4225 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4226 TemplateArgumentLoc Loc;
4227 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004228 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004229 TransArgs.addArgument(Loc);
4230 }
4231 }
4232
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004233 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004234 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004235}
Mike Stump11289f42009-09-09 15:08:12 +00004236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004239TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004240 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004241}
Mike Stump11289f42009-09-09 15:08:12 +00004242
Douglas Gregora16548e2009-08-11 05:31:07 +00004243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004245TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004246 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004247}
Mike Stump11289f42009-09-09 15:08:12 +00004248
Douglas Gregora16548e2009-08-11 05:31:07 +00004249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004251TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004252 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregora16548e2009-08-11 05:31:07 +00004255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004257TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004258 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004259}
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregora16548e2009-08-11 05:31:07 +00004261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004263TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004264 return SemaRef.Owned(E->Retain());
4265}
4266
4267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004269TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004270 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004271 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004273
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004275 return SemaRef.Owned(E->Retain());
4276
John McCallb268a282010-08-23 23:25:46 +00004277 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 E->getRParen());
4279}
4280
Mike Stump11289f42009-09-09 15:08:12 +00004281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004283TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004284 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004289 return SemaRef.Owned(E->Retain());
4290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4292 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004293 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004294}
Mike Stump11289f42009-09-09 15:08:12 +00004295
Douglas Gregora16548e2009-08-11 05:31:07 +00004296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004297ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004298TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4299 // Transform the type.
4300 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4301 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004302 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004303
Douglas Gregor882211c2010-04-28 22:16:22 +00004304 // Transform all of the components into components similar to what the
4305 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004306 // FIXME: It would be slightly more efficient in the non-dependent case to
4307 // just map FieldDecls, rather than requiring the rebuilder to look for
4308 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004309 // template code that we don't care.
4310 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004311 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004312 typedef OffsetOfExpr::OffsetOfNode Node;
4313 llvm::SmallVector<Component, 4> Components;
4314 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4315 const Node &ON = E->getComponent(I);
4316 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004317 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004318 Comp.LocStart = ON.getRange().getBegin();
4319 Comp.LocEnd = ON.getRange().getEnd();
4320 switch (ON.getKind()) {
4321 case Node::Array: {
4322 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004323 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004324 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004325 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004326
Douglas Gregor882211c2010-04-28 22:16:22 +00004327 ExprChanged = ExprChanged || Index.get() != FromIndex;
4328 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004329 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004330 break;
4331 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004332
Douglas Gregor882211c2010-04-28 22:16:22 +00004333 case Node::Field:
4334 case Node::Identifier:
4335 Comp.isBrackets = false;
4336 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004337 if (!Comp.U.IdentInfo)
4338 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004339
Douglas Gregor882211c2010-04-28 22:16:22 +00004340 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004341
Douglas Gregord1702062010-04-29 00:18:15 +00004342 case Node::Base:
4343 // Will be recomputed during the rebuild.
4344 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004346
Douglas Gregor882211c2010-04-28 22:16:22 +00004347 Components.push_back(Comp);
4348 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004349
Douglas Gregor882211c2010-04-28 22:16:22 +00004350 // If nothing changed, retain the existing expression.
4351 if (!getDerived().AlwaysRebuild() &&
4352 Type == E->getTypeSourceInfo() &&
4353 !ExprChanged)
4354 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004355
Douglas Gregor882211c2010-04-28 22:16:22 +00004356 // Build a new offsetof expression.
4357 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4358 Components.data(), Components.size(),
4359 E->getRParenLoc());
4360}
4361
4362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004364TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004366 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004367
John McCallbcd03502009-12-07 02:54:59 +00004368 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004369 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall4c98fd82009-11-04 07:28:41 +00004372 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004373 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004374
John McCall4c98fd82009-11-04 07:28:41 +00004375 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004376 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 E->getSourceRange());
4378 }
Mike Stump11289f42009-09-09 15:08:12 +00004379
John McCalldadc5752010-08-24 06:29:42 +00004380 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004381 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 // C++0x [expr.sizeof]p1:
4383 // The operand is either an expression, which is an unevaluated operand
4384 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004385 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004386
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4388 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004390
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4392 return SemaRef.Owned(E->Retain());
4393 }
Mike Stump11289f42009-09-09 15:08:12 +00004394
John McCallb268a282010-08-23 23:25:46 +00004395 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 E->isSizeOf(),
4397 E->getSourceRange());
4398}
Mike Stump11289f42009-09-09 15:08:12 +00004399
Douglas Gregora16548e2009-08-11 05:31:07 +00004400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004402TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004403 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004406
John McCalldadc5752010-08-24 06:29:42 +00004407 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004410
4411
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 if (!getDerived().AlwaysRebuild() &&
4413 LHS.get() == E->getLHS() &&
4414 RHS.get() == E->getRHS())
4415 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004416
John McCallb268a282010-08-23 23:25:46 +00004417 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004419 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 E->getRBracketLoc());
4421}
Mike Stump11289f42009-09-09 15:08:12 +00004422
4423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004425TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004427 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004429 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004430
4431 // Transform arguments.
4432 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004433 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4435 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004436 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004438 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 // FIXME: Wrong source location information for the ','.
4441 FakeCommaLocs.push_back(
4442 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004443
4444 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004445 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 }
Mike Stump11289f42009-09-09 15:08:12 +00004447
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 if (!getDerived().AlwaysRebuild() &&
4449 Callee.get() == E->getCallee() &&
4450 !ArgChanged)
4451 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004452
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004454 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004456 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004457 move_arg(Args),
4458 FakeCommaLocs.data(),
4459 E->getRParenLoc());
4460}
Mike Stump11289f42009-09-09 15:08:12 +00004461
4462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004463ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004464TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004465 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004466 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004469 NestedNameSpecifier *Qualifier = 0;
4470 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004471 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004472 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004473 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004474 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004475 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004476 }
Mike Stump11289f42009-09-09 15:08:12 +00004477
Eli Friedman2cfcef62009-12-04 06:40:45 +00004478 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004479 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4480 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004483
John McCall16df1e52010-03-30 21:47:33 +00004484 NamedDecl *FoundDecl = E->getFoundDecl();
4485 if (FoundDecl == E->getMemberDecl()) {
4486 FoundDecl = Member;
4487 } else {
4488 FoundDecl = cast_or_null<NamedDecl>(
4489 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4490 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004491 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004492 }
4493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 if (!getDerived().AlwaysRebuild() &&
4495 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004496 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004497 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004498 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004499 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004500
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004501 // Mark it referenced in the new context regardless.
4502 // FIXME: this is a bit instantiation-specific.
4503 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004504 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004505 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004506
John McCall6b51f282009-11-23 01:53:49 +00004507 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004508 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004509 TransArgs.setLAngleLoc(E->getLAngleLoc());
4510 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004511 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004512 TemplateArgumentLoc Loc;
4513 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00004514 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004515 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004516 }
4517 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004518
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 // FIXME: Bogus source location for the operator
4520 SourceLocation FakeOperatorLoc
4521 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4522
John McCall38836f02010-01-15 08:34:02 +00004523 // FIXME: to do this check properly, we will need to preserve the
4524 // first-qualifier-in-scope here, just in case we had a dependent
4525 // base (and therefore couldn't do the check) and a
4526 // nested-name-qualifier (and therefore could do the lookup).
4527 NamedDecl *FirstQualifierInScope = 0;
4528
John McCallb268a282010-08-23 23:25:46 +00004529 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004531 Qualifier,
4532 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004533 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004534 Member,
John McCall16df1e52010-03-30 21:47:33 +00004535 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004536 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004537 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004538 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004543TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004544 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004547
John McCalldadc5752010-08-24 06:29:42 +00004548 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004551
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 if (!getDerived().AlwaysRebuild() &&
4553 LHS.get() == E->getLHS() &&
4554 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004555 return SemaRef.Owned(E->Retain());
4556
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004558 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004559}
4560
Mike Stump11289f42009-09-09 15:08:12 +00004561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004562ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004563TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004564 CompoundAssignOperator *E) {
4565 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004566}
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004570TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004571 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004574
John McCalldadc5752010-08-24 06:29:42 +00004575 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004578
John McCalldadc5752010-08-24 06:29:42 +00004579 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004582
Douglas Gregora16548e2009-08-11 05:31:07 +00004583 if (!getDerived().AlwaysRebuild() &&
4584 Cond.get() == E->getCond() &&
4585 LHS.get() == E->getLHS() &&
4586 RHS.get() == E->getRHS())
4587 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCallb268a282010-08-23 23:25:46 +00004589 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004590 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00004591 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004592 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004593 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004594}
Mike Stump11289f42009-09-09 15:08:12 +00004595
4596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004598TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004599 // Implicit casts are eliminated during transformation, since they
4600 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004601 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004602}
Mike Stump11289f42009-09-09 15:08:12 +00004603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004606TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004607 TypeSourceInfo *OldT;
4608 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 {
4610 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004611 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004612 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4613 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004614
John McCall97513962010-01-15 18:39:57 +00004615 OldT = E->getTypeInfoAsWritten();
4616 NewT = getDerived().TransformType(OldT);
4617 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004618 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004619 }
Mike Stump11289f42009-09-09 15:08:12 +00004620
John McCalldadc5752010-08-24 06:29:42 +00004621 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004622 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004625
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004627 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004628 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004629 return SemaRef.Owned(E->Retain());
4630
John McCall97513962010-01-15 18:39:57 +00004631 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4632 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004634 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004635}
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004639TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004640 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4641 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4642 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004644
John McCalldadc5752010-08-24 06:29:42 +00004645 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004648
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004650 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004652 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004653
John McCall5d7aa7f2010-01-19 22:33:45 +00004654 // Note: the expression type doesn't necessarily match the
4655 // type-as-written, but that's okay, because it should always be
4656 // derivable from the initializer.
4657
John McCalle15bbff2010-01-18 19:35:47 +00004658 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00004660 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004661}
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregora16548e2009-08-11 05:31:07 +00004663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004665TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004666 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregora16548e2009-08-11 05:31:07 +00004670 if (!getDerived().AlwaysRebuild() &&
4671 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004672 return SemaRef.Owned(E->Retain());
4673
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004675 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00004677 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004678 E->getAccessorLoc(),
4679 E->getAccessor());
4680}
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregora16548e2009-08-11 05:31:07 +00004682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004684TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004685 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004686
John McCall37ad5512010-08-23 06:44:23 +00004687 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004689 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00004694 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 }
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004698 return SemaRef.Owned(E->Retain());
4699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004701 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004702}
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregora16548e2009-08-11 05:31:07 +00004704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004706TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregorebe10102009-08-20 07:17:43 +00004709 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00004710 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregorebe10102009-08-20 07:17:43 +00004714 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00004715 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 bool ExprChanged = false;
4717 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4718 DEnd = E->designators_end();
4719 D != DEnd; ++D) {
4720 if (D->isFieldDesignator()) {
4721 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4722 D->getDotLoc(),
4723 D->getFieldLoc()));
4724 continue;
4725 }
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00004728 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
4732 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregora16548e2009-08-11 05:31:07 +00004735 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4736 ArrayExprs.push_back(Index.release());
4737 continue;
4738 }
Mike Stump11289f42009-09-09 15:08:12 +00004739
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00004741 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4743 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004745
John McCalldadc5752010-08-24 06:29:42 +00004746 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
4750 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 End.get(),
4752 D->getLBracketLoc(),
4753 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4756 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 ArrayExprs.push_back(Start.release());
4759 ArrayExprs.push_back(End.release());
4760 }
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762 if (!getDerived().AlwaysRebuild() &&
4763 Init.get() == E->getInit() &&
4764 !ExprChanged)
4765 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4768 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004769 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004770}
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregora16548e2009-08-11 05:31:07 +00004772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004773ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004774TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004775 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004776 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004777
Douglas Gregor3da3c062009-10-28 00:29:27 +00004778 // FIXME: Will we ever have proper type location here? Will we actually
4779 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 QualType T = getDerived().TransformType(E->getType());
4781 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 if (!getDerived().AlwaysRebuild() &&
4785 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004786 return SemaRef.Owned(E->Retain());
4787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 return getDerived().RebuildImplicitValueInitExpr(T);
4789}
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregora16548e2009-08-11 05:31:07 +00004791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004793TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00004794 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4795 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004797
John McCalldadc5752010-08-24 06:29:42 +00004798 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004800 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00004803 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 SubExpr.get() == E->getSubExpr())
4805 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004806
John McCallb268a282010-08-23 23:25:46 +00004807 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00004808 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004809}
4810
4811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004812ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004813TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004815 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004816 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004817 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004819 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregora16548e2009-08-11 05:31:07 +00004821 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00004822 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 }
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4826 move_arg(Inits),
4827 E->getRParenLoc());
4828}
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830/// \brief Transform an address-of-label expression.
4831///
4832/// By default, the transformation of an address-of-label expression always
4833/// rebuilds the expression, so that the label identifier can be resolved to
4834/// the corresponding label statement by semantic analysis.
4835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004837TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4839 E->getLabel());
4840}
Mike Stump11289f42009-09-09 15:08:12 +00004841
4842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004844TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004845 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4847 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 if (!getDerived().AlwaysRebuild() &&
4851 SubStmt.get() == E->getSubStmt())
4852 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004853
4854 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004855 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 E->getRParenLoc());
4857}
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregora16548e2009-08-11 05:31:07 +00004859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004860ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004861TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Abramo Bagnara092990a2010-08-10 08:50:03 +00004862 TypeSourceInfo *TInfo1;
4863 TypeSourceInfo *TInfo2;
Douglas Gregor7058c262010-08-10 14:27:00 +00004864
4865 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4866 if (!TInfo1)
John McCallfaf5fb42010-08-26 23:41:50 +00004867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004868
Douglas Gregor7058c262010-08-10 14:27:00 +00004869 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4870 if (!TInfo2)
John McCallfaf5fb42010-08-26 23:41:50 +00004871 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004872
4873 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara092990a2010-08-10 08:50:03 +00004874 TInfo1 == E->getArgTInfo1() &&
4875 TInfo2 == E->getArgTInfo2())
Mike Stump11289f42009-09-09 15:08:12 +00004876 return SemaRef.Owned(E->Retain());
4877
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
Abramo Bagnara092990a2010-08-10 08:50:03 +00004879 TInfo1, TInfo2,
4880 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004881}
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregora16548e2009-08-11 05:31:07 +00004883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004885TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004886 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00004887 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
John McCalldadc5752010-08-24 06:29:42 +00004890 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004893
John McCalldadc5752010-08-24 06:29:42 +00004894 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004897
Douglas Gregora16548e2009-08-11 05:31:07 +00004898 if (!getDerived().AlwaysRebuild() &&
4899 Cond.get() == E->getCond() &&
4900 LHS.get() == E->getLHS() &&
4901 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004902 return SemaRef.Owned(E->Retain());
4903
Douglas Gregora16548e2009-08-11 05:31:07 +00004904 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00004905 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004906 E->getRParenLoc());
4907}
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregora16548e2009-08-11 05:31:07 +00004909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004910ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004911TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004912 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004913}
4914
4915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004916ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004917TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004918 switch (E->getOperator()) {
4919 case OO_New:
4920 case OO_Delete:
4921 case OO_Array_New:
4922 case OO_Array_Delete:
4923 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00004924 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004925
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004926 case OO_Call: {
4927 // This is a call to an object's operator().
4928 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4929
4930 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00004931 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004932 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004934
4935 // FIXME: Poor location information
4936 SourceLocation FakeLParenLoc
4937 = SemaRef.PP.getLocForEndOfToken(
4938 static_cast<Expr *>(Object.get())->getLocEnd());
4939
4940 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00004941 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004942 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4943 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004944 if (getDerived().DropCallArgument(E->getArg(I)))
4945 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004946
John McCalldadc5752010-08-24 06:29:42 +00004947 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004948 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004949 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004950
4951 // FIXME: Poor source location information.
4952 SourceLocation FakeCommaLoc
4953 = SemaRef.PP.getLocForEndOfToken(
4954 static_cast<Expr *>(Arg.get())->getLocEnd());
4955 FakeCommaLocs.push_back(FakeCommaLoc);
4956 Args.push_back(Arg.release());
4957 }
4958
John McCallb268a282010-08-23 23:25:46 +00004959 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004960 move_arg(Args),
4961 FakeCommaLocs.data(),
4962 E->getLocEnd());
4963 }
4964
4965#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4966 case OO_##Name:
4967#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4968#include "clang/Basic/OperatorKinds.def"
4969 case OO_Subscript:
4970 // Handled below.
4971 break;
4972
4973 case OO_Conditional:
4974 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00004975 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004976
4977 case OO_None:
4978 case NUM_OVERLOADED_OPERATORS:
4979 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004981 }
4982
John McCalldadc5752010-08-24 06:29:42 +00004983 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004986
John McCalldadc5752010-08-24 06:29:42 +00004987 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004988 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004990
John McCalldadc5752010-08-24 06:29:42 +00004991 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 if (E->getNumArgs() == 2) {
4993 Second = getDerived().TransformExpr(E->getArg(1));
4994 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004996 }
Mike Stump11289f42009-09-09 15:08:12 +00004997
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 if (!getDerived().AlwaysRebuild() &&
4999 Callee.get() == E->getCallee() &&
5000 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005001 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5002 return SemaRef.Owned(E->Retain());
5003
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5005 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005006 Callee.get(),
5007 First.get(),
5008 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005009}
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005013TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5014 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005015}
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005018ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005019TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005020 TypeSourceInfo *OldT;
5021 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 {
5023 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005024 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5026 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005027
John McCall97513962010-01-15 18:39:57 +00005028 OldT = E->getTypeInfoAsWritten();
5029 NewT = getDerived().TransformType(OldT);
5030 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005031 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 }
Mike Stump11289f42009-09-09 15:08:12 +00005033
John McCalldadc5752010-08-24 06:29:42 +00005034 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005035 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregora16548e2009-08-11 05:31:07 +00005039 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005040 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005042 return SemaRef.Owned(E->Retain());
5043
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005045 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5047 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5048 SourceLocation FakeRParenLoc
5049 = SemaRef.PP.getLocForEndOfToken(
5050 E->getSubExpr()->getSourceRange().getEnd());
5051 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005052 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005054 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 FakeRAngleLoc,
5056 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005057 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 FakeRParenLoc);
5059}
Mike Stump11289f42009-09-09 15:08:12 +00005060
Douglas Gregora16548e2009-08-11 05:31:07 +00005061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005063TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5064 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
5067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5070 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005071}
5072
Douglas Gregora16548e2009-08-11 05:31:07 +00005073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005074ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005075TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005076 CXXReinterpretCastExpr *E) {
5077 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005078}
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregora16548e2009-08-11 05:31:07 +00005080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5083 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005084}
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005087ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005088TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005089 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005090 TypeSourceInfo *OldT;
5091 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 {
5093 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005094
John McCall97513962010-01-15 18:39:57 +00005095 OldT = E->getTypeInfoAsWritten();
5096 NewT = getDerived().TransformType(OldT);
5097 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005098 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005099 }
Mike Stump11289f42009-09-09 15:08:12 +00005100
John McCalldadc5752010-08-24 06:29:42 +00005101 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005102 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005107 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005109 return SemaRef.Owned(E->Retain());
5110
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 // FIXME: The end of the type's source range is wrong
5112 return getDerived().RebuildCXXFunctionalCastExpr(
5113 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005114 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005116 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 E->getRParenLoc());
5118}
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregora16548e2009-08-11 05:31:07 +00005120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005121ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005122TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005124 TypeSourceInfo *TInfo
5125 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5126 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005128
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005130 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregor9da64192010-04-26 22:37:10 +00005133 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5134 E->getLocStart(),
5135 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 E->getLocEnd());
5137 }
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 // We don't know whether the expression is potentially evaluated until
5140 // after we perform semantic analysis, so the expression is potentially
5141 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005142 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005143 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005144
John McCalldadc5752010-08-24 06:29:42 +00005145 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005147 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005148
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 if (!getDerived().AlwaysRebuild() &&
5150 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005151 return SemaRef.Owned(E->Retain());
5152
Douglas Gregor9da64192010-04-26 22:37:10 +00005153 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5154 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005155 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 E->getLocEnd());
5157}
5158
5159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005161TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005162 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005163}
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005166ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005167TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005168 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005169 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005170}
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregora16548e2009-08-11 05:31:07 +00005172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005174TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005175 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 QualType T = getDerived().TransformType(E->getType());
5178 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 if (!getDerived().AlwaysRebuild() &&
5182 T == E->getType())
5183 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregorb15af892010-01-07 23:12:05 +00005185 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregora16548e2009-08-11 05:31:07 +00005188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005191 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005194
Douglas Gregora16548e2009-08-11 05:31:07 +00005195 if (!getDerived().AlwaysRebuild() &&
5196 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005197 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005198
John McCallb268a282010-08-23 23:25:46 +00005199 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005200}
Mike Stump11289f42009-09-09 15:08:12 +00005201
Douglas Gregora16548e2009-08-11 05:31:07 +00005202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005204TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005205 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005206 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5207 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005208 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005210
Chandler Carruth794da4c2010-02-08 06:42:49 +00005211 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005212 Param == E->getParam())
5213 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005214
Douglas Gregor033f6752009-12-23 23:03:06 +00005215 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005216}
Mike Stump11289f42009-09-09 15:08:12 +00005217
Douglas Gregora16548e2009-08-11 05:31:07 +00005218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005219ExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005220TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5222
5223 QualType T = getDerived().TransformType(E->getType());
5224 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregora16548e2009-08-11 05:31:07 +00005227 if (!getDerived().AlwaysRebuild() &&
5228 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005229 return SemaRef.Owned(E->Retain());
5230
Douglas Gregor747eb782010-07-08 06:14:04 +00005231 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5232 /*FIXME:*/E->getTypeBeginLoc(),
5233 T,
5234 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005235}
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005239TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 // Transform the type that we're allocating
5241 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5242 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5243 if (AllocType.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005247 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregora16548e2009-08-11 05:31:07 +00005251 // Transform the placement arguments (if any).
5252 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005253 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005254 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005255 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5260 PlacementArgs.push_back(Arg.take());
5261 }
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregorebe10102009-08-20 07:17:43 +00005263 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005264 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005266 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5267 break;
5268
John McCalldadc5752010-08-24 06:29:42 +00005269 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregora16548e2009-08-11 05:31:07 +00005273 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5274 ConstructorArgs.push_back(Arg.take());
5275 }
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregord2d9da02010-02-26 00:38:10 +00005277 // Transform constructor, new operator, and delete operator.
5278 CXXConstructorDecl *Constructor = 0;
5279 if (E->getConstructor()) {
5280 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005281 getDerived().TransformDecl(E->getLocStart(),
5282 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005283 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005284 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005285 }
5286
5287 FunctionDecl *OperatorNew = 0;
5288 if (E->getOperatorNew()) {
5289 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005290 getDerived().TransformDecl(E->getLocStart(),
5291 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005292 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005293 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005294 }
5295
5296 FunctionDecl *OperatorDelete = 0;
5297 if (E->getOperatorDelete()) {
5298 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005299 getDerived().TransformDecl(E->getLocStart(),
5300 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005301 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005303 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005304
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 if (!getDerived().AlwaysRebuild() &&
5306 AllocType == E->getAllocatedType() &&
5307 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005308 Constructor == E->getConstructor() &&
5309 OperatorNew == E->getOperatorNew() &&
5310 OperatorDelete == E->getOperatorDelete() &&
5311 !ArgumentChanged) {
5312 // Mark any declarations we need as referenced.
5313 // FIXME: instantiation-specific.
5314 if (Constructor)
5315 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5316 if (OperatorNew)
5317 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5318 if (OperatorDelete)
5319 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005320 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005321 }
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005323 if (!ArraySize.get()) {
5324 // If no array size was specified, but the new expression was
5325 // instantiated with an array type (e.g., "new T" where T is
5326 // instantiated with "int[4]"), extract the outer bound from the
5327 // array type as our array size. We do this with constant and
5328 // dependently-sized array types.
5329 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5330 if (!ArrayT) {
5331 // Do nothing
5332 } else if (const ConstantArrayType *ConsArrayT
5333 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005334 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005335 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005336 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005337 SemaRef.Context.getSizeType(),
5338 /*FIXME:*/E->getLocStart()));
5339 AllocType = ConsArrayT->getElementType();
5340 } else if (const DependentSizedArrayType *DepArrayT
5341 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5342 if (DepArrayT->getSizeExpr()) {
5343 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5344 AllocType = DepArrayT->getElementType();
5345 }
5346 }
5347 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005348 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5349 E->isGlobalNew(),
5350 /*FIXME:*/E->getLocStart(),
5351 move_arg(PlacementArgs),
5352 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005353 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005354 AllocType,
5355 /*FIXME:*/E->getLocStart(),
5356 /*FIXME:*/SourceRange(),
John McCallb268a282010-08-23 23:25:46 +00005357 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 /*FIXME:*/E->getLocStart(),
5359 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005360 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005361}
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregora16548e2009-08-11 05:31:07 +00005363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005365TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005366 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005369
Douglas Gregord2d9da02010-02-26 00:38:10 +00005370 // Transform the delete operator, if known.
5371 FunctionDecl *OperatorDelete = 0;
5372 if (E->getOperatorDelete()) {
5373 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005374 getDerived().TransformDecl(E->getLocStart(),
5375 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005376 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005377 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005378 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005379
Douglas Gregora16548e2009-08-11 05:31:07 +00005380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005381 Operand.get() == E->getArgument() &&
5382 OperatorDelete == E->getOperatorDelete()) {
5383 // Mark any declarations we need as referenced.
5384 // FIXME: instantiation-specific.
5385 if (OperatorDelete)
5386 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005387 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005388 }
Mike Stump11289f42009-09-09 15:08:12 +00005389
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5391 E->isGlobalDelete(),
5392 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005393 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005394}
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005397ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005398TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005399 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005400 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005401 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005403
John McCallba7bf592010-08-24 05:47:05 +00005404 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005405 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005406 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005407 E->getOperatorLoc(),
5408 E->isArrow()? tok::arrow : tok::period,
5409 ObjectTypePtr,
5410 MayBePseudoDestructor);
5411 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005413
John McCallba7bf592010-08-24 05:47:05 +00005414 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005415 NestedNameSpecifier *Qualifier
5416 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005417 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005418 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005419 if (E->getQualifier() && !Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005420 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005421
Douglas Gregor678f90d2010-02-25 01:56:36 +00005422 PseudoDestructorTypeStorage Destroyed;
5423 if (E->getDestroyedTypeInfo()) {
5424 TypeSourceInfo *DestroyedTypeInfo
5425 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5426 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005427 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005428 Destroyed = DestroyedTypeInfo;
5429 } else if (ObjectType->isDependentType()) {
5430 // We aren't likely to be able to resolve the identifier down to a type
5431 // now anyway, so just retain the identifier.
5432 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5433 E->getDestroyedTypeLoc());
5434 } else {
5435 // Look for a destructor known with the given name.
5436 CXXScopeSpec SS;
5437 if (Qualifier) {
5438 SS.setScopeRep(Qualifier);
5439 SS.setRange(E->getQualifierRange());
5440 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005441
John McCallba7bf592010-08-24 05:47:05 +00005442 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005443 *E->getDestroyedTypeIdentifier(),
5444 E->getDestroyedTypeLoc(),
5445 /*Scope=*/0,
5446 SS, ObjectTypePtr,
5447 false);
5448 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005449 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005450
Douglas Gregor678f90d2010-02-25 01:56:36 +00005451 Destroyed
5452 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5453 E->getDestroyedTypeLoc());
5454 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005455
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005456 TypeSourceInfo *ScopeTypeInfo = 0;
5457 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005458 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005459 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005460 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005462 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005463
John McCallb268a282010-08-23 23:25:46 +00005464 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005465 E->getOperatorLoc(),
5466 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005467 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005468 E->getQualifierRange(),
5469 ScopeTypeInfo,
5470 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005471 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005472 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005473}
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregorad8a3362009-09-04 17:36:40 +00005475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005476ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005477TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005478 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005479 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5480
5481 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5482 Sema::LookupOrdinaryName);
5483
5484 // Transform all the decls.
5485 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5486 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005487 NamedDecl *InstD = static_cast<NamedDecl*>(
5488 getDerived().TransformDecl(Old->getNameLoc(),
5489 *I));
John McCall84d87672009-12-10 09:41:52 +00005490 if (!InstD) {
5491 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5492 // This can happen because of dependent hiding.
5493 if (isa<UsingShadowDecl>(*I))
5494 continue;
5495 else
John McCallfaf5fb42010-08-26 23:41:50 +00005496 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005497 }
John McCalle66edc12009-11-24 19:00:30 +00005498
5499 // Expand using declarations.
5500 if (isa<UsingDecl>(InstD)) {
5501 UsingDecl *UD = cast<UsingDecl>(InstD);
5502 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5503 E = UD->shadow_end(); I != E; ++I)
5504 R.addDecl(*I);
5505 continue;
5506 }
5507
5508 R.addDecl(InstD);
5509 }
5510
5511 // Resolve a kind, but don't do any further analysis. If it's
5512 // ambiguous, the callee needs to deal with it.
5513 R.resolveKind();
5514
5515 // Rebuild the nested-name qualifier, if present.
5516 CXXScopeSpec SS;
5517 NestedNameSpecifier *Qualifier = 0;
5518 if (Old->getQualifier()) {
5519 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005520 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005521 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005523
John McCalle66edc12009-11-24 19:00:30 +00005524 SS.setScopeRep(Qualifier);
5525 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005526 }
5527
Douglas Gregor9262f472010-04-27 18:19:34 +00005528 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005529 CXXRecordDecl *NamingClass
5530 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5531 Old->getNameLoc(),
5532 Old->getNamingClass()));
5533 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005534 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005535
Douglas Gregorda7be082010-04-27 16:10:10 +00005536 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005537 }
5538
5539 // If we have no template arguments, it's a normal declaration name.
5540 if (!Old->hasExplicitTemplateArgs())
5541 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5542
5543 // If we have template arguments, rebuild them, then rebuild the
5544 // templateid expression.
5545 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5546 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5547 TemplateArgumentLoc Loc;
5548 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005550 TransArgs.addArgument(Loc);
5551 }
5552
5553 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5554 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005555}
Mike Stump11289f42009-09-09 15:08:12 +00005556
Douglas Gregora16548e2009-08-11 05:31:07 +00005557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005559TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 QualType T = getDerived().TransformType(E->getQueriedType());
5563 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005565
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 if (!getDerived().AlwaysRebuild() &&
5567 T == E->getQueriedType())
5568 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregora16548e2009-08-11 05:31:07 +00005570 // FIXME: Bad location information
5571 SourceLocation FakeLParenLoc
5572 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005573
5574 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 E->getLocStart(),
5576 /*FIXME:*/FakeLParenLoc,
5577 T,
5578 E->getLocEnd());
5579}
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005582ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005583TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005584 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005586 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005587 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00005589 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005590
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005591 DeclarationNameInfo NameInfo
5592 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5593 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005595
John McCalle66edc12009-11-24 19:00:30 +00005596 if (!E->hasExplicitTemplateArgs()) {
5597 if (!getDerived().AlwaysRebuild() &&
5598 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005599 // Note: it is sufficient to compare the Name component of NameInfo:
5600 // if name has not changed, DNLoc has not changed either.
5601 NameInfo.getName() == E->getDeclName())
John McCalle66edc12009-11-24 19:00:30 +00005602 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005603
John McCalle66edc12009-11-24 19:00:30 +00005604 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5605 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005606 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005607 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005608 }
John McCall6b51f282009-11-23 01:53:49 +00005609
5610 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005612 TemplateArgumentLoc Loc;
5613 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005615 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005616 }
5617
John McCalle66edc12009-11-24 19:00:30 +00005618 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5619 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005620 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00005621 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005622}
5623
5624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005626TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005627 // CXXConstructExprs are always implicit, so when we have a
5628 // 1-argument construction we just transform that argument.
5629 if (E->getNumArgs() == 1 ||
5630 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5631 return getDerived().TransformExpr(E->getArg(0));
5632
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5634
5635 QualType T = getDerived().TransformType(E->getType());
5636 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005638
5639 CXXConstructorDecl *Constructor
5640 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005641 getDerived().TransformDecl(E->getLocStart(),
5642 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005647 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005648 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 ArgEnd = E->arg_end();
5650 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005651 if (getDerived().DropCallArgument(*Arg)) {
5652 ArgumentChanged = true;
5653 break;
5654 }
5655
John McCalldadc5752010-08-24 06:29:42 +00005656 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00005661 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 }
5663
5664 if (!getDerived().AlwaysRebuild() &&
5665 T == E->getType() &&
5666 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005667 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005668 // Mark the constructor as referenced.
5669 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005670 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005672 }
Mike Stump11289f42009-09-09 15:08:12 +00005673
Douglas Gregordb121ba2009-12-14 16:27:04 +00005674 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5675 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00005676 move_arg(Args),
5677 E->requiresZeroInitialization(),
5678 E->getConstructionKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00005679}
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregora16548e2009-08-11 05:31:07 +00005681/// \brief Transform a C++ temporary-binding expression.
5682///
Douglas Gregor363b1512009-12-24 18:51:59 +00005683/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5684/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005686ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005687TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005688 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005689}
Mike Stump11289f42009-09-09 15:08:12 +00005690
Anders Carlssonba6c4372010-01-29 02:39:32 +00005691/// \brief Transform a C++ reference-binding expression.
5692///
5693/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5694/// transform the subexpression and return that.
5695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005696ExprResult
Anders Carlssonba6c4372010-01-29 02:39:32 +00005697TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5698 return getDerived().TransformExpr(E->getSubExpr());
5699}
5700
Mike Stump11289f42009-09-09 15:08:12 +00005701/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005702/// be destroyed after the expression is evaluated.
5703///
Douglas Gregor363b1512009-12-24 18:51:59 +00005704/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5705/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005708TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005709 CXXExprWithTemporaries *E) {
5710 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005711}
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregora16548e2009-08-11 05:31:07 +00005713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005714ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005715TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005716 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005717 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5718 QualType T = getDerived().TransformType(E->getType());
5719 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722 CXXConstructorDecl *Constructor
5723 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005724 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005725 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregora16548e2009-08-11 05:31:07 +00005729 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005730 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005731 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005732 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 ArgEnd = E->arg_end();
5734 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005735 if (getDerived().DropCallArgument(*Arg)) {
5736 ArgumentChanged = true;
5737 break;
5738 }
5739
John McCalldadc5752010-08-24 06:29:42 +00005740 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005743
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5745 Args.push_back((Expr *)TransArg.release());
5746 }
Mike Stump11289f42009-09-09 15:08:12 +00005747
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 if (!getDerived().AlwaysRebuild() &&
5749 T == E->getType() &&
5750 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005751 !ArgumentChanged) {
5752 // FIXME: Instantiation-specific
5753 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005754 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005755 }
Mike Stump11289f42009-09-09 15:08:12 +00005756
Douglas Gregora16548e2009-08-11 05:31:07 +00005757 // FIXME: Bogus location information
5758 SourceLocation CommaLoc;
5759 if (Args.size() > 1) {
5760 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005761 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005762 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5763 }
5764 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5765 T,
5766 /*FIXME:*/E->getTypeBeginLoc(),
5767 move_arg(Args),
5768 &CommaLoc,
5769 E->getLocEnd());
5770}
Mike Stump11289f42009-09-09 15:08:12 +00005771
Douglas Gregora16548e2009-08-11 05:31:07 +00005772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005773ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005774TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005775 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5777 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5778 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005780
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005782 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5784 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5785 ArgEnd = E->arg_end();
5786 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00005787 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5792 FakeCommaLocs.push_back(
5793 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
John McCallb268a282010-08-23 23:25:46 +00005794 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 }
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (!getDerived().AlwaysRebuild() &&
5798 T == E->getTypeAsWritten() &&
5799 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005800 return SemaRef.Owned(E->Retain());
5801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 // FIXME: we're faking the locations of the commas
5803 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5804 T,
5805 E->getLParenLoc(),
5806 move_arg(Args),
5807 FakeCommaLocs.data(),
5808 E->getRParenLoc());
5809}
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregora16548e2009-08-11 05:31:07 +00005811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812ExprResult
John McCall8cd78132009-11-19 22:55:06 +00005813TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005814 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005816 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005817 Expr *OldBase;
5818 QualType BaseType;
5819 QualType ObjectType;
5820 if (!E->isImplicitAccess()) {
5821 OldBase = E->getBase();
5822 Base = getDerived().TransformExpr(OldBase);
5823 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005825
John McCall2d74de92009-12-01 22:10:20 +00005826 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00005827 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00005828 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005829 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005830 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005831 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005832 ObjectTy,
5833 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005834 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005836
John McCallba7bf592010-08-24 05:47:05 +00005837 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00005838 BaseType = ((Expr*) Base.get())->getType();
5839 } else {
5840 OldBase = 0;
5841 BaseType = getDerived().TransformType(E->getBaseType());
5842 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5843 }
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005845 // Transform the first part of the nested-name-specifier that qualifies
5846 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005847 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005848 = getDerived().TransformFirstQualifierInScope(
5849 E->getFirstQualifierFoundInScope(),
5850 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005851
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005852 NestedNameSpecifier *Qualifier = 0;
5853 if (E->getQualifier()) {
5854 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5855 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005856 ObjectType,
5857 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005858 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005859 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005860 }
Mike Stump11289f42009-09-09 15:08:12 +00005861
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005862 DeclarationNameInfo NameInfo
5863 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5864 ObjectType);
5865 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005867
John McCall2d74de92009-12-01 22:10:20 +00005868 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005869 // This is a reference to a member without an explicitly-specified
5870 // template argument list. Optimize for this common case.
5871 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005872 Base.get() == OldBase &&
5873 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005874 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005875 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005876 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005877 return SemaRef.Owned(E->Retain());
5878
John McCallb268a282010-08-23 23:25:46 +00005879 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005880 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005881 E->isArrow(),
5882 E->getOperatorLoc(),
5883 Qualifier,
5884 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005885 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005886 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005887 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005888 }
5889
John McCall6b51f282009-11-23 01:53:49 +00005890 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005891 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005892 TemplateArgumentLoc Loc;
5893 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005895 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005896 }
Mike Stump11289f42009-09-09 15:08:12 +00005897
John McCallb268a282010-08-23 23:25:46 +00005898 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005899 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005900 E->isArrow(),
5901 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005902 Qualifier,
5903 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005904 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005905 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00005906 &TransArgs);
5907}
5908
5909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005910ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005911TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005912 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00005913 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00005914 QualType BaseType;
5915 if (!Old->isImplicitAccess()) {
5916 Base = getDerived().TransformExpr(Old->getBase());
5917 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00005919 BaseType = ((Expr*) Base.get())->getType();
5920 } else {
5921 BaseType = getDerived().TransformType(Old->getBaseType());
5922 }
John McCall10eae182009-11-30 22:42:35 +00005923
5924 NestedNameSpecifier *Qualifier = 0;
5925 if (Old->getQualifier()) {
5926 Qualifier
5927 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005928 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005929 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005930 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005931 }
5932
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005933 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00005934 Sema::LookupOrdinaryName);
5935
5936 // Transform all the decls.
5937 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5938 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005939 NamedDecl *InstD = static_cast<NamedDecl*>(
5940 getDerived().TransformDecl(Old->getMemberLoc(),
5941 *I));
John McCall84d87672009-12-10 09:41:52 +00005942 if (!InstD) {
5943 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5944 // This can happen because of dependent hiding.
5945 if (isa<UsingShadowDecl>(*I))
5946 continue;
5947 else
John McCallfaf5fb42010-08-26 23:41:50 +00005948 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005949 }
John McCall10eae182009-11-30 22:42:35 +00005950
5951 // Expand using declarations.
5952 if (isa<UsingDecl>(InstD)) {
5953 UsingDecl *UD = cast<UsingDecl>(InstD);
5954 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5955 E = UD->shadow_end(); I != E; ++I)
5956 R.addDecl(*I);
5957 continue;
5958 }
5959
5960 R.addDecl(InstD);
5961 }
5962
5963 R.resolveKind();
5964
Douglas Gregor9262f472010-04-27 18:19:34 +00005965 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005966 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005967 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005968 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005969 Old->getMemberLoc(),
5970 Old->getNamingClass()));
5971 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005972 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005973
Douglas Gregorda7be082010-04-27 16:10:10 +00005974 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005975 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005976
John McCall10eae182009-11-30 22:42:35 +00005977 TemplateArgumentListInfo TransArgs;
5978 if (Old->hasExplicitTemplateArgs()) {
5979 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5980 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5981 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5982 TemplateArgumentLoc Loc;
5983 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5984 Loc))
John McCallfaf5fb42010-08-26 23:41:50 +00005985 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00005986 TransArgs.addArgument(Loc);
5987 }
5988 }
John McCall38836f02010-01-15 08:34:02 +00005989
5990 // FIXME: to do this check properly, we will need to preserve the
5991 // first-qualifier-in-scope here, just in case we had a dependent
5992 // base (and therefore couldn't do the check) and a
5993 // nested-name-qualifier (and therefore could do the lookup).
5994 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005995
John McCallb268a282010-08-23 23:25:46 +00005996 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00005997 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005998 Old->getOperatorLoc(),
5999 Old->isArrow(),
6000 Qualifier,
6001 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006002 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006003 R,
6004 (Old->hasExplicitTemplateArgs()
6005 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006006}
6007
6008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006011 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006012}
6013
Mike Stump11289f42009-09-09 15:08:12 +00006014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006015ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006016TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006017 TypeSourceInfo *EncodedTypeInfo
6018 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6019 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregora16548e2009-08-11 05:31:07 +00006022 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006023 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006024 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006025
6026 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006027 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 E->getRParenLoc());
6029}
Mike Stump11289f42009-09-09 15:08:12 +00006030
Douglas Gregora16548e2009-08-11 05:31:07 +00006031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006033TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006034 // Transform arguments.
6035 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006036 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006037 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006038 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006039 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006041
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006042 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006043 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006044 }
6045
6046 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6047 // Class message: transform the receiver type.
6048 TypeSourceInfo *ReceiverTypeInfo
6049 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6050 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006052
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006053 // If nothing changed, just retain the existing message send.
6054 if (!getDerived().AlwaysRebuild() &&
6055 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6056 return SemaRef.Owned(E->Retain());
6057
6058 // Build a new class message send.
6059 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6060 E->getSelector(),
6061 E->getMethodDecl(),
6062 E->getLeftLoc(),
6063 move_arg(Args),
6064 E->getRightLoc());
6065 }
6066
6067 // Instance message: transform the receiver
6068 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6069 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006070 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006071 = getDerived().TransformExpr(E->getInstanceReceiver());
6072 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006074
6075 // If nothing changed, just retain the existing message send.
6076 if (!getDerived().AlwaysRebuild() &&
6077 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6078 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006079
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006080 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006081 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006082 E->getSelector(),
6083 E->getMethodDecl(),
6084 E->getLeftLoc(),
6085 move_arg(Args),
6086 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006087}
6088
Mike Stump11289f42009-09-09 15:08:12 +00006089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006092 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006093}
6094
Mike Stump11289f42009-09-09 15:08:12 +00006095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006098 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006099}
6100
Mike Stump11289f42009-09-09 15:08:12 +00006101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006103TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006104 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006105 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006106 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006107 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006108
6109 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006110
Douglas Gregord51d90d2010-04-26 20:11:03 +00006111 // If nothing changed, just retain the existing expression.
6112 if (!getDerived().AlwaysRebuild() &&
6113 Base.get() == E->getBase())
6114 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006115
John McCallb268a282010-08-23 23:25:46 +00006116 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006117 E->getLocation(),
6118 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006119}
6120
Mike Stump11289f42009-09-09 15:08:12 +00006121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006124 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006125 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006126 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006128
Douglas Gregor9faee212010-04-26 20:47:02 +00006129 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006130
Douglas Gregor9faee212010-04-26 20:47:02 +00006131 // If nothing changed, just retain the existing expression.
6132 if (!getDerived().AlwaysRebuild() &&
6133 Base.get() == E->getBase())
6134 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006135
John McCallb268a282010-08-23 23:25:46 +00006136 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
Douglas Gregor9faee212010-04-26 20:47:02 +00006137 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006138}
6139
Mike Stump11289f42009-09-09 15:08:12 +00006140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006141ExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006142TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006143 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006144 // If this implicit setter/getter refers to class methods, it cannot have any
6145 // dependent parts. Just retain the existing declaration.
6146 if (E->getInterfaceDecl())
6147 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006148
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006149 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006150 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006151 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006152 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006153
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006154 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006155
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006156 // If nothing changed, just retain the existing expression.
6157 if (!getDerived().AlwaysRebuild() &&
6158 Base.get() == E->getBase())
6159 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006160
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006161 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6162 E->getGetterMethod(),
6163 E->getType(),
6164 E->getSetterMethod(),
6165 E->getLocation(),
John McCallb268a282010-08-23 23:25:46 +00006166 Base.get());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168}
6169
Mike Stump11289f42009-09-09 15:08:12 +00006170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006173 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006174 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006175}
6176
Mike Stump11289f42009-09-09 15:08:12 +00006177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006179TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006180 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006181 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006182 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006184
Douglas Gregord51d90d2010-04-26 20:11:03 +00006185 // If nothing changed, just retain the existing expression.
6186 if (!getDerived().AlwaysRebuild() &&
6187 Base.get() == E->getBase())
6188 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006189
John McCallb268a282010-08-23 23:25:46 +00006190 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006191 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006192}
6193
Mike Stump11289f42009-09-09 15:08:12 +00006194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006195ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006196TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006198 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006199 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006200 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006205 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 }
Mike Stump11289f42009-09-09 15:08:12 +00006207
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() &&
6209 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006210 return SemaRef.Owned(E->Retain());
6211
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6213 move_arg(SubExprs),
6214 E->getRParenLoc());
6215}
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>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006220 SourceLocation CaretLoc(E->getExprLoc());
6221
6222 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6223 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6224 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6225 llvm::SmallVector<ParmVarDecl*, 4> Params;
6226 llvm::SmallVector<QualType, 4> ParamTypes;
6227
6228 // Parameter substitution.
6229 const BlockDecl *BD = E->getBlockDecl();
6230 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6231 EN = BD->param_end(); P != EN; ++P) {
6232 ParmVarDecl *OldParm = (*P);
6233 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6234 QualType NewType = NewParm->getType();
6235 Params.push_back(NewParm);
6236 ParamTypes.push_back(NewParm->getType());
6237 }
6238
6239 const FunctionType *BExprFunctionType = E->getFunctionType();
6240 QualType BExprResultType = BExprFunctionType->getResultType();
6241 if (!BExprResultType.isNull()) {
6242 if (!BExprResultType->isDependentType())
6243 CurBlock->ReturnType = BExprResultType;
6244 else if (BExprResultType != SemaRef.Context.DependentTy)
6245 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6246 }
6247
6248 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006249 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006250 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006252 // Set the parameters on the block decl.
6253 if (!Params.empty())
6254 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6255
6256 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6257 CurBlock->ReturnType,
6258 ParamTypes.data(),
6259 ParamTypes.size(),
6260 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006261 0,
6262 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006263
6264 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006265 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006266}
6267
Mike Stump11289f42009-09-09 15:08:12 +00006268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006269ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006270TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006271 NestedNameSpecifier *Qualifier = 0;
6272
6273 ValueDecl *ND
6274 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6275 E->getDecl()));
6276 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006277 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006278
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006279 if (!getDerived().AlwaysRebuild() &&
6280 ND == E->getDecl()) {
6281 // Mark it referenced in the new context regardless.
6282 // FIXME: this is a bit instantiation-specific.
6283 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6284
6285 return SemaRef.Owned(E->Retain());
6286 }
6287
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006288 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006289 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006290 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006291}
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregora16548e2009-08-11 05:31:07 +00006293//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006294// Type reconstruction
6295//===----------------------------------------------------------------------===//
6296
Mike Stump11289f42009-09-09 15:08:12 +00006297template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006298QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6299 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006300 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006301 getDerived().getBaseEntity());
6302}
6303
Mike Stump11289f42009-09-09 15:08:12 +00006304template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006305QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6306 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006307 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006308 getDerived().getBaseEntity());
6309}
6310
Mike Stump11289f42009-09-09 15:08:12 +00006311template<typename Derived>
6312QualType
John McCall70dd5f62009-10-30 00:06:24 +00006313TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6314 bool WrittenAsLValue,
6315 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006316 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006317 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006318}
6319
6320template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006321QualType
John McCall70dd5f62009-10-30 00:06:24 +00006322TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6323 QualType ClassType,
6324 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006325 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006326 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006327}
6328
6329template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006330QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006331TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6332 ArrayType::ArraySizeModifier SizeMod,
6333 const llvm::APInt *Size,
6334 Expr *SizeExpr,
6335 unsigned IndexTypeQuals,
6336 SourceRange BracketsRange) {
6337 if (SizeExpr || !Size)
6338 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6339 IndexTypeQuals, BracketsRange,
6340 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006341
6342 QualType Types[] = {
6343 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6344 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6345 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006346 };
6347 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6348 QualType SizeType;
6349 for (unsigned I = 0; I != NumTypes; ++I)
6350 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6351 SizeType = Types[I];
6352 break;
6353 }
Mike Stump11289f42009-09-09 15:08:12 +00006354
Douglas Gregord6ff3322009-08-04 16:50:30 +00006355 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006356 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006357 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006358 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006359}
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregord6ff3322009-08-04 16:50:30 +00006361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006362QualType
6363TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006364 ArrayType::ArraySizeModifier SizeMod,
6365 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006366 unsigned IndexTypeQuals,
6367 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006368 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006369 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006370}
6371
6372template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006373QualType
Mike Stump11289f42009-09-09 15:08:12 +00006374TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006375 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006376 unsigned IndexTypeQuals,
6377 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006378 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006379 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregord6ff3322009-08-04 16:50:30 +00006382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006383QualType
6384TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006385 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006386 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006387 unsigned IndexTypeQuals,
6388 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006389 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006390 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006391 IndexTypeQuals, BracketsRange);
6392}
6393
6394template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006395QualType
6396TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006397 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006398 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006399 unsigned IndexTypeQuals,
6400 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006401 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006402 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006403 IndexTypeQuals, BracketsRange);
6404}
6405
6406template<typename Derived>
6407QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006408 unsigned NumElements,
6409 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006410 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006411 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414template<typename Derived>
6415QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6416 unsigned NumElements,
6417 SourceLocation AttributeLoc) {
6418 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6419 NumElements, true);
6420 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006421 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006422 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006423 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424}
Mike Stump11289f42009-09-09 15:08:12 +00006425
Douglas Gregord6ff3322009-08-04 16:50:30 +00006426template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006427QualType
6428TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006429 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006430 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006431 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006432}
Mike Stump11289f42009-09-09 15:08:12 +00006433
Douglas Gregord6ff3322009-08-04 16:50:30 +00006434template<typename Derived>
6435QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006436 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006437 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006438 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006439 unsigned Quals,
6440 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006441 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006442 Quals,
6443 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006444 getDerived().getBaseEntity(),
6445 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006446}
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregord6ff3322009-08-04 16:50:30 +00006448template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006449QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6450 return SemaRef.Context.getFunctionNoProtoType(T);
6451}
6452
6453template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006454QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6455 assert(D && "no decl found");
6456 if (D->isInvalidDecl()) return QualType();
6457
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006458 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006459 TypeDecl *Ty;
6460 if (isa<UsingDecl>(D)) {
6461 UsingDecl *Using = cast<UsingDecl>(D);
6462 assert(Using->isTypeName() &&
6463 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6464
6465 // A valid resolved using typename decl points to exactly one type decl.
6466 assert(++Using->shadow_begin() == Using->shadow_end());
6467 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006468
John McCallb96ec562009-12-04 22:46:56 +00006469 } else {
6470 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6471 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6472 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6473 }
6474
6475 return SemaRef.Context.getTypeDeclType(Ty);
6476}
6477
6478template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006479QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6480 return SemaRef.BuildTypeofExprType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006481}
6482
6483template<typename Derived>
6484QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6485 return SemaRef.Context.getTypeOfType(Underlying);
6486}
6487
6488template<typename Derived>
John McCallb268a282010-08-23 23:25:46 +00006489QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6490 return SemaRef.BuildDecltypeType(E);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006491}
6492
6493template<typename Derived>
6494QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006495 TemplateName Template,
6496 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006497 const TemplateArgumentListInfo &TemplateArgs) {
6498 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006499}
Mike Stump11289f42009-09-09 15:08:12 +00006500
Douglas Gregor1135c352009-08-06 05:28:30 +00006501template<typename Derived>
6502NestedNameSpecifier *
6503TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6504 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006505 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006506 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006507 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006508 CXXScopeSpec SS;
6509 // FIXME: The source location information is all wrong.
6510 SS.setRange(Range);
6511 SS.setScopeRep(Prefix);
6512 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006513 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006514 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006515 ObjectType,
6516 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006517 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006518}
6519
6520template<typename Derived>
6521NestedNameSpecifier *
6522TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6523 SourceRange Range,
6524 NamespaceDecl *NS) {
6525 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6526}
6527
6528template<typename Derived>
6529NestedNameSpecifier *
6530TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6531 SourceRange Range,
6532 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006533 QualType T) {
6534 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006535 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006536 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006537 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6538 T.getTypePtr());
6539 }
Mike Stump11289f42009-09-09 15:08:12 +00006540
Douglas Gregor1135c352009-08-06 05:28:30 +00006541 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6542 return 0;
6543}
Mike Stump11289f42009-09-09 15:08:12 +00006544
Douglas Gregor71dc5092009-08-06 06:41:21 +00006545template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006546TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006547TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6548 bool TemplateKW,
6549 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006550 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006551 Template);
6552}
6553
6554template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006555TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006556TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006557 const IdentifierInfo &II,
6558 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006559 CXXScopeSpec SS;
6560 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006561 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006562 UnqualifiedId Name;
6563 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006564 Sema::TemplateTy Template;
6565 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6566 /*FIXME:*/getDerived().getBaseLocation(),
6567 SS,
6568 Name,
John McCallba7bf592010-08-24 05:47:05 +00006569 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006570 /*EnteringContext=*/false,
6571 Template);
6572 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006573}
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregora16548e2009-08-11 05:31:07 +00006575template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006576TemplateName
6577TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6578 OverloadedOperatorKind Operator,
6579 QualType ObjectType) {
6580 CXXScopeSpec SS;
6581 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6582 SS.setScopeRep(Qualifier);
6583 UnqualifiedId Name;
6584 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6585 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6586 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006587 Sema::TemplateTy Template;
6588 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006589 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006590 SS,
6591 Name,
John McCallba7bf592010-08-24 05:47:05 +00006592 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006593 /*EnteringContext=*/false,
6594 Template);
6595 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006596}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006597
Douglas Gregor71395fa2009-11-04 00:56:37 +00006598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006599ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006600TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6601 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006602 Expr *OrigCallee,
6603 Expr *First,
6604 Expr *Second) {
6605 Expr *Callee = OrigCallee->IgnoreParenCasts();
6606 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006607
Douglas Gregora16548e2009-08-11 05:31:07 +00006608 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006609 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00006610 if (!First->getType()->isOverloadableType() &&
6611 !Second->getType()->isOverloadableType())
6612 return getSema().CreateBuiltinArraySubscriptExpr(First,
6613 Callee->getLocStart(),
6614 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006615 } else if (Op == OO_Arrow) {
6616 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00006617 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6618 } else if (Second == 0 || isPostIncDec) {
6619 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 // The argument is not of overloadable type, so try to create a
6621 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00006622 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006624
John McCallb268a282010-08-23 23:25:46 +00006625 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 }
6627 } else {
John McCallb268a282010-08-23 23:25:46 +00006628 if (!First->getType()->isOverloadableType() &&
6629 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 // Neither of the arguments is an overloadable type, so try to
6631 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00006632 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006633 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00006634 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00006635 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006637
Douglas Gregora16548e2009-08-11 05:31:07 +00006638 return move(Result);
6639 }
6640 }
Mike Stump11289f42009-09-09 15:08:12 +00006641
6642 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006644 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006645
John McCallb268a282010-08-23 23:25:46 +00006646 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00006647 assert(ULE->requiresADL());
6648
6649 // FIXME: Do we have to check
6650 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006651 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006652 } else {
John McCallb268a282010-08-23 23:25:46 +00006653 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006654 }
Mike Stump11289f42009-09-09 15:08:12 +00006655
Douglas Gregora16548e2009-08-11 05:31:07 +00006656 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00006657 Expr *Args[2] = { First, Second };
6658 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregora16548e2009-08-11 05:31:07 +00006660 // Create the overloaded operator invocation for unary operators.
6661 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00006662 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00006664 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 }
Mike Stump11289f42009-09-09 15:08:12 +00006666
Sebastian Redladba46e2009-10-29 20:17:01 +00006667 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00006668 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00006669 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00006670 First,
6671 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00006672
Douglas Gregora16548e2009-08-11 05:31:07 +00006673 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00006674 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00006675 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6677 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006679
Mike Stump11289f42009-09-09 15:08:12 +00006680 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006681}
Mike Stump11289f42009-09-09 15:08:12 +00006682
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006684ExprResult
John McCallb268a282010-08-23 23:25:46 +00006685TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006686 SourceLocation OperatorLoc,
6687 bool isArrow,
6688 NestedNameSpecifier *Qualifier,
6689 SourceRange QualifierRange,
6690 TypeSourceInfo *ScopeType,
6691 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006692 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006693 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006694 CXXScopeSpec SS;
6695 if (Qualifier) {
6696 SS.setRange(QualifierRange);
6697 SS.setScopeRep(Qualifier);
6698 }
6699
John McCallb268a282010-08-23 23:25:46 +00006700 QualType BaseType = Base->getType();
6701 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006702 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006703 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006704 !BaseType->getAs<PointerType>()->getPointeeType()
6705 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006706 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00006707 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006708 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006709 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006710 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006711 /*FIXME?*/true);
6712 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006713
Douglas Gregor678f90d2010-02-25 01:56:36 +00006714 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006715 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6716 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6717 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6718 NameInfo.setNamedTypeInfo(DestroyedType);
6719
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006720 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006721
John McCallb268a282010-08-23 23:25:46 +00006722 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006723 OperatorLoc, isArrow,
6724 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006725 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006726 /*TemplateArgs*/ 0);
6727}
6728
Douglas Gregord6ff3322009-08-04 16:50:30 +00006729} // end namespace clang
6730
6731#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H