blob: 992b8499046867911dbf249b3d816bce3ab74ab2 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-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 McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCall781472f2010-08-25 08:40:02 +000037using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000038
Douglas Gregor577f75a2009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump1eb44332009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump1eb44332009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
92protected:
93 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +000094
Mike Stump1eb44332009-09-09 15:08:12 +000095public:
Douglas Gregor577f75a2009-08-04 16:50:30 +000096 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +000097 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +000098
Douglas Gregor577f75a2009-08-04 16:50:30 +000099 /// \brief Retrieves a reference to the derived class.
100 Derived &getDerived() { return static_cast<Derived&>(*this); }
101
102 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000103 const Derived &getDerived() const {
104 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000105 }
106
John McCall60d7b3a2010-08-24 06:29:42 +0000107 static inline ExprResult Owned(Expr *E) { return E; }
108 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000109
Douglas Gregor577f75a2009-08-04 16:50:30 +0000110 /// \brief Retrieves a reference to the semantic analysis object used for
111 /// this tree transform.
112 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000113
Douglas Gregor577f75a2009-08-04 16:50:30 +0000114 /// \brief Whether the transformation should always rebuild AST nodes, even
115 /// if none of the children have changed.
116 ///
117 /// Subclasses may override this function to specify when the transformation
118 /// should rebuild all AST nodes.
119 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000120
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Returns the location of the entity being transformed, if that
122 /// information was not available elsewhere in the AST.
123 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000124 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 /// provide an alternative implementation that provides better location
126 /// information.
127 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000128
Douglas Gregor577f75a2009-08-04 16:50:30 +0000129 /// \brief Returns the name of the entity being transformed, if that
130 /// information was not available elsewhere in the AST.
131 ///
132 /// By default, returns an empty name. Subclasses can provide an alternative
133 /// implementation with a more precise name.
134 DeclarationName getBaseEntity() { return DeclarationName(); }
135
Douglas Gregorb98b1992009-08-11 05:31:07 +0000136 /// \brief Sets the "base" location and entity when that
137 /// information is known based on another transformation.
138 ///
139 /// By default, the source location and entity are ignored. Subclasses can
140 /// override this function to provide a customized implementation.
141 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000142
Douglas Gregorb98b1992009-08-11 05:31:07 +0000143 /// \brief RAII object that temporarily sets the base location and entity
144 /// used for reporting diagnostics in types.
145 class TemporaryBase {
146 TreeTransform &Self;
147 SourceLocation OldLocation;
148 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000149
Douglas Gregorb98b1992009-08-11 05:31:07 +0000150 public:
151 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000152 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000153 OldLocation = Self.getDerived().getBaseLocation();
154 OldEntity = Self.getDerived().getBaseEntity();
155 Self.getDerived().setBase(Location, Entity);
156 }
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Douglas Gregorb98b1992009-08-11 05:31:07 +0000158 ~TemporaryBase() {
159 Self.getDerived().setBase(OldLocation, OldEntity);
160 }
161 };
Mike Stump1eb44332009-09-09 15:08:12 +0000162
163 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000164 /// transformed.
165 ///
166 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000167 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000168 /// not change. For example, template instantiation need not traverse
169 /// non-dependent types.
170 bool AlreadyTransformed(QualType T) {
171 return T.isNull();
172 }
173
Douglas Gregor6eef5192009-12-14 19:27:10 +0000174 /// \brief Determine whether the given call argument should be dropped, e.g.,
175 /// because it is a default argument.
176 ///
177 /// Subclasses can provide an alternative implementation of this routine to
178 /// determine which kinds of call arguments get dropped. By default,
179 /// CXXDefaultArgument nodes are dropped (prior to transformation).
180 bool DropCallArgument(Expr *E) {
181 return E->isDefaultArgument();
182 }
Sean Huntc3021132010-05-05 15:23:54 +0000183
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000184 /// \brief Determine whether we should expand a pack expansion with the
185 /// given set of parameter packs into separate arguments by repeatedly
186 /// transforming the pattern.
187 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000188 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000189 /// Subclasses can override this routine to provide different behavior.
190 ///
191 /// \param EllipsisLoc The location of the ellipsis that identifies the
192 /// pack expansion.
193 ///
194 /// \param PatternRange The source range that covers the entire pattern of
195 /// the pack expansion.
196 ///
197 /// \param Unexpanded The set of unexpanded parameter packs within the
198 /// pattern.
199 ///
200 /// \param NumUnexpanded The number of unexpanded parameter packs in
201 /// \p Unexpanded.
202 ///
203 /// \param ShouldExpand Will be set to \c true if the transformer should
204 /// expand the corresponding pack expansions into separate arguments. When
205 /// set, \c NumExpansions must also be set.
206 ///
207 /// \param NumExpansions The number of separate arguments that will be in
208 /// the expanded form of the corresponding pack expansion. Must be set when
209 /// \c ShouldExpand is \c true.
210 ///
211 /// \returns true if an error occurred (e.g., because the parameter packs
212 /// are to be instantiated with arguments of different lengths), false
213 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
214 /// must be set.
215 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
216 SourceRange PatternRange,
217 const UnexpandedParameterPack *Unexpanded,
218 unsigned NumUnexpanded,
219 bool &ShouldExpand,
220 unsigned &NumExpansions) {
221 ShouldExpand = false;
222 return false;
223 }
224
Douglas Gregor577f75a2009-08-04 16:50:30 +0000225 /// \brief Transforms the given type into another type.
226 ///
John McCalla2becad2009-10-21 00:40:46 +0000227 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000228 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000229 /// function. This is expensive, but we don't mind, because
230 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000231 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000232 ///
233 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000234 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000235
John McCalla2becad2009-10-21 00:40:46 +0000236 /// \brief Transforms the given type-with-location into a new
237 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000238 ///
John McCalla2becad2009-10-21 00:40:46 +0000239 /// By default, this routine transforms a type by delegating to the
240 /// appropriate TransformXXXType to build a new type. Subclasses
241 /// may override this function (to take over all type
242 /// transformations) or some set of the TransformXXXType functions
243 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000244 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000245
246 /// \brief Transform the given type-with-location into a new
247 /// type, collecting location information in the given builder
248 /// as necessary.
249 ///
John McCall43fed0d2010-11-12 08:19:04 +0000250 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000251
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000252 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000253 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000254 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000255 /// appropriate TransformXXXStmt function to transform a specific kind of
256 /// statement or the TransformExpr() function to transform an expression.
257 /// Subclasses may override this function to transform statements using some
258 /// other mechanism.
259 ///
260 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000261 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000262
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000263 /// \brief Transform the given expression.
264 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000265 /// By default, this routine transforms an expression by delegating to the
266 /// appropriate TransformXXXExpr function to build a new expression.
267 /// Subclasses may override this function to transform expressions using some
268 /// other mechanism.
269 ///
270 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000271 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Douglas Gregor577f75a2009-08-04 16:50:30 +0000273 /// \brief Transform the given declaration, which is referenced from a type
274 /// or expression.
275 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000276 /// By default, acts as the identity function on declarations. Subclasses
277 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000278 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000279
280 /// \brief Transform the definition of the given declaration.
281 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000282 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000283 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000284 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
285 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000286 }
Mike Stump1eb44332009-09-09 15:08:12 +0000287
Douglas Gregor6cd21982009-10-20 05:58:46 +0000288 /// \brief Transform the given declaration, which was the first part of a
289 /// nested-name-specifier in a member access expression.
290 ///
Sean Huntc3021132010-05-05 15:23:54 +0000291 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000292 /// identifier in a nested-name-specifier of a member access expression, e.g.,
293 /// the \c T in \c x->T::member
294 ///
295 /// By default, invokes TransformDecl() to transform the declaration.
296 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000297 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
298 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000299 }
Sean Huntc3021132010-05-05 15:23:54 +0000300
Douglas Gregor577f75a2009-08-04 16:50:30 +0000301 /// \brief Transform the given nested-name-specifier.
302 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000303 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000304 /// nested-name-specifier. Subclasses may override this function to provide
305 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000307 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000308 QualType ObjectType = QualType(),
309 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000310
Douglas Gregor81499bb2009-09-03 22:13:48 +0000311 /// \brief Transform the given declaration name.
312 ///
313 /// By default, transforms the types of conversion function, constructor,
314 /// and destructor names and then (if needed) rebuilds the declaration name.
315 /// Identifiers and selectors are returned unmodified. Sublcasses may
316 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000317 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000318 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000319
Douglas Gregor577f75a2009-08-04 16:50:30 +0000320 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000321 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000322 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000323 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000324 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000325 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000326 QualType ObjectType = QualType(),
327 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Douglas Gregor577f75a2009-08-04 16:50:30 +0000329 /// \brief Transform the given template argument.
330 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000331 /// By default, this operation transforms the type, expression, or
332 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000333 /// new template argument from the transformed result. Subclasses may
334 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000335 ///
336 /// Returns true if there was an error.
337 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
338 TemplateArgumentLoc &Output);
339
Douglas Gregorfcc12532010-12-20 17:31:10 +0000340 /// \brief Transform the given set of template arguments.
341 ///
342 /// By default, this operation transforms all of the template arguments
343 /// in the input set using \c TransformTemplateArgument(), and appends
344 /// the transformed arguments to the output list.
345 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000346 /// Note that this overload of \c TransformTemplateArguments() is merely
347 /// a convenience function. Subclasses that wish to override this behavior
348 /// should override the iterator-based member template version.
349 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000350 /// \param Inputs The set of template arguments to be transformed.
351 ///
352 /// \param NumInputs The number of template arguments in \p Inputs.
353 ///
354 /// \param Outputs The set of transformed template arguments output by this
355 /// routine.
356 ///
357 /// Returns true if an error occurred.
358 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
359 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000360 TemplateArgumentListInfo &Outputs) {
361 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
362 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000363
364 /// \brief Transform the given set of template arguments.
365 ///
366 /// By default, this operation transforms all of the template arguments
367 /// in the input set using \c TransformTemplateArgument(), and appends
368 /// the transformed arguments to the output list.
369 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000370 /// \param First An iterator to the first template argument.
371 ///
372 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000373 ///
374 /// \param Outputs The set of transformed template arguments output by this
375 /// routine.
376 ///
377 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000378 template<typename InputIterator>
379 bool TransformTemplateArguments(InputIterator First,
380 InputIterator Last,
381 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000382
John McCall833ca992009-10-29 08:12:44 +0000383 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
384 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
385 TemplateArgumentLoc &ArgLoc);
386
John McCalla93c9342009-12-07 02:54:59 +0000387 /// \brief Fakes up a TypeSourceInfo for a type.
388 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
389 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000390 getDerived().getBaseLocation());
391 }
Mike Stump1eb44332009-09-09 15:08:12 +0000392
John McCalla2becad2009-10-21 00:40:46 +0000393#define ABSTRACT_TYPELOC(CLASS, PARENT)
394#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000395 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000396#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000397
John McCall43fed0d2010-11-12 08:19:04 +0000398 QualType
399 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
400 TemplateSpecializationTypeLoc TL,
401 TemplateName Template);
402
403 QualType
404 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
405 DependentTemplateSpecializationTypeLoc TL,
406 NestedNameSpecifier *Prefix);
407
John McCall21ef0fa2010-03-11 09:03:00 +0000408 /// \brief Transforms the parameters of a function type into the
409 /// given vectors.
410 ///
411 /// The result vectors should be kept in sync; null entries in the
412 /// variables vector are acceptable.
413 ///
414 /// Return true on error.
415 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
416 llvm::SmallVectorImpl<QualType> &PTypes,
417 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
418
419 /// \brief Transforms a single function-type parameter. Return null
420 /// on error.
421 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
422
John McCall43fed0d2010-11-12 08:19:04 +0000423 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000424
John McCall60d7b3a2010-08-24 06:29:42 +0000425 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
426 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000427
Douglas Gregor43959a92009-08-20 07:17:43 +0000428#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000429 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000430#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000431 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000432#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000433#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000434
Douglas Gregor577f75a2009-08-04 16:50:30 +0000435 /// \brief Build a new pointer type given its pointee type.
436 ///
437 /// By default, performs semantic analysis when building the pointer type.
438 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000439 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000440
441 /// \brief Build a new block pointer type given its pointee type.
442 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000443 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000444 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000445 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000446
John McCall85737a72009-10-30 00:06:24 +0000447 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000448 ///
John McCall85737a72009-10-30 00:06:24 +0000449 /// By default, performs semantic analysis when building the
450 /// reference type. Subclasses may override this routine to provide
451 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000452 ///
John McCall85737a72009-10-30 00:06:24 +0000453 /// \param LValue whether the type was written with an lvalue sigil
454 /// or an rvalue sigil.
455 QualType RebuildReferenceType(QualType ReferentType,
456 bool LValue,
457 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000458
Douglas Gregor577f75a2009-08-04 16:50:30 +0000459 /// \brief Build a new member pointer type given the pointee type and the
460 /// class type it refers into.
461 ///
462 /// By default, performs semantic analysis when building the member pointer
463 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000464 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
465 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000466
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467 /// \brief Build a new array type given the element type, size
468 /// modifier, size of the array (if known), size expression, and index type
469 /// qualifiers.
470 ///
471 /// By default, performs semantic analysis when building the array type.
472 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000473 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000474 QualType RebuildArrayType(QualType ElementType,
475 ArrayType::ArraySizeModifier SizeMod,
476 const llvm::APInt *Size,
477 Expr *SizeExpr,
478 unsigned IndexTypeQuals,
479 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000480
Douglas Gregor577f75a2009-08-04 16:50:30 +0000481 /// \brief Build a new constant array type given the element type, size
482 /// modifier, (known) size of the array, and index type qualifiers.
483 ///
484 /// By default, performs semantic analysis when building the array type.
485 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000486 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000487 ArrayType::ArraySizeModifier SizeMod,
488 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000489 unsigned IndexTypeQuals,
490 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000491
Douglas Gregor577f75a2009-08-04 16:50:30 +0000492 /// \brief Build a new incomplete array type given the element type, size
493 /// modifier, and index type qualifiers.
494 ///
495 /// By default, performs semantic analysis when building the array type.
496 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000497 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000498 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000499 unsigned IndexTypeQuals,
500 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501
Mike Stump1eb44332009-09-09 15:08:12 +0000502 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000503 /// size modifier, size expression, and index type qualifiers.
504 ///
505 /// By default, performs semantic analysis when building the array type.
506 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000507 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000509 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000510 unsigned IndexTypeQuals,
511 SourceRange BracketsRange);
512
Mike Stump1eb44332009-09-09 15:08:12 +0000513 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000514 /// size modifier, size expression, and index type qualifiers.
515 ///
516 /// By default, performs semantic analysis when building the array type.
517 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000518 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000519 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000520 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521 unsigned IndexTypeQuals,
522 SourceRange BracketsRange);
523
524 /// \brief Build a new vector type given the element type and
525 /// number of elements.
526 ///
527 /// By default, performs semantic analysis when building the vector type.
528 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000529 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000530 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000531
Douglas Gregor577f75a2009-08-04 16:50:30 +0000532 /// \brief Build a new extended vector type given the element type and
533 /// number of elements.
534 ///
535 /// By default, performs semantic analysis when building the vector type.
536 /// Subclasses may override this routine to provide different behavior.
537 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
538 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
540 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541 /// given the element type and number of elements.
542 ///
543 /// By default, performs semantic analysis when building the vector type.
544 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000545 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000546 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000548
Douglas Gregor577f75a2009-08-04 16:50:30 +0000549 /// \brief Build a new function type.
550 ///
551 /// By default, performs semantic analysis when building the function type.
552 /// Subclasses may override this routine to provide different behavior.
553 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000554 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000555 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000556 bool Variadic, unsigned Quals,
557 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000558
John McCalla2becad2009-10-21 00:40:46 +0000559 /// \brief Build a new unprototyped function type.
560 QualType RebuildFunctionNoProtoType(QualType ResultType);
561
John McCalled976492009-12-04 22:46:56 +0000562 /// \brief Rebuild an unresolved typename type, given the decl that
563 /// the UnresolvedUsingTypenameDecl was transformed to.
564 QualType RebuildUnresolvedUsingType(Decl *D);
565
Douglas Gregor577f75a2009-08-04 16:50:30 +0000566 /// \brief Build a new typedef type.
567 QualType RebuildTypedefType(TypedefDecl *Typedef) {
568 return SemaRef.Context.getTypeDeclType(Typedef);
569 }
570
571 /// \brief Build a new class/struct/union type.
572 QualType RebuildRecordType(RecordDecl *Record) {
573 return SemaRef.Context.getTypeDeclType(Record);
574 }
575
576 /// \brief Build a new Enum type.
577 QualType RebuildEnumType(EnumDecl *Enum) {
578 return SemaRef.Context.getTypeDeclType(Enum);
579 }
John McCall7da24312009-09-05 00:15:47 +0000580
Mike Stump1eb44332009-09-09 15:08:12 +0000581 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000582 ///
583 /// By default, performs semantic analysis when building the typeof type.
584 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000585 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586
Mike Stump1eb44332009-09-09 15:08:12 +0000587 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 ///
589 /// By default, builds a new TypeOfType with the given underlying type.
590 QualType RebuildTypeOfType(QualType Underlying);
591
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 ///
594 /// By default, performs semantic analysis when building the decltype type.
595 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000596 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000597
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598 /// \brief Build a new template specialization type.
599 ///
600 /// By default, performs semantic analysis when building the template
601 /// specialization type. Subclasses may override this routine to provide
602 /// different behavior.
603 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000604 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000605 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000606
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000607 /// \brief Build a new parenthesized type.
608 ///
609 /// By default, builds a new ParenType type from the inner type.
610 /// Subclasses may override this routine to provide different behavior.
611 QualType RebuildParenType(QualType InnerType) {
612 return SemaRef.Context.getParenType(InnerType);
613 }
614
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 /// \brief Build a new qualified name type.
616 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000617 /// By default, builds a new ElaboratedType type from the keyword,
618 /// the nested-name-specifier and the named type.
619 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000620 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
621 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000622 NestedNameSpecifier *NNS, QualType Named) {
623 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000624 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625
626 /// \brief Build a new typename type that refers to a template-id.
627 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000628 /// By default, builds a new DependentNameType type from the
629 /// nested-name-specifier and the given type. Subclasses may override
630 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000631 QualType RebuildDependentTemplateSpecializationType(
632 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000633 NestedNameSpecifier *Qualifier,
634 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000635 const IdentifierInfo *Name,
636 SourceLocation NameLoc,
637 const TemplateArgumentListInfo &Args) {
638 // Rebuild the template name.
639 // TODO: avoid TemplateName abstraction
640 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000641 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000642 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000643
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000644 if (InstName.isNull())
645 return QualType();
646
John McCall33500952010-06-11 00:33:02 +0000647 // If it's still dependent, make a dependent specialization.
648 if (InstName.getAsDependentTemplateName())
649 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000650 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000651
652 // Otherwise, make an elaborated type wrapping a non-dependent
653 // specialization.
654 QualType T =
655 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
656 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000657
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000658 // NOTE: NNS is already recorded in template specialization type T.
659 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000660 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661
662 /// \brief Build a new typename type that refers to an identifier.
663 ///
664 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000665 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000666 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000667 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000668 NestedNameSpecifier *NNS,
669 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000670 SourceLocation KeywordLoc,
671 SourceRange NNSRange,
672 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000673 CXXScopeSpec SS;
674 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000675 SS.setRange(NNSRange);
676
Douglas Gregor40336422010-03-31 22:19:08 +0000677 if (NNS->isDependent()) {
678 // If the name is still dependent, just build a new dependent name type.
679 if (!SemaRef.computeDeclContext(SS))
680 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
681 }
682
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000683 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000684 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
685 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000686
687 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
688
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000689 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000690 // into a non-dependent elaborated-type-specifier. Find the tag we're
691 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000692 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000693 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
694 if (!DC)
695 return QualType();
696
John McCall56138762010-05-27 06:40:31 +0000697 if (SemaRef.RequireCompleteDeclContext(SS, DC))
698 return QualType();
699
Douglas Gregor40336422010-03-31 22:19:08 +0000700 TagDecl *Tag = 0;
701 SemaRef.LookupQualifiedName(Result, DC);
702 switch (Result.getResultKind()) {
703 case LookupResult::NotFound:
704 case LookupResult::NotFoundInCurrentInstantiation:
705 break;
Sean Huntc3021132010-05-05 15:23:54 +0000706
Douglas Gregor40336422010-03-31 22:19:08 +0000707 case LookupResult::Found:
708 Tag = Result.getAsSingle<TagDecl>();
709 break;
Sean Huntc3021132010-05-05 15:23:54 +0000710
Douglas Gregor40336422010-03-31 22:19:08 +0000711 case LookupResult::FoundOverloaded:
712 case LookupResult::FoundUnresolvedValue:
713 llvm_unreachable("Tag lookup cannot find non-tags");
714 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000715
Douglas Gregor40336422010-03-31 22:19:08 +0000716 case LookupResult::Ambiguous:
717 // Let the LookupResult structure handle ambiguities.
718 return QualType();
719 }
720
721 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000722 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000723 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000724 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000725 return QualType();
726 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000727
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000728 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
729 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000730 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
731 return QualType();
732 }
733
734 // Build the elaborated-type-specifier type.
735 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000736 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000737 }
Mike Stump1eb44332009-09-09 15:08:12 +0000738
Douglas Gregordcee1a12009-08-06 05:28:30 +0000739 /// \brief Build a new nested-name-specifier given the prefix and an
740 /// identifier that names the next step in the nested-name-specifier.
741 ///
742 /// By default, performs semantic analysis when building the new
743 /// nested-name-specifier. Subclasses may override this routine to provide
744 /// different behavior.
745 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
746 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000747 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000748 QualType ObjectType,
749 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000750
751 /// \brief Build a new nested-name-specifier given the prefix and the
752 /// namespace named in the next step in the nested-name-specifier.
753 ///
754 /// By default, performs semantic analysis when building the new
755 /// nested-name-specifier. Subclasses may override this routine to provide
756 /// different behavior.
757 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
758 SourceRange Range,
759 NamespaceDecl *NS);
760
761 /// \brief Build a new nested-name-specifier given the prefix and the
762 /// type named in the next step in the nested-name-specifier.
763 ///
764 /// By default, performs semantic analysis when building the new
765 /// nested-name-specifier. Subclasses may override this routine to provide
766 /// different behavior.
767 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
768 SourceRange Range,
769 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000770 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000771
772 /// \brief Build a new template name given a nested name specifier, a flag
773 /// indicating whether the "template" keyword was provided, and the template
774 /// that the template name refers to.
775 ///
776 /// By default, builds the new template name directly. Subclasses may override
777 /// this routine to provide different behavior.
778 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
779 bool TemplateKW,
780 TemplateDecl *Template);
781
Douglas Gregord1067e52009-08-06 06:41:21 +0000782 /// \brief Build a new template name given a nested name specifier and the
783 /// name that is referred to as a template.
784 ///
785 /// By default, performs semantic analysis to determine whether the name can
786 /// be resolved to a specific template, then builds the appropriate kind of
787 /// template name. Subclasses may override this routine to provide different
788 /// behavior.
789 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000790 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000791 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000792 QualType ObjectType,
793 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000794
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000795 /// \brief Build a new template name given a nested name specifier and the
796 /// overloaded operator name that is referred to as a template.
797 ///
798 /// By default, performs semantic analysis to determine whether the name can
799 /// be resolved to a specific template, then builds the appropriate kind of
800 /// template name. Subclasses may override this routine to provide different
801 /// behavior.
802 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
803 OverloadedOperatorKind Operator,
804 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000805
Douglas Gregor43959a92009-08-20 07:17:43 +0000806 /// \brief Build a new compound statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000810 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000811 MultiStmtArg Statements,
812 SourceLocation RBraceLoc,
813 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000814 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000815 IsStmtExpr);
816 }
817
818 /// \brief Build a new case statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000822 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000823 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000824 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000825 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000826 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000827 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000828 ColonLoc);
829 }
Mike Stump1eb44332009-09-09 15:08:12 +0000830
Douglas Gregor43959a92009-08-20 07:17:43 +0000831 /// \brief Attach the body to a new case statement.
832 ///
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000835 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000836 getSema().ActOnCaseStmtBody(S, Body);
837 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000838 }
Mike Stump1eb44332009-09-09 15:08:12 +0000839
Douglas Gregor43959a92009-08-20 07:17:43 +0000840 /// \brief Build a new default statement.
841 ///
842 /// By default, performs semantic analysis to build the new statement.
843 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000844 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000845 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000846 Stmt *SubStmt) {
847 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000848 /*CurScope=*/0);
849 }
Mike Stump1eb44332009-09-09 15:08:12 +0000850
Douglas Gregor43959a92009-08-20 07:17:43 +0000851 /// \brief Build a new label statement.
852 ///
853 /// By default, performs semantic analysis to build the new statement.
854 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000855 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000856 IdentifierInfo *Id,
857 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000858 Stmt *SubStmt, bool HasUnusedAttr) {
859 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
860 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000861 }
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Douglas Gregor43959a92009-08-20 07:17:43 +0000863 /// \brief Build a new "if" statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000867 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000868 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000869 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000870 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000871 }
Mike Stump1eb44332009-09-09 15:08:12 +0000872
Douglas Gregor43959a92009-08-20 07:17:43 +0000873 /// \brief Start building a new switch statement.
874 ///
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000877 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000878 Expr *Cond, VarDecl *CondVar) {
879 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000880 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000881 }
Mike Stump1eb44332009-09-09 15:08:12 +0000882
Douglas Gregor43959a92009-08-20 07:17:43 +0000883 /// \brief Attach the body to the switch statement.
884 ///
885 /// By default, performs semantic analysis to build the new statement.
886 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000887 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000888 Stmt *Switch, Stmt *Body) {
889 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000890 }
891
892 /// \brief Build a new while statement.
893 ///
894 /// By default, performs semantic analysis to build the new statement.
895 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000896 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000897 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000898 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000899 Stmt *Body) {
900 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000901 }
Mike Stump1eb44332009-09-09 15:08:12 +0000902
Douglas Gregor43959a92009-08-20 07:17:43 +0000903 /// \brief Build a new do-while statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000907 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000908 SourceLocation WhileLoc,
909 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000910 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000911 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000912 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
913 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000914 }
915
916 /// \brief Build a new for statement.
917 ///
918 /// By default, performs semantic analysis to build the new statement.
919 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000920 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000921 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000922 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000923 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000924 SourceLocation RParenLoc, Stmt *Body) {
925 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000926 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000927 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000928 }
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Douglas Gregor43959a92009-08-20 07:17:43 +0000930 /// \brief Build a new goto statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000934 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000935 SourceLocation LabelLoc,
936 LabelStmt *Label) {
937 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
938 }
939
940 /// \brief Build a new indirect goto statement.
941 ///
942 /// By default, performs semantic analysis to build the new statement.
943 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000944 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000945 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000946 Expr *Target) {
947 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000948 }
Mike Stump1eb44332009-09-09 15:08:12 +0000949
Douglas Gregor43959a92009-08-20 07:17:43 +0000950 /// \brief Build a new return statement.
951 ///
952 /// By default, performs semantic analysis to build the new statement.
953 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000954 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000955 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000956
John McCall9ae2f072010-08-23 23:25:46 +0000957 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000958 }
Mike Stump1eb44332009-09-09 15:08:12 +0000959
Douglas Gregor43959a92009-08-20 07:17:43 +0000960 /// \brief Build a new declaration statement.
961 ///
962 /// By default, performs semantic analysis to build the new statement.
963 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000964 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000965 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000966 SourceLocation EndLoc) {
967 return getSema().Owned(
968 new (getSema().Context) DeclStmt(
969 DeclGroupRef::Create(getSema().Context,
970 Decls, NumDecls),
971 StartLoc, EndLoc));
972 }
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Anders Carlsson703e3942010-01-24 05:50:09 +0000974 /// \brief Build a new inline asm statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000978 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +0000979 bool IsSimple,
980 bool IsVolatile,
981 unsigned NumOutputs,
982 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000983 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000984 MultiExprArg Constraints,
985 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +0000986 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +0000987 MultiExprArg Clobbers,
988 SourceLocation RParenLoc,
989 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +0000990 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +0000991 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +0000992 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +0000993 RParenLoc, MSAsm);
994 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +0000995
996 /// \brief Build a new Objective-C @try statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001000 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001001 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001002 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001003 Stmt *Finally) {
1004 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1005 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001006 }
1007
Douglas Gregorbe270a02010-04-26 17:57:08 +00001008 /// \brief Rebuild an Objective-C exception declaration.
1009 ///
1010 /// By default, performs semantic analysis to build the new declaration.
1011 /// Subclasses may override this routine to provide different behavior.
1012 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1013 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001014 return getSema().BuildObjCExceptionDecl(TInfo, T,
1015 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001016 ExceptionDecl->getLocation());
1017 }
Sean Huntc3021132010-05-05 15:23:54 +00001018
Douglas Gregorbe270a02010-04-26 17:57:08 +00001019 /// \brief Build a new Objective-C @catch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001023 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001024 SourceLocation RParenLoc,
1025 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001026 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001027 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001028 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001029 }
Sean Huntc3021132010-05-05 15:23:54 +00001030
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001031 /// \brief Build a new Objective-C @finally statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001035 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001036 Stmt *Body) {
1037 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001038 }
Sean Huntc3021132010-05-05 15:23:54 +00001039
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001040 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001044 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001045 Expr *Operand) {
1046 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001047 }
Sean Huntc3021132010-05-05 15:23:54 +00001048
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001049 /// \brief Build a new Objective-C @synchronized statement.
1050 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001053 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001054 Expr *Object,
1055 Stmt *Body) {
1056 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1057 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001058 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001059
1060 /// \brief Build a new Objective-C fast enumeration statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001064 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001065 SourceLocation LParenLoc,
1066 Stmt *Element,
1067 Expr *Collection,
1068 SourceLocation RParenLoc,
1069 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001070 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001071 Element,
1072 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001073 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001074 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001075 }
Sean Huntc3021132010-05-05 15:23:54 +00001076
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 /// \brief Build a new C++ exception declaration.
1078 ///
1079 /// By default, performs semantic analysis to build the new decaration.
1080 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001081 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001082 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001084 SourceLocation Loc) {
1085 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001086 }
1087
1088 /// \brief Build a new C++ catch statement.
1089 ///
1090 /// By default, performs semantic analysis to build the new statement.
1091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001092 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001093 VarDecl *ExceptionDecl,
1094 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001095 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1096 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 }
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregor43959a92009-08-20 07:17:43 +00001099 /// \brief Build a new C++ try statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001104 Stmt *TryBlock,
1105 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001106 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001107 }
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregorb98b1992009-08-11 05:31:07 +00001109 /// \brief Build a new expression that references a declaration.
1110 ///
1111 /// By default, performs semantic analysis to build the new expression.
1112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001113 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001114 LookupResult &R,
1115 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001116 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1117 }
1118
1119
1120 /// \brief Build a new expression that references a declaration.
1121 ///
1122 /// By default, performs semantic analysis to build the new expression.
1123 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001124 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001125 SourceRange QualifierRange,
1126 ValueDecl *VD,
1127 const DeclarationNameInfo &NameInfo,
1128 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001129 CXXScopeSpec SS;
1130 SS.setScopeRep(Qualifier);
1131 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001132
1133 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001134
1135 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001136 }
Mike Stump1eb44332009-09-09 15:08:12 +00001137
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001139 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001140 /// By default, performs semantic analysis to build the new expression.
1141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001142 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001143 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001144 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001145 }
1146
Douglas Gregora71d8192009-09-04 17:36:40 +00001147 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001148 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001149 /// By default, performs semantic analysis to build the new expression.
1150 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001151 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001152 SourceLocation OperatorLoc,
1153 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001154 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001155 SourceRange QualifierRange,
1156 TypeSourceInfo *ScopeType,
1157 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001158 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001159 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Douglas Gregorb98b1992009-08-11 05:31:07 +00001161 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001162 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001163 /// By default, performs semantic analysis to build the new expression.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001166 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001167 Expr *SubExpr) {
1168 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001169 }
Mike Stump1eb44332009-09-09 15:08:12 +00001170
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001171 /// \brief Build a new builtin offsetof expression.
1172 ///
1173 /// By default, performs semantic analysis to build the new expression.
1174 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001175 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001176 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001177 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001178 unsigned NumComponents,
1179 SourceLocation RParenLoc) {
1180 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1181 NumComponents, RParenLoc);
1182 }
Sean Huntc3021132010-05-05 15:23:54 +00001183
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001185 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001188 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001189 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001190 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001191 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001192 }
1193
Mike Stump1eb44332009-09-09 15:08:12 +00001194 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001195 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001196 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001197 /// By default, performs semantic analysis to build the new expression.
1198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001199 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001200 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001201 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001202 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001205
Douglas Gregorb98b1992009-08-11 05:31:07 +00001206 return move(Result);
1207 }
Mike Stump1eb44332009-09-09 15:08:12 +00001208
Douglas Gregorb98b1992009-08-11 05:31:07 +00001209 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001210 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001215 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001217 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1218 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 RBracketLoc);
1220 }
1221
1222 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001223 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001224 /// By default, performs semantic analysis to build the new expression.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001229 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001230 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 }
1232
1233 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001234 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001238 bool isArrow,
1239 NestedNameSpecifier *Qualifier,
1240 SourceRange QualifierRange,
1241 const DeclarationNameInfo &MemberNameInfo,
1242 ValueDecl *Member,
1243 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001244 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001245 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001246 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001247 // We have a reference to an unnamed field. This is always the
1248 // base of an anonymous struct/union member access, i.e. the
1249 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001250 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001251 assert(Member->getType()->isRecordType() &&
1252 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001253
John McCall9ae2f072010-08-23 23:25:46 +00001254 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001255 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001256 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001257
John McCallf89e55a2010-11-18 06:31:45 +00001258 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001259 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001260 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001261 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001262 cast<FieldDecl>(Member)->getType(),
1263 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001264 return getSema().Owned(ME);
1265 }
Mike Stump1eb44332009-09-09 15:08:12 +00001266
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001267 CXXScopeSpec SS;
1268 if (Qualifier) {
1269 SS.setRange(QualifierRange);
1270 SS.setScopeRep(Qualifier);
1271 }
1272
John McCall9ae2f072010-08-23 23:25:46 +00001273 getSema().DefaultFunctionArrayConversion(Base);
1274 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001275
John McCall6bb80172010-03-30 21:47:33 +00001276 // FIXME: this involves duplicating earlier analysis in a lot of
1277 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001278 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001279 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001280 R.resolveKind();
1281
John McCall9ae2f072010-08-23 23:25:46 +00001282 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001283 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001284 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 }
Mike Stump1eb44332009-09-09 15:08:12 +00001286
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001288 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001291 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001292 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001293 Expr *LHS, Expr *RHS) {
1294 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 }
1296
1297 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001298 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001301 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001303 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001304 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001305 Expr *RHS) {
1306 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1307 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 }
1309
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001311 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001315 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001317 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001318 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001319 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001323 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001326 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001327 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001329 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001330 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001331 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001335 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001338 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 SourceLocation OpLoc,
1340 SourceLocation AccessorLoc,
1341 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001342
John McCall129e2df2009-11-30 22:42:35 +00001343 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001344 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001345 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001346 OpLoc, /*IsArrow*/ false,
1347 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001348 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001349 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 }
Mike Stump1eb44332009-09-09 15:08:12 +00001351
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001353 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 /// By default, performs semantic analysis to build the new expression.
1355 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001356 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001358 SourceLocation RBraceLoc,
1359 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001360 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001361 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1362 if (Result.isInvalid() || ResultTy->isDependentType())
1363 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001364
Douglas Gregore48319a2009-11-09 17:16:50 +00001365 // Patch in the result type we were given, which may have been computed
1366 // when the initial InitListExpr was built.
1367 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1368 ILE->setType(ResultTy);
1369 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 }
Mike Stump1eb44332009-09-09 15:08:12 +00001371
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001373 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 /// By default, performs semantic analysis to build the new expression.
1375 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001376 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 MultiExprArg ArrayExprs,
1378 SourceLocation EqualOrColonLoc,
1379 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001380 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001381 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001383 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001386
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 ArrayExprs.release();
1388 return move(Result);
1389 }
Mike Stump1eb44332009-09-09 15:08:12 +00001390
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001392 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 /// By default, builds the implicit value initialization without performing
1394 /// any semantic analysis. Subclasses may override this routine to provide
1395 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001396 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1398 }
Mike Stump1eb44332009-09-09 15:08:12 +00001399
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001401 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001404 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001405 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001406 SourceLocation RParenLoc) {
1407 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001409 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 }
1411
1412 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001413 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001416 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 MultiExprArg SubExprs,
1418 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001419 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001420 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 }
Mike Stump1eb44332009-09-09 15:08:12 +00001422
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001424 ///
1425 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// rather than attempting to map the label statement itself.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 SourceLocation LabelLoc,
1430 LabelStmt *Label) {
1431 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001435 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001439 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001441 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 }
Mike Stump1eb44332009-09-09 15:08:12 +00001443
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 /// \brief Build a new __builtin_choose_expr expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001448 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001449 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 SourceLocation RParenLoc) {
1451 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001452 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 RParenLoc);
1454 }
Mike Stump1eb44332009-09-09 15:08:12 +00001455
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 /// \brief Build a new overloaded operator call expression.
1457 ///
1458 /// By default, performs semantic analysis to build the new expression.
1459 /// The semantic analysis provides the behavior of template instantiation,
1460 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001461 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// argument-dependent lookup, etc. Subclasses may override this routine to
1463 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001464 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001466 Expr *Callee,
1467 Expr *First,
1468 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001469
1470 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 /// reinterpret_cast.
1472 ///
1473 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001474 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 Stmt::StmtClass Class,
1478 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001479 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation RAngleLoc,
1481 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001482 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 SourceLocation RParenLoc) {
1484 switch (Class) {
1485 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001486 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001487 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001488 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489
1490 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001491 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001492 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001493 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001494
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001496 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001497 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001498 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001500
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001502 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001503 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001504 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001505
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 default:
1507 assert(false && "Invalid C++ named cast");
1508 break;
1509 }
Mike Stump1eb44332009-09-09 15:08:12 +00001510
John McCallf312b1e2010-08-26 23:41:50 +00001511 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 }
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// \brief Build a new C++ static_cast expression.
1515 ///
1516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001518 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001520 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 SourceLocation RAngleLoc,
1522 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001523 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001524 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001525 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001526 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001527 SourceRange(LAngleLoc, RAngleLoc),
1528 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 }
1530
1531 /// \brief Build a new C++ dynamic_cast expression.
1532 ///
1533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001535 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001537 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 SourceLocation RAngleLoc,
1539 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001540 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001542 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001543 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001544 SourceRange(LAngleLoc, RAngleLoc),
1545 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
1547
1548 /// \brief Build a new C++ reinterpret_cast expression.
1549 ///
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001554 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 SourceLocation RAngleLoc,
1556 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001557 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001559 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001560 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001561 SourceRange(LAngleLoc, RAngleLoc),
1562 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 }
1564
1565 /// \brief Build a new C++ const_cast expression.
1566 ///
1567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001571 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 SourceLocation RAngleLoc,
1573 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001574 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001576 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001577 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001578 SourceRange(LAngleLoc, RAngleLoc),
1579 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 }
Mike Stump1eb44332009-09-09 15:08:12 +00001581
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// \brief Build a new C++ functional-style cast expression.
1583 ///
1584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001586 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1587 SourceLocation LParenLoc,
1588 Expr *Sub,
1589 SourceLocation RParenLoc) {
1590 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001591 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 RParenLoc);
1593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new C++ typeid(type) expression.
1596 ///
1597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001600 SourceLocation TypeidLoc,
1601 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001603 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001604 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 }
Mike Stump1eb44332009-09-09 15:08:12 +00001606
Francois Pichet01b7c302010-09-08 12:20:18 +00001607
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// \brief Build a new C++ typeid(expr) expression.
1609 ///
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001612 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001613 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001614 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001616 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001617 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001618 }
1619
Francois Pichet01b7c302010-09-08 12:20:18 +00001620 /// \brief Build a new C++ __uuidof(type) expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
1624 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1625 SourceLocation TypeidLoc,
1626 TypeSourceInfo *Operand,
1627 SourceLocation RParenLoc) {
1628 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1629 RParenLoc);
1630 }
1631
1632 /// \brief Build a new C++ __uuidof(expr) expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
1636 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1637 SourceLocation TypeidLoc,
1638 Expr *Operand,
1639 SourceLocation RParenLoc) {
1640 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1641 RParenLoc);
1642 }
1643
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// \brief Build a new C++ "this" expression.
1645 ///
1646 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001647 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001649 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001650 QualType ThisType,
1651 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001653 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1654 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new C++ throw expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001662 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 }
1664
1665 /// \brief Build a new C++ default-argument expression.
1666 ///
1667 /// By default, builds a new default-argument expression, which does not
1668 /// require any semantic analysis. Subclasses may override this routine to
1669 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001670 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001671 ParmVarDecl *Param) {
1672 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1673 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 }
1675
1676 /// \brief Build a new C++ zero-initialization expression.
1677 ///
1678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001680 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1681 SourceLocation LParenLoc,
1682 SourceLocation RParenLoc) {
1683 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001684 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001685 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
Mike Stump1eb44332009-09-09 15:08:12 +00001687
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 /// \brief Build a new C++ "new" expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001692 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001693 bool UseGlobal,
1694 SourceLocation PlacementLParen,
1695 MultiExprArg PlacementArgs,
1696 SourceLocation PlacementRParen,
1697 SourceRange TypeIdParens,
1698 QualType AllocatedType,
1699 TypeSourceInfo *AllocatedTypeInfo,
1700 Expr *ArraySize,
1701 SourceLocation ConstructorLParen,
1702 MultiExprArg ConstructorArgs,
1703 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001704 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 PlacementLParen,
1706 move(PlacementArgs),
1707 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001708 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001709 AllocatedType,
1710 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001711 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 ConstructorLParen,
1713 move(ConstructorArgs),
1714 ConstructorRParen);
1715 }
Mike Stump1eb44332009-09-09 15:08:12 +00001716
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// \brief Build a new C++ "delete" expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001721 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 bool IsGlobalDelete,
1723 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001724 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001726 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 }
Mike Stump1eb44332009-09-09 15:08:12 +00001728
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 /// \brief Build a new unary type trait expression.
1730 ///
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001733 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001734 SourceLocation StartLoc,
1735 TypeSourceInfo *T,
1736 SourceLocation RParenLoc) {
1737 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 }
1739
Francois Pichet6ad6f282010-12-07 00:08:36 +00001740 /// \brief Build a new binary type trait expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
1744 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1745 SourceLocation StartLoc,
1746 TypeSourceInfo *LhsT,
1747 TypeSourceInfo *RhsT,
1748 SourceLocation RParenLoc) {
1749 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1750 }
1751
Mike Stump1eb44332009-09-09 15:08:12 +00001752 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 /// expression.
1754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001757 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001759 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001760 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 CXXScopeSpec SS;
1762 SS.setRange(QualifierRange);
1763 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001764
1765 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001766 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001767 *TemplateArgs);
1768
Abramo Bagnara25777432010-08-11 22:01:17 +00001769 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 }
1771
1772 /// \brief Build a new template-id expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001777 LookupResult &R,
1778 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001779 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001780 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 }
1782
1783 /// \brief Build a new object-construction expression.
1784 ///
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001787 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001788 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 CXXConstructorDecl *Constructor,
1790 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001791 MultiExprArg Args,
1792 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001793 CXXConstructExpr::ConstructionKind ConstructKind,
1794 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001795 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001796 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001797 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001798 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001799
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001800 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001801 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001802 RequiresZeroInit, ConstructKind,
1803 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 }
1805
1806 /// \brief Build a new object-construction expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001810 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1811 SourceLocation LParenLoc,
1812 MultiExprArg Args,
1813 SourceLocation RParenLoc) {
1814 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 LParenLoc,
1816 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 RParenLoc);
1818 }
1819
1820 /// \brief Build a new object-construction expression.
1821 ///
1822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001824 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1825 SourceLocation LParenLoc,
1826 MultiExprArg Args,
1827 SourceLocation RParenLoc) {
1828 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 LParenLoc,
1830 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 RParenLoc);
1832 }
Mike Stump1eb44332009-09-09 15:08:12 +00001833
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 /// \brief Build a new member reference expression.
1835 ///
1836 /// By default, performs semantic analysis to build the new expression.
1837 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001838 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001839 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 bool IsArrow,
1841 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001842 NestedNameSpecifier *Qualifier,
1843 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001844 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001845 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001846 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001848 SS.setRange(QualifierRange);
1849 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001850
John McCall9ae2f072010-08-23 23:25:46 +00001851 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001852 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001853 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001854 MemberNameInfo,
1855 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 }
1857
John McCall129e2df2009-11-30 22:42:35 +00001858 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001862 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001863 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001864 SourceLocation OperatorLoc,
1865 bool IsArrow,
1866 NestedNameSpecifier *Qualifier,
1867 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001868 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001869 LookupResult &R,
1870 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001871 CXXScopeSpec SS;
1872 SS.setRange(QualifierRange);
1873 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001874
John McCall9ae2f072010-08-23 23:25:46 +00001875 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001876 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001877 SS, FirstQualifierInScope,
1878 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001879 }
Mike Stump1eb44332009-09-09 15:08:12 +00001880
Sebastian Redl2e156222010-09-10 20:55:43 +00001881 /// \brief Build a new noexcept expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
1885 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1886 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1887 }
1888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new Objective-C @encode expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001893 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001894 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001896 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001898 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899
Douglas Gregor92e986e2010-04-22 16:44:27 +00001900 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001901 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001902 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001903 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001904 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001905 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001906 MultiExprArg Args,
1907 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001908 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1909 ReceiverTypeInfo->getType(),
1910 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001911 Sel, Method, LBracLoc, SelectorLoc,
1912 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001913 }
1914
1915 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001916 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001917 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001918 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001919 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001920 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001921 MultiExprArg Args,
1922 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001923 return SemaRef.BuildInstanceMessage(Receiver,
1924 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001925 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001926 Sel, Method, LBracLoc, SelectorLoc,
1927 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001928 }
1929
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001930 /// \brief Build a new Objective-C ivar reference expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001934 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001935 SourceLocation IvarLoc,
1936 bool IsArrow, bool IsFreeIvar) {
1937 // FIXME: We lose track of the IsFreeIvar bit.
1938 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001939 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001940 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1941 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001942 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001943 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001944 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001945 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001946 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001947 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001948
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001949 if (Result.get())
1950 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001951
John McCall9ae2f072010-08-23 23:25:46 +00001952 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001953 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001954 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001955 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001956 /*TemplateArgs=*/0);
1957 }
Douglas Gregore3303542010-04-26 20:47:02 +00001958
1959 /// \brief Build a new Objective-C property reference expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001963 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00001964 ObjCPropertyDecl *Property,
1965 SourceLocation PropertyLoc) {
1966 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001967 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00001968 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1969 Sema::LookupMemberName);
1970 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00001971 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00001972 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00001973 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00001974 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001975 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001976
Douglas Gregore3303542010-04-26 20:47:02 +00001977 if (Result.get())
1978 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001979
John McCall9ae2f072010-08-23 23:25:46 +00001980 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001981 /*FIXME:*/PropertyLoc, IsArrow,
1982 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00001983 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001984 R,
Douglas Gregore3303542010-04-26 20:47:02 +00001985 /*TemplateArgs=*/0);
1986 }
Sean Huntc3021132010-05-05 15:23:54 +00001987
John McCall12f78a62010-12-02 01:19:52 +00001988 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00001989 ///
1990 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00001991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1993 ObjCMethodDecl *Getter,
1994 ObjCMethodDecl *Setter,
1995 SourceLocation PropertyLoc) {
1996 // Since these expressions can only be value-dependent, we do not
1997 // need to perform semantic analysis again.
1998 return Owned(
1999 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2000 VK_LValue, OK_ObjCProperty,
2001 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002002 }
2003
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002004 /// \brief Build a new Objective-C "isa" expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002008 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002009 bool IsArrow) {
2010 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002011 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002012 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2013 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002014 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002015 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002016 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002017 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002018 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002019
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002020 if (Result.get())
2021 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002022
John McCall9ae2f072010-08-23 23:25:46 +00002023 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002024 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002025 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002026 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002027 /*TemplateArgs=*/0);
2028 }
Sean Huntc3021132010-05-05 15:23:54 +00002029
Douglas Gregorb98b1992009-08-11 05:31:07 +00002030 /// \brief Build a new shuffle vector expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002034 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002035 MultiExprArg SubExprs,
2036 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002038 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002039 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2040 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2041 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2042 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 // Build a reference to the __builtin_shufflevector builtin
2045 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002046 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002048 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002049 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002050
2051 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002052 unsigned NumSubExprs = SubExprs.size();
2053 Expr **Subs = (Expr **)SubExprs.release();
2054 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2055 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002056 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002057 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002058 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002059 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002060
Douglas Gregorb98b1992009-08-11 05:31:07 +00002061 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002062 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002063 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002064 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002065
Douglas Gregorb98b1992009-08-11 05:31:07 +00002066 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002067 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002068 }
John McCall43fed0d2010-11-12 08:19:04 +00002069
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002070 /// \brief Build a new template argument pack expansion.
2071 ///
2072 /// By default, performs semantic analysis to build a new pack expansion
2073 /// for a template argument. Subclasses may override this routine to provide
2074 /// different behavior.
2075 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2076 SourceLocation EllipsisLoc) {
2077 switch (Pattern.getArgument().getKind()) {
2078 case TemplateArgument::Expression:
2079 case TemplateArgument::Template:
2080 llvm_unreachable("Unsupported pack expansion of expressions/templates");
2081
2082 case TemplateArgument::Null:
2083 case TemplateArgument::Integral:
2084 case TemplateArgument::Declaration:
2085 case TemplateArgument::Pack:
2086 llvm_unreachable("Pack expansion pattern has no parameter packs");
2087
2088 case TemplateArgument::Type:
2089 if (TypeSourceInfo *Expansion
2090 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2091 EllipsisLoc))
2092 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2093 Expansion);
2094 break;
2095 }
2096
2097 return TemplateArgumentLoc();
2098 }
2099
John McCall43fed0d2010-11-12 08:19:04 +00002100private:
2101 QualType TransformTypeInObjectScope(QualType T,
2102 QualType ObjectType,
2103 NamedDecl *FirstQualifierInScope,
2104 NestedNameSpecifier *Prefix);
2105
2106 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2107 QualType ObjectType,
2108 NamedDecl *FirstQualifierInScope,
2109 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002110};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002111
Douglas Gregor43959a92009-08-20 07:17:43 +00002112template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002113StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002114 if (!S)
2115 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002116
Douglas Gregor43959a92009-08-20 07:17:43 +00002117 switch (S->getStmtClass()) {
2118 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002119
Douglas Gregor43959a92009-08-20 07:17:43 +00002120 // Transform individual statement nodes
2121#define STMT(Node, Parent) \
2122 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2123#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002124#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002125
Douglas Gregor43959a92009-08-20 07:17:43 +00002126 // Transform expressions by calling TransformExpr.
2127#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002128#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002129#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002130#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002131 {
John McCall60d7b3a2010-08-24 06:29:42 +00002132 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002133 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002134 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002135
John McCall9ae2f072010-08-23 23:25:46 +00002136 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002137 }
Mike Stump1eb44332009-09-09 15:08:12 +00002138 }
2139
John McCall3fa5cae2010-10-26 07:05:15 +00002140 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002141}
Mike Stump1eb44332009-09-09 15:08:12 +00002142
2143
Douglas Gregor670444e2009-08-04 22:27:00 +00002144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002145ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 if (!E)
2147 return SemaRef.Owned(E);
2148
2149 switch (E->getStmtClass()) {
2150 case Stmt::NoStmtClass: break;
2151#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002152#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002153#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002154 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002155#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002156 }
2157
John McCall3fa5cae2010-10-26 07:05:15 +00002158 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002159}
2160
2161template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002162NestedNameSpecifier *
2163TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002164 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002165 QualType ObjectType,
2166 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002167 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregor43959a92009-08-20 07:17:43 +00002169 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002170 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002171 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002172 ObjectType,
2173 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002174 if (!Prefix)
2175 return 0;
2176 }
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregordcee1a12009-08-06 05:28:30 +00002178 switch (NNS->getKind()) {
2179 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002180 if (Prefix) {
2181 // The object type and qualifier-in-scope really apply to the
2182 // leftmost entity.
2183 ObjectType = QualType();
2184 FirstQualifierInScope = 0;
2185 }
2186
Mike Stump1eb44332009-09-09 15:08:12 +00002187 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002188 "Identifier nested-name-specifier with no prefix or object type");
2189 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2190 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002191 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002192
2193 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002194 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002195 ObjectType,
2196 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002197
Douglas Gregordcee1a12009-08-06 05:28:30 +00002198 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002199 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002200 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002201 getDerived().TransformDecl(Range.getBegin(),
2202 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002203 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002204 Prefix == NNS->getPrefix() &&
2205 NS == NNS->getAsNamespace())
2206 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002207
Douglas Gregordcee1a12009-08-06 05:28:30 +00002208 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2209 }
Mike Stump1eb44332009-09-09 15:08:12 +00002210
Douglas Gregordcee1a12009-08-06 05:28:30 +00002211 case NestedNameSpecifier::Global:
2212 // There is no meaningful transformation that one could perform on the
2213 // global scope.
2214 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002215
Douglas Gregordcee1a12009-08-06 05:28:30 +00002216 case NestedNameSpecifier::TypeSpecWithTemplate:
2217 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002218 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002219 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2220 ObjectType,
2221 FirstQualifierInScope,
2222 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002223 if (T.isNull())
2224 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002225
Douglas Gregordcee1a12009-08-06 05:28:30 +00002226 if (!getDerived().AlwaysRebuild() &&
2227 Prefix == NNS->getPrefix() &&
2228 T == QualType(NNS->getAsType(), 0))
2229 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002230
2231 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2232 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002233 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002234 }
2235 }
Mike Stump1eb44332009-09-09 15:08:12 +00002236
Douglas Gregordcee1a12009-08-06 05:28:30 +00002237 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002238 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002239}
2240
2241template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002242DeclarationNameInfo
2243TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002244::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002245 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002246 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002247 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002248
2249 switch (Name.getNameKind()) {
2250 case DeclarationName::Identifier:
2251 case DeclarationName::ObjCZeroArgSelector:
2252 case DeclarationName::ObjCOneArgSelector:
2253 case DeclarationName::ObjCMultiArgSelector:
2254 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002255 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002256 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002257 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002258
Douglas Gregor81499bb2009-09-03 22:13:48 +00002259 case DeclarationName::CXXConstructorName:
2260 case DeclarationName::CXXDestructorName:
2261 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002262 TypeSourceInfo *NewTInfo;
2263 CanQualType NewCanTy;
2264 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002265 NewTInfo = getDerived().TransformType(OldTInfo);
2266 if (!NewTInfo)
2267 return DeclarationNameInfo();
2268 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002269 }
2270 else {
2271 NewTInfo = 0;
2272 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002273 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002274 if (NewT.isNull())
2275 return DeclarationNameInfo();
2276 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2277 }
Mike Stump1eb44332009-09-09 15:08:12 +00002278
Abramo Bagnara25777432010-08-11 22:01:17 +00002279 DeclarationName NewName
2280 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2281 NewCanTy);
2282 DeclarationNameInfo NewNameInfo(NameInfo);
2283 NewNameInfo.setName(NewName);
2284 NewNameInfo.setNamedTypeInfo(NewTInfo);
2285 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002286 }
Mike Stump1eb44332009-09-09 15:08:12 +00002287 }
2288
Abramo Bagnara25777432010-08-11 22:01:17 +00002289 assert(0 && "Unknown name kind.");
2290 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002291}
2292
2293template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002294TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002295TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002296 QualType ObjectType,
2297 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002298 SourceLocation Loc = getDerived().getBaseLocation();
2299
Douglas Gregord1067e52009-08-06 06:41:21 +00002300 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002301 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002302 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002303 /*FIXME*/ SourceRange(Loc),
2304 ObjectType,
2305 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002306 if (!NNS)
2307 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002308
Douglas Gregord1067e52009-08-06 06:41:21 +00002309 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002310 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002311 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002312 if (!TransTemplate)
2313 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002314
Douglas Gregord1067e52009-08-06 06:41:21 +00002315 if (!getDerived().AlwaysRebuild() &&
2316 NNS == QTN->getQualifier() &&
2317 TransTemplate == Template)
2318 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002319
Douglas Gregord1067e52009-08-06 06:41:21 +00002320 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2321 TransTemplate);
2322 }
Mike Stump1eb44332009-09-09 15:08:12 +00002323
John McCallf7a1a742009-11-24 19:00:30 +00002324 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002325 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002326 }
Mike Stump1eb44332009-09-09 15:08:12 +00002327
Douglas Gregord1067e52009-08-06 06:41:21 +00002328 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002329 NestedNameSpecifier *NNS = DTN->getQualifier();
2330 if (NNS) {
2331 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2332 /*FIXME:*/SourceRange(Loc),
2333 ObjectType,
2334 FirstQualifierInScope);
2335 if (!NNS) return TemplateName();
2336
2337 // These apply to the scope specifier, not the template.
2338 ObjectType = QualType();
2339 FirstQualifierInScope = 0;
2340 }
Mike Stump1eb44332009-09-09 15:08:12 +00002341
Douglas Gregord1067e52009-08-06 06:41:21 +00002342 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002343 NNS == DTN->getQualifier() &&
2344 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002345 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002346
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002347 if (DTN->isIdentifier()) {
2348 // FIXME: Bad range
2349 SourceRange QualifierRange(getDerived().getBaseLocation());
2350 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2351 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002352 ObjectType,
2353 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002354 }
Sean Huntc3021132010-05-05 15:23:54 +00002355
2356 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002357 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002358 }
Mike Stump1eb44332009-09-09 15:08:12 +00002359
Douglas Gregord1067e52009-08-06 06:41:21 +00002360 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002361 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002362 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002363 if (!TransTemplate)
2364 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002365
Douglas Gregord1067e52009-08-06 06:41:21 +00002366 if (!getDerived().AlwaysRebuild() &&
2367 TransTemplate == Template)
2368 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002369
Douglas Gregord1067e52009-08-06 06:41:21 +00002370 return TemplateName(TransTemplate);
2371 }
Mike Stump1eb44332009-09-09 15:08:12 +00002372
John McCallf7a1a742009-11-24 19:00:30 +00002373 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002374 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002375 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002376}
2377
2378template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002379void TreeTransform<Derived>::InventTemplateArgumentLoc(
2380 const TemplateArgument &Arg,
2381 TemplateArgumentLoc &Output) {
2382 SourceLocation Loc = getDerived().getBaseLocation();
2383 switch (Arg.getKind()) {
2384 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002385 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002386 break;
2387
2388 case TemplateArgument::Type:
2389 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002390 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002391
John McCall833ca992009-10-29 08:12:44 +00002392 break;
2393
Douglas Gregor788cd062009-11-11 01:00:40 +00002394 case TemplateArgument::Template:
2395 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2396 break;
Sean Huntc3021132010-05-05 15:23:54 +00002397
John McCall833ca992009-10-29 08:12:44 +00002398 case TemplateArgument::Expression:
2399 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2400 break;
2401
2402 case TemplateArgument::Declaration:
2403 case TemplateArgument::Integral:
2404 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002405 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002406 break;
2407 }
2408}
2409
2410template<typename Derived>
2411bool TreeTransform<Derived>::TransformTemplateArgument(
2412 const TemplateArgumentLoc &Input,
2413 TemplateArgumentLoc &Output) {
2414 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002415 switch (Arg.getKind()) {
2416 case TemplateArgument::Null:
2417 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002418 Output = Input;
2419 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002420
Douglas Gregor670444e2009-08-04 22:27:00 +00002421 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002422 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002423 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002424 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002425
2426 DI = getDerived().TransformType(DI);
2427 if (!DI) return true;
2428
2429 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2430 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002431 }
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregor670444e2009-08-04 22:27:00 +00002433 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002434 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002435 DeclarationName Name;
2436 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2437 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002438 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002439 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002440 if (!D) return true;
2441
John McCall828bff22009-10-29 18:45:58 +00002442 Expr *SourceExpr = Input.getSourceDeclExpression();
2443 if (SourceExpr) {
2444 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002445 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002446 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002447 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002448 }
2449
2450 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002451 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002452 }
Mike Stump1eb44332009-09-09 15:08:12 +00002453
Douglas Gregor788cd062009-11-11 01:00:40 +00002454 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002455 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002456 TemplateName Template
2457 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2458 if (Template.isNull())
2459 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002460
Douglas Gregor788cd062009-11-11 01:00:40 +00002461 Output = TemplateArgumentLoc(TemplateArgument(Template),
2462 Input.getTemplateQualifierRange(),
2463 Input.getTemplateNameLoc());
2464 return false;
2465 }
Sean Huntc3021132010-05-05 15:23:54 +00002466
Douglas Gregor670444e2009-08-04 22:27:00 +00002467 case TemplateArgument::Expression: {
2468 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002469 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002470 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002471
John McCall833ca992009-10-29 08:12:44 +00002472 Expr *InputExpr = Input.getSourceExpression();
2473 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2474
John McCall60d7b3a2010-08-24 06:29:42 +00002475 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002476 = getDerived().TransformExpr(InputExpr);
2477 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002478 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002479 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002480 }
Mike Stump1eb44332009-09-09 15:08:12 +00002481
Douglas Gregor670444e2009-08-04 22:27:00 +00002482 case TemplateArgument::Pack: {
2483 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2484 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002485 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002486 AEnd = Arg.pack_end();
2487 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002488
John McCall833ca992009-10-29 08:12:44 +00002489 // FIXME: preserve source information here when we start
2490 // caring about parameter packs.
2491
John McCall828bff22009-10-29 18:45:58 +00002492 TemplateArgumentLoc InputArg;
2493 TemplateArgumentLoc OutputArg;
2494 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2495 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002496 return true;
2497
John McCall828bff22009-10-29 18:45:58 +00002498 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002499 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002500
2501 TemplateArgument *TransformedArgsPtr
2502 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2503 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2504 TransformedArgsPtr);
2505 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2506 TransformedArgs.size()),
2507 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002508 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002509 }
2510 }
Mike Stump1eb44332009-09-09 15:08:12 +00002511
Douglas Gregor670444e2009-08-04 22:27:00 +00002512 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002513 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002514}
2515
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002516/// \brief Iterator adaptor that invents template argument location information
2517/// for each of the template arguments in its underlying iterator.
2518template<typename Derived, typename InputIterator>
2519class TemplateArgumentLocInventIterator {
2520 TreeTransform<Derived> &Self;
2521 InputIterator Iter;
2522
2523public:
2524 typedef TemplateArgumentLoc value_type;
2525 typedef TemplateArgumentLoc reference;
2526 typedef typename std::iterator_traits<InputIterator>::difference_type
2527 difference_type;
2528 typedef std::input_iterator_tag iterator_category;
2529
2530 class pointer {
2531 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002532
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002533 public:
2534 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2535
2536 const TemplateArgumentLoc *operator->() const { return &Arg; }
2537 };
2538
2539 TemplateArgumentLocInventIterator() { }
2540
2541 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2542 InputIterator Iter)
2543 : Self(Self), Iter(Iter) { }
2544
2545 TemplateArgumentLocInventIterator &operator++() {
2546 ++Iter;
2547 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002548 }
2549
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002550 TemplateArgumentLocInventIterator operator++(int) {
2551 TemplateArgumentLocInventIterator Old(*this);
2552 ++(*this);
2553 return Old;
2554 }
2555
2556 reference operator*() const {
2557 TemplateArgumentLoc Result;
2558 Self.InventTemplateArgumentLoc(*Iter, Result);
2559 return Result;
2560 }
2561
2562 pointer operator->() const { return pointer(**this); }
2563
2564 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2565 const TemplateArgumentLocInventIterator &Y) {
2566 return X.Iter == Y.Iter;
2567 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002568
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002569 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2570 const TemplateArgumentLocInventIterator &Y) {
2571 return X.Iter != Y.Iter;
2572 }
2573};
2574
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002575template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002576template<typename InputIterator>
2577bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2578 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002579 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002580 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002581 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002582 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002583
2584 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2585 // Unpack argument packs, which we translate them into separate
2586 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002587 // FIXME: We could do much better if we could guarantee that the
2588 // TemplateArgumentLocInfo for the pack expansion would be usable for
2589 // all of the template arguments in the argument pack.
2590 typedef TemplateArgumentLocInventIterator<Derived,
2591 TemplateArgument::pack_iterator>
2592 PackLocIterator;
2593 if (TransformTemplateArguments(PackLocIterator(*this,
2594 In.getArgument().pack_begin()),
2595 PackLocIterator(*this,
2596 In.getArgument().pack_end()),
2597 Outputs))
2598 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002599
2600 continue;
2601 }
2602
2603 if (In.getArgument().isPackExpansion()) {
2604 // We have a pack expansion, for which we will be substituting into
2605 // the pattern.
2606 SourceLocation Ellipsis;
2607 TemplateArgumentLoc Pattern
2608 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2609
2610 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2611 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2612 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2613
2614 // Determine whether the set of unexpanded parameter packs can and should
2615 // be expanded.
2616 bool Expand = true;
2617 unsigned NumExpansions = 0;
2618 if (getDerived().TryExpandParameterPacks(Ellipsis,
2619 Pattern.getSourceRange(),
2620 Unexpanded.data(),
2621 Unexpanded.size(),
2622 Expand, NumExpansions))
2623 return true;
2624
2625 if (!Expand) {
2626 // The transform has determined that we should perform a simple
2627 // transformation on the pack expansion, producing another pack
2628 // expansion.
2629 TemplateArgumentLoc OutPattern;
2630 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2631 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2632 return true;
2633
2634 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2635 if (Out.getArgument().isNull())
2636 return true;
2637
2638 Outputs.addArgument(Out);
2639 continue;
2640 }
2641
2642 // The transform has determined that we should perform an elementwise
2643 // expansion of the pattern. Do so.
2644 for (unsigned I = 0; I != NumExpansions; ++I) {
2645 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2646
2647 if (getDerived().TransformTemplateArgument(Pattern, Out))
2648 return true;
2649
2650 Outputs.addArgument(Out);
2651 }
2652
2653 continue;
2654 }
2655
2656 // The simple case:
2657 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002658 return true;
2659
2660 Outputs.addArgument(Out);
2661 }
2662
2663 return false;
2664
2665}
2666
Douglas Gregor577f75a2009-08-04 16:50:30 +00002667//===----------------------------------------------------------------------===//
2668// Type transformation
2669//===----------------------------------------------------------------------===//
2670
2671template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002672QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002673 if (getDerived().AlreadyTransformed(T))
2674 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002675
John McCalla2becad2009-10-21 00:40:46 +00002676 // Temporary workaround. All of these transformations should
2677 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002678 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002679 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002680
John McCall43fed0d2010-11-12 08:19:04 +00002681 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002682
John McCalla2becad2009-10-21 00:40:46 +00002683 if (!NewDI)
2684 return QualType();
2685
2686 return NewDI->getType();
2687}
2688
2689template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002690TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002691 if (getDerived().AlreadyTransformed(DI->getType()))
2692 return DI;
2693
2694 TypeLocBuilder TLB;
2695
2696 TypeLoc TL = DI->getTypeLoc();
2697 TLB.reserve(TL.getFullDataSize());
2698
John McCall43fed0d2010-11-12 08:19:04 +00002699 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002700 if (Result.isNull())
2701 return 0;
2702
John McCalla93c9342009-12-07 02:54:59 +00002703 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002704}
2705
2706template<typename Derived>
2707QualType
John McCall43fed0d2010-11-12 08:19:04 +00002708TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002709 switch (T.getTypeLocClass()) {
2710#define ABSTRACT_TYPELOC(CLASS, PARENT)
2711#define TYPELOC(CLASS, PARENT) \
2712 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002713 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002714#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002715 }
Mike Stump1eb44332009-09-09 15:08:12 +00002716
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002717 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002718 return QualType();
2719}
2720
2721/// FIXME: By default, this routine adds type qualifiers only to types
2722/// that can have qualifiers, and silently suppresses those qualifiers
2723/// that are not permitted (e.g., qualifiers on reference or function
2724/// types). This is the right thing for template instantiation, but
2725/// probably not for other clients.
2726template<typename Derived>
2727QualType
2728TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002729 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002730 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002731
John McCall43fed0d2010-11-12 08:19:04 +00002732 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002733 if (Result.isNull())
2734 return QualType();
2735
2736 // Silently suppress qualifiers if the result type can't be qualified.
2737 // FIXME: this is the right thing for template instantiation, but
2738 // probably not for other clients.
2739 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002740 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002741
John McCall28654742010-06-05 06:41:15 +00002742 if (!Quals.empty()) {
2743 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2744 TLB.push<QualifiedTypeLoc>(Result);
2745 // No location information to preserve.
2746 }
John McCalla2becad2009-10-21 00:40:46 +00002747
2748 return Result;
2749}
2750
John McCall43fed0d2010-11-12 08:19:04 +00002751/// \brief Transforms a type that was written in a scope specifier,
2752/// given an object type, the results of unqualified lookup, and
2753/// an already-instantiated prefix.
2754///
2755/// The object type is provided iff the scope specifier qualifies the
2756/// member of a dependent member-access expression. The prefix is
2757/// provided iff the the scope specifier in which this appears has a
2758/// prefix.
2759///
2760/// This is private to TreeTransform.
2761template<typename Derived>
2762QualType
2763TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2764 QualType ObjectType,
2765 NamedDecl *UnqualLookup,
2766 NestedNameSpecifier *Prefix) {
2767 if (getDerived().AlreadyTransformed(T))
2768 return T;
2769
2770 TypeSourceInfo *TSI =
2771 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2772
2773 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2774 UnqualLookup, Prefix);
2775 if (!TSI) return QualType();
2776 return TSI->getType();
2777}
2778
2779template<typename Derived>
2780TypeSourceInfo *
2781TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2782 QualType ObjectType,
2783 NamedDecl *UnqualLookup,
2784 NestedNameSpecifier *Prefix) {
2785 // TODO: in some cases, we might be some verification to do here.
2786 if (ObjectType.isNull())
2787 return getDerived().TransformType(TSI);
2788
2789 QualType T = TSI->getType();
2790 if (getDerived().AlreadyTransformed(T))
2791 return TSI;
2792
2793 TypeLocBuilder TLB;
2794 QualType Result;
2795
2796 if (isa<TemplateSpecializationType>(T)) {
2797 TemplateSpecializationTypeLoc TL
2798 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2799
2800 TemplateName Template =
2801 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2802 ObjectType, UnqualLookup);
2803 if (Template.isNull()) return 0;
2804
2805 Result = getDerived()
2806 .TransformTemplateSpecializationType(TLB, TL, Template);
2807 } else if (isa<DependentTemplateSpecializationType>(T)) {
2808 DependentTemplateSpecializationTypeLoc TL
2809 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2810
2811 Result = getDerived()
2812 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2813 } else {
2814 // Nothing special needs to be done for these.
2815 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2816 }
2817
2818 if (Result.isNull()) return 0;
2819 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2820}
2821
John McCalla2becad2009-10-21 00:40:46 +00002822template <class TyLoc> static inline
2823QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2824 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2825 NewT.setNameLoc(T.getNameLoc());
2826 return T.getType();
2827}
2828
John McCalla2becad2009-10-21 00:40:46 +00002829template<typename Derived>
2830QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002831 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002832 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2833 NewT.setBuiltinLoc(T.getBuiltinLoc());
2834 if (T.needsExtraLocalData())
2835 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2836 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002837}
Mike Stump1eb44332009-09-09 15:08:12 +00002838
Douglas Gregor577f75a2009-08-04 16:50:30 +00002839template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002840QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002841 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002842 // FIXME: recurse?
2843 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002844}
Mike Stump1eb44332009-09-09 15:08:12 +00002845
Douglas Gregor577f75a2009-08-04 16:50:30 +00002846template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002847QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002848 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00002849 QualType PointeeType
2850 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002851 if (PointeeType.isNull())
2852 return QualType();
2853
2854 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002855 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002856 // A dependent pointer type 'T *' has is being transformed such
2857 // that an Objective-C class type is being replaced for 'T'. The
2858 // resulting pointer type is an ObjCObjectPointerType, not a
2859 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002860 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002861
John McCallc12c5bb2010-05-15 11:32:37 +00002862 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2863 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002864 return Result;
2865 }
John McCall43fed0d2010-11-12 08:19:04 +00002866
Douglas Gregor92e986e2010-04-22 16:44:27 +00002867 if (getDerived().AlwaysRebuild() ||
2868 PointeeType != TL.getPointeeLoc().getType()) {
2869 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2870 if (Result.isNull())
2871 return QualType();
2872 }
Sean Huntc3021132010-05-05 15:23:54 +00002873
Douglas Gregor92e986e2010-04-22 16:44:27 +00002874 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2875 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00002876 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002877}
Mike Stump1eb44332009-09-09 15:08:12 +00002878
2879template<typename Derived>
2880QualType
John McCalla2becad2009-10-21 00:40:46 +00002881TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002882 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002883 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00002884 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2885 if (PointeeType.isNull())
2886 return QualType();
2887
2888 QualType Result = TL.getType();
2889 if (getDerived().AlwaysRebuild() ||
2890 PointeeType != TL.getPointeeLoc().getType()) {
2891 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002892 TL.getSigilLoc());
2893 if (Result.isNull())
2894 return QualType();
2895 }
2896
Douglas Gregor39968ad2010-04-22 16:50:51 +00002897 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00002898 NewT.setSigilLoc(TL.getSigilLoc());
2899 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002900}
2901
John McCall85737a72009-10-30 00:06:24 +00002902/// Transforms a reference type. Note that somewhat paradoxically we
2903/// don't care whether the type itself is an l-value type or an r-value
2904/// type; we only care if the type was *written* as an l-value type
2905/// or an r-value type.
2906template<typename Derived>
2907QualType
2908TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002909 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002910 const ReferenceType *T = TL.getTypePtr();
2911
2912 // Note that this works with the pointee-as-written.
2913 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2914 if (PointeeType.isNull())
2915 return QualType();
2916
2917 QualType Result = TL.getType();
2918 if (getDerived().AlwaysRebuild() ||
2919 PointeeType != T->getPointeeTypeAsWritten()) {
2920 Result = getDerived().RebuildReferenceType(PointeeType,
2921 T->isSpelledAsLValue(),
2922 TL.getSigilLoc());
2923 if (Result.isNull())
2924 return QualType();
2925 }
2926
2927 // r-value references can be rebuilt as l-value references.
2928 ReferenceTypeLoc NewTL;
2929 if (isa<LValueReferenceType>(Result))
2930 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2931 else
2932 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2933 NewTL.setSigilLoc(TL.getSigilLoc());
2934
2935 return Result;
2936}
2937
Mike Stump1eb44332009-09-09 15:08:12 +00002938template<typename Derived>
2939QualType
John McCalla2becad2009-10-21 00:40:46 +00002940TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002941 LValueReferenceTypeLoc TL) {
2942 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002943}
2944
Mike Stump1eb44332009-09-09 15:08:12 +00002945template<typename Derived>
2946QualType
John McCalla2becad2009-10-21 00:40:46 +00002947TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002948 RValueReferenceTypeLoc TL) {
2949 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002950}
Mike Stump1eb44332009-09-09 15:08:12 +00002951
Douglas Gregor577f75a2009-08-04 16:50:30 +00002952template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002953QualType
John McCalla2becad2009-10-21 00:40:46 +00002954TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002955 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002956 MemberPointerType *T = TL.getTypePtr();
2957
2958 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002959 if (PointeeType.isNull())
2960 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002961
John McCalla2becad2009-10-21 00:40:46 +00002962 // TODO: preserve source information for this.
2963 QualType ClassType
2964 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002965 if (ClassType.isNull())
2966 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002967
John McCalla2becad2009-10-21 00:40:46 +00002968 QualType Result = TL.getType();
2969 if (getDerived().AlwaysRebuild() ||
2970 PointeeType != T->getPointeeType() ||
2971 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002972 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2973 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002974 if (Result.isNull())
2975 return QualType();
2976 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002977
John McCalla2becad2009-10-21 00:40:46 +00002978 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2979 NewTL.setSigilLoc(TL.getSigilLoc());
2980
2981 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002982}
2983
Mike Stump1eb44332009-09-09 15:08:12 +00002984template<typename Derived>
2985QualType
John McCalla2becad2009-10-21 00:40:46 +00002986TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002987 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00002988 ConstantArrayType *T = TL.getTypePtr();
2989 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002990 if (ElementType.isNull())
2991 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002992
John McCalla2becad2009-10-21 00:40:46 +00002993 QualType Result = TL.getType();
2994 if (getDerived().AlwaysRebuild() ||
2995 ElementType != T->getElementType()) {
2996 Result = getDerived().RebuildConstantArrayType(ElementType,
2997 T->getSizeModifier(),
2998 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002999 T->getIndexTypeCVRQualifiers(),
3000 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003001 if (Result.isNull())
3002 return QualType();
3003 }
Sean Huntc3021132010-05-05 15:23:54 +00003004
John McCalla2becad2009-10-21 00:40:46 +00003005 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3006 NewTL.setLBracketLoc(TL.getLBracketLoc());
3007 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003008
John McCalla2becad2009-10-21 00:40:46 +00003009 Expr *Size = TL.getSizeExpr();
3010 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003011 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003012 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3013 }
3014 NewTL.setSizeExpr(Size);
3015
3016 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003017}
Mike Stump1eb44332009-09-09 15:08:12 +00003018
Douglas Gregor577f75a2009-08-04 16:50:30 +00003019template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003020QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003021 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003022 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003023 IncompleteArrayType *T = TL.getTypePtr();
3024 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003025 if (ElementType.isNull())
3026 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003027
John McCalla2becad2009-10-21 00:40:46 +00003028 QualType Result = TL.getType();
3029 if (getDerived().AlwaysRebuild() ||
3030 ElementType != T->getElementType()) {
3031 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003032 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003033 T->getIndexTypeCVRQualifiers(),
3034 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003035 if (Result.isNull())
3036 return QualType();
3037 }
Sean Huntc3021132010-05-05 15:23:54 +00003038
John McCalla2becad2009-10-21 00:40:46 +00003039 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3040 NewTL.setLBracketLoc(TL.getLBracketLoc());
3041 NewTL.setRBracketLoc(TL.getRBracketLoc());
3042 NewTL.setSizeExpr(0);
3043
3044 return Result;
3045}
3046
3047template<typename Derived>
3048QualType
3049TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003050 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003051 VariableArrayType *T = TL.getTypePtr();
3052 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3053 if (ElementType.isNull())
3054 return QualType();
3055
3056 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003057 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003058
John McCall60d7b3a2010-08-24 06:29:42 +00003059 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003060 = getDerived().TransformExpr(T->getSizeExpr());
3061 if (SizeResult.isInvalid())
3062 return QualType();
3063
John McCall9ae2f072010-08-23 23:25:46 +00003064 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003065
3066 QualType Result = TL.getType();
3067 if (getDerived().AlwaysRebuild() ||
3068 ElementType != T->getElementType() ||
3069 Size != T->getSizeExpr()) {
3070 Result = getDerived().RebuildVariableArrayType(ElementType,
3071 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003072 Size,
John McCalla2becad2009-10-21 00:40:46 +00003073 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003074 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003075 if (Result.isNull())
3076 return QualType();
3077 }
Sean Huntc3021132010-05-05 15:23:54 +00003078
John McCalla2becad2009-10-21 00:40:46 +00003079 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3080 NewTL.setLBracketLoc(TL.getLBracketLoc());
3081 NewTL.setRBracketLoc(TL.getRBracketLoc());
3082 NewTL.setSizeExpr(Size);
3083
3084 return Result;
3085}
3086
3087template<typename Derived>
3088QualType
3089TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003090 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003091 DependentSizedArrayType *T = TL.getTypePtr();
3092 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3093 if (ElementType.isNull())
3094 return QualType();
3095
3096 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003097 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003098
John McCall60d7b3a2010-08-24 06:29:42 +00003099 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003100 = getDerived().TransformExpr(T->getSizeExpr());
3101 if (SizeResult.isInvalid())
3102 return QualType();
3103
3104 Expr *Size = static_cast<Expr*>(SizeResult.get());
3105
3106 QualType Result = TL.getType();
3107 if (getDerived().AlwaysRebuild() ||
3108 ElementType != T->getElementType() ||
3109 Size != T->getSizeExpr()) {
3110 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3111 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003112 Size,
John McCalla2becad2009-10-21 00:40:46 +00003113 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003114 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003115 if (Result.isNull())
3116 return QualType();
3117 }
3118 else SizeResult.take();
3119
3120 // We might have any sort of array type now, but fortunately they
3121 // all have the same location layout.
3122 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3123 NewTL.setLBracketLoc(TL.getLBracketLoc());
3124 NewTL.setRBracketLoc(TL.getRBracketLoc());
3125 NewTL.setSizeExpr(Size);
3126
3127 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003128}
Mike Stump1eb44332009-09-09 15:08:12 +00003129
3130template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003131QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003132 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003133 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003134 DependentSizedExtVectorType *T = TL.getTypePtr();
3135
3136 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003137 QualType ElementType = getDerived().TransformType(T->getElementType());
3138 if (ElementType.isNull())
3139 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003140
Douglas Gregor670444e2009-08-04 22:27:00 +00003141 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003142 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003143
John McCall60d7b3a2010-08-24 06:29:42 +00003144 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003145 if (Size.isInvalid())
3146 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003147
John McCalla2becad2009-10-21 00:40:46 +00003148 QualType Result = TL.getType();
3149 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003150 ElementType != T->getElementType() ||
3151 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003152 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003153 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003154 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003155 if (Result.isNull())
3156 return QualType();
3157 }
John McCalla2becad2009-10-21 00:40:46 +00003158
3159 // Result might be dependent or not.
3160 if (isa<DependentSizedExtVectorType>(Result)) {
3161 DependentSizedExtVectorTypeLoc NewTL
3162 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3163 NewTL.setNameLoc(TL.getNameLoc());
3164 } else {
3165 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3166 NewTL.setNameLoc(TL.getNameLoc());
3167 }
3168
3169 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003170}
Mike Stump1eb44332009-09-09 15:08:12 +00003171
3172template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003173QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003174 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003175 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003176 QualType ElementType = getDerived().TransformType(T->getElementType());
3177 if (ElementType.isNull())
3178 return QualType();
3179
John McCalla2becad2009-10-21 00:40:46 +00003180 QualType Result = TL.getType();
3181 if (getDerived().AlwaysRebuild() ||
3182 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003183 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003184 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003185 if (Result.isNull())
3186 return QualType();
3187 }
Sean Huntc3021132010-05-05 15:23:54 +00003188
John McCalla2becad2009-10-21 00:40:46 +00003189 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3190 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003191
John McCalla2becad2009-10-21 00:40:46 +00003192 return Result;
3193}
3194
3195template<typename Derived>
3196QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003197 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003198 VectorType *T = TL.getTypePtr();
3199 QualType ElementType = getDerived().TransformType(T->getElementType());
3200 if (ElementType.isNull())
3201 return QualType();
3202
3203 QualType Result = TL.getType();
3204 if (getDerived().AlwaysRebuild() ||
3205 ElementType != T->getElementType()) {
3206 Result = getDerived().RebuildExtVectorType(ElementType,
3207 T->getNumElements(),
3208 /*FIXME*/ SourceLocation());
3209 if (Result.isNull())
3210 return QualType();
3211 }
Sean Huntc3021132010-05-05 15:23:54 +00003212
John McCalla2becad2009-10-21 00:40:46 +00003213 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3214 NewTL.setNameLoc(TL.getNameLoc());
3215
3216 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003217}
Mike Stump1eb44332009-09-09 15:08:12 +00003218
3219template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003220ParmVarDecl *
3221TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3222 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3223 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3224 if (!NewDI)
3225 return 0;
3226
3227 if (NewDI == OldDI)
3228 return OldParm;
3229 else
3230 return ParmVarDecl::Create(SemaRef.Context,
3231 OldParm->getDeclContext(),
3232 OldParm->getLocation(),
3233 OldParm->getIdentifier(),
3234 NewDI->getType(),
3235 NewDI,
3236 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003237 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003238 /* DefArg */ NULL);
3239}
3240
3241template<typename Derived>
3242bool TreeTransform<Derived>::
3243 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3244 llvm::SmallVectorImpl<QualType> &PTypes,
3245 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3246 FunctionProtoType *T = TL.getTypePtr();
3247
3248 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3249 ParmVarDecl *OldParm = TL.getArg(i);
3250
3251 QualType NewType;
3252 ParmVarDecl *NewParm;
3253
3254 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00003255 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3256 if (!NewParm)
3257 return true;
3258 NewType = NewParm->getType();
3259
3260 // Deal with the possibility that we don't have a parameter
3261 // declaration for this parameter.
3262 } else {
3263 NewParm = 0;
3264
3265 QualType OldType = T->getArgType(i);
3266 NewType = getDerived().TransformType(OldType);
3267 if (NewType.isNull())
3268 return true;
3269 }
3270
3271 PTypes.push_back(NewType);
3272 PVars.push_back(NewParm);
3273 }
3274
3275 return false;
3276}
3277
3278template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003279QualType
John McCalla2becad2009-10-21 00:40:46 +00003280TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003281 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003282 // Transform the parameters and return type.
3283 //
3284 // We instantiate in source order, with the return type first followed by
3285 // the parameters, because users tend to expect this (even if they shouldn't
3286 // rely on it!).
3287 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003288 // When the function has a trailing return type, we instantiate the
3289 // parameters before the return type, since the return type can then refer
3290 // to the parameters themselves (via decltype, sizeof, etc.).
3291 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003292 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003293 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003294 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003295
Douglas Gregordab60ad2010-10-01 18:44:50 +00003296 QualType ResultType;
3297
3298 if (TL.getTrailingReturn()) {
3299 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3300 return QualType();
3301
3302 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3303 if (ResultType.isNull())
3304 return QualType();
3305 }
3306 else {
3307 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3308 if (ResultType.isNull())
3309 return QualType();
3310
3311 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3312 return QualType();
3313 }
3314
John McCalla2becad2009-10-21 00:40:46 +00003315 QualType Result = TL.getType();
3316 if (getDerived().AlwaysRebuild() ||
3317 ResultType != T->getResultType() ||
3318 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3319 Result = getDerived().RebuildFunctionProtoType(ResultType,
3320 ParamTypes.data(),
3321 ParamTypes.size(),
3322 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003323 T->getTypeQuals(),
3324 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003325 if (Result.isNull())
3326 return QualType();
3327 }
Mike Stump1eb44332009-09-09 15:08:12 +00003328
John McCalla2becad2009-10-21 00:40:46 +00003329 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3330 NewTL.setLParenLoc(TL.getLParenLoc());
3331 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003332 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003333 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3334 NewTL.setArg(i, ParamDecls[i]);
3335
3336 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003337}
Mike Stump1eb44332009-09-09 15:08:12 +00003338
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339template<typename Derived>
3340QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003341 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003342 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003343 FunctionNoProtoType *T = TL.getTypePtr();
3344 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3345 if (ResultType.isNull())
3346 return QualType();
3347
3348 QualType Result = TL.getType();
3349 if (getDerived().AlwaysRebuild() ||
3350 ResultType != T->getResultType())
3351 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3352
3353 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3354 NewTL.setLParenLoc(TL.getLParenLoc());
3355 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003356 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003357
3358 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003359}
Mike Stump1eb44332009-09-09 15:08:12 +00003360
John McCalled976492009-12-04 22:46:56 +00003361template<typename Derived> QualType
3362TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003363 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003364 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003365 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003366 if (!D)
3367 return QualType();
3368
3369 QualType Result = TL.getType();
3370 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3371 Result = getDerived().RebuildUnresolvedUsingType(D);
3372 if (Result.isNull())
3373 return QualType();
3374 }
3375
3376 // We might get an arbitrary type spec type back. We should at
3377 // least always get a type spec type, though.
3378 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3379 NewTL.setNameLoc(TL.getNameLoc());
3380
3381 return Result;
3382}
3383
Douglas Gregor577f75a2009-08-04 16:50:30 +00003384template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003385QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003386 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003387 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003388 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003389 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3390 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003391 if (!Typedef)
3392 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003393
John McCalla2becad2009-10-21 00:40:46 +00003394 QualType Result = TL.getType();
3395 if (getDerived().AlwaysRebuild() ||
3396 Typedef != T->getDecl()) {
3397 Result = getDerived().RebuildTypedefType(Typedef);
3398 if (Result.isNull())
3399 return QualType();
3400 }
Mike Stump1eb44332009-09-09 15:08:12 +00003401
John McCalla2becad2009-10-21 00:40:46 +00003402 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3403 NewTL.setNameLoc(TL.getNameLoc());
3404
3405 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003406}
Mike Stump1eb44332009-09-09 15:08:12 +00003407
Douglas Gregor577f75a2009-08-04 16:50:30 +00003408template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003409QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003410 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003411 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003412 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003413
John McCall60d7b3a2010-08-24 06:29:42 +00003414 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415 if (E.isInvalid())
3416 return QualType();
3417
John McCalla2becad2009-10-21 00:40:46 +00003418 QualType Result = TL.getType();
3419 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003420 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003421 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003422 if (Result.isNull())
3423 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003424 }
John McCalla2becad2009-10-21 00:40:46 +00003425 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003426
John McCalla2becad2009-10-21 00:40:46 +00003427 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003428 NewTL.setTypeofLoc(TL.getTypeofLoc());
3429 NewTL.setLParenLoc(TL.getLParenLoc());
3430 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003431
3432 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003433}
Mike Stump1eb44332009-09-09 15:08:12 +00003434
3435template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003436QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003437 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003438 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3439 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3440 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003441 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003442
John McCalla2becad2009-10-21 00:40:46 +00003443 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003444 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3445 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003446 if (Result.isNull())
3447 return QualType();
3448 }
Mike Stump1eb44332009-09-09 15:08:12 +00003449
John McCalla2becad2009-10-21 00:40:46 +00003450 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003451 NewTL.setTypeofLoc(TL.getTypeofLoc());
3452 NewTL.setLParenLoc(TL.getLParenLoc());
3453 NewTL.setRParenLoc(TL.getRParenLoc());
3454 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003455
3456 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003457}
Mike Stump1eb44332009-09-09 15:08:12 +00003458
3459template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003460QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003461 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003462 DecltypeType *T = TL.getTypePtr();
3463
Douglas Gregor670444e2009-08-04 22:27:00 +00003464 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003465 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003466
John McCall60d7b3a2010-08-24 06:29:42 +00003467 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003468 if (E.isInvalid())
3469 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003470
John McCalla2becad2009-10-21 00:40:46 +00003471 QualType Result = TL.getType();
3472 if (getDerived().AlwaysRebuild() ||
3473 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003474 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003475 if (Result.isNull())
3476 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003477 }
John McCalla2becad2009-10-21 00:40:46 +00003478 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003479
John McCalla2becad2009-10-21 00:40:46 +00003480 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3481 NewTL.setNameLoc(TL.getNameLoc());
3482
3483 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003484}
3485
3486template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003487QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003488 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003489 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003490 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003491 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3492 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003493 if (!Record)
3494 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003495
John McCalla2becad2009-10-21 00:40:46 +00003496 QualType Result = TL.getType();
3497 if (getDerived().AlwaysRebuild() ||
3498 Record != T->getDecl()) {
3499 Result = getDerived().RebuildRecordType(Record);
3500 if (Result.isNull())
3501 return QualType();
3502 }
Mike Stump1eb44332009-09-09 15:08:12 +00003503
John McCalla2becad2009-10-21 00:40:46 +00003504 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3505 NewTL.setNameLoc(TL.getNameLoc());
3506
3507 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003508}
Mike Stump1eb44332009-09-09 15:08:12 +00003509
3510template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003511QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003512 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003513 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003514 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003515 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3516 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517 if (!Enum)
3518 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003519
John McCalla2becad2009-10-21 00:40:46 +00003520 QualType Result = TL.getType();
3521 if (getDerived().AlwaysRebuild() ||
3522 Enum != T->getDecl()) {
3523 Result = getDerived().RebuildEnumType(Enum);
3524 if (Result.isNull())
3525 return QualType();
3526 }
Mike Stump1eb44332009-09-09 15:08:12 +00003527
John McCalla2becad2009-10-21 00:40:46 +00003528 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3529 NewTL.setNameLoc(TL.getNameLoc());
3530
3531 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003532}
John McCall7da24312009-09-05 00:15:47 +00003533
John McCall3cb0ebd2010-03-10 03:28:59 +00003534template<typename Derived>
3535QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3536 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003537 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003538 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3539 TL.getTypePtr()->getDecl());
3540 if (!D) return QualType();
3541
3542 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3543 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3544 return T;
3545}
3546
Mike Stump1eb44332009-09-09 15:08:12 +00003547
Douglas Gregor577f75a2009-08-04 16:50:30 +00003548template<typename Derived>
3549QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003550 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003551 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003552 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003553}
3554
Mike Stump1eb44332009-09-09 15:08:12 +00003555template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003556QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003557 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003558 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003559 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003560}
3561
3562template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003563QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003564 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003565 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003566 const TemplateSpecializationType *T = TL.getTypePtr();
3567
Mike Stump1eb44332009-09-09 15:08:12 +00003568 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003569 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570 if (Template.isNull())
3571 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003572
John McCall43fed0d2010-11-12 08:19:04 +00003573 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3574}
3575
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003576namespace {
3577 /// \brief Simple iterator that traverses the template arguments in a
3578 /// container that provides a \c getArgLoc() member function.
3579 ///
3580 /// This iterator is intended to be used with the iterator form of
3581 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3582 template<typename ArgLocContainer>
3583 class TemplateArgumentLocContainerIterator {
3584 ArgLocContainer *Container;
3585 unsigned Index;
3586
3587 public:
3588 typedef TemplateArgumentLoc value_type;
3589 typedef TemplateArgumentLoc reference;
3590 typedef int difference_type;
3591 typedef std::input_iterator_tag iterator_category;
3592
3593 class pointer {
3594 TemplateArgumentLoc Arg;
3595
3596 public:
3597 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3598
3599 const TemplateArgumentLoc *operator->() const {
3600 return &Arg;
3601 }
3602 };
3603
3604
3605 TemplateArgumentLocContainerIterator() {}
3606
3607 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3608 unsigned Index)
3609 : Container(&Container), Index(Index) { }
3610
3611 TemplateArgumentLocContainerIterator &operator++() {
3612 ++Index;
3613 return *this;
3614 }
3615
3616 TemplateArgumentLocContainerIterator operator++(int) {
3617 TemplateArgumentLocContainerIterator Old(*this);
3618 ++(*this);
3619 return Old;
3620 }
3621
3622 TemplateArgumentLoc operator*() const {
3623 return Container->getArgLoc(Index);
3624 }
3625
3626 pointer operator->() const {
3627 return pointer(Container->getArgLoc(Index));
3628 }
3629
3630 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003631 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003632 return X.Container == Y.Container && X.Index == Y.Index;
3633 }
3634
3635 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003636 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003637 return !(X == Y);
3638 }
3639 };
3640}
3641
3642
John McCall43fed0d2010-11-12 08:19:04 +00003643template <typename Derived>
3644QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3645 TypeLocBuilder &TLB,
3646 TemplateSpecializationTypeLoc TL,
3647 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00003648 TemplateArgumentListInfo NewTemplateArgs;
3649 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3650 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003651 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3652 ArgIterator;
3653 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3654 ArgIterator(TL, TL.getNumArgs()),
3655 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003656 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003657
John McCall833ca992009-10-29 08:12:44 +00003658 // FIXME: maybe don't rebuild if all the template arguments are the same.
3659
3660 QualType Result =
3661 getDerived().RebuildTemplateSpecializationType(Template,
3662 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003663 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003664
3665 if (!Result.isNull()) {
3666 TemplateSpecializationTypeLoc NewTL
3667 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3668 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3669 NewTL.setLAngleLoc(TL.getLAngleLoc());
3670 NewTL.setRAngleLoc(TL.getRAngleLoc());
3671 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3672 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003673 }
Mike Stump1eb44332009-09-09 15:08:12 +00003674
John McCall833ca992009-10-29 08:12:44 +00003675 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
Mike Stump1eb44332009-09-09 15:08:12 +00003677
3678template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003679QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003680TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003681 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003682 ElaboratedType *T = TL.getTypePtr();
3683
3684 NestedNameSpecifier *NNS = 0;
3685 // NOTE: the qualifier in an ElaboratedType is optional.
3686 if (T->getQualifier() != 0) {
3687 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003688 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003689 if (!NNS)
3690 return QualType();
3691 }
Mike Stump1eb44332009-09-09 15:08:12 +00003692
John McCall43fed0d2010-11-12 08:19:04 +00003693 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3694 if (NamedT.isNull())
3695 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00003696
John McCalla2becad2009-10-21 00:40:46 +00003697 QualType Result = TL.getType();
3698 if (getDerived().AlwaysRebuild() ||
3699 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003700 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003701 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3702 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003703 if (Result.isNull())
3704 return QualType();
3705 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003706
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003707 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003708 NewTL.setKeywordLoc(TL.getKeywordLoc());
3709 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003710
3711 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003712}
Mike Stump1eb44332009-09-09 15:08:12 +00003713
3714template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00003715QualType
3716TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3717 ParenTypeLoc TL) {
3718 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3719 if (Inner.isNull())
3720 return QualType();
3721
3722 QualType Result = TL.getType();
3723 if (getDerived().AlwaysRebuild() ||
3724 Inner != TL.getInnerLoc().getType()) {
3725 Result = getDerived().RebuildParenType(Inner);
3726 if (Result.isNull())
3727 return QualType();
3728 }
3729
3730 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3731 NewTL.setLParenLoc(TL.getLParenLoc());
3732 NewTL.setRParenLoc(TL.getRParenLoc());
3733 return Result;
3734}
3735
3736template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003737QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003738 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003739 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003740
Douglas Gregor577f75a2009-08-04 16:50:30 +00003741 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003742 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003743 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003744 if (!NNS)
3745 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003746
John McCall33500952010-06-11 00:33:02 +00003747 QualType Result
3748 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3749 T->getIdentifier(),
3750 TL.getKeywordLoc(),
3751 TL.getQualifierRange(),
3752 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003753 if (Result.isNull())
3754 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003755
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003756 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3757 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003758 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3759
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003760 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3761 NewTL.setKeywordLoc(TL.getKeywordLoc());
3762 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003763 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003764 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3765 NewTL.setKeywordLoc(TL.getKeywordLoc());
3766 NewTL.setQualifierRange(TL.getQualifierRange());
3767 NewTL.setNameLoc(TL.getNameLoc());
3768 }
John McCalla2becad2009-10-21 00:40:46 +00003769 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003770}
Mike Stump1eb44332009-09-09 15:08:12 +00003771
Douglas Gregor577f75a2009-08-04 16:50:30 +00003772template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003773QualType TreeTransform<Derived>::
3774 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003775 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00003776 DependentTemplateSpecializationType *T = TL.getTypePtr();
3777
3778 NestedNameSpecifier *NNS
3779 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003780 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003781 if (!NNS)
3782 return QualType();
3783
John McCall43fed0d2010-11-12 08:19:04 +00003784 return getDerived()
3785 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3786}
3787
3788template<typename Derived>
3789QualType TreeTransform<Derived>::
3790 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3791 DependentTemplateSpecializationTypeLoc TL,
3792 NestedNameSpecifier *NNS) {
3793 DependentTemplateSpecializationType *T = TL.getTypePtr();
3794
John McCall33500952010-06-11 00:33:02 +00003795 TemplateArgumentListInfo NewTemplateArgs;
3796 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3797 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003798
3799 typedef TemplateArgumentLocContainerIterator<
3800 DependentTemplateSpecializationTypeLoc> ArgIterator;
3801 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3802 ArgIterator(TL, TL.getNumArgs()),
3803 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003804 return QualType();
John McCall33500952010-06-11 00:33:02 +00003805
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003806 QualType Result
3807 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3808 NNS,
3809 TL.getQualifierRange(),
3810 T->getIdentifier(),
3811 TL.getNameLoc(),
3812 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003813 if (Result.isNull())
3814 return QualType();
3815
3816 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3817 QualType NamedT = ElabT->getNamedType();
3818
3819 // Copy information relevant to the template specialization.
3820 TemplateSpecializationTypeLoc NamedTL
3821 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3822 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3823 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3824 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3825 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3826
3827 // Copy information relevant to the elaborated type.
3828 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3829 NewTL.setKeywordLoc(TL.getKeywordLoc());
3830 NewTL.setQualifierRange(TL.getQualifierRange());
3831 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003832 TypeLoc NewTL(Result, TL.getOpaqueData());
3833 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003834 }
3835 return Result;
3836}
3837
3838template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00003839QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3840 PackExpansionTypeLoc TL) {
3841 // FIXME: Implement!
3842 getSema().Diag(TL.getEllipsisLoc(),
3843 diag::err_pack_expansion_instantiation_unsupported);
3844 return QualType();
3845}
3846
3847template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003848QualType
3849TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003850 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003851 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003852 TLB.pushFullCopy(TL);
3853 return TL.getType();
3854}
3855
3856template<typename Derived>
3857QualType
3858TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003859 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00003860 // ObjCObjectType is never dependent.
3861 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003862 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003863}
Mike Stump1eb44332009-09-09 15:08:12 +00003864
3865template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003866QualType
3867TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003868 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003869 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003870 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003871 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003872}
3873
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003875// Statement transformation
3876//===----------------------------------------------------------------------===//
3877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003878StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003879TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00003880 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003881}
3882
3883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003884StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00003885TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3886 return getDerived().TransformCompoundStmt(S, false);
3887}
3888
3889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003890StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003891TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003892 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00003893 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00003894 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00003895 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00003896 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3897 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00003898 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00003899 if (Result.isInvalid()) {
3900 // Immediately fail if this was a DeclStmt, since it's very
3901 // likely that this will cause problems for future statements.
3902 if (isa<DeclStmt>(*B))
3903 return StmtError();
3904
3905 // Otherwise, just keep processing substatements and fail later.
3906 SubStmtInvalid = true;
3907 continue;
3908 }
Mike Stump1eb44332009-09-09 15:08:12 +00003909
Douglas Gregor43959a92009-08-20 07:17:43 +00003910 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3911 Statements.push_back(Result.takeAs<Stmt>());
3912 }
Mike Stump1eb44332009-09-09 15:08:12 +00003913
John McCall7114cba2010-08-27 19:56:05 +00003914 if (SubStmtInvalid)
3915 return StmtError();
3916
Douglas Gregor43959a92009-08-20 07:17:43 +00003917 if (!getDerived().AlwaysRebuild() &&
3918 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00003919 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00003920
3921 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3922 move_arg(Statements),
3923 S->getRBracLoc(),
3924 IsStmtExpr);
3925}
Mike Stump1eb44332009-09-09 15:08:12 +00003926
Douglas Gregor43959a92009-08-20 07:17:43 +00003927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003928StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003929TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003930 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00003931 {
3932 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00003933 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003934
Eli Friedman264c1f82009-11-19 03:14:00 +00003935 // Transform the left-hand case value.
3936 LHS = getDerived().TransformExpr(S->getLHS());
3937 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003938 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003939
Eli Friedman264c1f82009-11-19 03:14:00 +00003940 // Transform the right-hand case value (for the GNU case-range extension).
3941 RHS = getDerived().TransformExpr(S->getRHS());
3942 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003943 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00003944 }
Mike Stump1eb44332009-09-09 15:08:12 +00003945
Douglas Gregor43959a92009-08-20 07:17:43 +00003946 // Build the case statement.
3947 // Case statements are always rebuilt so that they will attached to their
3948 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00003949 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003950 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003951 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003952 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003953 S->getColonLoc());
3954 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003955 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003956
Douglas Gregor43959a92009-08-20 07:17:43 +00003957 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00003958 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003959 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003960 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003961
Douglas Gregor43959a92009-08-20 07:17:43 +00003962 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00003963 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003964}
3965
3966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003967StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003968TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003969 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00003970 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003971 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003972 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003973
Douglas Gregor43959a92009-08-20 07:17:43 +00003974 // Default statements are always rebuilt
3975 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00003976 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00003977}
Mike Stump1eb44332009-09-09 15:08:12 +00003978
Douglas Gregor43959a92009-08-20 07:17:43 +00003979template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003980StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003981TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00003982 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00003983 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00003984 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003985
Douglas Gregor43959a92009-08-20 07:17:43 +00003986 // FIXME: Pass the real colon location in.
3987 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3988 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00003989 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00003990}
Mike Stump1eb44332009-09-09 15:08:12 +00003991
Douglas Gregor43959a92009-08-20 07:17:43 +00003992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00003993StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003994TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003995 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00003996 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003997 VarDecl *ConditionVar = 0;
3998 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00003999 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004000 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004001 getDerived().TransformDefinition(
4002 S->getConditionVariable()->getLocation(),
4003 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004004 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004005 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004006 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004007 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004008
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004009 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004010 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004011
4012 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004013 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004014 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4015 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004016 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004017 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004018
John McCall9ae2f072010-08-23 23:25:46 +00004019 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004020 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004021 }
Sean Huntc3021132010-05-05 15:23:54 +00004022
John McCall9ae2f072010-08-23 23:25:46 +00004023 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4024 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004025 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004026
Douglas Gregor43959a92009-08-20 07:17:43 +00004027 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004028 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004029 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004030 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004031
Douglas Gregor43959a92009-08-20 07:17:43 +00004032 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004033 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004034 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004035 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004036
Douglas Gregor43959a92009-08-20 07:17:43 +00004037 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004038 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004039 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004040 Then.get() == S->getThen() &&
4041 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004042 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004043
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004044 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004045 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004046 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004047}
4048
4049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004050StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004051TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004052 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004053 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004054 VarDecl *ConditionVar = 0;
4055 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004056 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004057 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004058 getDerived().TransformDefinition(
4059 S->getConditionVariable()->getLocation(),
4060 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004061 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004062 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004063 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004064 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004065
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004066 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004067 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004068 }
Mike Stump1eb44332009-09-09 15:08:12 +00004069
Douglas Gregor43959a92009-08-20 07:17:43 +00004070 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004071 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004072 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004073 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004074 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004075 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004076
Douglas Gregor43959a92009-08-20 07:17:43 +00004077 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004078 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004079 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004080 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004081
Douglas Gregor43959a92009-08-20 07:17:43 +00004082 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004083 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4084 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004085}
Mike Stump1eb44332009-09-09 15:08:12 +00004086
Douglas Gregor43959a92009-08-20 07:17:43 +00004087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004088StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004089TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004090 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004091 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004092 VarDecl *ConditionVar = 0;
4093 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004094 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004095 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004096 getDerived().TransformDefinition(
4097 S->getConditionVariable()->getLocation(),
4098 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004099 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004100 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004101 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004102 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004103
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004104 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004105 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004106
4107 if (S->getCond()) {
4108 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004109 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4110 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004111 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004112 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004113 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004114 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004115 }
Mike Stump1eb44332009-09-09 15:08:12 +00004116
John McCall9ae2f072010-08-23 23:25:46 +00004117 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4118 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004119 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004120
Douglas Gregor43959a92009-08-20 07:17:43 +00004121 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004122 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004123 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004124 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004125
Douglas Gregor43959a92009-08-20 07:17:43 +00004126 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004127 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004128 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004129 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004130 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004131
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004132 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004133 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004134}
Mike Stump1eb44332009-09-09 15:08:12 +00004135
Douglas Gregor43959a92009-08-20 07:17:43 +00004136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004137StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004138TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004139 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004140 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004141 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004142 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004143
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004144 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004145 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004146 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004147 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004148
Douglas Gregor43959a92009-08-20 07:17:43 +00004149 if (!getDerived().AlwaysRebuild() &&
4150 Cond.get() == S->getCond() &&
4151 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004152 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004153
John McCall9ae2f072010-08-23 23:25:46 +00004154 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4155 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004156 S->getRParenLoc());
4157}
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregor43959a92009-08-20 07:17:43 +00004159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004160StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004161TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004162 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004163 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004164 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004165 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004166
Douglas Gregor43959a92009-08-20 07:17:43 +00004167 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004168 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004169 VarDecl *ConditionVar = 0;
4170 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004171 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004172 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004173 getDerived().TransformDefinition(
4174 S->getConditionVariable()->getLocation(),
4175 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004176 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004177 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004178 } else {
4179 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004180
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004181 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004182 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004183
4184 if (S->getCond()) {
4185 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004186 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4187 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004188 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004189 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004190
John McCall9ae2f072010-08-23 23:25:46 +00004191 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004192 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004193 }
Mike Stump1eb44332009-09-09 15:08:12 +00004194
John McCall9ae2f072010-08-23 23:25:46 +00004195 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4196 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004197 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004198
Douglas Gregor43959a92009-08-20 07:17:43 +00004199 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004200 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004201 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
John McCall9ae2f072010-08-23 23:25:46 +00004204 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4205 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004206 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004207
Douglas Gregor43959a92009-08-20 07:17:43 +00004208 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004209 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004210 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004211 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004212
Douglas Gregor43959a92009-08-20 07:17:43 +00004213 if (!getDerived().AlwaysRebuild() &&
4214 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004215 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004216 Inc.get() == S->getInc() &&
4217 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004218 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004219
Douglas Gregor43959a92009-08-20 07:17:43 +00004220 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004221 Init.get(), FullCond, ConditionVar,
4222 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004223}
4224
4225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004226StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004227TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004228 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004229 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004230 S->getLabel());
4231}
4232
4233template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004234StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004235TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004236 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004237 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004238 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004239
Douglas Gregor43959a92009-08-20 07:17:43 +00004240 if (!getDerived().AlwaysRebuild() &&
4241 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004242 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004243
4244 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004245 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004246}
4247
4248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004249StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004250TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004251 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004252}
Mike Stump1eb44332009-09-09 15:08:12 +00004253
Douglas Gregor43959a92009-08-20 07:17:43 +00004254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004255StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004256TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004257 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004258}
Mike Stump1eb44332009-09-09 15:08:12 +00004259
Douglas Gregor43959a92009-08-20 07:17:43 +00004260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004261StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004262TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004263 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004264 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004265 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004266
Mike Stump1eb44332009-09-09 15:08:12 +00004267 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004268 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004269 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004270}
Mike Stump1eb44332009-09-09 15:08:12 +00004271
Douglas Gregor43959a92009-08-20 07:17:43 +00004272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004273StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004274TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004275 bool DeclChanged = false;
4276 llvm::SmallVector<Decl *, 4> Decls;
4277 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4278 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004279 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4280 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004281 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004282 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004283
Douglas Gregor43959a92009-08-20 07:17:43 +00004284 if (Transformed != *D)
4285 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004286
Douglas Gregor43959a92009-08-20 07:17:43 +00004287 Decls.push_back(Transformed);
4288 }
Mike Stump1eb44332009-09-09 15:08:12 +00004289
Douglas Gregor43959a92009-08-20 07:17:43 +00004290 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004291 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004292
4293 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004294 S->getStartLoc(), S->getEndLoc());
4295}
Mike Stump1eb44332009-09-09 15:08:12 +00004296
Douglas Gregor43959a92009-08-20 07:17:43 +00004297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004298StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004299TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004300 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004301 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004302}
4303
4304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004305StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004306TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004307
John McCallca0408f2010-08-23 06:44:23 +00004308 ASTOwningVector<Expr*> Constraints(getSema());
4309 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004310 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004311
John McCall60d7b3a2010-08-24 06:29:42 +00004312 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004313 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004314
4315 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004316
Anders Carlsson703e3942010-01-24 05:50:09 +00004317 // Go through the outputs.
4318 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004319 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004320
Anders Carlsson703e3942010-01-24 05:50:09 +00004321 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004322 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004323
Anders Carlsson703e3942010-01-24 05:50:09 +00004324 // Transform the output expr.
4325 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004326 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004327 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004328 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004329
Anders Carlsson703e3942010-01-24 05:50:09 +00004330 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004331
John McCall9ae2f072010-08-23 23:25:46 +00004332 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004333 }
Sean Huntc3021132010-05-05 15:23:54 +00004334
Anders Carlsson703e3942010-01-24 05:50:09 +00004335 // Go through the inputs.
4336 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004337 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004338
Anders Carlsson703e3942010-01-24 05:50:09 +00004339 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004340 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004341
Anders Carlsson703e3942010-01-24 05:50:09 +00004342 // Transform the input expr.
4343 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004344 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004345 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004346 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004347
Anders Carlsson703e3942010-01-24 05:50:09 +00004348 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004349
John McCall9ae2f072010-08-23 23:25:46 +00004350 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004351 }
Sean Huntc3021132010-05-05 15:23:54 +00004352
Anders Carlsson703e3942010-01-24 05:50:09 +00004353 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004354 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004355
4356 // Go through the clobbers.
4357 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004358 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004359
4360 // No need to transform the asm string literal.
4361 AsmString = SemaRef.Owned(S->getAsmString());
4362
4363 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4364 S->isSimple(),
4365 S->isVolatile(),
4366 S->getNumOutputs(),
4367 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004368 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004369 move_arg(Constraints),
4370 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004371 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004372 move_arg(Clobbers),
4373 S->getRParenLoc(),
4374 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004375}
4376
4377
4378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004379StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004380TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004381 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004382 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004383 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004384 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004385
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004386 // Transform the @catch statements (if present).
4387 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004388 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004389 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004390 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004391 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004392 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004393 if (Catch.get() != S->getCatchStmt(I))
4394 AnyCatchChanged = true;
4395 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004396 }
Sean Huntc3021132010-05-05 15:23:54 +00004397
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004398 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004399 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004400 if (S->getFinallyStmt()) {
4401 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4402 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004403 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004404 }
4405
4406 // If nothing changed, just retain this statement.
4407 if (!getDerived().AlwaysRebuild() &&
4408 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004409 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004410 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004411 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004412
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004413 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004414 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4415 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004416}
Mike Stump1eb44332009-09-09 15:08:12 +00004417
Douglas Gregor43959a92009-08-20 07:17:43 +00004418template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004419StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004420TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004421 // Transform the @catch parameter, if there is one.
4422 VarDecl *Var = 0;
4423 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4424 TypeSourceInfo *TSInfo = 0;
4425 if (FromVar->getTypeSourceInfo()) {
4426 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4427 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004428 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004429 }
Sean Huntc3021132010-05-05 15:23:54 +00004430
Douglas Gregorbe270a02010-04-26 17:57:08 +00004431 QualType T;
4432 if (TSInfo)
4433 T = TSInfo->getType();
4434 else {
4435 T = getDerived().TransformType(FromVar->getType());
4436 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004437 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004438 }
Sean Huntc3021132010-05-05 15:23:54 +00004439
Douglas Gregorbe270a02010-04-26 17:57:08 +00004440 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4441 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004442 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004443 }
Sean Huntc3021132010-05-05 15:23:54 +00004444
John McCall60d7b3a2010-08-24 06:29:42 +00004445 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004446 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004447 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004448
4449 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004450 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004451 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004452}
Mike Stump1eb44332009-09-09 15:08:12 +00004453
Douglas Gregor43959a92009-08-20 07:17:43 +00004454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004455StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004456TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004457 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004458 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004459 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004460 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004461
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004462 // If nothing changed, just retain this statement.
4463 if (!getDerived().AlwaysRebuild() &&
4464 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004465 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004466
4467 // Build a new statement.
4468 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004469 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004470}
Mike Stump1eb44332009-09-09 15:08:12 +00004471
Douglas Gregor43959a92009-08-20 07:17:43 +00004472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004473StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004474TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004475 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004476 if (S->getThrowExpr()) {
4477 Operand = getDerived().TransformExpr(S->getThrowExpr());
4478 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004479 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004480 }
Sean Huntc3021132010-05-05 15:23:54 +00004481
Douglas Gregord1377b22010-04-22 21:44:01 +00004482 if (!getDerived().AlwaysRebuild() &&
4483 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004484 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004485
John McCall9ae2f072010-08-23 23:25:46 +00004486 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004487}
Mike Stump1eb44332009-09-09 15:08:12 +00004488
Douglas Gregor43959a92009-08-20 07:17:43 +00004489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004490StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004491TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004492 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004493 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004494 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004495 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004496 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004497
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004498 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004499 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004500 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004501 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004502
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004503 // If nothing change, just retain the current statement.
4504 if (!getDerived().AlwaysRebuild() &&
4505 Object.get() == S->getSynchExpr() &&
4506 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004507 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004508
4509 // Build a new statement.
4510 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004511 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004512}
4513
4514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004515StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004516TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004517 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004518 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004519 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004520 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004521 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004522
Douglas Gregorc3203e72010-04-22 23:10:45 +00004523 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004524 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004525 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004526 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004527
Douglas Gregorc3203e72010-04-22 23:10:45 +00004528 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004529 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004530 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004531 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004532
Douglas Gregorc3203e72010-04-22 23:10:45 +00004533 // If nothing changed, just retain this statement.
4534 if (!getDerived().AlwaysRebuild() &&
4535 Element.get() == S->getElement() &&
4536 Collection.get() == S->getCollection() &&
4537 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004538 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004539
Douglas Gregorc3203e72010-04-22 23:10:45 +00004540 // Build a new statement.
4541 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4542 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004543 Element.get(),
4544 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004545 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004546 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004547}
4548
4549
4550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004551StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004552TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4553 // Transform the exception declaration, if any.
4554 VarDecl *Var = 0;
4555 if (S->getExceptionDecl()) {
4556 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004557 TypeSourceInfo *T = getDerived().TransformType(
4558 ExceptionDecl->getTypeSourceInfo());
4559 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004560 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004561
Douglas Gregor83cb9422010-09-09 17:09:21 +00004562 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004563 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004564 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004565 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004566 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004567 }
Mike Stump1eb44332009-09-09 15:08:12 +00004568
Douglas Gregor43959a92009-08-20 07:17:43 +00004569 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004570 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004571 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004572 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004573
Douglas Gregor43959a92009-08-20 07:17:43 +00004574 if (!getDerived().AlwaysRebuild() &&
4575 !Var &&
4576 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004577 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004578
4579 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4580 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004581 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004582}
Mike Stump1eb44332009-09-09 15:08:12 +00004583
Douglas Gregor43959a92009-08-20 07:17:43 +00004584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004585StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004586TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4587 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004588 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004589 = getDerived().TransformCompoundStmt(S->getTryBlock());
4590 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004591 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004592
Douglas Gregor43959a92009-08-20 07:17:43 +00004593 // Transform the handlers.
4594 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004595 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004596 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004597 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004598 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4599 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004600 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004601
Douglas Gregor43959a92009-08-20 07:17:43 +00004602 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4603 Handlers.push_back(Handler.takeAs<Stmt>());
4604 }
Mike Stump1eb44332009-09-09 15:08:12 +00004605
Douglas Gregor43959a92009-08-20 07:17:43 +00004606 if (!getDerived().AlwaysRebuild() &&
4607 TryBlock.get() == S->getTryBlock() &&
4608 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004609 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004610
John McCall9ae2f072010-08-23 23:25:46 +00004611 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004612 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004613}
Mike Stump1eb44332009-09-09 15:08:12 +00004614
Douglas Gregor43959a92009-08-20 07:17:43 +00004615//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004616// Expression transformation
4617//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004619ExprResult
John McCall454feb92009-12-08 09:21:05 +00004620TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004621 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004622}
Mike Stump1eb44332009-09-09 15:08:12 +00004623
4624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004625ExprResult
John McCall454feb92009-12-08 09:21:05 +00004626TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004627 NestedNameSpecifier *Qualifier = 0;
4628 if (E->getQualifier()) {
4629 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004630 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004631 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004632 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004633 }
John McCalldbd872f2009-12-08 09:08:17 +00004634
4635 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004636 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4637 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004638 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004639 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004640
John McCallec8045d2010-08-17 21:27:17 +00004641 DeclarationNameInfo NameInfo = E->getNameInfo();
4642 if (NameInfo.getName()) {
4643 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4644 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004645 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004646 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004647
4648 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004649 Qualifier == E->getQualifier() &&
4650 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004651 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004652 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004653
4654 // Mark it referenced in the new context regardless.
4655 // FIXME: this is a bit instantiation-specific.
4656 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4657
John McCall3fa5cae2010-10-26 07:05:15 +00004658 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004659 }
John McCalldbd872f2009-12-08 09:08:17 +00004660
4661 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004662 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004663 TemplateArgs = &TransArgs;
4664 TransArgs.setLAngleLoc(E->getLAngleLoc());
4665 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00004666 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4667 E->getNumTemplateArgs(),
4668 TransArgs))
4669 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004670 }
4671
Douglas Gregora2813ce2009-10-23 18:54:35 +00004672 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004673 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004674}
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004677ExprResult
John McCall454feb92009-12-08 09:21:05 +00004678TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004679 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004680}
Mike Stump1eb44332009-09-09 15:08:12 +00004681
Douglas Gregorb98b1992009-08-11 05:31:07 +00004682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004683ExprResult
John McCall454feb92009-12-08 09:21:05 +00004684TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004685 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004686}
Mike Stump1eb44332009-09-09 15:08:12 +00004687
Douglas Gregorb98b1992009-08-11 05:31:07 +00004688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004689ExprResult
John McCall454feb92009-12-08 09:21:05 +00004690TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004691 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004692}
Mike Stump1eb44332009-09-09 15:08:12 +00004693
Douglas Gregorb98b1992009-08-11 05:31:07 +00004694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004695ExprResult
John McCall454feb92009-12-08 09:21:05 +00004696TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004697 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698}
Mike Stump1eb44332009-09-09 15:08:12 +00004699
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004701ExprResult
John McCall454feb92009-12-08 09:21:05 +00004702TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004703 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004704}
4705
4706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004707ExprResult
John McCall454feb92009-12-08 09:21:05 +00004708TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004709 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004710 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004712
Douglas Gregorb98b1992009-08-11 05:31:07 +00004713 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004714 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004715
John McCall9ae2f072010-08-23 23:25:46 +00004716 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004717 E->getRParen());
4718}
4719
Mike Stump1eb44332009-09-09 15:08:12 +00004720template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004721ExprResult
John McCall454feb92009-12-08 09:21:05 +00004722TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004723 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004725 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004726
Douglas Gregorb98b1992009-08-11 05:31:07 +00004727 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004728 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004729
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4731 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004732 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004733}
Mike Stump1eb44332009-09-09 15:08:12 +00004734
Douglas Gregorb98b1992009-08-11 05:31:07 +00004735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004736ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004737TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4738 // Transform the type.
4739 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4740 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004741 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004742
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004743 // Transform all of the components into components similar to what the
4744 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004745 // FIXME: It would be slightly more efficient in the non-dependent case to
4746 // just map FieldDecls, rather than requiring the rebuilder to look for
4747 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004748 // template code that we don't care.
4749 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004750 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004751 typedef OffsetOfExpr::OffsetOfNode Node;
4752 llvm::SmallVector<Component, 4> Components;
4753 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4754 const Node &ON = E->getComponent(I);
4755 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004756 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004757 Comp.LocStart = ON.getRange().getBegin();
4758 Comp.LocEnd = ON.getRange().getEnd();
4759 switch (ON.getKind()) {
4760 case Node::Array: {
4761 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004762 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004763 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004764 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004765
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004766 ExprChanged = ExprChanged || Index.get() != FromIndex;
4767 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004768 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004769 break;
4770 }
Sean Huntc3021132010-05-05 15:23:54 +00004771
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004772 case Node::Field:
4773 case Node::Identifier:
4774 Comp.isBrackets = false;
4775 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004776 if (!Comp.U.IdentInfo)
4777 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004778
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004779 break;
Sean Huntc3021132010-05-05 15:23:54 +00004780
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004781 case Node::Base:
4782 // Will be recomputed during the rebuild.
4783 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004784 }
Sean Huntc3021132010-05-05 15:23:54 +00004785
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004786 Components.push_back(Comp);
4787 }
Sean Huntc3021132010-05-05 15:23:54 +00004788
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004789 // If nothing changed, retain the existing expression.
4790 if (!getDerived().AlwaysRebuild() &&
4791 Type == E->getTypeSourceInfo() &&
4792 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004793 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004794
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004795 // Build a new offsetof expression.
4796 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4797 Components.data(), Components.size(),
4798 E->getRParenLoc());
4799}
4800
4801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004802ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00004803TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4804 assert(getDerived().AlreadyTransformed(E->getType()) &&
4805 "opaque value expression requires transformation");
4806 return SemaRef.Owned(E);
4807}
4808
4809template<typename Derived>
4810ExprResult
John McCall454feb92009-12-08 09:21:05 +00004811TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004812 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004813 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004814
John McCalla93c9342009-12-07 02:54:59 +00004815 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004816 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004818
John McCall5ab75172009-11-04 07:28:41 +00004819 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004820 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004821
John McCall5ab75172009-11-04 07:28:41 +00004822 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004823 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004824 E->getSourceRange());
4825 }
Mike Stump1eb44332009-09-09 15:08:12 +00004826
John McCall60d7b3a2010-08-24 06:29:42 +00004827 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004828 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829 // C++0x [expr.sizeof]p1:
4830 // The operand is either an expression, which is an unevaluated operand
4831 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004832 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004833
Douglas Gregorb98b1992009-08-11 05:31:07 +00004834 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4835 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004837
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004839 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004840 }
Mike Stump1eb44332009-09-09 15:08:12 +00004841
John McCall9ae2f072010-08-23 23:25:46 +00004842 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004843 E->isSizeOf(),
4844 E->getSourceRange());
4845}
Mike Stump1eb44332009-09-09 15:08:12 +00004846
Douglas Gregorb98b1992009-08-11 05:31:07 +00004847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004848ExprResult
John McCall454feb92009-12-08 09:21:05 +00004849TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004850 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004851 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004852 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004853
John McCall60d7b3a2010-08-24 06:29:42 +00004854 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004855 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004857
4858
Douglas Gregorb98b1992009-08-11 05:31:07 +00004859 if (!getDerived().AlwaysRebuild() &&
4860 LHS.get() == E->getLHS() &&
4861 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004862 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004863
John McCall9ae2f072010-08-23 23:25:46 +00004864 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004865 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00004866 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004867 E->getRBracketLoc());
4868}
Mike Stump1eb44332009-09-09 15:08:12 +00004869
4870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004871ExprResult
John McCall454feb92009-12-08 09:21:05 +00004872TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004873 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00004874 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004875 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004876 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00004877
4878 // Transform arguments.
4879 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004880 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004881 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004882 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004884 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004885
Mike Stump1eb44332009-09-09 15:08:12 +00004886 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00004887 Args.push_back(Arg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004888 }
Mike Stump1eb44332009-09-09 15:08:12 +00004889
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890 if (!getDerived().AlwaysRebuild() &&
4891 Callee.get() == E->getCallee() &&
4892 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004893 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004894
Douglas Gregorb98b1992009-08-11 05:31:07 +00004895 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00004896 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004897 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00004898 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004899 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004900 E->getRParenLoc());
4901}
Mike Stump1eb44332009-09-09 15:08:12 +00004902
4903template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004904ExprResult
John McCall454feb92009-12-08 09:21:05 +00004905TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004906 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004907 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004908 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004909
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004910 NestedNameSpecifier *Qualifier = 0;
4911 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00004912 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004913 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004914 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00004915 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00004916 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004917 }
Mike Stump1eb44332009-09-09 15:08:12 +00004918
Eli Friedmanf595cc42009-12-04 06:40:45 +00004919 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004920 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4921 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004922 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00004923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004924
John McCall6bb80172010-03-30 21:47:33 +00004925 NamedDecl *FoundDecl = E->getFoundDecl();
4926 if (FoundDecl == E->getMemberDecl()) {
4927 FoundDecl = Member;
4928 } else {
4929 FoundDecl = cast_or_null<NamedDecl>(
4930 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4931 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00004932 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00004933 }
4934
Douglas Gregorb98b1992009-08-11 05:31:07 +00004935 if (!getDerived().AlwaysRebuild() &&
4936 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004937 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004938 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00004939 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00004940 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00004941
Anders Carlsson1f240322009-12-22 05:24:09 +00004942 // Mark it referenced in the new context regardless.
4943 // FIXME: this is a bit instantiation-specific.
4944 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00004945 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00004946 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004947
John McCalld5532b62009-11-23 01:53:49 +00004948 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00004949 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00004950 TransArgs.setLAngleLoc(E->getLAngleLoc());
4951 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00004952 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4953 E->getNumTemplateArgs(),
4954 TransArgs))
4955 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004956 }
Sean Huntc3021132010-05-05 15:23:54 +00004957
Douglas Gregorb98b1992009-08-11 05:31:07 +00004958 // FIXME: Bogus source location for the operator
4959 SourceLocation FakeOperatorLoc
4960 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4961
John McCallc2233c52010-01-15 08:34:02 +00004962 // FIXME: to do this check properly, we will need to preserve the
4963 // first-qualifier-in-scope here, just in case we had a dependent
4964 // base (and therefore couldn't do the check) and a
4965 // nested-name-qualifier (and therefore could do the lookup).
4966 NamedDecl *FirstQualifierInScope = 0;
4967
John McCall9ae2f072010-08-23 23:25:46 +00004968 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004969 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00004970 Qualifier,
4971 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004972 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00004973 Member,
John McCall6bb80172010-03-30 21:47:33 +00004974 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00004975 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00004976 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00004977 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004978}
Mike Stump1eb44332009-09-09 15:08:12 +00004979
Douglas Gregorb98b1992009-08-11 05:31:07 +00004980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004981ExprResult
John McCall454feb92009-12-08 09:21:05 +00004982TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004983 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004984 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004985 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004986
John McCall60d7b3a2010-08-24 06:29:42 +00004987 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004989 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004990
Douglas Gregorb98b1992009-08-11 05:31:07 +00004991 if (!getDerived().AlwaysRebuild() &&
4992 LHS.get() == E->getLHS() &&
4993 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004994 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004995
Douglas Gregorb98b1992009-08-11 05:31:07 +00004996 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004997 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004998}
4999
Mike Stump1eb44332009-09-09 15:08:12 +00005000template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005001ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005003 CompoundAssignOperator *E) {
5004 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005005}
Mike Stump1eb44332009-09-09 15:08:12 +00005006
Douglas Gregorb98b1992009-08-11 05:31:07 +00005007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005008ExprResult
John McCall454feb92009-12-08 09:21:05 +00005009TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005010 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005012 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005013
John McCall60d7b3a2010-08-24 06:29:42 +00005014 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005015 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005016 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005017
John McCall60d7b3a2010-08-24 06:29:42 +00005018 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005019 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005020 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005021
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022 if (!getDerived().AlwaysRebuild() &&
5023 Cond.get() == E->getCond() &&
5024 LHS.get() == E->getLHS() &&
5025 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005026 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005027
John McCall9ae2f072010-08-23 23:25:46 +00005028 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005029 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005030 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005031 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005032 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005033}
Mike Stump1eb44332009-09-09 15:08:12 +00005034
5035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005036ExprResult
John McCall454feb92009-12-08 09:21:05 +00005037TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005038 // Implicit casts are eliminated during transformation, since they
5039 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005040 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005041}
Mike Stump1eb44332009-09-09 15:08:12 +00005042
Douglas Gregorb98b1992009-08-11 05:31:07 +00005043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005044ExprResult
John McCall454feb92009-12-08 09:21:05 +00005045TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005046 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5047 if (!Type)
5048 return ExprError();
5049
John McCall60d7b3a2010-08-24 06:29:42 +00005050 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005051 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005052 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005053 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005054
Douglas Gregorb98b1992009-08-11 05:31:07 +00005055 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005056 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005057 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005058 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005059
John McCall9d125032010-01-15 18:39:57 +00005060 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005061 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005062 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005063 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005064}
Mike Stump1eb44332009-09-09 15:08:12 +00005065
Douglas Gregorb98b1992009-08-11 05:31:07 +00005066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005067ExprResult
John McCall454feb92009-12-08 09:21:05 +00005068TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005069 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5070 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5071 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005073
John McCall60d7b3a2010-08-24 06:29:42 +00005074 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005075 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005076 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005077
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005079 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005081 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005082
John McCall1d7d8d62010-01-19 22:33:45 +00005083 // Note: the expression type doesn't necessarily match the
5084 // type-as-written, but that's okay, because it should always be
5085 // derivable from the initializer.
5086
John McCall42f56b52010-01-18 19:35:47 +00005087 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005089 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090}
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093ExprResult
John McCall454feb92009-12-08 09:21:05 +00005094TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005095 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005096 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005098
Douglas Gregorb98b1992009-08-11 05:31:07 +00005099 if (!getDerived().AlwaysRebuild() &&
5100 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005101 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005102
Douglas Gregorb98b1992009-08-11 05:31:07 +00005103 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005104 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005105 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005106 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 E->getAccessorLoc(),
5108 E->getAccessor());
5109}
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005112ExprResult
John McCall454feb92009-12-08 09:21:05 +00005113TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005114 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005115
John McCallca0408f2010-08-23 06:44:23 +00005116 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005117 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005118 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCall9ae2f072010-08-23 23:25:46 +00005123 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005124 }
Mike Stump1eb44332009-09-09 15:08:12 +00005125
Douglas Gregorb98b1992009-08-11 05:31:07 +00005126 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005127 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregorb98b1992009-08-11 05:31:07 +00005129 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005130 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131}
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregorb98b1992009-08-11 05:31:07 +00005133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134ExprResult
John McCall454feb92009-12-08 09:21:05 +00005135TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005136 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005139 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005141 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005142
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005144 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145 bool ExprChanged = false;
5146 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5147 DEnd = E->designators_end();
5148 D != DEnd; ++D) {
5149 if (D->isFieldDesignator()) {
5150 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5151 D->getDotLoc(),
5152 D->getFieldLoc()));
5153 continue;
5154 }
Mike Stump1eb44332009-09-09 15:08:12 +00005155
Douglas Gregorb98b1992009-08-11 05:31:07 +00005156 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005157 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005159 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005160
5161 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005162 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregorb98b1992009-08-11 05:31:07 +00005164 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5165 ArrayExprs.push_back(Index.release());
5166 continue;
5167 }
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregorb98b1992009-08-11 05:31:07 +00005169 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005170 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005171 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5172 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005174
John McCall60d7b3a2010-08-24 06:29:42 +00005175 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005176 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005178
5179 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005180 End.get(),
5181 D->getLBracketLoc(),
5182 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5185 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregorb98b1992009-08-11 05:31:07 +00005187 ArrayExprs.push_back(Start.release());
5188 ArrayExprs.push_back(End.release());
5189 }
Mike Stump1eb44332009-09-09 15:08:12 +00005190
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191 if (!getDerived().AlwaysRebuild() &&
5192 Init.get() == E->getInit() &&
5193 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005194 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5197 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005198 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199}
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005202ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005204 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005205 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005206
Douglas Gregor5557b252009-10-28 00:29:27 +00005207 // FIXME: Will we ever have proper type location here? Will we actually
5208 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209 QualType T = getDerived().TransformType(E->getType());
5210 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Douglas Gregorb98b1992009-08-11 05:31:07 +00005213 if (!getDerived().AlwaysRebuild() &&
5214 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005215 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregorb98b1992009-08-11 05:31:07 +00005217 return getDerived().RebuildImplicitValueInitExpr(T);
5218}
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005221ExprResult
John McCall454feb92009-12-08 09:21:05 +00005222TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005223 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5224 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005225 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005226
John McCall60d7b3a2010-08-24 06:29:42 +00005227 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005228 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005229 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregorb98b1992009-08-11 05:31:07 +00005231 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005232 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005234 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005235
John McCall9ae2f072010-08-23 23:25:46 +00005236 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005237 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005238}
5239
5240template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005241ExprResult
John McCall454feb92009-12-08 09:21:05 +00005242TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005243 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005244 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005245 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00005251 Inits.push_back(Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252 }
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregorb98b1992009-08-11 05:31:07 +00005254 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5255 move_arg(Inits),
5256 E->getRParenLoc());
5257}
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259/// \brief Transform an address-of-label expression.
5260///
5261/// By default, the transformation of an address-of-label expression always
5262/// rebuilds the expression, so that the label identifier can be resolved to
5263/// the corresponding label statement by semantic analysis.
5264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005265ExprResult
John McCall454feb92009-12-08 09:21:05 +00005266TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5268 E->getLabel());
5269}
Mike Stump1eb44332009-09-09 15:08:12 +00005270
5271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005272ExprResult
John McCall454feb92009-12-08 09:21:05 +00005273TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005274 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005275 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5276 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005278
Douglas Gregorb98b1992009-08-11 05:31:07 +00005279 if (!getDerived().AlwaysRebuild() &&
5280 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005281 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005282
5283 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005284 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005285 E->getRParenLoc());
5286}
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregorb98b1992009-08-11 05:31:07 +00005288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005289ExprResult
John McCall454feb92009-12-08 09:21:05 +00005290TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005291 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005292 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005294
John McCall60d7b3a2010-08-24 06:29:42 +00005295 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005298
John McCall60d7b3a2010-08-24 06:29:42 +00005299 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005300 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregorb98b1992009-08-11 05:31:07 +00005303 if (!getDerived().AlwaysRebuild() &&
5304 Cond.get() == E->getCond() &&
5305 LHS.get() == E->getLHS() &&
5306 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005307 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregorb98b1992009-08-11 05:31:07 +00005309 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005310 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005311 E->getRParenLoc());
5312}
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregorb98b1992009-08-11 05:31:07 +00005314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005315ExprResult
John McCall454feb92009-12-08 09:21:05 +00005316TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005317 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318}
5319
5320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005321ExprResult
John McCall454feb92009-12-08 09:21:05 +00005322TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005323 switch (E->getOperator()) {
5324 case OO_New:
5325 case OO_Delete:
5326 case OO_Array_New:
5327 case OO_Array_Delete:
5328 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005329 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005330
Douglas Gregor668d6d92009-12-13 20:44:55 +00005331 case OO_Call: {
5332 // This is a call to an object's operator().
5333 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5334
5335 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005336 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005337 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005339
5340 // FIXME: Poor location information
5341 SourceLocation FakeLParenLoc
5342 = SemaRef.PP.getLocForEndOfToken(
5343 static_cast<Expr *>(Object.get())->getLocEnd());
5344
5345 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005346 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor668d6d92009-12-13 20:44:55 +00005347 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00005348 if (getDerived().DropCallArgument(E->getArg(I)))
5349 break;
Sean Huntc3021132010-05-05 15:23:54 +00005350
John McCall60d7b3a2010-08-24 06:29:42 +00005351 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005352 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005354
Douglas Gregor668d6d92009-12-13 20:44:55 +00005355 Args.push_back(Arg.release());
5356 }
5357
John McCall9ae2f072010-08-23 23:25:46 +00005358 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005359 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005360 E->getLocEnd());
5361 }
5362
5363#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5364 case OO_##Name:
5365#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5366#include "clang/Basic/OperatorKinds.def"
5367 case OO_Subscript:
5368 // Handled below.
5369 break;
5370
5371 case OO_Conditional:
5372 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005373 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005374
5375 case OO_None:
5376 case NUM_OVERLOADED_OPERATORS:
5377 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005378 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005379 }
5380
John McCall60d7b3a2010-08-24 06:29:42 +00005381 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005384
John McCall60d7b3a2010-08-24 06:29:42 +00005385 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005386 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005388
John McCall60d7b3a2010-08-24 06:29:42 +00005389 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005390 if (E->getNumArgs() == 2) {
5391 Second = getDerived().TransformExpr(E->getArg(1));
5392 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005393 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394 }
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregorb98b1992009-08-11 05:31:07 +00005396 if (!getDerived().AlwaysRebuild() &&
5397 Callee.get() == E->getCallee() &&
5398 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005399 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005400 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005401
Douglas Gregorb98b1992009-08-11 05:31:07 +00005402 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5403 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005404 Callee.get(),
5405 First.get(),
5406 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005407}
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Douglas Gregorb98b1992009-08-11 05:31:07 +00005409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005410ExprResult
John McCall454feb92009-12-08 09:21:05 +00005411TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5412 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005413}
Mike Stump1eb44332009-09-09 15:08:12 +00005414
Douglas Gregorb98b1992009-08-11 05:31:07 +00005415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005416ExprResult
John McCall454feb92009-12-08 09:21:05 +00005417TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005418 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5419 if (!Type)
5420 return ExprError();
5421
John McCall60d7b3a2010-08-24 06:29:42 +00005422 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005423 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005424 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregorb98b1992009-08-11 05:31:07 +00005427 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005428 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005429 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005430 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregorb98b1992009-08-11 05:31:07 +00005432 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005433 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005434 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5435 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5436 SourceLocation FakeRParenLoc
5437 = SemaRef.PP.getLocForEndOfToken(
5438 E->getSubExpr()->getSourceRange().getEnd());
5439 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005440 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005441 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005442 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005443 FakeRAngleLoc,
5444 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005445 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005446 FakeRParenLoc);
5447}
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregorb98b1992009-08-11 05:31:07 +00005449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005450ExprResult
John McCall454feb92009-12-08 09:21:05 +00005451TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5452 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453}
Mike Stump1eb44332009-09-09 15:08:12 +00005454
5455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005456ExprResult
John McCall454feb92009-12-08 09:21:05 +00005457TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5458 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005459}
5460
Douglas Gregorb98b1992009-08-11 05:31:07 +00005461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005462ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005463TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005464 CXXReinterpretCastExpr *E) {
5465 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005466}
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregorb98b1992009-08-11 05:31:07 +00005468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005469ExprResult
John McCall454feb92009-12-08 09:21:05 +00005470TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5471 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005472}
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregorb98b1992009-08-11 05:31:07 +00005474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005475ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005476TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005477 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005478 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5479 if (!Type)
5480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005481
John McCall60d7b3a2010-08-24 06:29:42 +00005482 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005483 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005484 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005486
Douglas Gregorb98b1992009-08-11 05:31:07 +00005487 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005488 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005489 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005490 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005491
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005492 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005493 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005494 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005495 E->getRParenLoc());
5496}
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregorb98b1992009-08-11 05:31:07 +00005498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499ExprResult
John McCall454feb92009-12-08 09:21:05 +00005500TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005502 TypeSourceInfo *TInfo
5503 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5504 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005505 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregorb98b1992009-08-11 05:31:07 +00005507 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005508 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005509 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005511 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5512 E->getLocStart(),
5513 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005514 E->getLocEnd());
5515 }
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517 // We don't know whether the expression is potentially evaluated until
5518 // after we perform semantic analysis, so the expression is potentially
5519 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005520 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005521 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005522
John McCall60d7b3a2010-08-24 06:29:42 +00005523 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005524 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregorb98b1992009-08-11 05:31:07 +00005527 if (!getDerived().AlwaysRebuild() &&
5528 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005529 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005531 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5532 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005533 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005534 E->getLocEnd());
5535}
5536
5537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005538ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005539TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5540 if (E->isTypeOperand()) {
5541 TypeSourceInfo *TInfo
5542 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5543 if (!TInfo)
5544 return ExprError();
5545
5546 if (!getDerived().AlwaysRebuild() &&
5547 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005548 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005549
5550 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5551 E->getLocStart(),
5552 TInfo,
5553 E->getLocEnd());
5554 }
5555
5556 // We don't know whether the expression is potentially evaluated until
5557 // after we perform semantic analysis, so the expression is potentially
5558 // potentially evaluated.
5559 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5560
5561 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5562 if (SubExpr.isInvalid())
5563 return ExprError();
5564
5565 if (!getDerived().AlwaysRebuild() &&
5566 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005567 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005568
5569 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5570 E->getLocStart(),
5571 SubExpr.get(),
5572 E->getLocEnd());
5573}
5574
5575template<typename Derived>
5576ExprResult
John McCall454feb92009-12-08 09:21:05 +00005577TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005578 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005579}
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005582ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005584 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005585 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005586}
Mike Stump1eb44332009-09-09 15:08:12 +00005587
Douglas Gregorb98b1992009-08-11 05:31:07 +00005588template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005589ExprResult
John McCall454feb92009-12-08 09:21:05 +00005590TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005591 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5592 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5593 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005595 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005596 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005597
Douglas Gregor828a1972010-01-07 23:12:05 +00005598 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005599}
Mike Stump1eb44332009-09-09 15:08:12 +00005600
Douglas Gregorb98b1992009-08-11 05:31:07 +00005601template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005602ExprResult
John McCall454feb92009-12-08 09:21:05 +00005603TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005604 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608 if (!getDerived().AlwaysRebuild() &&
5609 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005610 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005611
John McCall9ae2f072010-08-23 23:25:46 +00005612 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613}
Mike Stump1eb44332009-09-09 15:08:12 +00005614
Douglas Gregorb98b1992009-08-11 05:31:07 +00005615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616ExprResult
John McCall454feb92009-12-08 09:21:05 +00005617TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005618 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005619 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5620 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005621 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005622 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005623
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005624 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005626 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005627
Douglas Gregor036aed12009-12-23 23:03:06 +00005628 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629}
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005632ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005633TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5634 CXXScalarValueInitExpr *E) {
5635 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5636 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005637 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005638
Douglas Gregorb98b1992009-08-11 05:31:07 +00005639 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005640 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005641 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005642
Douglas Gregorab6677e2010-09-08 00:15:04 +00005643 return getDerived().RebuildCXXScalarValueInitExpr(T,
5644 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005645 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005646}
Mike Stump1eb44332009-09-09 15:08:12 +00005647
Douglas Gregorb98b1992009-08-11 05:31:07 +00005648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005649ExprResult
John McCall454feb92009-12-08 09:21:05 +00005650TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005652 TypeSourceInfo *AllocTypeInfo
5653 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5654 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregorb98b1992009-08-11 05:31:07 +00005657 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005658 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005660 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Douglas Gregorb98b1992009-08-11 05:31:07 +00005662 // Transform the placement arguments (if any).
5663 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005664 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005666 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5667 ArgumentChanged = true;
5668 break;
5669 }
5670
John McCall60d7b3a2010-08-24 06:29:42 +00005671 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5676 PlacementArgs.push_back(Arg.take());
5677 }
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Douglas Gregor43959a92009-08-20 07:17:43 +00005679 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005680 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005681 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall63d5fb32010-10-05 22:36:42 +00005682 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5683 ArgumentChanged = true;
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005684 break;
John McCall63d5fb32010-10-05 22:36:42 +00005685 }
Douglas Gregorff2e4f42010-05-26 07:10:06 +00005686
John McCall60d7b3a2010-08-24 06:29:42 +00005687 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5692 ConstructorArgs.push_back(Arg.take());
5693 }
Mike Stump1eb44332009-09-09 15:08:12 +00005694
Douglas Gregor1af74512010-02-26 00:38:10 +00005695 // Transform constructor, new operator, and delete operator.
5696 CXXConstructorDecl *Constructor = 0;
5697 if (E->getConstructor()) {
5698 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005699 getDerived().TransformDecl(E->getLocStart(),
5700 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005701 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005702 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005703 }
5704
5705 FunctionDecl *OperatorNew = 0;
5706 if (E->getOperatorNew()) {
5707 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005708 getDerived().TransformDecl(E->getLocStart(),
5709 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005710 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005711 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005712 }
5713
5714 FunctionDecl *OperatorDelete = 0;
5715 if (E->getOperatorDelete()) {
5716 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005717 getDerived().TransformDecl(E->getLocStart(),
5718 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005719 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005720 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005721 }
Sean Huntc3021132010-05-05 15:23:54 +00005722
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005724 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005725 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005726 Constructor == E->getConstructor() &&
5727 OperatorNew == E->getOperatorNew() &&
5728 OperatorDelete == E->getOperatorDelete() &&
5729 !ArgumentChanged) {
5730 // Mark any declarations we need as referenced.
5731 // FIXME: instantiation-specific.
5732 if (Constructor)
5733 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5734 if (OperatorNew)
5735 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5736 if (OperatorDelete)
5737 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005738 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005739 }
Mike Stump1eb44332009-09-09 15:08:12 +00005740
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005741 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005742 if (!ArraySize.get()) {
5743 // If no array size was specified, but the new expression was
5744 // instantiated with an array type (e.g., "new T" where T is
5745 // instantiated with "int[4]"), extract the outer bound from the
5746 // array type as our array size. We do this with constant and
5747 // dependently-sized array types.
5748 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5749 if (!ArrayT) {
5750 // Do nothing
5751 } else if (const ConstantArrayType *ConsArrayT
5752 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005753 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005754 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5755 ConsArrayT->getSize(),
5756 SemaRef.Context.getSizeType(),
5757 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005758 AllocType = ConsArrayT->getElementType();
5759 } else if (const DependentSizedArrayType *DepArrayT
5760 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5761 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005762 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005763 AllocType = DepArrayT->getElementType();
5764 }
5765 }
5766 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005767
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5769 E->isGlobalNew(),
5770 /*FIXME:*/E->getLocStart(),
5771 move_arg(PlacementArgs),
5772 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005773 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005775 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005776 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 /*FIXME:*/E->getLocStart(),
5778 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005779 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780}
Mike Stump1eb44332009-09-09 15:08:12 +00005781
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005783ExprResult
John McCall454feb92009-12-08 09:21:05 +00005784TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005785 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005786 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005788
Douglas Gregor1af74512010-02-26 00:38:10 +00005789 // Transform the delete operator, if known.
5790 FunctionDecl *OperatorDelete = 0;
5791 if (E->getOperatorDelete()) {
5792 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005793 getDerived().TransformDecl(E->getLocStart(),
5794 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005795 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005796 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005797 }
Sean Huntc3021132010-05-05 15:23:54 +00005798
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005800 Operand.get() == E->getArgument() &&
5801 OperatorDelete == E->getOperatorDelete()) {
5802 // Mark any declarations we need as referenced.
5803 // FIXME: instantiation-specific.
5804 if (OperatorDelete)
5805 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005806
5807 if (!E->getArgument()->isTypeDependent()) {
5808 QualType Destroyed = SemaRef.Context.getBaseElementType(
5809 E->getDestroyedType());
5810 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5811 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5812 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5813 SemaRef.LookupDestructor(Record));
5814 }
5815 }
5816
John McCall3fa5cae2010-10-26 07:05:15 +00005817 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005818 }
Mike Stump1eb44332009-09-09 15:08:12 +00005819
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5821 E->isGlobalDelete(),
5822 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005823 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005824}
Mike Stump1eb44332009-09-09 15:08:12 +00005825
Douglas Gregorb98b1992009-08-11 05:31:07 +00005826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005827ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005828TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005829 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005830 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005831 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005833
John McCallb3d87482010-08-24 05:47:05 +00005834 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005835 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005836 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005837 E->getOperatorLoc(),
5838 E->isArrow()? tok::arrow : tok::period,
5839 ObjectTypePtr,
5840 MayBePseudoDestructor);
5841 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005842 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005843
John McCallb3d87482010-08-24 05:47:05 +00005844 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00005845 NestedNameSpecifier *Qualifier = E->getQualifier();
5846 if (Qualifier) {
5847 Qualifier
5848 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5849 E->getQualifierRange(),
5850 ObjectType);
5851 if (!Qualifier)
5852 return ExprError();
5853 }
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005855 PseudoDestructorTypeStorage Destroyed;
5856 if (E->getDestroyedTypeInfo()) {
5857 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00005858 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5859 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005860 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005861 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005862 Destroyed = DestroyedTypeInfo;
5863 } else if (ObjectType->isDependentType()) {
5864 // We aren't likely to be able to resolve the identifier down to a type
5865 // now anyway, so just retain the identifier.
5866 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5867 E->getDestroyedTypeLoc());
5868 } else {
5869 // Look for a destructor known with the given name.
5870 CXXScopeSpec SS;
5871 if (Qualifier) {
5872 SS.setScopeRep(Qualifier);
5873 SS.setRange(E->getQualifierRange());
5874 }
Sean Huntc3021132010-05-05 15:23:54 +00005875
John McCallb3d87482010-08-24 05:47:05 +00005876 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005877 *E->getDestroyedTypeIdentifier(),
5878 E->getDestroyedTypeLoc(),
5879 /*Scope=*/0,
5880 SS, ObjectTypePtr,
5881 false);
5882 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005883 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005884
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005885 Destroyed
5886 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5887 E->getDestroyedTypeLoc());
5888 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005889
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005890 TypeSourceInfo *ScopeTypeInfo = 0;
5891 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00005892 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005893 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005894 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005895 }
Sean Huntc3021132010-05-05 15:23:54 +00005896
John McCall9ae2f072010-08-23 23:25:46 +00005897 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005898 E->getOperatorLoc(),
5899 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005900 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005901 E->getQualifierRange(),
5902 ScopeTypeInfo,
5903 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005904 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005905 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00005906}
Mike Stump1eb44332009-09-09 15:08:12 +00005907
Douglas Gregora71d8192009-09-04 17:36:40 +00005908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005909ExprResult
John McCallba135432009-11-21 08:51:07 +00005910TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00005911 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00005912 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5913
5914 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5915 Sema::LookupOrdinaryName);
5916
5917 // Transform all the decls.
5918 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5919 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005920 NamedDecl *InstD = static_cast<NamedDecl*>(
5921 getDerived().TransformDecl(Old->getNameLoc(),
5922 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005923 if (!InstD) {
5924 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5925 // This can happen because of dependent hiding.
5926 if (isa<UsingShadowDecl>(*I))
5927 continue;
5928 else
John McCallf312b1e2010-08-26 23:41:50 +00005929 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00005930 }
John McCallf7a1a742009-11-24 19:00:30 +00005931
5932 // Expand using declarations.
5933 if (isa<UsingDecl>(InstD)) {
5934 UsingDecl *UD = cast<UsingDecl>(InstD);
5935 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5936 E = UD->shadow_end(); I != E; ++I)
5937 R.addDecl(*I);
5938 continue;
5939 }
5940
5941 R.addDecl(InstD);
5942 }
5943
5944 // Resolve a kind, but don't do any further analysis. If it's
5945 // ambiguous, the callee needs to deal with it.
5946 R.resolveKind();
5947
5948 // Rebuild the nested-name qualifier, if present.
5949 CXXScopeSpec SS;
5950 NestedNameSpecifier *Qualifier = 0;
5951 if (Old->getQualifier()) {
5952 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005953 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00005954 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005955 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005956
John McCallf7a1a742009-11-24 19:00:30 +00005957 SS.setScopeRep(Qualifier);
5958 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00005959 }
5960
Douglas Gregorc96be1e2010-04-27 18:19:34 +00005961 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00005962 CXXRecordDecl *NamingClass
5963 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5964 Old->getNameLoc(),
5965 Old->getNamingClass()));
5966 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00005967 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005968
Douglas Gregor66c45152010-04-27 16:10:10 +00005969 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00005970 }
5971
5972 // If we have no template arguments, it's a normal declaration name.
5973 if (!Old->hasExplicitTemplateArgs())
5974 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5975
5976 // If we have template arguments, rebuild them, then rebuild the
5977 // templateid expression.
5978 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005979 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
5980 Old->getNumTemplateArgs(),
5981 TransArgs))
5982 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00005983
5984 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5985 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005986}
Mike Stump1eb44332009-09-09 15:08:12 +00005987
Douglas Gregorb98b1992009-08-11 05:31:07 +00005988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005989ExprResult
John McCall454feb92009-12-08 09:21:05 +00005990TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005991 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5992 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005994
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00005996 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005997 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005998
Mike Stump1eb44332009-09-09 15:08:12 +00005999 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001 T,
6002 E->getLocEnd());
6003}
Mike Stump1eb44332009-09-09 15:08:12 +00006004
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006006ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006007TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6008 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6009 if (!LhsT)
6010 return ExprError();
6011
6012 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6013 if (!RhsT)
6014 return ExprError();
6015
6016 if (!getDerived().AlwaysRebuild() &&
6017 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6018 return SemaRef.Owned(E);
6019
6020 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6021 E->getLocStart(),
6022 LhsT, RhsT,
6023 E->getLocEnd());
6024}
6025
6026template<typename Derived>
6027ExprResult
John McCall865d4472009-11-19 22:55:06 +00006028TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006029 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006031 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006032 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006035
John McCall43fed0d2010-11-12 08:19:04 +00006036 // TODO: If this is a conversion-function-id, verify that the
6037 // destination type name (if present) resolves the same way after
6038 // instantiation as it did in the local scope.
6039
Abramo Bagnara25777432010-08-11 22:01:17 +00006040 DeclarationNameInfo NameInfo
6041 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6042 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006043 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006044
John McCallf7a1a742009-11-24 19:00:30 +00006045 if (!E->hasExplicitTemplateArgs()) {
6046 if (!getDerived().AlwaysRebuild() &&
6047 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006048 // Note: it is sufficient to compare the Name component of NameInfo:
6049 // if name has not changed, DNLoc has not changed either.
6050 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006051 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006052
John McCallf7a1a742009-11-24 19:00:30 +00006053 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6054 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006055 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006056 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006057 }
John McCalld5532b62009-11-23 01:53:49 +00006058
6059 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006060 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6061 E->getNumTemplateArgs(),
6062 TransArgs))
6063 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064
John McCallf7a1a742009-11-24 19:00:30 +00006065 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6066 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006067 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006068 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069}
6070
6071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006072ExprResult
John McCall454feb92009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006074 // CXXConstructExprs are always implicit, so when we have a
6075 // 1-argument construction we just transform that argument.
6076 if (E->getNumArgs() == 1 ||
6077 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6078 return getDerived().TransformExpr(E->getArg(0));
6079
Douglas Gregorb98b1992009-08-11 05:31:07 +00006080 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6081
6082 QualType T = getDerived().TransformType(E->getType());
6083 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006084 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085
6086 CXXConstructorDecl *Constructor
6087 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006088 getDerived().TransformDecl(E->getLocStart(),
6089 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006092
Douglas Gregorb98b1992009-08-11 05:31:07 +00006093 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006094 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00006095 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096 ArgEnd = E->arg_end();
6097 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00006098 if (getDerived().DropCallArgument(*Arg)) {
6099 ArgumentChanged = true;
6100 break;
6101 }
6102
John McCall60d7b3a2010-08-24 06:29:42 +00006103 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006104 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006106
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00006108 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109 }
6110
6111 if (!getDerived().AlwaysRebuild() &&
6112 T == E->getType() &&
6113 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006114 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006115 // Mark the constructor as referenced.
6116 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006117 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006118 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006119 }
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006121 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6122 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006123 move_arg(Args),
6124 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006125 E->getConstructionKind(),
6126 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127}
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129/// \brief Transform a C++ temporary-binding expression.
6130///
Douglas Gregor51326552009-12-24 18:51:59 +00006131/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6132/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006136 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
Mike Stump1eb44332009-09-09 15:08:12 +00006138
John McCall4765fa02010-12-06 08:20:24 +00006139/// \brief Transform a C++ expression that contains cleanups that should
6140/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141///
John McCall4765fa02010-12-06 08:20:24 +00006142/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006143/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006145ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006146TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006147 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148}
Mike Stump1eb44332009-09-09 15:08:12 +00006149
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006151ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006153 CXXTemporaryObjectExpr *E) {
6154 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6155 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006156 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006157
Douglas Gregorb98b1992009-08-11 05:31:07 +00006158 CXXConstructorDecl *Constructor
6159 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006160 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006161 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006162 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006163 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006164
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006166 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00006168 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169 ArgEnd = E->arg_end();
6170 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00006171 if (getDerived().DropCallArgument(*Arg)) {
6172 ArgumentChanged = true;
6173 break;
6174 }
6175
John McCall60d7b3a2010-08-24 06:29:42 +00006176 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006177 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006179
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
6181 Args.push_back((Expr *)TransArg.release());
6182 }
Mike Stump1eb44332009-09-09 15:08:12 +00006183
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006185 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006187 !ArgumentChanged) {
6188 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006189 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006190 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006191 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006192
6193 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6194 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 E->getLocEnd());
6197}
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006200ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006202 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006203 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6204 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006208 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
6210 ArgEnd = E->arg_end();
6211 Arg != ArgEnd; ++Arg) {
John McCall60d7b3a2010-08-24 06:29:42 +00006212 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 if (TransArg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006214 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006215
Douglas Gregorb98b1992009-08-11 05:31:07 +00006216 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCall9ae2f072010-08-23 23:25:46 +00006217 Args.push_back(TransArg.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218 }
Mike Stump1eb44332009-09-09 15:08:12 +00006219
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006221 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006224
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006226 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 E->getLParenLoc(),
6228 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006229 E->getRParenLoc());
6230}
Mike Stump1eb44332009-09-09 15:08:12 +00006231
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
John McCall865d4472009-11-19 22:55:06 +00006234TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006235 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006237 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006238 Expr *OldBase;
6239 QualType BaseType;
6240 QualType ObjectType;
6241 if (!E->isImplicitAccess()) {
6242 OldBase = E->getBase();
6243 Base = getDerived().TransformExpr(OldBase);
6244 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006246
John McCallaa81e162009-12-01 22:10:20 +00006247 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006248 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006249 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006250 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006251 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006252 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006253 ObjectTy,
6254 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006255 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006256 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006257
John McCallb3d87482010-08-24 05:47:05 +00006258 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006259 BaseType = ((Expr*) Base.get())->getType();
6260 } else {
6261 OldBase = 0;
6262 BaseType = getDerived().TransformType(E->getBaseType());
6263 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6264 }
Mike Stump1eb44332009-09-09 15:08:12 +00006265
Douglas Gregor6cd21982009-10-20 05:58:46 +00006266 // Transform the first part of the nested-name-specifier that qualifies
6267 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006268 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006269 = getDerived().TransformFirstQualifierInScope(
6270 E->getFirstQualifierFoundInScope(),
6271 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006272
Douglas Gregora38c6872009-09-03 16:14:30 +00006273 NestedNameSpecifier *Qualifier = 0;
6274 if (E->getQualifier()) {
6275 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6276 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006277 ObjectType,
6278 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006279 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006281 }
Mike Stump1eb44332009-09-09 15:08:12 +00006282
John McCall43fed0d2010-11-12 08:19:04 +00006283 // TODO: If this is a conversion-function-id, verify that the
6284 // destination type name (if present) resolves the same way after
6285 // instantiation as it did in the local scope.
6286
Abramo Bagnara25777432010-08-11 22:01:17 +00006287 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006288 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006289 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006291
John McCallaa81e162009-12-01 22:10:20 +00006292 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006293 // This is a reference to a member without an explicitly-specified
6294 // template argument list. Optimize for this common case.
6295 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006296 Base.get() == OldBase &&
6297 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006298 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006299 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006300 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006302
John McCall9ae2f072010-08-23 23:25:46 +00006303 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006304 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006305 E->isArrow(),
6306 E->getOperatorLoc(),
6307 Qualifier,
6308 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006309 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006310 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006311 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006312 }
6313
John McCalld5532b62009-11-23 01:53:49 +00006314 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006315 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6316 E->getNumTemplateArgs(),
6317 TransArgs))
6318 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006319
John McCall9ae2f072010-08-23 23:25:46 +00006320 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006321 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 E->isArrow(),
6323 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006324 Qualifier,
6325 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006326 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006327 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006328 &TransArgs);
6329}
6330
6331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006332ExprResult
John McCall454feb92009-12-08 09:21:05 +00006333TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006334 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006335 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006336 QualType BaseType;
6337 if (!Old->isImplicitAccess()) {
6338 Base = getDerived().TransformExpr(Old->getBase());
6339 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006340 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006341 BaseType = ((Expr*) Base.get())->getType();
6342 } else {
6343 BaseType = getDerived().TransformType(Old->getBaseType());
6344 }
John McCall129e2df2009-11-30 22:42:35 +00006345
6346 NestedNameSpecifier *Qualifier = 0;
6347 if (Old->getQualifier()) {
6348 Qualifier
6349 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006350 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006351 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006352 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006353 }
6354
Abramo Bagnara25777432010-08-11 22:01:17 +00006355 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006356 Sema::LookupOrdinaryName);
6357
6358 // Transform all the decls.
6359 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6360 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006361 NamedDecl *InstD = static_cast<NamedDecl*>(
6362 getDerived().TransformDecl(Old->getMemberLoc(),
6363 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006364 if (!InstD) {
6365 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6366 // This can happen because of dependent hiding.
6367 if (isa<UsingShadowDecl>(*I))
6368 continue;
6369 else
John McCallf312b1e2010-08-26 23:41:50 +00006370 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006371 }
John McCall129e2df2009-11-30 22:42:35 +00006372
6373 // Expand using declarations.
6374 if (isa<UsingDecl>(InstD)) {
6375 UsingDecl *UD = cast<UsingDecl>(InstD);
6376 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6377 E = UD->shadow_end(); I != E; ++I)
6378 R.addDecl(*I);
6379 continue;
6380 }
6381
6382 R.addDecl(InstD);
6383 }
6384
6385 R.resolveKind();
6386
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006387 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006388 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006389 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006390 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006391 Old->getMemberLoc(),
6392 Old->getNamingClass()));
6393 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006395
Douglas Gregor66c45152010-04-27 16:10:10 +00006396 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006397 }
Sean Huntc3021132010-05-05 15:23:54 +00006398
John McCall129e2df2009-11-30 22:42:35 +00006399 TemplateArgumentListInfo TransArgs;
6400 if (Old->hasExplicitTemplateArgs()) {
6401 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6402 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006403 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6404 Old->getNumTemplateArgs(),
6405 TransArgs))
6406 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006407 }
John McCallc2233c52010-01-15 08:34:02 +00006408
6409 // FIXME: to do this check properly, we will need to preserve the
6410 // first-qualifier-in-scope here, just in case we had a dependent
6411 // base (and therefore couldn't do the check) and a
6412 // nested-name-qualifier (and therefore could do the lookup).
6413 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006414
John McCall9ae2f072010-08-23 23:25:46 +00006415 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006416 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006417 Old->getOperatorLoc(),
6418 Old->isArrow(),
6419 Qualifier,
6420 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006421 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006422 R,
6423 (Old->hasExplicitTemplateArgs()
6424 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425}
6426
6427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006428ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006429TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6430 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6431 if (SubExpr.isInvalid())
6432 return ExprError();
6433
6434 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006435 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006436
6437 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6438}
6439
6440template<typename Derived>
6441ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006442TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6443 llvm_unreachable("pack expansion expression in unhandled context");
6444 return ExprError();
6445}
6446
6447template<typename Derived>
6448ExprResult
John McCall454feb92009-12-08 09:21:05 +00006449TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006450 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451}
6452
Mike Stump1eb44332009-09-09 15:08:12 +00006453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006454ExprResult
John McCall454feb92009-12-08 09:21:05 +00006455TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006456 TypeSourceInfo *EncodedTypeInfo
6457 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6458 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006459 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006462 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006463 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464
6465 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006466 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 E->getRParenLoc());
6468}
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006471ExprResult
John McCall454feb92009-12-08 09:21:05 +00006472TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006473 // Transform arguments.
6474 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006475 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006476 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006477 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregor92e986e2010-04-22 16:44:27 +00006478 if (Arg.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006479 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006480
Douglas Gregor92e986e2010-04-22 16:44:27 +00006481 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCall9ae2f072010-08-23 23:25:46 +00006482 Args.push_back(Arg.get());
Douglas Gregor92e986e2010-04-22 16:44:27 +00006483 }
6484
6485 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6486 // Class message: transform the receiver type.
6487 TypeSourceInfo *ReceiverTypeInfo
6488 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6489 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006490 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006491
Douglas Gregor92e986e2010-04-22 16:44:27 +00006492 // If nothing changed, just retain the existing message send.
6493 if (!getDerived().AlwaysRebuild() &&
6494 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006496
6497 // Build a new class message send.
6498 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6499 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006500 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006501 E->getMethodDecl(),
6502 E->getLeftLoc(),
6503 move_arg(Args),
6504 E->getRightLoc());
6505 }
6506
6507 // Instance message: transform the receiver
6508 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6509 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006510 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006511 = getDerived().TransformExpr(E->getInstanceReceiver());
6512 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006513 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006514
6515 // If nothing changed, just retain the existing message send.
6516 if (!getDerived().AlwaysRebuild() &&
6517 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006518 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006519
Douglas Gregor92e986e2010-04-22 16:44:27 +00006520 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006521 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006522 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006523 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006524 E->getMethodDecl(),
6525 E->getLeftLoc(),
6526 move_arg(Args),
6527 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528}
6529
Mike Stump1eb44332009-09-09 15:08:12 +00006530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006531ExprResult
John McCall454feb92009-12-08 09:21:05 +00006532TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006533 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534}
6535
Mike Stump1eb44332009-09-09 15:08:12 +00006536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006537ExprResult
John McCall454feb92009-12-08 09:21:05 +00006538TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006539 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540}
6541
Mike Stump1eb44332009-09-09 15:08:12 +00006542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006543ExprResult
John McCall454feb92009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006545 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006546 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006547 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006549
6550 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006551
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006552 // If nothing changed, just retain the existing expression.
6553 if (!getDerived().AlwaysRebuild() &&
6554 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006555 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006556
John McCall9ae2f072010-08-23 23:25:46 +00006557 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006558 E->getLocation(),
6559 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560}
6561
Mike Stump1eb44332009-09-09 15:08:12 +00006562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006563ExprResult
John McCall454feb92009-12-08 09:21:05 +00006564TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006565 // 'super' and types never change. Property never changes. Just
6566 // retain the existing expression.
6567 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006568 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006569
Douglas Gregore3303542010-04-26 20:47:02 +00006570 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006571 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006572 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006573 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006574
Douglas Gregore3303542010-04-26 20:47:02 +00006575 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006576
Douglas Gregore3303542010-04-26 20:47:02 +00006577 // If nothing changed, just retain the existing expression.
6578 if (!getDerived().AlwaysRebuild() &&
6579 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006580 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581
John McCall12f78a62010-12-02 01:19:52 +00006582 if (E->isExplicitProperty())
6583 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6584 E->getExplicitProperty(),
6585 E->getLocation());
6586
6587 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6588 E->getType(),
6589 E->getImplicitPropertyGetter(),
6590 E->getImplicitPropertySetter(),
6591 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592}
6593
Mike Stump1eb44332009-09-09 15:08:12 +00006594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006595ExprResult
John McCall454feb92009-12-08 09:21:05 +00006596TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006597 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006598 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006599 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006600 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006601
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006602 // If nothing changed, just retain the existing expression.
6603 if (!getDerived().AlwaysRebuild() &&
6604 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006605 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006606
John McCall9ae2f072010-08-23 23:25:46 +00006607 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006608 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609}
6610
Mike Stump1eb44332009-09-09 15:08:12 +00006611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006612ExprResult
John McCall454feb92009-12-08 09:21:05 +00006613TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006615 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006617 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCall9ae2f072010-08-23 23:25:46 +00006622 SubExprs.push_back(SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 }
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 if (!getDerived().AlwaysRebuild() &&
6626 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006627 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6630 move_arg(SubExprs),
6631 E->getRParenLoc());
6632}
6633
Mike Stump1eb44332009-09-09 15:08:12 +00006634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006635ExprResult
John McCall454feb92009-12-08 09:21:05 +00006636TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006637 SourceLocation CaretLoc(E->getExprLoc());
6638
6639 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6640 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6641 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6642 llvm::SmallVector<ParmVarDecl*, 4> Params;
6643 llvm::SmallVector<QualType, 4> ParamTypes;
6644
6645 // Parameter substitution.
6646 const BlockDecl *BD = E->getBlockDecl();
6647 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6648 EN = BD->param_end(); P != EN; ++P) {
6649 ParmVarDecl *OldParm = (*P);
6650 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6651 QualType NewType = NewParm->getType();
6652 Params.push_back(NewParm);
6653 ParamTypes.push_back(NewParm->getType());
6654 }
6655
6656 const FunctionType *BExprFunctionType = E->getFunctionType();
6657 QualType BExprResultType = BExprFunctionType->getResultType();
6658 if (!BExprResultType.isNull()) {
6659 if (!BExprResultType->isDependentType())
6660 CurBlock->ReturnType = BExprResultType;
6661 else if (BExprResultType != SemaRef.Context.DependentTy)
6662 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6663 }
6664
6665 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00006666 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006667 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006668 return ExprError();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006669 // Set the parameters on the block decl.
6670 if (!Params.empty())
6671 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6672
6673 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6674 CurBlock->ReturnType,
6675 ParamTypes.data(),
6676 ParamTypes.size(),
6677 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006678 0,
6679 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006680
6681 CurBlock->FunctionType = FunctionType;
John McCall9ae2f072010-08-23 23:25:46 +00006682 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683}
6684
Mike Stump1eb44332009-09-09 15:08:12 +00006685template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006686ExprResult
John McCall454feb92009-12-08 09:21:05 +00006687TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006688 NestedNameSpecifier *Qualifier = 0;
6689
6690 ValueDecl *ND
6691 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6692 E->getDecl()));
6693 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006694 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006695
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006696 if (!getDerived().AlwaysRebuild() &&
6697 ND == E->getDecl()) {
6698 // Mark it referenced in the new context regardless.
6699 // FIXME: this is a bit instantiation-specific.
6700 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6701
John McCall3fa5cae2010-10-26 07:05:15 +00006702 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006703 }
6704
Abramo Bagnara25777432010-08-11 22:01:17 +00006705 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006706 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006707 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708}
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006711// Type reconstruction
6712//===----------------------------------------------------------------------===//
6713
Mike Stump1eb44332009-09-09 15:08:12 +00006714template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006715QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6716 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006717 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006718 getDerived().getBaseEntity());
6719}
6720
Mike Stump1eb44332009-09-09 15:08:12 +00006721template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006722QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6723 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006724 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006725 getDerived().getBaseEntity());
6726}
6727
Mike Stump1eb44332009-09-09 15:08:12 +00006728template<typename Derived>
6729QualType
John McCall85737a72009-10-30 00:06:24 +00006730TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6731 bool WrittenAsLValue,
6732 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006733 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006734 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006735}
6736
6737template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006738QualType
John McCall85737a72009-10-30 00:06:24 +00006739TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6740 QualType ClassType,
6741 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006742 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006743 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006744}
6745
6746template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006747QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006748TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6749 ArrayType::ArraySizeModifier SizeMod,
6750 const llvm::APInt *Size,
6751 Expr *SizeExpr,
6752 unsigned IndexTypeQuals,
6753 SourceRange BracketsRange) {
6754 if (SizeExpr || !Size)
6755 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6756 IndexTypeQuals, BracketsRange,
6757 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006758
6759 QualType Types[] = {
6760 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6761 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6762 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006763 };
6764 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6765 QualType SizeType;
6766 for (unsigned I = 0; I != NumTypes; ++I)
6767 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6768 SizeType = Types[I];
6769 break;
6770 }
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006772 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6773 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006774 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006775 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006776 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006777}
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregor577f75a2009-08-04 16:50:30 +00006779template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006780QualType
6781TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006782 ArrayType::ArraySizeModifier SizeMod,
6783 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006784 unsigned IndexTypeQuals,
6785 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006786 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006787 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006788}
6789
6790template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006791QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006792TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006793 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006794 unsigned IndexTypeQuals,
6795 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006796 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006797 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006798}
Mike Stump1eb44332009-09-09 15:08:12 +00006799
Douglas Gregor577f75a2009-08-04 16:50:30 +00006800template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006801QualType
6802TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006803 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006804 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006805 unsigned IndexTypeQuals,
6806 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006807 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006808 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006809 IndexTypeQuals, BracketsRange);
6810}
6811
6812template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006813QualType
6814TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006815 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006816 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006817 unsigned IndexTypeQuals,
6818 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006819 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006820 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006821 IndexTypeQuals, BracketsRange);
6822}
6823
6824template<typename Derived>
6825QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00006826 unsigned NumElements,
6827 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006828 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00006829 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006830}
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregor577f75a2009-08-04 16:50:30 +00006832template<typename Derived>
6833QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6834 unsigned NumElements,
6835 SourceLocation AttributeLoc) {
6836 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6837 NumElements, true);
6838 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006839 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6840 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006841 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006842}
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregor577f75a2009-08-04 16:50:30 +00006844template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006845QualType
6846TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006847 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006848 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006849 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006850}
Mike Stump1eb44332009-09-09 15:08:12 +00006851
Douglas Gregor577f75a2009-08-04 16:50:30 +00006852template<typename Derived>
6853QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006854 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006855 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006856 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006857 unsigned Quals,
6858 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006859 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006860 Quals,
6861 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006862 getDerived().getBaseEntity(),
6863 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006864}
Mike Stump1eb44332009-09-09 15:08:12 +00006865
Douglas Gregor577f75a2009-08-04 16:50:30 +00006866template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006867QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6868 return SemaRef.Context.getFunctionNoProtoType(T);
6869}
6870
6871template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006872QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6873 assert(D && "no decl found");
6874 if (D->isInvalidDecl()) return QualType();
6875
Douglas Gregor92e986e2010-04-22 16:44:27 +00006876 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006877 TypeDecl *Ty;
6878 if (isa<UsingDecl>(D)) {
6879 UsingDecl *Using = cast<UsingDecl>(D);
6880 assert(Using->isTypeName() &&
6881 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6882
6883 // A valid resolved using typename decl points to exactly one type decl.
6884 assert(++Using->shadow_begin() == Using->shadow_end());
6885 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006886
John McCalled976492009-12-04 22:46:56 +00006887 } else {
6888 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6889 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6890 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6891 }
6892
6893 return SemaRef.Context.getTypeDeclType(Ty);
6894}
6895
6896template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006897QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6898 SourceLocation Loc) {
6899 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006900}
6901
6902template<typename Derived>
6903QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6904 return SemaRef.Context.getTypeOfType(Underlying);
6905}
6906
6907template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006908QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6909 SourceLocation Loc) {
6910 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006911}
6912
6913template<typename Derived>
6914QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00006915 TemplateName Template,
6916 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00006917 const TemplateArgumentListInfo &TemplateArgs) {
6918 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006919}
Mike Stump1eb44332009-09-09 15:08:12 +00006920
Douglas Gregordcee1a12009-08-06 05:28:30 +00006921template<typename Derived>
6922NestedNameSpecifier *
6923TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6924 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00006925 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006926 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00006927 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00006928 CXXScopeSpec SS;
6929 // FIXME: The source location information is all wrong.
6930 SS.setRange(Range);
6931 SS.setScopeRep(Prefix);
6932 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00006933 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00006934 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00006935 ObjectType,
6936 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00006937 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00006938}
6939
6940template<typename Derived>
6941NestedNameSpecifier *
6942TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6943 SourceRange Range,
6944 NamespaceDecl *NS) {
6945 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6946}
6947
6948template<typename Derived>
6949NestedNameSpecifier *
6950TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6951 SourceRange Range,
6952 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00006953 QualType T) {
6954 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00006955 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00006956 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00006957 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6958 T.getTypePtr());
6959 }
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregordcee1a12009-08-06 05:28:30 +00006961 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6962 return 0;
6963}
Mike Stump1eb44332009-09-09 15:08:12 +00006964
Douglas Gregord1067e52009-08-06 06:41:21 +00006965template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006966TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006967TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6968 bool TemplateKW,
6969 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00006970 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00006971 Template);
6972}
6973
6974template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006975TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00006976TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006977 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006978 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00006979 QualType ObjectType,
6980 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00006981 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00006982 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00006983 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00006984 UnqualifiedId Name;
6985 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00006986 Sema::TemplateTy Template;
6987 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6988 /*FIXME:*/getDerived().getBaseLocation(),
6989 SS,
6990 Name,
John McCallb3d87482010-08-24 05:47:05 +00006991 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00006992 /*EnteringContext=*/false,
6993 Template);
John McCall43fed0d2010-11-12 08:19:04 +00006994 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00006995}
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00006998TemplateName
6999TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7000 OverloadedOperatorKind Operator,
7001 QualType ObjectType) {
7002 CXXScopeSpec SS;
7003 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7004 SS.setScopeRep(Qualifier);
7005 UnqualifiedId Name;
7006 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7007 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7008 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007009 Sema::TemplateTy Template;
7010 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007011 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007012 SS,
7013 Name,
John McCallb3d87482010-08-24 05:47:05 +00007014 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007015 /*EnteringContext=*/false,
7016 Template);
7017 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007018}
Sean Huntc3021132010-05-05 15:23:54 +00007019
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007021ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7023 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007024 Expr *OrigCallee,
7025 Expr *First,
7026 Expr *Second) {
7027 Expr *Callee = OrigCallee->IgnoreParenCasts();
7028 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007031 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007032 if (!First->getType()->isOverloadableType() &&
7033 !Second->getType()->isOverloadableType())
7034 return getSema().CreateBuiltinArraySubscriptExpr(First,
7035 Callee->getLocStart(),
7036 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007037 } else if (Op == OO_Arrow) {
7038 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007039 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7040 } else if (Second == 0 || isPostIncDec) {
7041 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042 // The argument is not of overloadable type, so try to create a
7043 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007044 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007046
John McCall9ae2f072010-08-23 23:25:46 +00007047 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 }
7049 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007050 if (!First->getType()->isOverloadableType() &&
7051 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052 // Neither of the arguments is an overloadable type, so try to
7053 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007054 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007055 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007056 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007058 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 return move(Result);
7061 }
7062 }
Mike Stump1eb44332009-09-09 15:08:12 +00007063
7064 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007066 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007067
John McCall9ae2f072010-08-23 23:25:46 +00007068 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007069 assert(ULE->requiresADL());
7070
7071 // FIXME: Do we have to check
7072 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007073 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007074 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007075 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007076 }
Mike Stump1eb44332009-09-09 15:08:12 +00007077
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007079 Expr *Args[2] = { First, Second };
7080 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 // Create the overloaded operator invocation for unary operators.
7083 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007084 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007086 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 }
Mike Stump1eb44332009-09-09 15:08:12 +00007088
Sebastian Redlf322ed62009-10-29 20:17:01 +00007089 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007090 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007091 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007092 First,
7093 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007094
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007096 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007097 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7099 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007100 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007101
Mike Stump1eb44332009-09-09 15:08:12 +00007102 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103}
Mike Stump1eb44332009-09-09 15:08:12 +00007104
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007106ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007107TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007108 SourceLocation OperatorLoc,
7109 bool isArrow,
7110 NestedNameSpecifier *Qualifier,
7111 SourceRange QualifierRange,
7112 TypeSourceInfo *ScopeType,
7113 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007114 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007115 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007116 CXXScopeSpec SS;
7117 if (Qualifier) {
7118 SS.setRange(QualifierRange);
7119 SS.setScopeRep(Qualifier);
7120 }
7121
John McCall9ae2f072010-08-23 23:25:46 +00007122 QualType BaseType = Base->getType();
7123 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007124 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007125 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007126 !BaseType->getAs<PointerType>()->getPointeeType()
7127 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007128 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007129 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007130 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007131 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007132 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007133 /*FIXME?*/true);
7134 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007135
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007136 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007137 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7138 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7139 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7140 NameInfo.setNamedTypeInfo(DestroyedType);
7141
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007142 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007143
John McCall9ae2f072010-08-23 23:25:46 +00007144 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007145 OperatorLoc, isArrow,
7146 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007147 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007148 /*TemplateArgs*/ 0);
7149}
7150
Douglas Gregor577f75a2009-08-04 16:50:30 +00007151} // end namespace clang
7152
7153#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H