blob: 919f2c879c894a404cd7a68cdad256f93d8f6584 [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 Gregoraa165f82011-01-03 19:04:46 +0000273 /// \brief Transform the given list of expressions.
274 ///
275 /// This routine transforms a list of expressions by invoking
276 /// \c TransformExpr() for each subexpression. However, it also provides
277 /// support for variadic templates by expanding any pack expansions (if the
278 /// derived class permits such expansion) along the way. When pack expansions
279 /// are present, the number of outputs may not equal the number of inputs.
280 ///
281 /// \param Inputs The set of expressions to be transformed.
282 ///
283 /// \param NumInputs The number of expressions in \c Inputs.
284 ///
285 /// \param IsCall If \c true, then this transform is being performed on
286 /// function-call arguments, and any arguments that should be dropped, will
287 /// be.
288 ///
289 /// \param Outputs The transformed input expressions will be added to this
290 /// vector.
291 ///
292 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
293 /// due to transformation.
294 ///
295 /// \returns true if an error occurred, false otherwise.
296 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
297 llvm::SmallVectorImpl<Expr *> &Outputs,
298 bool *ArgChanged = 0);
299
Douglas Gregor577f75a2009-08-04 16:50:30 +0000300 /// \brief Transform the given declaration, which is referenced from a type
301 /// or expression.
302 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000303 /// By default, acts as the identity function on declarations. Subclasses
304 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000305 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000306
307 /// \brief Transform the definition of the given declaration.
308 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000309 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000310 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000311 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
312 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000313 }
Mike Stump1eb44332009-09-09 15:08:12 +0000314
Douglas Gregor6cd21982009-10-20 05:58:46 +0000315 /// \brief Transform the given declaration, which was the first part of a
316 /// nested-name-specifier in a member access expression.
317 ///
Sean Huntc3021132010-05-05 15:23:54 +0000318 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000319 /// identifier in a nested-name-specifier of a member access expression, e.g.,
320 /// the \c T in \c x->T::member
321 ///
322 /// By default, invokes TransformDecl() to transform the declaration.
323 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000324 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
325 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000326 }
Sean Huntc3021132010-05-05 15:23:54 +0000327
Douglas Gregor577f75a2009-08-04 16:50:30 +0000328 /// \brief Transform the given nested-name-specifier.
329 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000330 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000331 /// nested-name-specifier. Subclasses may override this function to provide
332 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000333 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000334 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000335 QualType ObjectType = QualType(),
336 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000337
Douglas Gregor81499bb2009-09-03 22:13:48 +0000338 /// \brief Transform the given declaration name.
339 ///
340 /// By default, transforms the types of conversion function, constructor,
341 /// and destructor names and then (if needed) rebuilds the declaration name.
342 /// Identifiers and selectors are returned unmodified. Sublcasses may
343 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000344 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000345 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000346
Douglas Gregor577f75a2009-08-04 16:50:30 +0000347 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000348 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000349 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000350 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000351 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000352 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000353 QualType ObjectType = QualType(),
354 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000355
Douglas Gregor577f75a2009-08-04 16:50:30 +0000356 /// \brief Transform the given template argument.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, this operation transforms the type, expression, or
359 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000360 /// new template argument from the transformed result. Subclasses may
361 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000362 ///
363 /// Returns true if there was an error.
364 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
365 TemplateArgumentLoc &Output);
366
Douglas Gregorfcc12532010-12-20 17:31:10 +0000367 /// \brief Transform the given set of template arguments.
368 ///
369 /// By default, this operation transforms all of the template arguments
370 /// in the input set using \c TransformTemplateArgument(), and appends
371 /// the transformed arguments to the output list.
372 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000373 /// Note that this overload of \c TransformTemplateArguments() is merely
374 /// a convenience function. Subclasses that wish to override this behavior
375 /// should override the iterator-based member template version.
376 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000377 /// \param Inputs The set of template arguments to be transformed.
378 ///
379 /// \param NumInputs The number of template arguments in \p Inputs.
380 ///
381 /// \param Outputs The set of transformed template arguments output by this
382 /// routine.
383 ///
384 /// Returns true if an error occurred.
385 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
386 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000387 TemplateArgumentListInfo &Outputs) {
388 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
389 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000390
391 /// \brief Transform the given set of template arguments.
392 ///
393 /// By default, this operation transforms all of the template arguments
394 /// in the input set using \c TransformTemplateArgument(), and appends
395 /// the transformed arguments to the output list.
396 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000397 /// \param First An iterator to the first template argument.
398 ///
399 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000400 ///
401 /// \param Outputs The set of transformed template arguments output by this
402 /// routine.
403 ///
404 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000405 template<typename InputIterator>
406 bool TransformTemplateArguments(InputIterator First,
407 InputIterator Last,
408 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000409
John McCall833ca992009-10-29 08:12:44 +0000410 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
411 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
412 TemplateArgumentLoc &ArgLoc);
413
John McCalla93c9342009-12-07 02:54:59 +0000414 /// \brief Fakes up a TypeSourceInfo for a type.
415 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
416 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000417 getDerived().getBaseLocation());
418 }
Mike Stump1eb44332009-09-09 15:08:12 +0000419
John McCalla2becad2009-10-21 00:40:46 +0000420#define ABSTRACT_TYPELOC(CLASS, PARENT)
421#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000422 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000423#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000424
John McCall43fed0d2010-11-12 08:19:04 +0000425 QualType
426 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
427 TemplateSpecializationTypeLoc TL,
428 TemplateName Template);
429
430 QualType
431 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
432 DependentTemplateSpecializationTypeLoc TL,
433 NestedNameSpecifier *Prefix);
434
John McCall21ef0fa2010-03-11 09:03:00 +0000435 /// \brief Transforms the parameters of a function type into the
436 /// given vectors.
437 ///
438 /// The result vectors should be kept in sync; null entries in the
439 /// variables vector are acceptable.
440 ///
441 /// Return true on error.
442 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
443 llvm::SmallVectorImpl<QualType> &PTypes,
444 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
445
446 /// \brief Transforms a single function-type parameter. Return null
447 /// on error.
448 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
449
John McCall43fed0d2010-11-12 08:19:04 +0000450 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000451
John McCall60d7b3a2010-08-24 06:29:42 +0000452 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
453 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000454
Douglas Gregor43959a92009-08-20 07:17:43 +0000455#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000456 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000457#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000458 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000459#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000460#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Build a new pointer type given its pointee type.
463 ///
464 /// By default, performs semantic analysis when building the pointer type.
465 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000466 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467
468 /// \brief Build a new block pointer type given its pointee type.
469 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000470 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000471 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000472 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473
John McCall85737a72009-10-30 00:06:24 +0000474 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000475 ///
John McCall85737a72009-10-30 00:06:24 +0000476 /// By default, performs semantic analysis when building the
477 /// reference type. Subclasses may override this routine to provide
478 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000479 ///
John McCall85737a72009-10-30 00:06:24 +0000480 /// \param LValue whether the type was written with an lvalue sigil
481 /// or an rvalue sigil.
482 QualType RebuildReferenceType(QualType ReferentType,
483 bool LValue,
484 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000485
Douglas Gregor577f75a2009-08-04 16:50:30 +0000486 /// \brief Build a new member pointer type given the pointee type and the
487 /// class type it refers into.
488 ///
489 /// By default, performs semantic analysis when building the member pointer
490 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000491 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
492 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000493
Douglas Gregor577f75a2009-08-04 16:50:30 +0000494 /// \brief Build a new array type given the element type, size
495 /// modifier, size of the array (if known), size expression, and index type
496 /// qualifiers.
497 ///
498 /// By default, performs semantic analysis when building the array type.
499 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000500 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000501 QualType RebuildArrayType(QualType ElementType,
502 ArrayType::ArraySizeModifier SizeMod,
503 const llvm::APInt *Size,
504 Expr *SizeExpr,
505 unsigned IndexTypeQuals,
506 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000507
Douglas Gregor577f75a2009-08-04 16:50:30 +0000508 /// \brief Build a new constant array type given the element type, size
509 /// modifier, (known) size of the array, and index type qualifiers.
510 ///
511 /// By default, performs semantic analysis when building the array type.
512 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000513 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000514 ArrayType::ArraySizeModifier SizeMod,
515 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000516 unsigned IndexTypeQuals,
517 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000518
Douglas Gregor577f75a2009-08-04 16:50:30 +0000519 /// \brief Build a new incomplete array type given the element type, size
520 /// modifier, and index type qualifiers.
521 ///
522 /// By default, performs semantic analysis when building the array type.
523 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000524 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000525 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000526 unsigned IndexTypeQuals,
527 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000528
Mike Stump1eb44332009-09-09 15:08:12 +0000529 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530 /// size modifier, size expression, and index type qualifiers.
531 ///
532 /// By default, performs semantic analysis when building the array type.
533 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000534 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000535 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000536 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000537 unsigned IndexTypeQuals,
538 SourceRange BracketsRange);
539
Mike Stump1eb44332009-09-09 15:08:12 +0000540 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541 /// size modifier, size expression, and index type qualifiers.
542 ///
543 /// By default, performs semantic analysis when building the array type.
544 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000545 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000546 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000547 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 unsigned IndexTypeQuals,
549 SourceRange BracketsRange);
550
551 /// \brief Build a new vector type given the element type and
552 /// number of elements.
553 ///
554 /// By default, performs semantic analysis when building the vector type.
555 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000556 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000557 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000558
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559 /// \brief Build a new extended vector type given the element type and
560 /// number of elements.
561 ///
562 /// By default, performs semantic analysis when building the vector type.
563 /// Subclasses may override this routine to provide different behavior.
564 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
565 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000566
567 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000568 /// given the element type and number of elements.
569 ///
570 /// By default, performs semantic analysis when building the vector type.
571 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000572 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000573 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000574 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000575
Douglas Gregor577f75a2009-08-04 16:50:30 +0000576 /// \brief Build a new function type.
577 ///
578 /// By default, performs semantic analysis when building the function type.
579 /// Subclasses may override this routine to provide different behavior.
580 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000581 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000582 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000583 bool Variadic, unsigned Quals,
584 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000585
John McCalla2becad2009-10-21 00:40:46 +0000586 /// \brief Build a new unprototyped function type.
587 QualType RebuildFunctionNoProtoType(QualType ResultType);
588
John McCalled976492009-12-04 22:46:56 +0000589 /// \brief Rebuild an unresolved typename type, given the decl that
590 /// the UnresolvedUsingTypenameDecl was transformed to.
591 QualType RebuildUnresolvedUsingType(Decl *D);
592
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// \brief Build a new typedef type.
594 QualType RebuildTypedefType(TypedefDecl *Typedef) {
595 return SemaRef.Context.getTypeDeclType(Typedef);
596 }
597
598 /// \brief Build a new class/struct/union type.
599 QualType RebuildRecordType(RecordDecl *Record) {
600 return SemaRef.Context.getTypeDeclType(Record);
601 }
602
603 /// \brief Build a new Enum type.
604 QualType RebuildEnumType(EnumDecl *Enum) {
605 return SemaRef.Context.getTypeDeclType(Enum);
606 }
John McCall7da24312009-09-05 00:15:47 +0000607
Mike Stump1eb44332009-09-09 15:08:12 +0000608 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000609 ///
610 /// By default, performs semantic analysis when building the typeof type.
611 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000612 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 ///
616 /// By default, builds a new TypeOfType with the given underlying type.
617 QualType RebuildTypeOfType(QualType Underlying);
618
Mike Stump1eb44332009-09-09 15:08:12 +0000619 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ///
621 /// By default, performs semantic analysis when building the decltype type.
622 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000623 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000624
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// \brief Build a new template specialization type.
626 ///
627 /// By default, performs semantic analysis when building the template
628 /// specialization type. Subclasses may override this routine to provide
629 /// different behavior.
630 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000631 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000632 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000633
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000634 /// \brief Build a new parenthesized type.
635 ///
636 /// By default, builds a new ParenType type from the inner type.
637 /// Subclasses may override this routine to provide different behavior.
638 QualType RebuildParenType(QualType InnerType) {
639 return SemaRef.Context.getParenType(InnerType);
640 }
641
Douglas Gregor577f75a2009-08-04 16:50:30 +0000642 /// \brief Build a new qualified name type.
643 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000644 /// By default, builds a new ElaboratedType type from the keyword,
645 /// the nested-name-specifier and the named type.
646 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000647 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
648 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000649 NestedNameSpecifier *NNS, QualType Named) {
650 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000651 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652
653 /// \brief Build a new typename type that refers to a template-id.
654 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000655 /// By default, builds a new DependentNameType type from the
656 /// nested-name-specifier and the given type. Subclasses may override
657 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000658 QualType RebuildDependentTemplateSpecializationType(
659 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000660 NestedNameSpecifier *Qualifier,
661 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000662 const IdentifierInfo *Name,
663 SourceLocation NameLoc,
664 const TemplateArgumentListInfo &Args) {
665 // Rebuild the template name.
666 // TODO: avoid TemplateName abstraction
667 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000668 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000669 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000670
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000671 if (InstName.isNull())
672 return QualType();
673
John McCall33500952010-06-11 00:33:02 +0000674 // If it's still dependent, make a dependent specialization.
675 if (InstName.getAsDependentTemplateName())
676 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000677 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000678
679 // Otherwise, make an elaborated type wrapping a non-dependent
680 // specialization.
681 QualType T =
682 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
683 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000684
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000685 // NOTE: NNS is already recorded in template specialization type T.
686 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000687 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000688
689 /// \brief Build a new typename type that refers to an identifier.
690 ///
691 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000692 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000694 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000695 NestedNameSpecifier *NNS,
696 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000697 SourceLocation KeywordLoc,
698 SourceRange NNSRange,
699 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000700 CXXScopeSpec SS;
701 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000702 SS.setRange(NNSRange);
703
Douglas Gregor40336422010-03-31 22:19:08 +0000704 if (NNS->isDependent()) {
705 // If the name is still dependent, just build a new dependent name type.
706 if (!SemaRef.computeDeclContext(SS))
707 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
708 }
709
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000710 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000711 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
712 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000713
714 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
715
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000716 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000717 // into a non-dependent elaborated-type-specifier. Find the tag we're
718 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000719 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000720 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
721 if (!DC)
722 return QualType();
723
John McCall56138762010-05-27 06:40:31 +0000724 if (SemaRef.RequireCompleteDeclContext(SS, DC))
725 return QualType();
726
Douglas Gregor40336422010-03-31 22:19:08 +0000727 TagDecl *Tag = 0;
728 SemaRef.LookupQualifiedName(Result, DC);
729 switch (Result.getResultKind()) {
730 case LookupResult::NotFound:
731 case LookupResult::NotFoundInCurrentInstantiation:
732 break;
Sean Huntc3021132010-05-05 15:23:54 +0000733
Douglas Gregor40336422010-03-31 22:19:08 +0000734 case LookupResult::Found:
735 Tag = Result.getAsSingle<TagDecl>();
736 break;
Sean Huntc3021132010-05-05 15:23:54 +0000737
Douglas Gregor40336422010-03-31 22:19:08 +0000738 case LookupResult::FoundOverloaded:
739 case LookupResult::FoundUnresolvedValue:
740 llvm_unreachable("Tag lookup cannot find non-tags");
741 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000742
Douglas Gregor40336422010-03-31 22:19:08 +0000743 case LookupResult::Ambiguous:
744 // Let the LookupResult structure handle ambiguities.
745 return QualType();
746 }
747
748 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000749 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000750 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000751 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000752 return QualType();
753 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000754
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000755 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
756 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000757 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
758 return QualType();
759 }
760
761 // Build the elaborated-type-specifier type.
762 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000763 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000764 }
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Douglas Gregordcee1a12009-08-06 05:28:30 +0000766 /// \brief Build a new nested-name-specifier given the prefix and an
767 /// identifier that names the next step in the nested-name-specifier.
768 ///
769 /// By default, performs semantic analysis when building the new
770 /// nested-name-specifier. Subclasses may override this routine to provide
771 /// different behavior.
772 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
773 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000774 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000775 QualType ObjectType,
776 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000777
778 /// \brief Build a new nested-name-specifier given the prefix and the
779 /// namespace named in the next step in the nested-name-specifier.
780 ///
781 /// By default, performs semantic analysis when building the new
782 /// nested-name-specifier. Subclasses may override this routine to provide
783 /// different behavior.
784 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
785 SourceRange Range,
786 NamespaceDecl *NS);
787
788 /// \brief Build a new nested-name-specifier given the prefix and the
789 /// type named in the next step in the nested-name-specifier.
790 ///
791 /// By default, performs semantic analysis when building the new
792 /// nested-name-specifier. Subclasses may override this routine to provide
793 /// different behavior.
794 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
795 SourceRange Range,
796 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000797 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000798
799 /// \brief Build a new template name given a nested name specifier, a flag
800 /// indicating whether the "template" keyword was provided, and the template
801 /// that the template name refers to.
802 ///
803 /// By default, builds the new template name directly. Subclasses may override
804 /// this routine to provide different behavior.
805 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
806 bool TemplateKW,
807 TemplateDecl *Template);
808
Douglas Gregord1067e52009-08-06 06:41:21 +0000809 /// \brief Build a new template name given a nested name specifier and the
810 /// name that is referred to as a template.
811 ///
812 /// By default, performs semantic analysis to determine whether the name can
813 /// be resolved to a specific template, then builds the appropriate kind of
814 /// template name. Subclasses may override this routine to provide different
815 /// behavior.
816 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000817 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000818 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000819 QualType ObjectType,
820 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000821
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000822 /// \brief Build a new template name given a nested name specifier and the
823 /// overloaded operator name that is referred to as a template.
824 ///
825 /// By default, performs semantic analysis to determine whether the name can
826 /// be resolved to a specific template, then builds the appropriate kind of
827 /// template name. Subclasses may override this routine to provide different
828 /// behavior.
829 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
830 OverloadedOperatorKind Operator,
831 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000832
Douglas Gregor43959a92009-08-20 07:17:43 +0000833 /// \brief Build a new compound statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000837 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000838 MultiStmtArg Statements,
839 SourceLocation RBraceLoc,
840 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000841 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000842 IsStmtExpr);
843 }
844
845 /// \brief Build a new case statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000849 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000850 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000851 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000852 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000853 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000854 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000855 ColonLoc);
856 }
Mike Stump1eb44332009-09-09 15:08:12 +0000857
Douglas Gregor43959a92009-08-20 07:17:43 +0000858 /// \brief Attach the body to a new case statement.
859 ///
860 /// By default, performs semantic analysis to build the new statement.
861 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000862 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000863 getSema().ActOnCaseStmtBody(S, Body);
864 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000865 }
Mike Stump1eb44332009-09-09 15:08:12 +0000866
Douglas Gregor43959a92009-08-20 07:17:43 +0000867 /// \brief Build a new default statement.
868 ///
869 /// By default, performs semantic analysis to build the new statement.
870 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000871 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000872 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000873 Stmt *SubStmt) {
874 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000875 /*CurScope=*/0);
876 }
Mike Stump1eb44332009-09-09 15:08:12 +0000877
Douglas Gregor43959a92009-08-20 07:17:43 +0000878 /// \brief Build a new label statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000882 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000883 IdentifierInfo *Id,
884 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000885 Stmt *SubStmt, bool HasUnusedAttr) {
886 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
887 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000888 }
Mike Stump1eb44332009-09-09 15:08:12 +0000889
Douglas Gregor43959a92009-08-20 07:17:43 +0000890 /// \brief Build a new "if" statement.
891 ///
892 /// By default, performs semantic analysis to build the new statement.
893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000894 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000895 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000896 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000897 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000898 }
Mike Stump1eb44332009-09-09 15:08:12 +0000899
Douglas Gregor43959a92009-08-20 07:17:43 +0000900 /// \brief Start building a new switch statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000904 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000905 Expr *Cond, VarDecl *CondVar) {
906 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000907 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000908 }
Mike Stump1eb44332009-09-09 15:08:12 +0000909
Douglas Gregor43959a92009-08-20 07:17:43 +0000910 /// \brief Attach the body to the switch statement.
911 ///
912 /// By default, performs semantic analysis to build the new statement.
913 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000914 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000915 Stmt *Switch, Stmt *Body) {
916 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000917 }
918
919 /// \brief Build a new while statement.
920 ///
921 /// By default, performs semantic analysis to build the new statement.
922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000923 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000924 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000925 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000926 Stmt *Body) {
927 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, 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 do-while 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 RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000935 SourceLocation WhileLoc,
936 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000937 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000938 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000939 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
940 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000941 }
942
943 /// \brief Build a new for statement.
944 ///
945 /// By default, performs semantic analysis to build the new statement.
946 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000947 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000948 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000949 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000950 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000951 SourceLocation RParenLoc, Stmt *Body) {
952 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000953 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000954 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000955 }
Mike Stump1eb44332009-09-09 15:08:12 +0000956
Douglas Gregor43959a92009-08-20 07:17:43 +0000957 /// \brief Build a new goto statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000961 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 SourceLocation LabelLoc,
963 LabelStmt *Label) {
964 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
965 }
966
967 /// \brief Build a new indirect goto statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000971 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000972 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000973 Expr *Target) {
974 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +0000975 }
Mike Stump1eb44332009-09-09 15:08:12 +0000976
Douglas Gregor43959a92009-08-20 07:17:43 +0000977 /// \brief Build a new return statement.
978 ///
979 /// By default, performs semantic analysis to build the new statement.
980 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000981 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000982 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000983
John McCall9ae2f072010-08-23 23:25:46 +0000984 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +0000985 }
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 /// \brief Build a new declaration statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000991 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000992 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 SourceLocation EndLoc) {
994 return getSema().Owned(
995 new (getSema().Context) DeclStmt(
996 DeclGroupRef::Create(getSema().Context,
997 Decls, NumDecls),
998 StartLoc, EndLoc));
999 }
Mike Stump1eb44332009-09-09 15:08:12 +00001000
Anders Carlsson703e3942010-01-24 05:50:09 +00001001 /// \brief Build a new inline asm statement.
1002 ///
1003 /// By default, performs semantic analysis to build the new statement.
1004 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001005 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001006 bool IsSimple,
1007 bool IsVolatile,
1008 unsigned NumOutputs,
1009 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001010 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001011 MultiExprArg Constraints,
1012 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001013 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001014 MultiExprArg Clobbers,
1015 SourceLocation RParenLoc,
1016 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001017 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001018 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001019 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001020 RParenLoc, MSAsm);
1021 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001022
1023 /// \brief Build a new Objective-C @try statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001028 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001029 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001030 Stmt *Finally) {
1031 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1032 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001033 }
1034
Douglas Gregorbe270a02010-04-26 17:57:08 +00001035 /// \brief Rebuild an Objective-C exception declaration.
1036 ///
1037 /// By default, performs semantic analysis to build the new declaration.
1038 /// Subclasses may override this routine to provide different behavior.
1039 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1040 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001041 return getSema().BuildObjCExceptionDecl(TInfo, T,
1042 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001043 ExceptionDecl->getLocation());
1044 }
Sean Huntc3021132010-05-05 15:23:54 +00001045
Douglas Gregorbe270a02010-04-26 17:57:08 +00001046 /// \brief Build a new Objective-C @catch statement.
1047 ///
1048 /// By default, performs semantic analysis to build the new statement.
1049 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001050 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001051 SourceLocation RParenLoc,
1052 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001053 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001054 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001055 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001056 }
Sean Huntc3021132010-05-05 15:23:54 +00001057
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001058 /// \brief Build a new Objective-C @finally statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001062 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001063 Stmt *Body) {
1064 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001065 }
Sean Huntc3021132010-05-05 15:23:54 +00001066
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001067 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001071 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001072 Expr *Operand) {
1073 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001074 }
Sean Huntc3021132010-05-05 15:23:54 +00001075
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001076 /// \brief Build a new Objective-C @synchronized statement.
1077 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001080 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001081 Expr *Object,
1082 Stmt *Body) {
1083 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1084 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001085 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001086
1087 /// \brief Build a new Objective-C fast enumeration statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001091 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001092 SourceLocation LParenLoc,
1093 Stmt *Element,
1094 Expr *Collection,
1095 SourceLocation RParenLoc,
1096 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001097 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001098 Element,
1099 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001100 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001101 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001102 }
Sean Huntc3021132010-05-05 15:23:54 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Build a new C++ exception declaration.
1105 ///
1106 /// By default, performs semantic analysis to build the new decaration.
1107 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001108 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001109 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001111 SourceLocation Loc) {
1112 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 }
1114
1115 /// \brief Build a new C++ catch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001119 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001120 VarDecl *ExceptionDecl,
1121 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001122 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1123 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001124 }
Mike Stump1eb44332009-09-09 15:08:12 +00001125
Douglas Gregor43959a92009-08-20 07:17:43 +00001126 /// \brief Build a new C++ try statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001130 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001131 Stmt *TryBlock,
1132 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001133 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001134 }
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregorb98b1992009-08-11 05:31:07 +00001136 /// \brief Build a new expression that references a declaration.
1137 ///
1138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001140 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001141 LookupResult &R,
1142 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001143 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1144 }
1145
1146
1147 /// \brief Build a new expression that references a declaration.
1148 ///
1149 /// 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 RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001152 SourceRange QualifierRange,
1153 ValueDecl *VD,
1154 const DeclarationNameInfo &NameInfo,
1155 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001156 CXXScopeSpec SS;
1157 SS.setScopeRep(Qualifier);
1158 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001159
1160 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001161
1162 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001163 }
Mike Stump1eb44332009-09-09 15:08:12 +00001164
Douglas Gregorb98b1992009-08-11 05:31:07 +00001165 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001166 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001167 /// By default, performs semantic analysis to build the new expression.
1168 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001169 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001170 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001171 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001172 }
1173
Douglas Gregora71d8192009-09-04 17:36:40 +00001174 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001175 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001176 /// By default, performs semantic analysis to build the new expression.
1177 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001178 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001179 SourceLocation OperatorLoc,
1180 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001181 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001182 SourceRange QualifierRange,
1183 TypeSourceInfo *ScopeType,
1184 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001185 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001186 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001187
Douglas Gregorb98b1992009-08-11 05:31:07 +00001188 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001189 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001190 /// By default, performs semantic analysis to build the new expression.
1191 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001192 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001193 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Expr *SubExpr) {
1195 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001196 }
Mike Stump1eb44332009-09-09 15:08:12 +00001197
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001198 /// \brief Build a new builtin offsetof expression.
1199 ///
1200 /// By default, performs semantic analysis to build the new expression.
1201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001202 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001203 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001204 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001205 unsigned NumComponents,
1206 SourceLocation RParenLoc) {
1207 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1208 NumComponents, RParenLoc);
1209 }
Sean Huntc3021132010-05-05 15:23:54 +00001210
Douglas Gregorb98b1992009-08-11 05:31:07 +00001211 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001212 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001215 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001216 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001218 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 }
1220
Mike Stump1eb44332009-09-09 15:08:12 +00001221 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 /// argument.
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 RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001228 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001229 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001230 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 return move(Result);
1234 }
Mike Stump1eb44332009-09-09 15:08:12 +00001235
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001237 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 /// By default, performs semantic analysis to build the new expression.
1239 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001240 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001242 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001243 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001244 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1245 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 RBracketLoc);
1247 }
1248
1249 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001250 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001254 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001255 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001256 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001257 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 }
1259
1260 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001261 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001265 bool isArrow,
1266 NestedNameSpecifier *Qualifier,
1267 SourceRange QualifierRange,
1268 const DeclarationNameInfo &MemberNameInfo,
1269 ValueDecl *Member,
1270 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001271 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001272 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001273 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001274 // We have a reference to an unnamed field. This is always the
1275 // base of an anonymous struct/union member access, i.e. the
1276 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001277 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001278 assert(Member->getType()->isRecordType() &&
1279 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001280
John McCall9ae2f072010-08-23 23:25:46 +00001281 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001282 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001283 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001284
John McCallf89e55a2010-11-18 06:31:45 +00001285 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001286 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001287 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001288 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001289 cast<FieldDecl>(Member)->getType(),
1290 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001291 return getSema().Owned(ME);
1292 }
Mike Stump1eb44332009-09-09 15:08:12 +00001293
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001294 CXXScopeSpec SS;
1295 if (Qualifier) {
1296 SS.setRange(QualifierRange);
1297 SS.setScopeRep(Qualifier);
1298 }
1299
John McCall9ae2f072010-08-23 23:25:46 +00001300 getSema().DefaultFunctionArrayConversion(Base);
1301 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001302
John McCall6bb80172010-03-30 21:47:33 +00001303 // FIXME: this involves duplicating earlier analysis in a lot of
1304 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001305 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001306 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001307 R.resolveKind();
1308
John McCall9ae2f072010-08-23 23:25:46 +00001309 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001310 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001311 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 }
Mike Stump1eb44332009-09-09 15:08:12 +00001313
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001315 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001318 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001319 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001320 Expr *LHS, Expr *RHS) {
1321 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 }
1323
1324 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001325 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001330 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001332 Expr *RHS) {
1333 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1334 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 }
1336
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001338 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001341 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001342 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001343 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001344 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001345 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001346 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 }
Mike Stump1eb44332009-09-09 15:08:12 +00001348
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001350 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001353 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001354 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001356 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001357 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001358 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 }
Mike Stump1eb44332009-09-09 15:08:12 +00001360
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001362 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001365 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 SourceLocation OpLoc,
1367 SourceLocation AccessorLoc,
1368 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001369
John McCall129e2df2009-11-30 22:42:35 +00001370 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001371 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001372 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001373 OpLoc, /*IsArrow*/ false,
1374 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001375 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001376 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 }
Mike Stump1eb44332009-09-09 15:08:12 +00001378
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001380 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 /// By default, performs semantic analysis to build the new expression.
1382 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001383 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001385 SourceLocation RBraceLoc,
1386 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001388 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1389 if (Result.isInvalid() || ResultTy->isDependentType())
1390 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001391
Douglas Gregore48319a2009-11-09 17:16:50 +00001392 // Patch in the result type we were given, which may have been computed
1393 // when the initial InitListExpr was built.
1394 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1395 ILE->setType(ResultTy);
1396 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 }
Mike Stump1eb44332009-09-09 15:08:12 +00001398
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001400 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001403 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 MultiExprArg ArrayExprs,
1405 SourceLocation EqualOrColonLoc,
1406 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001407 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001408 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001410 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001412 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001413
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 ArrayExprs.release();
1415 return move(Result);
1416 }
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001419 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 /// By default, builds the implicit value initialization without performing
1421 /// any semantic analysis. Subclasses may override this routine to provide
1422 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001423 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1425 }
Mike Stump1eb44332009-09-09 15:08:12 +00001426
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001428 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001431 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001432 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001433 SourceLocation RParenLoc) {
1434 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001436 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 }
1438
1439 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001440 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001443 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 MultiExprArg SubExprs,
1445 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001446 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001447 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 }
Mike Stump1eb44332009-09-09 15:08:12 +00001449
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001451 ///
1452 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// rather than attempting to map the label statement itself.
1454 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001455 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 SourceLocation LabelLoc,
1457 LabelStmt *Label) {
1458 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1459 }
Mike Stump1eb44332009-09-09 15:08:12 +00001460
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001465 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001466 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001468 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 }
Mike Stump1eb44332009-09-09 15:08:12 +00001470
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 /// \brief Build a new __builtin_choose_expr expression.
1472 ///
1473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001475 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001476 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 SourceLocation RParenLoc) {
1478 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001479 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 RParenLoc);
1481 }
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// \brief Build a new overloaded operator call expression.
1484 ///
1485 /// By default, performs semantic analysis to build the new expression.
1486 /// The semantic analysis provides the behavior of template instantiation,
1487 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001488 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// argument-dependent lookup, etc. Subclasses may override this routine to
1490 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001491 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001493 Expr *Callee,
1494 Expr *First,
1495 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001496
1497 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// reinterpret_cast.
1499 ///
1500 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001501 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001503 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 Stmt::StmtClass Class,
1505 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001506 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 SourceLocation RAngleLoc,
1508 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001509 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 SourceLocation RParenLoc) {
1511 switch (Class) {
1512 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001513 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001514 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001515 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516
1517 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001518 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001519 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001520 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001521
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001523 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001524 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001525 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001527
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001529 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001530 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001531 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 default:
1534 assert(false && "Invalid C++ named cast");
1535 break;
1536 }
Mike Stump1eb44332009-09-09 15:08:12 +00001537
John McCallf312b1e2010-08-26 23:41:50 +00001538 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 }
Mike Stump1eb44332009-09-09 15:08:12 +00001540
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 /// \brief Build a new C++ static_cast expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001545 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001547 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 SourceLocation RAngleLoc,
1549 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001550 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001552 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001553 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001554 SourceRange(LAngleLoc, RAngleLoc),
1555 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
1557
1558 /// \brief Build a new C++ dynamic_cast expression.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001562 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001564 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 SourceLocation RAngleLoc,
1566 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001567 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001569 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001570 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001571 SourceRange(LAngleLoc, RAngleLoc),
1572 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new C++ reinterpret_cast expression.
1576 ///
1577 /// By default, performs semantic analysis to build the new expression.
1578 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001581 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 SourceLocation RAngleLoc,
1583 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001584 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001586 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001587 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001588 SourceRange(LAngleLoc, RAngleLoc),
1589 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
1591
1592 /// \brief Build a new C++ const_cast expression.
1593 ///
1594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001598 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 SourceLocation RAngleLoc,
1600 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001603 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001604 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001605 SourceRange(LAngleLoc, RAngleLoc),
1606 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new C++ functional-style cast expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001613 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1614 SourceLocation LParenLoc,
1615 Expr *Sub,
1616 SourceLocation RParenLoc) {
1617 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001618 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 RParenLoc);
1620 }
Mike Stump1eb44332009-09-09 15:08:12 +00001621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// \brief Build a new C++ typeid(type) expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001626 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001627 SourceLocation TypeidLoc,
1628 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001630 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001631 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
Francois Pichet01b7c302010-09-08 12:20:18 +00001634
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 /// \brief Build a new C++ typeid(expr) expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001639 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001640 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001641 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001643 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001644 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001645 }
1646
Francois Pichet01b7c302010-09-08 12:20:18 +00001647 /// \brief Build a new C++ __uuidof(type) expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
1651 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1652 SourceLocation TypeidLoc,
1653 TypeSourceInfo *Operand,
1654 SourceLocation RParenLoc) {
1655 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1656 RParenLoc);
1657 }
1658
1659 /// \brief Build a new C++ __uuidof(expr) expression.
1660 ///
1661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
1663 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1664 SourceLocation TypeidLoc,
1665 Expr *Operand,
1666 SourceLocation RParenLoc) {
1667 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1668 RParenLoc);
1669 }
1670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new C++ "this" expression.
1672 ///
1673 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001674 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001676 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001677 QualType ThisType,
1678 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001680 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1681 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 }
1683
1684 /// \brief Build a new C++ throw expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001689 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 }
1691
1692 /// \brief Build a new C++ default-argument expression.
1693 ///
1694 /// By default, builds a new default-argument expression, which does not
1695 /// require any semantic analysis. Subclasses may override this routine to
1696 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001698 ParmVarDecl *Param) {
1699 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1700 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 }
1702
1703 /// \brief Build a new C++ zero-initialization expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001707 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1708 SourceLocation LParenLoc,
1709 SourceLocation RParenLoc) {
1710 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001711 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001712 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 }
Mike Stump1eb44332009-09-09 15:08:12 +00001714
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// \brief Build a new C++ "new" expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001719 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001720 bool UseGlobal,
1721 SourceLocation PlacementLParen,
1722 MultiExprArg PlacementArgs,
1723 SourceLocation PlacementRParen,
1724 SourceRange TypeIdParens,
1725 QualType AllocatedType,
1726 TypeSourceInfo *AllocatedTypeInfo,
1727 Expr *ArraySize,
1728 SourceLocation ConstructorLParen,
1729 MultiExprArg ConstructorArgs,
1730 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001731 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 PlacementLParen,
1733 move(PlacementArgs),
1734 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001735 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001736 AllocatedType,
1737 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001738 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 ConstructorLParen,
1740 move(ConstructorArgs),
1741 ConstructorRParen);
1742 }
Mike Stump1eb44332009-09-09 15:08:12 +00001743
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 /// \brief Build a new C++ "delete" expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001748 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 bool IsGlobalDelete,
1750 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001751 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001753 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 }
Mike Stump1eb44332009-09-09 15:08:12 +00001755
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// \brief Build a new unary type trait expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001760 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001761 SourceLocation StartLoc,
1762 TypeSourceInfo *T,
1763 SourceLocation RParenLoc) {
1764 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 }
1766
Francois Pichet6ad6f282010-12-07 00:08:36 +00001767 /// \brief Build a new binary type trait expression.
1768 ///
1769 /// By default, performs semantic analysis to build the new expression.
1770 /// Subclasses may override this routine to provide different behavior.
1771 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1772 SourceLocation StartLoc,
1773 TypeSourceInfo *LhsT,
1774 TypeSourceInfo *RhsT,
1775 SourceLocation RParenLoc) {
1776 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1777 }
1778
Mike Stump1eb44332009-09-09 15:08:12 +00001779 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 /// expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001786 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001787 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 CXXScopeSpec SS;
1789 SS.setRange(QualifierRange);
1790 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001791
1792 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001793 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001794 *TemplateArgs);
1795
Abramo Bagnara25777432010-08-11 22:01:17 +00001796 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 }
1798
1799 /// \brief Build a new template-id expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001803 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001804 LookupResult &R,
1805 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001806 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001807 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 }
1809
1810 /// \brief Build a new object-construction expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001814 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001815 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 CXXConstructorDecl *Constructor,
1817 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001818 MultiExprArg Args,
1819 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001820 CXXConstructExpr::ConstructionKind ConstructKind,
1821 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001822 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001823 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001824 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001825 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001826
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001827 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001828 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001829 RequiresZeroInit, ConstructKind,
1830 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 }
1832
1833 /// \brief Build a new object-construction expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001837 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1838 SourceLocation LParenLoc,
1839 MultiExprArg Args,
1840 SourceLocation RParenLoc) {
1841 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 LParenLoc,
1843 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 RParenLoc);
1845 }
1846
1847 /// \brief Build a new object-construction expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001851 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1852 SourceLocation LParenLoc,
1853 MultiExprArg Args,
1854 SourceLocation RParenLoc) {
1855 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 LParenLoc,
1857 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 RParenLoc);
1859 }
Mike Stump1eb44332009-09-09 15:08:12 +00001860
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 /// \brief Build a new member reference expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001865 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001866 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 bool IsArrow,
1868 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001869 NestedNameSpecifier *Qualifier,
1870 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001871 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001872 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001873 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001875 SS.setRange(QualifierRange);
1876 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001877
John McCall9ae2f072010-08-23 23:25:46 +00001878 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001879 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001880 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001881 MemberNameInfo,
1882 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 }
1884
John McCall129e2df2009-11-30 22:42:35 +00001885 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001889 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001890 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001891 SourceLocation OperatorLoc,
1892 bool IsArrow,
1893 NestedNameSpecifier *Qualifier,
1894 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001895 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001896 LookupResult &R,
1897 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001898 CXXScopeSpec SS;
1899 SS.setRange(QualifierRange);
1900 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001901
John McCall9ae2f072010-08-23 23:25:46 +00001902 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001903 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001904 SS, FirstQualifierInScope,
1905 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001906 }
Mike Stump1eb44332009-09-09 15:08:12 +00001907
Sebastian Redl2e156222010-09-10 20:55:43 +00001908 /// \brief Build a new noexcept expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
1912 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1913 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1914 }
1915
Douglas Gregoree8aff02011-01-04 17:33:58 +00001916 /// \brief Build a new expression to compute the length of a parameter pack.
1917 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1918 SourceLocation PackLoc,
1919 SourceLocation RParenLoc,
1920 unsigned Length) {
1921 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1922 OperatorLoc, Pack, PackLoc,
1923 RParenLoc, Length);
1924 }
1925
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 /// \brief Build a new Objective-C @encode expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001930 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001931 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001933 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001935 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936
Douglas Gregor92e986e2010-04-22 16:44:27 +00001937 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001938 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001939 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001940 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001941 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001942 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001943 MultiExprArg Args,
1944 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001945 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1946 ReceiverTypeInfo->getType(),
1947 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001948 Sel, Method, LBracLoc, SelectorLoc,
1949 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001950 }
1951
1952 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001953 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001954 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001955 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001956 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001957 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001958 MultiExprArg Args,
1959 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001960 return SemaRef.BuildInstanceMessage(Receiver,
1961 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00001962 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001963 Sel, Method, LBracLoc, SelectorLoc,
1964 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001965 }
1966
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001967 /// \brief Build a new Objective-C ivar reference expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001971 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001972 SourceLocation IvarLoc,
1973 bool IsArrow, bool IsFreeIvar) {
1974 // FIXME: We lose track of the IsFreeIvar bit.
1975 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00001976 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001977 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1978 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00001979 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001980 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00001981 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00001982 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001983 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001984 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001985
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001986 if (Result.get())
1987 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001988
John McCall9ae2f072010-08-23 23:25:46 +00001989 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00001990 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001991 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00001992 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001993 /*TemplateArgs=*/0);
1994 }
Douglas Gregore3303542010-04-26 20:47:02 +00001995
1996 /// \brief Build a new Objective-C property reference expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002000 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002001 ObjCPropertyDecl *Property,
2002 SourceLocation PropertyLoc) {
2003 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002004 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002005 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2006 Sema::LookupMemberName);
2007 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002008 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002009 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002010 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002011 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002012 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002013
Douglas Gregore3303542010-04-26 20:47:02 +00002014 if (Result.get())
2015 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002016
John McCall9ae2f072010-08-23 23:25:46 +00002017 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002018 /*FIXME:*/PropertyLoc, IsArrow,
2019 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002020 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002021 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002022 /*TemplateArgs=*/0);
2023 }
Sean Huntc3021132010-05-05 15:23:54 +00002024
John McCall12f78a62010-12-02 01:19:52 +00002025 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002026 ///
2027 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2030 ObjCMethodDecl *Getter,
2031 ObjCMethodDecl *Setter,
2032 SourceLocation PropertyLoc) {
2033 // Since these expressions can only be value-dependent, we do not
2034 // need to perform semantic analysis again.
2035 return Owned(
2036 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2037 VK_LValue, OK_ObjCProperty,
2038 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002039 }
2040
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002041 /// \brief Build a new Objective-C "isa" expression.
2042 ///
2043 /// By default, performs semantic analysis to build the new expression.
2044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002045 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002046 bool IsArrow) {
2047 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002048 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002049 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2050 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002051 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002052 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002053 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002054 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002055 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002056
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002057 if (Result.get())
2058 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002059
John McCall9ae2f072010-08-23 23:25:46 +00002060 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002061 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002062 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002063 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002064 /*TemplateArgs=*/0);
2065 }
Sean Huntc3021132010-05-05 15:23:54 +00002066
Douglas Gregorb98b1992009-08-11 05:31:07 +00002067 /// \brief Build a new shuffle vector expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002071 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002072 MultiExprArg SubExprs,
2073 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002075 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2077 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2078 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2079 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002080
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 // Build a reference to the __builtin_shufflevector builtin
2082 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002083 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002085 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002087
2088 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002089 unsigned NumSubExprs = SubExprs.size();
2090 Expr **Subs = (Expr **)SubExprs.release();
2091 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2092 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002093 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002094 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002095 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002097
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002099 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002101 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002102
Douglas Gregorb98b1992009-08-11 05:31:07 +00002103 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002104 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 }
John McCall43fed0d2010-11-12 08:19:04 +00002106
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002107 /// \brief Build a new template argument pack expansion.
2108 ///
2109 /// By default, performs semantic analysis to build a new pack expansion
2110 /// for a template argument. Subclasses may override this routine to provide
2111 /// different behavior.
2112 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2113 SourceLocation EllipsisLoc) {
2114 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002115 case TemplateArgument::Expression: {
2116 ExprResult Result
2117 = getSema().ActOnPackExpansion(Pattern.getSourceExpression(),
2118 EllipsisLoc);
2119 if (Result.isInvalid())
2120 return TemplateArgumentLoc();
2121
2122 return TemplateArgumentLoc(Result.get(), Result.get());
2123 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002124
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002125 case TemplateArgument::Template:
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002126 llvm_unreachable("Unsupported pack expansion of templates");
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002127
2128 case TemplateArgument::Null:
2129 case TemplateArgument::Integral:
2130 case TemplateArgument::Declaration:
2131 case TemplateArgument::Pack:
2132 llvm_unreachable("Pack expansion pattern has no parameter packs");
2133
2134 case TemplateArgument::Type:
2135 if (TypeSourceInfo *Expansion
2136 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2137 EllipsisLoc))
2138 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2139 Expansion);
2140 break;
2141 }
2142
2143 return TemplateArgumentLoc();
2144 }
2145
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002146 /// \brief Build a new expression pack expansion.
2147 ///
2148 /// By default, performs semantic analysis to build a new pack expansion
2149 /// for an expression. Subclasses may override this routine to provide
2150 /// different behavior.
2151 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2152 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2153 }
2154
John McCall43fed0d2010-11-12 08:19:04 +00002155private:
2156 QualType TransformTypeInObjectScope(QualType T,
2157 QualType ObjectType,
2158 NamedDecl *FirstQualifierInScope,
2159 NestedNameSpecifier *Prefix);
2160
2161 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2162 QualType ObjectType,
2163 NamedDecl *FirstQualifierInScope,
2164 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002165};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166
Douglas Gregor43959a92009-08-20 07:17:43 +00002167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002168StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002169 if (!S)
2170 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002171
Douglas Gregor43959a92009-08-20 07:17:43 +00002172 switch (S->getStmtClass()) {
2173 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002174
Douglas Gregor43959a92009-08-20 07:17:43 +00002175 // Transform individual statement nodes
2176#define STMT(Node, Parent) \
2177 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2178#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002179#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002180
Douglas Gregor43959a92009-08-20 07:17:43 +00002181 // Transform expressions by calling TransformExpr.
2182#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002183#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002184#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002185#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002186 {
John McCall60d7b3a2010-08-24 06:29:42 +00002187 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002188 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002189 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002190
John McCall9ae2f072010-08-23 23:25:46 +00002191 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002192 }
Mike Stump1eb44332009-09-09 15:08:12 +00002193 }
2194
John McCall3fa5cae2010-10-26 07:05:15 +00002195 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002196}
Mike Stump1eb44332009-09-09 15:08:12 +00002197
2198
Douglas Gregor670444e2009-08-04 22:27:00 +00002199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002200ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002201 if (!E)
2202 return SemaRef.Owned(E);
2203
2204 switch (E->getStmtClass()) {
2205 case Stmt::NoStmtClass: break;
2206#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002207#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002208#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002209 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002210#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002211 }
2212
John McCall3fa5cae2010-10-26 07:05:15 +00002213 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002214}
2215
2216template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002217bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2218 unsigned NumInputs,
2219 bool IsCall,
2220 llvm::SmallVectorImpl<Expr *> &Outputs,
2221 bool *ArgChanged) {
2222 for (unsigned I = 0; I != NumInputs; ++I) {
2223 // If requested, drop call arguments that need to be dropped.
2224 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2225 if (ArgChanged)
2226 *ArgChanged = true;
2227
2228 break;
2229 }
2230
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002231 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2232 Expr *Pattern = Expansion->getPattern();
2233
2234 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2235 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2236 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2237
2238 // Determine whether the set of unexpanded parameter packs can and should
2239 // be expanded.
2240 bool Expand = true;
2241 unsigned NumExpansions = 0;
2242 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2243 Pattern->getSourceRange(),
2244 Unexpanded.data(),
2245 Unexpanded.size(),
2246 Expand, NumExpansions))
2247 return true;
2248
2249 if (!Expand) {
2250 // The transform has determined that we should perform a simple
2251 // transformation on the pack expansion, producing another pack
2252 // expansion.
2253 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2254 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2255 if (OutPattern.isInvalid())
2256 return true;
2257
2258 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2259 Expansion->getEllipsisLoc());
2260 if (Out.isInvalid())
2261 return true;
2262
2263 if (ArgChanged)
2264 *ArgChanged = true;
2265 Outputs.push_back(Out.get());
2266 continue;
2267 }
2268
2269 // The transform has determined that we should perform an elementwise
2270 // expansion of the pattern. Do so.
2271 for (unsigned I = 0; I != NumExpansions; ++I) {
2272 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2273 ExprResult Out = getDerived().TransformExpr(Pattern);
2274 if (Out.isInvalid())
2275 return true;
2276
2277 if (ArgChanged)
2278 *ArgChanged = true;
2279 Outputs.push_back(Out.get());
2280 }
2281
2282 continue;
2283 }
2284
Douglas Gregoraa165f82011-01-03 19:04:46 +00002285 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2286 if (Result.isInvalid())
2287 return true;
2288
2289 if (Result.get() != Inputs[I] && ArgChanged)
2290 *ArgChanged = true;
2291
2292 Outputs.push_back(Result.get());
2293 }
2294
2295 return false;
2296}
2297
2298template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002299NestedNameSpecifier *
2300TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002301 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002302 QualType ObjectType,
2303 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002304 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002305
Douglas Gregor43959a92009-08-20 07:17:43 +00002306 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002307 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002308 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002309 ObjectType,
2310 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002311 if (!Prefix)
2312 return 0;
2313 }
Mike Stump1eb44332009-09-09 15:08:12 +00002314
Douglas Gregordcee1a12009-08-06 05:28:30 +00002315 switch (NNS->getKind()) {
2316 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002317 if (Prefix) {
2318 // The object type and qualifier-in-scope really apply to the
2319 // leftmost entity.
2320 ObjectType = QualType();
2321 FirstQualifierInScope = 0;
2322 }
2323
Mike Stump1eb44332009-09-09 15:08:12 +00002324 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002325 "Identifier nested-name-specifier with no prefix or object type");
2326 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2327 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002328 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002329
2330 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002331 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002332 ObjectType,
2333 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002334
Douglas Gregordcee1a12009-08-06 05:28:30 +00002335 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002336 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002337 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002338 getDerived().TransformDecl(Range.getBegin(),
2339 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002340 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002341 Prefix == NNS->getPrefix() &&
2342 NS == NNS->getAsNamespace())
2343 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002344
Douglas Gregordcee1a12009-08-06 05:28:30 +00002345 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2346 }
Mike Stump1eb44332009-09-09 15:08:12 +00002347
Douglas Gregordcee1a12009-08-06 05:28:30 +00002348 case NestedNameSpecifier::Global:
2349 // There is no meaningful transformation that one could perform on the
2350 // global scope.
2351 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002352
Douglas Gregordcee1a12009-08-06 05:28:30 +00002353 case NestedNameSpecifier::TypeSpecWithTemplate:
2354 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002355 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002356 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2357 ObjectType,
2358 FirstQualifierInScope,
2359 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002360 if (T.isNull())
2361 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002362
Douglas Gregordcee1a12009-08-06 05:28:30 +00002363 if (!getDerived().AlwaysRebuild() &&
2364 Prefix == NNS->getPrefix() &&
2365 T == QualType(NNS->getAsType(), 0))
2366 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002367
2368 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2369 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002370 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002371 }
2372 }
Mike Stump1eb44332009-09-09 15:08:12 +00002373
Douglas Gregordcee1a12009-08-06 05:28:30 +00002374 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002375 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002376}
2377
2378template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002379DeclarationNameInfo
2380TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002381::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002382 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002383 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002384 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002385
2386 switch (Name.getNameKind()) {
2387 case DeclarationName::Identifier:
2388 case DeclarationName::ObjCZeroArgSelector:
2389 case DeclarationName::ObjCOneArgSelector:
2390 case DeclarationName::ObjCMultiArgSelector:
2391 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002392 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002393 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002394 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002395
Douglas Gregor81499bb2009-09-03 22:13:48 +00002396 case DeclarationName::CXXConstructorName:
2397 case DeclarationName::CXXDestructorName:
2398 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002399 TypeSourceInfo *NewTInfo;
2400 CanQualType NewCanTy;
2401 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002402 NewTInfo = getDerived().TransformType(OldTInfo);
2403 if (!NewTInfo)
2404 return DeclarationNameInfo();
2405 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002406 }
2407 else {
2408 NewTInfo = 0;
2409 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002410 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002411 if (NewT.isNull())
2412 return DeclarationNameInfo();
2413 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2414 }
Mike Stump1eb44332009-09-09 15:08:12 +00002415
Abramo Bagnara25777432010-08-11 22:01:17 +00002416 DeclarationName NewName
2417 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2418 NewCanTy);
2419 DeclarationNameInfo NewNameInfo(NameInfo);
2420 NewNameInfo.setName(NewName);
2421 NewNameInfo.setNamedTypeInfo(NewTInfo);
2422 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002423 }
Mike Stump1eb44332009-09-09 15:08:12 +00002424 }
2425
Abramo Bagnara25777432010-08-11 22:01:17 +00002426 assert(0 && "Unknown name kind.");
2427 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002428}
2429
2430template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002431TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002432TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002433 QualType ObjectType,
2434 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002435 SourceLocation Loc = getDerived().getBaseLocation();
2436
Douglas Gregord1067e52009-08-06 06:41:21 +00002437 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002438 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002439 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002440 /*FIXME*/ SourceRange(Loc),
2441 ObjectType,
2442 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002443 if (!NNS)
2444 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002445
Douglas Gregord1067e52009-08-06 06:41:21 +00002446 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002447 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002448 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002449 if (!TransTemplate)
2450 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002451
Douglas Gregord1067e52009-08-06 06:41:21 +00002452 if (!getDerived().AlwaysRebuild() &&
2453 NNS == QTN->getQualifier() &&
2454 TransTemplate == Template)
2455 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002456
Douglas Gregord1067e52009-08-06 06:41:21 +00002457 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2458 TransTemplate);
2459 }
Mike Stump1eb44332009-09-09 15:08:12 +00002460
John McCallf7a1a742009-11-24 19:00:30 +00002461 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002462 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002463 }
Mike Stump1eb44332009-09-09 15:08:12 +00002464
Douglas Gregord1067e52009-08-06 06:41:21 +00002465 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002466 NestedNameSpecifier *NNS = DTN->getQualifier();
2467 if (NNS) {
2468 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2469 /*FIXME:*/SourceRange(Loc),
2470 ObjectType,
2471 FirstQualifierInScope);
2472 if (!NNS) return TemplateName();
2473
2474 // These apply to the scope specifier, not the template.
2475 ObjectType = QualType();
2476 FirstQualifierInScope = 0;
2477 }
Mike Stump1eb44332009-09-09 15:08:12 +00002478
Douglas Gregord1067e52009-08-06 06:41:21 +00002479 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002480 NNS == DTN->getQualifier() &&
2481 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002482 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002483
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002484 if (DTN->isIdentifier()) {
2485 // FIXME: Bad range
2486 SourceRange QualifierRange(getDerived().getBaseLocation());
2487 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2488 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002489 ObjectType,
2490 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002491 }
Sean Huntc3021132010-05-05 15:23:54 +00002492
2493 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002494 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002495 }
Mike Stump1eb44332009-09-09 15:08:12 +00002496
Douglas Gregord1067e52009-08-06 06:41:21 +00002497 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002498 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002499 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002500 if (!TransTemplate)
2501 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002502
Douglas Gregord1067e52009-08-06 06:41:21 +00002503 if (!getDerived().AlwaysRebuild() &&
2504 TransTemplate == Template)
2505 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002506
Douglas Gregord1067e52009-08-06 06:41:21 +00002507 return TemplateName(TransTemplate);
2508 }
Mike Stump1eb44332009-09-09 15:08:12 +00002509
John McCallf7a1a742009-11-24 19:00:30 +00002510 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002511 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002512 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002513}
2514
2515template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002516void TreeTransform<Derived>::InventTemplateArgumentLoc(
2517 const TemplateArgument &Arg,
2518 TemplateArgumentLoc &Output) {
2519 SourceLocation Loc = getDerived().getBaseLocation();
2520 switch (Arg.getKind()) {
2521 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002522 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002523 break;
2524
2525 case TemplateArgument::Type:
2526 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002527 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002528
John McCall833ca992009-10-29 08:12:44 +00002529 break;
2530
Douglas Gregor788cd062009-11-11 01:00:40 +00002531 case TemplateArgument::Template:
2532 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2533 break;
Sean Huntc3021132010-05-05 15:23:54 +00002534
John McCall833ca992009-10-29 08:12:44 +00002535 case TemplateArgument::Expression:
2536 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2537 break;
2538
2539 case TemplateArgument::Declaration:
2540 case TemplateArgument::Integral:
2541 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002542 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002543 break;
2544 }
2545}
2546
2547template<typename Derived>
2548bool TreeTransform<Derived>::TransformTemplateArgument(
2549 const TemplateArgumentLoc &Input,
2550 TemplateArgumentLoc &Output) {
2551 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002552 switch (Arg.getKind()) {
2553 case TemplateArgument::Null:
2554 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002555 Output = Input;
2556 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002557
Douglas Gregor670444e2009-08-04 22:27:00 +00002558 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002559 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002560 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002561 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002562
2563 DI = getDerived().TransformType(DI);
2564 if (!DI) return true;
2565
2566 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2567 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002568 }
Mike Stump1eb44332009-09-09 15:08:12 +00002569
Douglas Gregor670444e2009-08-04 22:27:00 +00002570 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002571 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002572 DeclarationName Name;
2573 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2574 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002575 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002576 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002577 if (!D) return true;
2578
John McCall828bff22009-10-29 18:45:58 +00002579 Expr *SourceExpr = Input.getSourceDeclExpression();
2580 if (SourceExpr) {
2581 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002582 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002583 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002584 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002585 }
2586
2587 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002588 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002589 }
Mike Stump1eb44332009-09-09 15:08:12 +00002590
Douglas Gregor788cd062009-11-11 01:00:40 +00002591 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002592 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002593 TemplateName Template
2594 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2595 if (Template.isNull())
2596 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002597
Douglas Gregor788cd062009-11-11 01:00:40 +00002598 Output = TemplateArgumentLoc(TemplateArgument(Template),
2599 Input.getTemplateQualifierRange(),
2600 Input.getTemplateNameLoc());
2601 return false;
2602 }
Sean Huntc3021132010-05-05 15:23:54 +00002603
Douglas Gregor670444e2009-08-04 22:27:00 +00002604 case TemplateArgument::Expression: {
2605 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002606 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002607 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002608
John McCall833ca992009-10-29 08:12:44 +00002609 Expr *InputExpr = Input.getSourceExpression();
2610 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2611
John McCall60d7b3a2010-08-24 06:29:42 +00002612 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002613 = getDerived().TransformExpr(InputExpr);
2614 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002615 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002616 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002617 }
Mike Stump1eb44332009-09-09 15:08:12 +00002618
Douglas Gregor670444e2009-08-04 22:27:00 +00002619 case TemplateArgument::Pack: {
2620 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2621 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002622 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002623 AEnd = Arg.pack_end();
2624 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002625
John McCall833ca992009-10-29 08:12:44 +00002626 // FIXME: preserve source information here when we start
2627 // caring about parameter packs.
2628
John McCall828bff22009-10-29 18:45:58 +00002629 TemplateArgumentLoc InputArg;
2630 TemplateArgumentLoc OutputArg;
2631 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2632 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002633 return true;
2634
John McCall828bff22009-10-29 18:45:58 +00002635 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002636 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002637
2638 TemplateArgument *TransformedArgsPtr
2639 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2640 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2641 TransformedArgsPtr);
2642 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2643 TransformedArgs.size()),
2644 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002645 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002646 }
2647 }
Mike Stump1eb44332009-09-09 15:08:12 +00002648
Douglas Gregor670444e2009-08-04 22:27:00 +00002649 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002650 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002651}
2652
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002653/// \brief Iterator adaptor that invents template argument location information
2654/// for each of the template arguments in its underlying iterator.
2655template<typename Derived, typename InputIterator>
2656class TemplateArgumentLocInventIterator {
2657 TreeTransform<Derived> &Self;
2658 InputIterator Iter;
2659
2660public:
2661 typedef TemplateArgumentLoc value_type;
2662 typedef TemplateArgumentLoc reference;
2663 typedef typename std::iterator_traits<InputIterator>::difference_type
2664 difference_type;
2665 typedef std::input_iterator_tag iterator_category;
2666
2667 class pointer {
2668 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002669
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002670 public:
2671 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2672
2673 const TemplateArgumentLoc *operator->() const { return &Arg; }
2674 };
2675
2676 TemplateArgumentLocInventIterator() { }
2677
2678 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2679 InputIterator Iter)
2680 : Self(Self), Iter(Iter) { }
2681
2682 TemplateArgumentLocInventIterator &operator++() {
2683 ++Iter;
2684 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002685 }
2686
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002687 TemplateArgumentLocInventIterator operator++(int) {
2688 TemplateArgumentLocInventIterator Old(*this);
2689 ++(*this);
2690 return Old;
2691 }
2692
2693 reference operator*() const {
2694 TemplateArgumentLoc Result;
2695 Self.InventTemplateArgumentLoc(*Iter, Result);
2696 return Result;
2697 }
2698
2699 pointer operator->() const { return pointer(**this); }
2700
2701 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2702 const TemplateArgumentLocInventIterator &Y) {
2703 return X.Iter == Y.Iter;
2704 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002705
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002706 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2707 const TemplateArgumentLocInventIterator &Y) {
2708 return X.Iter != Y.Iter;
2709 }
2710};
2711
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002712template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002713template<typename InputIterator>
2714bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2715 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002716 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002717 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002718 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002719 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002720
2721 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2722 // Unpack argument packs, which we translate them into separate
2723 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002724 // FIXME: We could do much better if we could guarantee that the
2725 // TemplateArgumentLocInfo for the pack expansion would be usable for
2726 // all of the template arguments in the argument pack.
2727 typedef TemplateArgumentLocInventIterator<Derived,
2728 TemplateArgument::pack_iterator>
2729 PackLocIterator;
2730 if (TransformTemplateArguments(PackLocIterator(*this,
2731 In.getArgument().pack_begin()),
2732 PackLocIterator(*this,
2733 In.getArgument().pack_end()),
2734 Outputs))
2735 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002736
2737 continue;
2738 }
2739
2740 if (In.getArgument().isPackExpansion()) {
2741 // We have a pack expansion, for which we will be substituting into
2742 // the pattern.
2743 SourceLocation Ellipsis;
2744 TemplateArgumentLoc Pattern
2745 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2746
2747 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2748 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2749 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2750
2751 // Determine whether the set of unexpanded parameter packs can and should
2752 // be expanded.
2753 bool Expand = true;
2754 unsigned NumExpansions = 0;
2755 if (getDerived().TryExpandParameterPacks(Ellipsis,
2756 Pattern.getSourceRange(),
2757 Unexpanded.data(),
2758 Unexpanded.size(),
2759 Expand, NumExpansions))
2760 return true;
2761
2762 if (!Expand) {
2763 // The transform has determined that we should perform a simple
2764 // transformation on the pack expansion, producing another pack
2765 // expansion.
2766 TemplateArgumentLoc OutPattern;
2767 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2768 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2769 return true;
2770
2771 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2772 if (Out.getArgument().isNull())
2773 return true;
2774
2775 Outputs.addArgument(Out);
2776 continue;
2777 }
2778
2779 // The transform has determined that we should perform an elementwise
2780 // expansion of the pattern. Do so.
2781 for (unsigned I = 0; I != NumExpansions; ++I) {
2782 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2783
2784 if (getDerived().TransformTemplateArgument(Pattern, Out))
2785 return true;
2786
2787 Outputs.addArgument(Out);
2788 }
2789
2790 continue;
2791 }
2792
2793 // The simple case:
2794 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002795 return true;
2796
2797 Outputs.addArgument(Out);
2798 }
2799
2800 return false;
2801
2802}
2803
Douglas Gregor577f75a2009-08-04 16:50:30 +00002804//===----------------------------------------------------------------------===//
2805// Type transformation
2806//===----------------------------------------------------------------------===//
2807
2808template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002809QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002810 if (getDerived().AlreadyTransformed(T))
2811 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002812
John McCalla2becad2009-10-21 00:40:46 +00002813 // Temporary workaround. All of these transformations should
2814 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002815 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002816 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002817
John McCall43fed0d2010-11-12 08:19:04 +00002818 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002819
John McCalla2becad2009-10-21 00:40:46 +00002820 if (!NewDI)
2821 return QualType();
2822
2823 return NewDI->getType();
2824}
2825
2826template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002827TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002828 if (getDerived().AlreadyTransformed(DI->getType()))
2829 return DI;
2830
2831 TypeLocBuilder TLB;
2832
2833 TypeLoc TL = DI->getTypeLoc();
2834 TLB.reserve(TL.getFullDataSize());
2835
John McCall43fed0d2010-11-12 08:19:04 +00002836 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002837 if (Result.isNull())
2838 return 0;
2839
John McCalla93c9342009-12-07 02:54:59 +00002840 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002841}
2842
2843template<typename Derived>
2844QualType
John McCall43fed0d2010-11-12 08:19:04 +00002845TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002846 switch (T.getTypeLocClass()) {
2847#define ABSTRACT_TYPELOC(CLASS, PARENT)
2848#define TYPELOC(CLASS, PARENT) \
2849 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002850 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002851#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002852 }
Mike Stump1eb44332009-09-09 15:08:12 +00002853
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002854 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002855 return QualType();
2856}
2857
2858/// FIXME: By default, this routine adds type qualifiers only to types
2859/// that can have qualifiers, and silently suppresses those qualifiers
2860/// that are not permitted (e.g., qualifiers on reference or function
2861/// types). This is the right thing for template instantiation, but
2862/// probably not for other clients.
2863template<typename Derived>
2864QualType
2865TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002866 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002867 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002868
John McCall43fed0d2010-11-12 08:19:04 +00002869 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002870 if (Result.isNull())
2871 return QualType();
2872
2873 // Silently suppress qualifiers if the result type can't be qualified.
2874 // FIXME: this is the right thing for template instantiation, but
2875 // probably not for other clients.
2876 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002877 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002878
John McCall28654742010-06-05 06:41:15 +00002879 if (!Quals.empty()) {
2880 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2881 TLB.push<QualifiedTypeLoc>(Result);
2882 // No location information to preserve.
2883 }
John McCalla2becad2009-10-21 00:40:46 +00002884
2885 return Result;
2886}
2887
John McCall43fed0d2010-11-12 08:19:04 +00002888/// \brief Transforms a type that was written in a scope specifier,
2889/// given an object type, the results of unqualified lookup, and
2890/// an already-instantiated prefix.
2891///
2892/// The object type is provided iff the scope specifier qualifies the
2893/// member of a dependent member-access expression. The prefix is
2894/// provided iff the the scope specifier in which this appears has a
2895/// prefix.
2896///
2897/// This is private to TreeTransform.
2898template<typename Derived>
2899QualType
2900TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2901 QualType ObjectType,
2902 NamedDecl *UnqualLookup,
2903 NestedNameSpecifier *Prefix) {
2904 if (getDerived().AlreadyTransformed(T))
2905 return T;
2906
2907 TypeSourceInfo *TSI =
2908 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2909
2910 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2911 UnqualLookup, Prefix);
2912 if (!TSI) return QualType();
2913 return TSI->getType();
2914}
2915
2916template<typename Derived>
2917TypeSourceInfo *
2918TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2919 QualType ObjectType,
2920 NamedDecl *UnqualLookup,
2921 NestedNameSpecifier *Prefix) {
2922 // TODO: in some cases, we might be some verification to do here.
2923 if (ObjectType.isNull())
2924 return getDerived().TransformType(TSI);
2925
2926 QualType T = TSI->getType();
2927 if (getDerived().AlreadyTransformed(T))
2928 return TSI;
2929
2930 TypeLocBuilder TLB;
2931 QualType Result;
2932
2933 if (isa<TemplateSpecializationType>(T)) {
2934 TemplateSpecializationTypeLoc TL
2935 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2936
2937 TemplateName Template =
2938 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2939 ObjectType, UnqualLookup);
2940 if (Template.isNull()) return 0;
2941
2942 Result = getDerived()
2943 .TransformTemplateSpecializationType(TLB, TL, Template);
2944 } else if (isa<DependentTemplateSpecializationType>(T)) {
2945 DependentTemplateSpecializationTypeLoc TL
2946 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2947
2948 Result = getDerived()
2949 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2950 } else {
2951 // Nothing special needs to be done for these.
2952 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2953 }
2954
2955 if (Result.isNull()) return 0;
2956 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2957}
2958
John McCalla2becad2009-10-21 00:40:46 +00002959template <class TyLoc> static inline
2960QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2961 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2962 NewT.setNameLoc(T.getNameLoc());
2963 return T.getType();
2964}
2965
John McCalla2becad2009-10-21 00:40:46 +00002966template<typename Derived>
2967QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002968 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002969 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2970 NewT.setBuiltinLoc(T.getBuiltinLoc());
2971 if (T.needsExtraLocalData())
2972 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2973 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002974}
Mike Stump1eb44332009-09-09 15:08:12 +00002975
Douglas Gregor577f75a2009-08-04 16:50:30 +00002976template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002977QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002978 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002979 // FIXME: recurse?
2980 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002981}
Mike Stump1eb44332009-09-09 15:08:12 +00002982
Douglas Gregor577f75a2009-08-04 16:50:30 +00002983template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002984QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002985 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00002986 QualType PointeeType
2987 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00002988 if (PointeeType.isNull())
2989 return QualType();
2990
2991 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00002992 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002993 // A dependent pointer type 'T *' has is being transformed such
2994 // that an Objective-C class type is being replaced for 'T'. The
2995 // resulting pointer type is an ObjCObjectPointerType, not a
2996 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00002997 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00002998
John McCallc12c5bb2010-05-15 11:32:37 +00002999 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3000 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003001 return Result;
3002 }
John McCall43fed0d2010-11-12 08:19:04 +00003003
Douglas Gregor92e986e2010-04-22 16:44:27 +00003004 if (getDerived().AlwaysRebuild() ||
3005 PointeeType != TL.getPointeeLoc().getType()) {
3006 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3007 if (Result.isNull())
3008 return QualType();
3009 }
Sean Huntc3021132010-05-05 15:23:54 +00003010
Douglas Gregor92e986e2010-04-22 16:44:27 +00003011 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3012 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003013 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003014}
Mike Stump1eb44332009-09-09 15:08:12 +00003015
3016template<typename Derived>
3017QualType
John McCalla2becad2009-10-21 00:40:46 +00003018TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003019 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003020 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003021 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3022 if (PointeeType.isNull())
3023 return QualType();
3024
3025 QualType Result = TL.getType();
3026 if (getDerived().AlwaysRebuild() ||
3027 PointeeType != TL.getPointeeLoc().getType()) {
3028 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003029 TL.getSigilLoc());
3030 if (Result.isNull())
3031 return QualType();
3032 }
3033
Douglas Gregor39968ad2010-04-22 16:50:51 +00003034 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003035 NewT.setSigilLoc(TL.getSigilLoc());
3036 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003037}
3038
John McCall85737a72009-10-30 00:06:24 +00003039/// Transforms a reference type. Note that somewhat paradoxically we
3040/// don't care whether the type itself is an l-value type or an r-value
3041/// type; we only care if the type was *written* as an l-value type
3042/// or an r-value type.
3043template<typename Derived>
3044QualType
3045TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003046 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003047 const ReferenceType *T = TL.getTypePtr();
3048
3049 // Note that this works with the pointee-as-written.
3050 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3051 if (PointeeType.isNull())
3052 return QualType();
3053
3054 QualType Result = TL.getType();
3055 if (getDerived().AlwaysRebuild() ||
3056 PointeeType != T->getPointeeTypeAsWritten()) {
3057 Result = getDerived().RebuildReferenceType(PointeeType,
3058 T->isSpelledAsLValue(),
3059 TL.getSigilLoc());
3060 if (Result.isNull())
3061 return QualType();
3062 }
3063
3064 // r-value references can be rebuilt as l-value references.
3065 ReferenceTypeLoc NewTL;
3066 if (isa<LValueReferenceType>(Result))
3067 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3068 else
3069 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3070 NewTL.setSigilLoc(TL.getSigilLoc());
3071
3072 return Result;
3073}
3074
Mike Stump1eb44332009-09-09 15:08:12 +00003075template<typename Derived>
3076QualType
John McCalla2becad2009-10-21 00:40:46 +00003077TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003078 LValueReferenceTypeLoc TL) {
3079 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003080}
3081
Mike Stump1eb44332009-09-09 15:08:12 +00003082template<typename Derived>
3083QualType
John McCalla2becad2009-10-21 00:40:46 +00003084TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003085 RValueReferenceTypeLoc TL) {
3086 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003087}
Mike Stump1eb44332009-09-09 15:08:12 +00003088
Douglas Gregor577f75a2009-08-04 16:50:30 +00003089template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003090QualType
John McCalla2becad2009-10-21 00:40:46 +00003091TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003092 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003093 MemberPointerType *T = TL.getTypePtr();
3094
3095 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003096 if (PointeeType.isNull())
3097 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003098
John McCalla2becad2009-10-21 00:40:46 +00003099 // TODO: preserve source information for this.
3100 QualType ClassType
3101 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102 if (ClassType.isNull())
3103 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003104
John McCalla2becad2009-10-21 00:40:46 +00003105 QualType Result = TL.getType();
3106 if (getDerived().AlwaysRebuild() ||
3107 PointeeType != T->getPointeeType() ||
3108 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003109 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3110 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003111 if (Result.isNull())
3112 return QualType();
3113 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003114
John McCalla2becad2009-10-21 00:40:46 +00003115 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3116 NewTL.setSigilLoc(TL.getSigilLoc());
3117
3118 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003119}
3120
Mike Stump1eb44332009-09-09 15:08:12 +00003121template<typename Derived>
3122QualType
John McCalla2becad2009-10-21 00:40:46 +00003123TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003124 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003125 ConstantArrayType *T = TL.getTypePtr();
3126 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003127 if (ElementType.isNull())
3128 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003129
John McCalla2becad2009-10-21 00:40:46 +00003130 QualType Result = TL.getType();
3131 if (getDerived().AlwaysRebuild() ||
3132 ElementType != T->getElementType()) {
3133 Result = getDerived().RebuildConstantArrayType(ElementType,
3134 T->getSizeModifier(),
3135 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003136 T->getIndexTypeCVRQualifiers(),
3137 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003138 if (Result.isNull())
3139 return QualType();
3140 }
Sean Huntc3021132010-05-05 15:23:54 +00003141
John McCalla2becad2009-10-21 00:40:46 +00003142 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3143 NewTL.setLBracketLoc(TL.getLBracketLoc());
3144 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003145
John McCalla2becad2009-10-21 00:40:46 +00003146 Expr *Size = TL.getSizeExpr();
3147 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003148 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003149 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3150 }
3151 NewTL.setSizeExpr(Size);
3152
3153 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003154}
Mike Stump1eb44332009-09-09 15:08:12 +00003155
Douglas Gregor577f75a2009-08-04 16:50:30 +00003156template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003157QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003158 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003159 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003160 IncompleteArrayType *T = TL.getTypePtr();
3161 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003162 if (ElementType.isNull())
3163 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003164
John McCalla2becad2009-10-21 00:40:46 +00003165 QualType Result = TL.getType();
3166 if (getDerived().AlwaysRebuild() ||
3167 ElementType != T->getElementType()) {
3168 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003169 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003170 T->getIndexTypeCVRQualifiers(),
3171 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003172 if (Result.isNull())
3173 return QualType();
3174 }
Sean Huntc3021132010-05-05 15:23:54 +00003175
John McCalla2becad2009-10-21 00:40:46 +00003176 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3177 NewTL.setLBracketLoc(TL.getLBracketLoc());
3178 NewTL.setRBracketLoc(TL.getRBracketLoc());
3179 NewTL.setSizeExpr(0);
3180
3181 return Result;
3182}
3183
3184template<typename Derived>
3185QualType
3186TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003187 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003188 VariableArrayType *T = TL.getTypePtr();
3189 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3190 if (ElementType.isNull())
3191 return QualType();
3192
3193 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003194 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003195
John McCall60d7b3a2010-08-24 06:29:42 +00003196 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003197 = getDerived().TransformExpr(T->getSizeExpr());
3198 if (SizeResult.isInvalid())
3199 return QualType();
3200
John McCall9ae2f072010-08-23 23:25:46 +00003201 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003202
3203 QualType Result = TL.getType();
3204 if (getDerived().AlwaysRebuild() ||
3205 ElementType != T->getElementType() ||
3206 Size != T->getSizeExpr()) {
3207 Result = getDerived().RebuildVariableArrayType(ElementType,
3208 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003209 Size,
John McCalla2becad2009-10-21 00:40:46 +00003210 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003211 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003212 if (Result.isNull())
3213 return QualType();
3214 }
Sean Huntc3021132010-05-05 15:23:54 +00003215
John McCalla2becad2009-10-21 00:40:46 +00003216 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3217 NewTL.setLBracketLoc(TL.getLBracketLoc());
3218 NewTL.setRBracketLoc(TL.getRBracketLoc());
3219 NewTL.setSizeExpr(Size);
3220
3221 return Result;
3222}
3223
3224template<typename Derived>
3225QualType
3226TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003227 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003228 DependentSizedArrayType *T = TL.getTypePtr();
3229 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3230 if (ElementType.isNull())
3231 return QualType();
3232
3233 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003234 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003235
John McCall60d7b3a2010-08-24 06:29:42 +00003236 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003237 = getDerived().TransformExpr(T->getSizeExpr());
3238 if (SizeResult.isInvalid())
3239 return QualType();
3240
3241 Expr *Size = static_cast<Expr*>(SizeResult.get());
3242
3243 QualType Result = TL.getType();
3244 if (getDerived().AlwaysRebuild() ||
3245 ElementType != T->getElementType() ||
3246 Size != T->getSizeExpr()) {
3247 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3248 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003249 Size,
John McCalla2becad2009-10-21 00:40:46 +00003250 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003251 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003252 if (Result.isNull())
3253 return QualType();
3254 }
3255 else SizeResult.take();
3256
3257 // We might have any sort of array type now, but fortunately they
3258 // all have the same location layout.
3259 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3260 NewTL.setLBracketLoc(TL.getLBracketLoc());
3261 NewTL.setRBracketLoc(TL.getRBracketLoc());
3262 NewTL.setSizeExpr(Size);
3263
3264 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003265}
Mike Stump1eb44332009-09-09 15:08:12 +00003266
3267template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003268QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003269 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003270 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003271 DependentSizedExtVectorType *T = TL.getTypePtr();
3272
3273 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003274 QualType ElementType = getDerived().TransformType(T->getElementType());
3275 if (ElementType.isNull())
3276 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003277
Douglas Gregor670444e2009-08-04 22:27:00 +00003278 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003279 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003280
John McCall60d7b3a2010-08-24 06:29:42 +00003281 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003282 if (Size.isInvalid())
3283 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003284
John McCalla2becad2009-10-21 00:40:46 +00003285 QualType Result = TL.getType();
3286 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003287 ElementType != T->getElementType() ||
3288 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003289 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003290 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003291 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003292 if (Result.isNull())
3293 return QualType();
3294 }
John McCalla2becad2009-10-21 00:40:46 +00003295
3296 // Result might be dependent or not.
3297 if (isa<DependentSizedExtVectorType>(Result)) {
3298 DependentSizedExtVectorTypeLoc NewTL
3299 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3300 NewTL.setNameLoc(TL.getNameLoc());
3301 } else {
3302 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3303 NewTL.setNameLoc(TL.getNameLoc());
3304 }
3305
3306 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003307}
Mike Stump1eb44332009-09-09 15:08:12 +00003308
3309template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003310QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003311 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003312 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003313 QualType ElementType = getDerived().TransformType(T->getElementType());
3314 if (ElementType.isNull())
3315 return QualType();
3316
John McCalla2becad2009-10-21 00:40:46 +00003317 QualType Result = TL.getType();
3318 if (getDerived().AlwaysRebuild() ||
3319 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003320 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003321 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003322 if (Result.isNull())
3323 return QualType();
3324 }
Sean Huntc3021132010-05-05 15:23:54 +00003325
John McCalla2becad2009-10-21 00:40:46 +00003326 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3327 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003328
John McCalla2becad2009-10-21 00:40:46 +00003329 return Result;
3330}
3331
3332template<typename Derived>
3333QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003334 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003335 VectorType *T = TL.getTypePtr();
3336 QualType ElementType = getDerived().TransformType(T->getElementType());
3337 if (ElementType.isNull())
3338 return QualType();
3339
3340 QualType Result = TL.getType();
3341 if (getDerived().AlwaysRebuild() ||
3342 ElementType != T->getElementType()) {
3343 Result = getDerived().RebuildExtVectorType(ElementType,
3344 T->getNumElements(),
3345 /*FIXME*/ SourceLocation());
3346 if (Result.isNull())
3347 return QualType();
3348 }
Sean Huntc3021132010-05-05 15:23:54 +00003349
John McCalla2becad2009-10-21 00:40:46 +00003350 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3351 NewTL.setNameLoc(TL.getNameLoc());
3352
3353 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003354}
Mike Stump1eb44332009-09-09 15:08:12 +00003355
3356template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003357ParmVarDecl *
3358TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3359 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3360 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3361 if (!NewDI)
3362 return 0;
3363
3364 if (NewDI == OldDI)
3365 return OldParm;
3366 else
3367 return ParmVarDecl::Create(SemaRef.Context,
3368 OldParm->getDeclContext(),
3369 OldParm->getLocation(),
3370 OldParm->getIdentifier(),
3371 NewDI->getType(),
3372 NewDI,
3373 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003374 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003375 /* DefArg */ NULL);
3376}
3377
3378template<typename Derived>
3379bool TreeTransform<Derived>::
3380 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3381 llvm::SmallVectorImpl<QualType> &PTypes,
3382 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3383 FunctionProtoType *T = TL.getTypePtr();
3384
3385 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3386 ParmVarDecl *OldParm = TL.getArg(i);
3387
3388 QualType NewType;
3389 ParmVarDecl *NewParm;
3390
3391 if (OldParm) {
John McCall21ef0fa2010-03-11 09:03:00 +00003392 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3393 if (!NewParm)
3394 return true;
3395 NewType = NewParm->getType();
3396
3397 // Deal with the possibility that we don't have a parameter
3398 // declaration for this parameter.
3399 } else {
3400 NewParm = 0;
3401
3402 QualType OldType = T->getArgType(i);
3403 NewType = getDerived().TransformType(OldType);
3404 if (NewType.isNull())
3405 return true;
3406 }
3407
3408 PTypes.push_back(NewType);
3409 PVars.push_back(NewParm);
3410 }
3411
3412 return false;
3413}
3414
3415template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003416QualType
John McCalla2becad2009-10-21 00:40:46 +00003417TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003418 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003419 // Transform the parameters and return type.
3420 //
3421 // We instantiate in source order, with the return type first followed by
3422 // the parameters, because users tend to expect this (even if they shouldn't
3423 // rely on it!).
3424 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003425 // When the function has a trailing return type, we instantiate the
3426 // parameters before the return type, since the return type can then refer
3427 // to the parameters themselves (via decltype, sizeof, etc.).
3428 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003429 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003430 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003431 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003432
Douglas Gregordab60ad2010-10-01 18:44:50 +00003433 QualType ResultType;
3434
3435 if (TL.getTrailingReturn()) {
3436 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3437 return QualType();
3438
3439 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3440 if (ResultType.isNull())
3441 return QualType();
3442 }
3443 else {
3444 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3445 if (ResultType.isNull())
3446 return QualType();
3447
3448 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3449 return QualType();
3450 }
3451
John McCalla2becad2009-10-21 00:40:46 +00003452 QualType Result = TL.getType();
3453 if (getDerived().AlwaysRebuild() ||
3454 ResultType != T->getResultType() ||
3455 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3456 Result = getDerived().RebuildFunctionProtoType(ResultType,
3457 ParamTypes.data(),
3458 ParamTypes.size(),
3459 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003460 T->getTypeQuals(),
3461 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003462 if (Result.isNull())
3463 return QualType();
3464 }
Mike Stump1eb44332009-09-09 15:08:12 +00003465
John McCalla2becad2009-10-21 00:40:46 +00003466 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3467 NewTL.setLParenLoc(TL.getLParenLoc());
3468 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003469 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003470 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3471 NewTL.setArg(i, ParamDecls[i]);
3472
3473 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003474}
Mike Stump1eb44332009-09-09 15:08:12 +00003475
Douglas Gregor577f75a2009-08-04 16:50:30 +00003476template<typename Derived>
3477QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003478 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003479 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003480 FunctionNoProtoType *T = TL.getTypePtr();
3481 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3482 if (ResultType.isNull())
3483 return QualType();
3484
3485 QualType Result = TL.getType();
3486 if (getDerived().AlwaysRebuild() ||
3487 ResultType != T->getResultType())
3488 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3489
3490 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3491 NewTL.setLParenLoc(TL.getLParenLoc());
3492 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003493 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003494
3495 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003496}
Mike Stump1eb44332009-09-09 15:08:12 +00003497
John McCalled976492009-12-04 22:46:56 +00003498template<typename Derived> QualType
3499TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003500 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003501 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003502 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003503 if (!D)
3504 return QualType();
3505
3506 QualType Result = TL.getType();
3507 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3508 Result = getDerived().RebuildUnresolvedUsingType(D);
3509 if (Result.isNull())
3510 return QualType();
3511 }
3512
3513 // We might get an arbitrary type spec type back. We should at
3514 // least always get a type spec type, though.
3515 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3516 NewTL.setNameLoc(TL.getNameLoc());
3517
3518 return Result;
3519}
3520
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003522QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003523 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003524 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003525 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003526 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3527 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003528 if (!Typedef)
3529 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003530
John McCalla2becad2009-10-21 00:40:46 +00003531 QualType Result = TL.getType();
3532 if (getDerived().AlwaysRebuild() ||
3533 Typedef != T->getDecl()) {
3534 Result = getDerived().RebuildTypedefType(Typedef);
3535 if (Result.isNull())
3536 return QualType();
3537 }
Mike Stump1eb44332009-09-09 15:08:12 +00003538
John McCalla2becad2009-10-21 00:40:46 +00003539 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3540 NewTL.setNameLoc(TL.getNameLoc());
3541
3542 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003543}
Mike Stump1eb44332009-09-09 15:08:12 +00003544
Douglas Gregor577f75a2009-08-04 16:50:30 +00003545template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003546QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003547 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003548 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003549 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003550
John McCall60d7b3a2010-08-24 06:29:42 +00003551 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003552 if (E.isInvalid())
3553 return QualType();
3554
John McCalla2becad2009-10-21 00:40:46 +00003555 QualType Result = TL.getType();
3556 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003557 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003558 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003559 if (Result.isNull())
3560 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003561 }
John McCalla2becad2009-10-21 00:40:46 +00003562 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003563
John McCalla2becad2009-10-21 00:40:46 +00003564 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003565 NewTL.setTypeofLoc(TL.getTypeofLoc());
3566 NewTL.setLParenLoc(TL.getLParenLoc());
3567 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003568
3569 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570}
Mike Stump1eb44332009-09-09 15:08:12 +00003571
3572template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003573QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003574 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003575 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3576 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3577 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003578 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003579
John McCalla2becad2009-10-21 00:40:46 +00003580 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003581 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3582 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003583 if (Result.isNull())
3584 return QualType();
3585 }
Mike Stump1eb44332009-09-09 15:08:12 +00003586
John McCalla2becad2009-10-21 00:40:46 +00003587 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003588 NewTL.setTypeofLoc(TL.getTypeofLoc());
3589 NewTL.setLParenLoc(TL.getLParenLoc());
3590 NewTL.setRParenLoc(TL.getRParenLoc());
3591 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003592
3593 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003594}
Mike Stump1eb44332009-09-09 15:08:12 +00003595
3596template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003597QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003598 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003599 DecltypeType *T = TL.getTypePtr();
3600
Douglas Gregor670444e2009-08-04 22:27:00 +00003601 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003602 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003603
John McCall60d7b3a2010-08-24 06:29:42 +00003604 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003605 if (E.isInvalid())
3606 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003607
John McCalla2becad2009-10-21 00:40:46 +00003608 QualType Result = TL.getType();
3609 if (getDerived().AlwaysRebuild() ||
3610 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003611 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003612 if (Result.isNull())
3613 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003614 }
John McCalla2becad2009-10-21 00:40:46 +00003615 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003616
John McCalla2becad2009-10-21 00:40:46 +00003617 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3618 NewTL.setNameLoc(TL.getNameLoc());
3619
3620 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003621}
3622
3623template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003624QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003625 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003626 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003627 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003628 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3629 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630 if (!Record)
3631 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003632
John McCalla2becad2009-10-21 00:40:46 +00003633 QualType Result = TL.getType();
3634 if (getDerived().AlwaysRebuild() ||
3635 Record != T->getDecl()) {
3636 Result = getDerived().RebuildRecordType(Record);
3637 if (Result.isNull())
3638 return QualType();
3639 }
Mike Stump1eb44332009-09-09 15:08:12 +00003640
John McCalla2becad2009-10-21 00:40:46 +00003641 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3642 NewTL.setNameLoc(TL.getNameLoc());
3643
3644 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003645}
Mike Stump1eb44332009-09-09 15:08:12 +00003646
3647template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003648QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003649 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003650 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003651 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003652 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3653 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003654 if (!Enum)
3655 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003656
John McCalla2becad2009-10-21 00:40:46 +00003657 QualType Result = TL.getType();
3658 if (getDerived().AlwaysRebuild() ||
3659 Enum != T->getDecl()) {
3660 Result = getDerived().RebuildEnumType(Enum);
3661 if (Result.isNull())
3662 return QualType();
3663 }
Mike Stump1eb44332009-09-09 15:08:12 +00003664
John McCalla2becad2009-10-21 00:40:46 +00003665 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3666 NewTL.setNameLoc(TL.getNameLoc());
3667
3668 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669}
John McCall7da24312009-09-05 00:15:47 +00003670
John McCall3cb0ebd2010-03-10 03:28:59 +00003671template<typename Derived>
3672QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3673 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003674 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003675 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3676 TL.getTypePtr()->getDecl());
3677 if (!D) return QualType();
3678
3679 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3680 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3681 return T;
3682}
3683
Mike Stump1eb44332009-09-09 15:08:12 +00003684
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685template<typename Derived>
3686QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003687 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003688 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003689 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003690}
3691
Mike Stump1eb44332009-09-09 15:08:12 +00003692template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003693QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003694 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003695 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003696 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003697}
3698
3699template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003700QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003701 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003702 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003703 const TemplateSpecializationType *T = TL.getTypePtr();
3704
Mike Stump1eb44332009-09-09 15:08:12 +00003705 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003706 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707 if (Template.isNull())
3708 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003709
John McCall43fed0d2010-11-12 08:19:04 +00003710 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3711}
3712
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003713namespace {
3714 /// \brief Simple iterator that traverses the template arguments in a
3715 /// container that provides a \c getArgLoc() member function.
3716 ///
3717 /// This iterator is intended to be used with the iterator form of
3718 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3719 template<typename ArgLocContainer>
3720 class TemplateArgumentLocContainerIterator {
3721 ArgLocContainer *Container;
3722 unsigned Index;
3723
3724 public:
3725 typedef TemplateArgumentLoc value_type;
3726 typedef TemplateArgumentLoc reference;
3727 typedef int difference_type;
3728 typedef std::input_iterator_tag iterator_category;
3729
3730 class pointer {
3731 TemplateArgumentLoc Arg;
3732
3733 public:
3734 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3735
3736 const TemplateArgumentLoc *operator->() const {
3737 return &Arg;
3738 }
3739 };
3740
3741
3742 TemplateArgumentLocContainerIterator() {}
3743
3744 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3745 unsigned Index)
3746 : Container(&Container), Index(Index) { }
3747
3748 TemplateArgumentLocContainerIterator &operator++() {
3749 ++Index;
3750 return *this;
3751 }
3752
3753 TemplateArgumentLocContainerIterator operator++(int) {
3754 TemplateArgumentLocContainerIterator Old(*this);
3755 ++(*this);
3756 return Old;
3757 }
3758
3759 TemplateArgumentLoc operator*() const {
3760 return Container->getArgLoc(Index);
3761 }
3762
3763 pointer operator->() const {
3764 return pointer(Container->getArgLoc(Index));
3765 }
3766
3767 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003768 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003769 return X.Container == Y.Container && X.Index == Y.Index;
3770 }
3771
3772 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003773 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003774 return !(X == Y);
3775 }
3776 };
3777}
3778
3779
John McCall43fed0d2010-11-12 08:19:04 +00003780template <typename Derived>
3781QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3782 TypeLocBuilder &TLB,
3783 TemplateSpecializationTypeLoc TL,
3784 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00003785 TemplateArgumentListInfo NewTemplateArgs;
3786 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3787 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003788 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3789 ArgIterator;
3790 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3791 ArgIterator(TL, TL.getNumArgs()),
3792 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003793 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003794
John McCall833ca992009-10-29 08:12:44 +00003795 // FIXME: maybe don't rebuild if all the template arguments are the same.
3796
3797 QualType Result =
3798 getDerived().RebuildTemplateSpecializationType(Template,
3799 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003800 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003801
3802 if (!Result.isNull()) {
3803 TemplateSpecializationTypeLoc NewTL
3804 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3805 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3806 NewTL.setLAngleLoc(TL.getLAngleLoc());
3807 NewTL.setRAngleLoc(TL.getRAngleLoc());
3808 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3809 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003810 }
Mike Stump1eb44332009-09-09 15:08:12 +00003811
John McCall833ca992009-10-29 08:12:44 +00003812 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003813}
Mike Stump1eb44332009-09-09 15:08:12 +00003814
3815template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003816QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003817TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003818 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003819 ElaboratedType *T = TL.getTypePtr();
3820
3821 NestedNameSpecifier *NNS = 0;
3822 // NOTE: the qualifier in an ElaboratedType is optional.
3823 if (T->getQualifier() != 0) {
3824 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003825 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003826 if (!NNS)
3827 return QualType();
3828 }
Mike Stump1eb44332009-09-09 15:08:12 +00003829
John McCall43fed0d2010-11-12 08:19:04 +00003830 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3831 if (NamedT.isNull())
3832 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00003833
John McCalla2becad2009-10-21 00:40:46 +00003834 QualType Result = TL.getType();
3835 if (getDerived().AlwaysRebuild() ||
3836 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003837 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003838 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3839 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003840 if (Result.isNull())
3841 return QualType();
3842 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003843
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003844 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003845 NewTL.setKeywordLoc(TL.getKeywordLoc());
3846 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849}
Mike Stump1eb44332009-09-09 15:08:12 +00003850
3851template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00003852QualType
3853TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3854 ParenTypeLoc TL) {
3855 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3856 if (Inner.isNull())
3857 return QualType();
3858
3859 QualType Result = TL.getType();
3860 if (getDerived().AlwaysRebuild() ||
3861 Inner != TL.getInnerLoc().getType()) {
3862 Result = getDerived().RebuildParenType(Inner);
3863 if (Result.isNull())
3864 return QualType();
3865 }
3866
3867 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3868 NewTL.setLParenLoc(TL.getLParenLoc());
3869 NewTL.setRParenLoc(TL.getRParenLoc());
3870 return Result;
3871}
3872
3873template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00003874QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003875 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00003876 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00003877
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003879 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003880 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003881 if (!NNS)
3882 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003883
John McCall33500952010-06-11 00:33:02 +00003884 QualType Result
3885 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3886 T->getIdentifier(),
3887 TL.getKeywordLoc(),
3888 TL.getQualifierRange(),
3889 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003890 if (Result.isNull())
3891 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003893 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3894 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00003895 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3896
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003897 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3898 NewTL.setKeywordLoc(TL.getKeywordLoc());
3899 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003900 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003901 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3902 NewTL.setKeywordLoc(TL.getKeywordLoc());
3903 NewTL.setQualifierRange(TL.getQualifierRange());
3904 NewTL.setNameLoc(TL.getNameLoc());
3905 }
John McCalla2becad2009-10-21 00:40:46 +00003906 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003907}
Mike Stump1eb44332009-09-09 15:08:12 +00003908
Douglas Gregor577f75a2009-08-04 16:50:30 +00003909template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00003910QualType TreeTransform<Derived>::
3911 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003912 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00003913 DependentTemplateSpecializationType *T = TL.getTypePtr();
3914
3915 NestedNameSpecifier *NNS
3916 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003917 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00003918 if (!NNS)
3919 return QualType();
3920
John McCall43fed0d2010-11-12 08:19:04 +00003921 return getDerived()
3922 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3923}
3924
3925template<typename Derived>
3926QualType TreeTransform<Derived>::
3927 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3928 DependentTemplateSpecializationTypeLoc TL,
3929 NestedNameSpecifier *NNS) {
3930 DependentTemplateSpecializationType *T = TL.getTypePtr();
3931
John McCall33500952010-06-11 00:33:02 +00003932 TemplateArgumentListInfo NewTemplateArgs;
3933 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3934 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003935
3936 typedef TemplateArgumentLocContainerIterator<
3937 DependentTemplateSpecializationTypeLoc> ArgIterator;
3938 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3939 ArgIterator(TL, TL.getNumArgs()),
3940 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003941 return QualType();
John McCall33500952010-06-11 00:33:02 +00003942
Douglas Gregor1efb6c72010-09-08 23:56:00 +00003943 QualType Result
3944 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3945 NNS,
3946 TL.getQualifierRange(),
3947 T->getIdentifier(),
3948 TL.getNameLoc(),
3949 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00003950 if (Result.isNull())
3951 return QualType();
3952
3953 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3954 QualType NamedT = ElabT->getNamedType();
3955
3956 // Copy information relevant to the template specialization.
3957 TemplateSpecializationTypeLoc NamedTL
3958 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3959 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3960 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3961 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3962 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3963
3964 // Copy information relevant to the elaborated type.
3965 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3966 NewTL.setKeywordLoc(TL.getKeywordLoc());
3967 NewTL.setQualifierRange(TL.getQualifierRange());
3968 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00003969 TypeLoc NewTL(Result, TL.getOpaqueData());
3970 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00003971 }
3972 return Result;
3973}
3974
3975template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00003976QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3977 PackExpansionTypeLoc TL) {
3978 // FIXME: Implement!
3979 getSema().Diag(TL.getEllipsisLoc(),
3980 diag::err_pack_expansion_instantiation_unsupported);
3981 return QualType();
3982}
3983
3984template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003985QualType
3986TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003987 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00003988 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00003989 TLB.pushFullCopy(TL);
3990 return TL.getType();
3991}
3992
3993template<typename Derived>
3994QualType
3995TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003996 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00003997 // ObjCObjectType is never dependent.
3998 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00003999 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004000}
Mike Stump1eb44332009-09-09 15:08:12 +00004001
4002template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004003QualType
4004TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004005 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004006 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004007 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004008 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004009}
4010
Douglas Gregor577f75a2009-08-04 16:50:30 +00004011//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004012// Statement transformation
4013//===----------------------------------------------------------------------===//
4014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004015StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004016TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004017 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004018}
4019
4020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004021StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004022TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4023 return getDerived().TransformCompoundStmt(S, false);
4024}
4025
4026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004027StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004028TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004029 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004030 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004031 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004032 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004033 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4034 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004035 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004036 if (Result.isInvalid()) {
4037 // Immediately fail if this was a DeclStmt, since it's very
4038 // likely that this will cause problems for future statements.
4039 if (isa<DeclStmt>(*B))
4040 return StmtError();
4041
4042 // Otherwise, just keep processing substatements and fail later.
4043 SubStmtInvalid = true;
4044 continue;
4045 }
Mike Stump1eb44332009-09-09 15:08:12 +00004046
Douglas Gregor43959a92009-08-20 07:17:43 +00004047 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4048 Statements.push_back(Result.takeAs<Stmt>());
4049 }
Mike Stump1eb44332009-09-09 15:08:12 +00004050
John McCall7114cba2010-08-27 19:56:05 +00004051 if (SubStmtInvalid)
4052 return StmtError();
4053
Douglas Gregor43959a92009-08-20 07:17:43 +00004054 if (!getDerived().AlwaysRebuild() &&
4055 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004056 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004057
4058 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4059 move_arg(Statements),
4060 S->getRBracLoc(),
4061 IsStmtExpr);
4062}
Mike Stump1eb44332009-09-09 15:08:12 +00004063
Douglas Gregor43959a92009-08-20 07:17:43 +00004064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004065StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004066TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004067 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004068 {
4069 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004070 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004071
Eli Friedman264c1f82009-11-19 03:14:00 +00004072 // Transform the left-hand case value.
4073 LHS = getDerived().TransformExpr(S->getLHS());
4074 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004075 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004076
Eli Friedman264c1f82009-11-19 03:14:00 +00004077 // Transform the right-hand case value (for the GNU case-range extension).
4078 RHS = getDerived().TransformExpr(S->getRHS());
4079 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004080 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004081 }
Mike Stump1eb44332009-09-09 15:08:12 +00004082
Douglas Gregor43959a92009-08-20 07:17:43 +00004083 // Build the case statement.
4084 // Case statements are always rebuilt so that they will attached to their
4085 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004086 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004087 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004088 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004089 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004090 S->getColonLoc());
4091 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004092 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004093
Douglas Gregor43959a92009-08-20 07:17:43 +00004094 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004095 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004096 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004097 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004098
Douglas Gregor43959a92009-08-20 07:17:43 +00004099 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004100 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004101}
4102
4103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004104StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004105TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004106 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004107 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004108 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004109 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004110
Douglas Gregor43959a92009-08-20 07:17:43 +00004111 // Default statements are always rebuilt
4112 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004113 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004114}
Mike Stump1eb44332009-09-09 15:08:12 +00004115
Douglas Gregor43959a92009-08-20 07:17:43 +00004116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004117StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004118TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004119 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004120 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004121 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004122
Douglas Gregor43959a92009-08-20 07:17:43 +00004123 // FIXME: Pass the real colon location in.
4124 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4125 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004126 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004127}
Mike Stump1eb44332009-09-09 15:08:12 +00004128
Douglas Gregor43959a92009-08-20 07:17:43 +00004129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004130StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004131TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004132 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004133 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004134 VarDecl *ConditionVar = 0;
4135 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004136 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004137 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004138 getDerived().TransformDefinition(
4139 S->getConditionVariable()->getLocation(),
4140 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004141 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004142 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004143 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004144 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004145
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004146 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004147 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004148
4149 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004150 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004151 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4152 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004153 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004154 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004155
John McCall9ae2f072010-08-23 23:25:46 +00004156 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004157 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004158 }
Sean Huntc3021132010-05-05 15:23:54 +00004159
John McCall9ae2f072010-08-23 23:25:46 +00004160 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4161 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004162 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004163
Douglas Gregor43959a92009-08-20 07:17:43 +00004164 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004165 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004166 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004168
Douglas Gregor43959a92009-08-20 07:17:43 +00004169 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004170 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004171 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004172 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004173
Douglas Gregor43959a92009-08-20 07:17:43 +00004174 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004175 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004176 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004177 Then.get() == S->getThen() &&
4178 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004179 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004180
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004181 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004182 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004183 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004184}
4185
4186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004187StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004188TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004189 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004190 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004191 VarDecl *ConditionVar = 0;
4192 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004193 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004194 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004195 getDerived().TransformDefinition(
4196 S->getConditionVariable()->getLocation(),
4197 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004198 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004199 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004200 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004201 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004202
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004203 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004204 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004205 }
Mike Stump1eb44332009-09-09 15:08:12 +00004206
Douglas Gregor43959a92009-08-20 07:17:43 +00004207 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004208 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004209 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004210 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004211 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004212 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004213
Douglas Gregor43959a92009-08-20 07:17:43 +00004214 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004215 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004216 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004217 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004218
Douglas Gregor43959a92009-08-20 07:17:43 +00004219 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004220 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4221 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004222}
Mike Stump1eb44332009-09-09 15:08:12 +00004223
Douglas Gregor43959a92009-08-20 07:17:43 +00004224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004225StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004226TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004227 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004228 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004229 VarDecl *ConditionVar = 0;
4230 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004231 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004232 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004233 getDerived().TransformDefinition(
4234 S->getConditionVariable()->getLocation(),
4235 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004236 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004237 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004238 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004239 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004240
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004241 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004242 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004243
4244 if (S->getCond()) {
4245 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004246 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4247 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004248 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004249 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004250 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004251 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004252 }
Mike Stump1eb44332009-09-09 15:08:12 +00004253
John McCall9ae2f072010-08-23 23:25:46 +00004254 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4255 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004256 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004257
Douglas Gregor43959a92009-08-20 07:17:43 +00004258 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004259 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004260 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004261 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004262
Douglas Gregor43959a92009-08-20 07:17:43 +00004263 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004264 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004265 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004266 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004267 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004268
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004269 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004270 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004271}
Mike Stump1eb44332009-09-09 15:08:12 +00004272
Douglas Gregor43959a92009-08-20 07:17:43 +00004273template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004274StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004275TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004276 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004277 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004278 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004279 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004280
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004281 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004282 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004283 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004284 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004285
Douglas Gregor43959a92009-08-20 07:17:43 +00004286 if (!getDerived().AlwaysRebuild() &&
4287 Cond.get() == S->getCond() &&
4288 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004289 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004290
John McCall9ae2f072010-08-23 23:25:46 +00004291 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4292 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004293 S->getRParenLoc());
4294}
Mike Stump1eb44332009-09-09 15:08:12 +00004295
Douglas Gregor43959a92009-08-20 07:17:43 +00004296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004297StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004298TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004299 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004300 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004301 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004302 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004303
Douglas Gregor43959a92009-08-20 07:17:43 +00004304 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004305 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004306 VarDecl *ConditionVar = 0;
4307 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004308 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004309 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004310 getDerived().TransformDefinition(
4311 S->getConditionVariable()->getLocation(),
4312 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004313 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004314 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004315 } else {
4316 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004317
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004318 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004319 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004320
4321 if (S->getCond()) {
4322 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004323 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4324 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004325 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004326 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004327
John McCall9ae2f072010-08-23 23:25:46 +00004328 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004329 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004330 }
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCall9ae2f072010-08-23 23:25:46 +00004332 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4333 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004334 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004335
Douglas Gregor43959a92009-08-20 07:17:43 +00004336 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004337 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004338 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004339 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004340
John McCall9ae2f072010-08-23 23:25:46 +00004341 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4342 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004343 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004344
Douglas Gregor43959a92009-08-20 07:17:43 +00004345 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004346 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004347 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004348 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004349
Douglas Gregor43959a92009-08-20 07:17:43 +00004350 if (!getDerived().AlwaysRebuild() &&
4351 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004352 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004353 Inc.get() == S->getInc() &&
4354 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004355 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004356
Douglas Gregor43959a92009-08-20 07:17:43 +00004357 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004358 Init.get(), FullCond, ConditionVar,
4359 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004360}
4361
4362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004363StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004364TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004365 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004366 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004367 S->getLabel());
4368}
4369
4370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004371StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004372TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004373 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004374 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004375 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004376
Douglas Gregor43959a92009-08-20 07:17:43 +00004377 if (!getDerived().AlwaysRebuild() &&
4378 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004379 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004380
4381 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004382 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004383}
4384
4385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004386StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004387TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004388 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
Douglas Gregor43959a92009-08-20 07:17:43 +00004391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004392StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004393TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004394 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004395}
Mike Stump1eb44332009-09-09 15:08:12 +00004396
Douglas Gregor43959a92009-08-20 07:17:43 +00004397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004398StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004399TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004400 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004401 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004402 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004403
Mike Stump1eb44332009-09-09 15:08:12 +00004404 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004405 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004406 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004407}
Mike Stump1eb44332009-09-09 15:08:12 +00004408
Douglas Gregor43959a92009-08-20 07:17:43 +00004409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004410StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004411TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004412 bool DeclChanged = false;
4413 llvm::SmallVector<Decl *, 4> Decls;
4414 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4415 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004416 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4417 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004418 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004419 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004420
Douglas Gregor43959a92009-08-20 07:17:43 +00004421 if (Transformed != *D)
4422 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004423
Douglas Gregor43959a92009-08-20 07:17:43 +00004424 Decls.push_back(Transformed);
4425 }
Mike Stump1eb44332009-09-09 15:08:12 +00004426
Douglas Gregor43959a92009-08-20 07:17:43 +00004427 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004428 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004429
4430 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004431 S->getStartLoc(), S->getEndLoc());
4432}
Mike Stump1eb44332009-09-09 15:08:12 +00004433
Douglas Gregor43959a92009-08-20 07:17:43 +00004434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004435StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004436TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004437 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004438 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004439}
4440
4441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004442StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004443TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004444
John McCallca0408f2010-08-23 06:44:23 +00004445 ASTOwningVector<Expr*> Constraints(getSema());
4446 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004447 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004448
John McCall60d7b3a2010-08-24 06:29:42 +00004449 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004450 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004451
4452 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004453
Anders Carlsson703e3942010-01-24 05:50:09 +00004454 // Go through the outputs.
4455 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004456 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004457
Anders Carlsson703e3942010-01-24 05:50:09 +00004458 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004459 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004460
Anders Carlsson703e3942010-01-24 05:50:09 +00004461 // Transform the output expr.
4462 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004463 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004464 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004465 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004466
Anders Carlsson703e3942010-01-24 05:50:09 +00004467 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004468
John McCall9ae2f072010-08-23 23:25:46 +00004469 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004470 }
Sean Huntc3021132010-05-05 15:23:54 +00004471
Anders Carlsson703e3942010-01-24 05:50:09 +00004472 // Go through the inputs.
4473 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004474 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004475
Anders Carlsson703e3942010-01-24 05:50:09 +00004476 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004477 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004478
Anders Carlsson703e3942010-01-24 05:50:09 +00004479 // Transform the input expr.
4480 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004481 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004482 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004483 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004484
Anders Carlsson703e3942010-01-24 05:50:09 +00004485 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004486
John McCall9ae2f072010-08-23 23:25:46 +00004487 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004488 }
Sean Huntc3021132010-05-05 15:23:54 +00004489
Anders Carlsson703e3942010-01-24 05:50:09 +00004490 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004491 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004492
4493 // Go through the clobbers.
4494 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004495 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004496
4497 // No need to transform the asm string literal.
4498 AsmString = SemaRef.Owned(S->getAsmString());
4499
4500 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4501 S->isSimple(),
4502 S->isVolatile(),
4503 S->getNumOutputs(),
4504 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004505 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004506 move_arg(Constraints),
4507 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004508 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004509 move_arg(Clobbers),
4510 S->getRParenLoc(),
4511 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004512}
4513
4514
4515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004516StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004517TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004518 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004519 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004520 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004521 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004522
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004523 // Transform the @catch statements (if present).
4524 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004525 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004526 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004527 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004528 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004529 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004530 if (Catch.get() != S->getCatchStmt(I))
4531 AnyCatchChanged = true;
4532 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004533 }
Sean Huntc3021132010-05-05 15:23:54 +00004534
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004535 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004536 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004537 if (S->getFinallyStmt()) {
4538 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4539 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004540 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004541 }
4542
4543 // If nothing changed, just retain this statement.
4544 if (!getDerived().AlwaysRebuild() &&
4545 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004546 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004547 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004548 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004549
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004550 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004551 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4552 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004553}
Mike Stump1eb44332009-09-09 15:08:12 +00004554
Douglas Gregor43959a92009-08-20 07:17:43 +00004555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004556StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004557TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004558 // Transform the @catch parameter, if there is one.
4559 VarDecl *Var = 0;
4560 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4561 TypeSourceInfo *TSInfo = 0;
4562 if (FromVar->getTypeSourceInfo()) {
4563 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4564 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004565 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004566 }
Sean Huntc3021132010-05-05 15:23:54 +00004567
Douglas Gregorbe270a02010-04-26 17:57:08 +00004568 QualType T;
4569 if (TSInfo)
4570 T = TSInfo->getType();
4571 else {
4572 T = getDerived().TransformType(FromVar->getType());
4573 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004574 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004575 }
Sean Huntc3021132010-05-05 15:23:54 +00004576
Douglas Gregorbe270a02010-04-26 17:57:08 +00004577 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4578 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004579 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004580 }
Sean Huntc3021132010-05-05 15:23:54 +00004581
John McCall60d7b3a2010-08-24 06:29:42 +00004582 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004583 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004584 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004585
4586 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004587 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004588 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004589}
Mike Stump1eb44332009-09-09 15:08:12 +00004590
Douglas Gregor43959a92009-08-20 07:17:43 +00004591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004592StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004593TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004594 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004595 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004596 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004597 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004598
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004599 // If nothing changed, just retain this statement.
4600 if (!getDerived().AlwaysRebuild() &&
4601 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004602 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004603
4604 // Build a new statement.
4605 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004606 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004607}
Mike Stump1eb44332009-09-09 15:08:12 +00004608
Douglas Gregor43959a92009-08-20 07:17:43 +00004609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004610StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004611TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004612 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004613 if (S->getThrowExpr()) {
4614 Operand = getDerived().TransformExpr(S->getThrowExpr());
4615 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004616 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004617 }
Sean Huntc3021132010-05-05 15:23:54 +00004618
Douglas Gregord1377b22010-04-22 21:44:01 +00004619 if (!getDerived().AlwaysRebuild() &&
4620 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004621 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004622
John McCall9ae2f072010-08-23 23:25:46 +00004623 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004624}
Mike Stump1eb44332009-09-09 15:08:12 +00004625
Douglas Gregor43959a92009-08-20 07:17:43 +00004626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004627StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004628TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004629 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004630 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004631 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004632 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004633 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004634
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004635 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004636 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004637 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004638 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004639
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004640 // If nothing change, just retain the current statement.
4641 if (!getDerived().AlwaysRebuild() &&
4642 Object.get() == S->getSynchExpr() &&
4643 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004644 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004645
4646 // Build a new statement.
4647 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004648 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004649}
4650
4651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004652StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004653TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004654 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004655 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004656 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004657 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004658 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004659
Douglas Gregorc3203e72010-04-22 23:10:45 +00004660 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004661 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004662 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004663 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004664
Douglas Gregorc3203e72010-04-22 23:10:45 +00004665 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004666 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004667 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004668 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004669
Douglas Gregorc3203e72010-04-22 23:10:45 +00004670 // If nothing changed, just retain this statement.
4671 if (!getDerived().AlwaysRebuild() &&
4672 Element.get() == S->getElement() &&
4673 Collection.get() == S->getCollection() &&
4674 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004675 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004676
Douglas Gregorc3203e72010-04-22 23:10:45 +00004677 // Build a new statement.
4678 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4679 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004680 Element.get(),
4681 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004682 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004683 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004684}
4685
4686
4687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004688StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004689TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4690 // Transform the exception declaration, if any.
4691 VarDecl *Var = 0;
4692 if (S->getExceptionDecl()) {
4693 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004694 TypeSourceInfo *T = getDerived().TransformType(
4695 ExceptionDecl->getTypeSourceInfo());
4696 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004697 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004698
Douglas Gregor83cb9422010-09-09 17:09:21 +00004699 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004700 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004701 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004702 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004703 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004704 }
Mike Stump1eb44332009-09-09 15:08:12 +00004705
Douglas Gregor43959a92009-08-20 07:17:43 +00004706 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004707 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004708 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004709 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004710
Douglas Gregor43959a92009-08-20 07:17:43 +00004711 if (!getDerived().AlwaysRebuild() &&
4712 !Var &&
4713 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004714 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004715
4716 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4717 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004718 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004719}
Mike Stump1eb44332009-09-09 15:08:12 +00004720
Douglas Gregor43959a92009-08-20 07:17:43 +00004721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004722StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004723TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4724 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004725 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004726 = getDerived().TransformCompoundStmt(S->getTryBlock());
4727 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004728 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004729
Douglas Gregor43959a92009-08-20 07:17:43 +00004730 // Transform the handlers.
4731 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004732 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004733 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004734 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004735 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4736 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004737 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
Douglas Gregor43959a92009-08-20 07:17:43 +00004739 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4740 Handlers.push_back(Handler.takeAs<Stmt>());
4741 }
Mike Stump1eb44332009-09-09 15:08:12 +00004742
Douglas Gregor43959a92009-08-20 07:17:43 +00004743 if (!getDerived().AlwaysRebuild() &&
4744 TryBlock.get() == S->getTryBlock() &&
4745 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004746 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004747
John McCall9ae2f072010-08-23 23:25:46 +00004748 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004749 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004750}
Mike Stump1eb44332009-09-09 15:08:12 +00004751
Douglas Gregor43959a92009-08-20 07:17:43 +00004752//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004753// Expression transformation
4754//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004756ExprResult
John McCall454feb92009-12-08 09:21:05 +00004757TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004758 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004759}
Mike Stump1eb44332009-09-09 15:08:12 +00004760
4761template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004762ExprResult
John McCall454feb92009-12-08 09:21:05 +00004763TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004764 NestedNameSpecifier *Qualifier = 0;
4765 if (E->getQualifier()) {
4766 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004767 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004768 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004769 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004770 }
John McCalldbd872f2009-12-08 09:08:17 +00004771
4772 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004773 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4774 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004775 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004777
John McCallec8045d2010-08-17 21:27:17 +00004778 DeclarationNameInfo NameInfo = E->getNameInfo();
4779 if (NameInfo.getName()) {
4780 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4781 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004782 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004783 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004784
4785 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004786 Qualifier == E->getQualifier() &&
4787 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004788 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004789 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004790
4791 // Mark it referenced in the new context regardless.
4792 // FIXME: this is a bit instantiation-specific.
4793 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4794
John McCall3fa5cae2010-10-26 07:05:15 +00004795 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004796 }
John McCalldbd872f2009-12-08 09:08:17 +00004797
4798 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004799 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004800 TemplateArgs = &TransArgs;
4801 TransArgs.setLAngleLoc(E->getLAngleLoc());
4802 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00004803 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4804 E->getNumTemplateArgs(),
4805 TransArgs))
4806 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004807 }
4808
Douglas Gregora2813ce2009-10-23 18:54:35 +00004809 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004810 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004811}
Mike Stump1eb44332009-09-09 15:08:12 +00004812
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004814ExprResult
John McCall454feb92009-12-08 09:21:05 +00004815TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004816 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817}
Mike Stump1eb44332009-09-09 15:08:12 +00004818
Douglas Gregorb98b1992009-08-11 05:31:07 +00004819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004820ExprResult
John McCall454feb92009-12-08 09:21:05 +00004821TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004822 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004823}
Mike Stump1eb44332009-09-09 15:08:12 +00004824
Douglas Gregorb98b1992009-08-11 05:31:07 +00004825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004826ExprResult
John McCall454feb92009-12-08 09:21:05 +00004827TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004828 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004829}
Mike Stump1eb44332009-09-09 15:08:12 +00004830
Douglas Gregorb98b1992009-08-11 05:31:07 +00004831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004832ExprResult
John McCall454feb92009-12-08 09:21:05 +00004833TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004834 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004835}
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregorb98b1992009-08-11 05:31:07 +00004837template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004838ExprResult
John McCall454feb92009-12-08 09:21:05 +00004839TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004840 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004841}
4842
4843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004844ExprResult
John McCall454feb92009-12-08 09:21:05 +00004845TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004846 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004847 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004848 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004849
Douglas Gregorb98b1992009-08-11 05:31:07 +00004850 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004851 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004852
John McCall9ae2f072010-08-23 23:25:46 +00004853 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004854 E->getRParen());
4855}
4856
Mike Stump1eb44332009-09-09 15:08:12 +00004857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004858ExprResult
John McCall454feb92009-12-08 09:21:05 +00004859TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004860 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004861 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregorb98b1992009-08-11 05:31:07 +00004864 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004865 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004866
Douglas Gregorb98b1992009-08-11 05:31:07 +00004867 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4868 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00004869 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870}
Mike Stump1eb44332009-09-09 15:08:12 +00004871
Douglas Gregorb98b1992009-08-11 05:31:07 +00004872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004873ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004874TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4875 // Transform the type.
4876 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4877 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00004878 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004879
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004880 // Transform all of the components into components similar to what the
4881 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00004882 // FIXME: It would be slightly more efficient in the non-dependent case to
4883 // just map FieldDecls, rather than requiring the rebuilder to look for
4884 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004885 // template code that we don't care.
4886 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00004887 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004888 typedef OffsetOfExpr::OffsetOfNode Node;
4889 llvm::SmallVector<Component, 4> Components;
4890 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4891 const Node &ON = E->getComponent(I);
4892 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00004893 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004894 Comp.LocStart = ON.getRange().getBegin();
4895 Comp.LocEnd = ON.getRange().getEnd();
4896 switch (ON.getKind()) {
4897 case Node::Array: {
4898 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00004899 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004900 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004901 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00004902
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004903 ExprChanged = ExprChanged || Index.get() != FromIndex;
4904 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00004905 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004906 break;
4907 }
Sean Huntc3021132010-05-05 15:23:54 +00004908
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004909 case Node::Field:
4910 case Node::Identifier:
4911 Comp.isBrackets = false;
4912 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00004913 if (!Comp.U.IdentInfo)
4914 continue;
Sean Huntc3021132010-05-05 15:23:54 +00004915
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004916 break;
Sean Huntc3021132010-05-05 15:23:54 +00004917
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00004918 case Node::Base:
4919 // Will be recomputed during the rebuild.
4920 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004921 }
Sean Huntc3021132010-05-05 15:23:54 +00004922
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004923 Components.push_back(Comp);
4924 }
Sean Huntc3021132010-05-05 15:23:54 +00004925
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004926 // If nothing changed, retain the existing expression.
4927 if (!getDerived().AlwaysRebuild() &&
4928 Type == E->getTypeSourceInfo() &&
4929 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004930 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00004931
Douglas Gregor8ecdb652010-04-28 22:16:22 +00004932 // Build a new offsetof expression.
4933 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4934 Components.data(), Components.size(),
4935 E->getRParenLoc());
4936}
4937
4938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004939ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00004940TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4941 assert(getDerived().AlreadyTransformed(E->getType()) &&
4942 "opaque value expression requires transformation");
4943 return SemaRef.Owned(E);
4944}
4945
4946template<typename Derived>
4947ExprResult
John McCall454feb92009-12-08 09:21:05 +00004948TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004949 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00004950 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00004951
John McCalla93c9342009-12-07 02:54:59 +00004952 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00004953 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00004954 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004955
John McCall5ab75172009-11-04 07:28:41 +00004956 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00004957 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004958
John McCall5ab75172009-11-04 07:28:41 +00004959 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004960 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004961 E->getSourceRange());
4962 }
Mike Stump1eb44332009-09-09 15:08:12 +00004963
John McCall60d7b3a2010-08-24 06:29:42 +00004964 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00004965 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004966 // C++0x [expr.sizeof]p1:
4967 // The operand is either an expression, which is an unevaluated operand
4968 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00004969 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004970
Douglas Gregorb98b1992009-08-11 05:31:07 +00004971 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4972 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004973 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004974
Douglas Gregorb98b1992009-08-11 05:31:07 +00004975 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004976 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004977 }
Mike Stump1eb44332009-09-09 15:08:12 +00004978
John McCall9ae2f072010-08-23 23:25:46 +00004979 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004980 E->isSizeOf(),
4981 E->getSourceRange());
4982}
Mike Stump1eb44332009-09-09 15:08:12 +00004983
Douglas Gregorb98b1992009-08-11 05:31:07 +00004984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004985ExprResult
John McCall454feb92009-12-08 09:21:05 +00004986TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004987 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004988 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004989 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004990
John McCall60d7b3a2010-08-24 06:29:42 +00004991 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004992 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004994
4995
Douglas Gregorb98b1992009-08-11 05:31:07 +00004996 if (!getDerived().AlwaysRebuild() &&
4997 LHS.get() == E->getLHS() &&
4998 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00004999 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005000
John McCall9ae2f072010-08-23 23:25:46 +00005001 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005003 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005004 E->getRBracketLoc());
5005}
Mike Stump1eb44332009-09-09 15:08:12 +00005006
5007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005008ExprResult
John McCall454feb92009-12-08 09:21:05 +00005009TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005010 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005011 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005012 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005013 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005014
5015 // Transform arguments.
5016 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005017 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005018 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5019 &ArgChanged))
5020 return ExprError();
5021
Douglas Gregorb98b1992009-08-11 05:31:07 +00005022 if (!getDerived().AlwaysRebuild() &&
5023 Callee.get() == E->getCallee() &&
5024 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005025 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005026
Douglas Gregorb98b1992009-08-11 05:31:07 +00005027 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005028 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005029 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005030 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005031 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032 E->getRParenLoc());
5033}
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>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005038 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005039 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005040 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005041
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005042 NestedNameSpecifier *Qualifier = 0;
5043 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005044 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005045 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005046 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005047 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005048 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005049 }
Mike Stump1eb44332009-09-09 15:08:12 +00005050
Eli Friedmanf595cc42009-12-04 06:40:45 +00005051 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005052 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5053 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005054 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005056
John McCall6bb80172010-03-30 21:47:33 +00005057 NamedDecl *FoundDecl = E->getFoundDecl();
5058 if (FoundDecl == E->getMemberDecl()) {
5059 FoundDecl = Member;
5060 } else {
5061 FoundDecl = cast_or_null<NamedDecl>(
5062 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5063 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005064 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005065 }
5066
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067 if (!getDerived().AlwaysRebuild() &&
5068 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005069 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005070 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005071 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005072 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005073
Anders Carlsson1f240322009-12-22 05:24:09 +00005074 // Mark it referenced in the new context regardless.
5075 // FIXME: this is a bit instantiation-specific.
5076 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005077 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005078 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079
John McCalld5532b62009-11-23 01:53:49 +00005080 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005081 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005082 TransArgs.setLAngleLoc(E->getLAngleLoc());
5083 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005084 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5085 E->getNumTemplateArgs(),
5086 TransArgs))
5087 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005088 }
Sean Huntc3021132010-05-05 15:23:54 +00005089
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090 // FIXME: Bogus source location for the operator
5091 SourceLocation FakeOperatorLoc
5092 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5093
John McCallc2233c52010-01-15 08:34:02 +00005094 // FIXME: to do this check properly, we will need to preserve the
5095 // first-qualifier-in-scope here, just in case we had a dependent
5096 // base (and therefore couldn't do the check) and a
5097 // nested-name-qualifier (and therefore could do the lookup).
5098 NamedDecl *FirstQualifierInScope = 0;
5099
John McCall9ae2f072010-08-23 23:25:46 +00005100 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005101 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005102 Qualifier,
5103 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005104 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005105 Member,
John McCall6bb80172010-03-30 21:47:33 +00005106 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005107 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005108 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005109 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110}
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregorb98b1992009-08-11 05:31:07 +00005112template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005113ExprResult
John McCall454feb92009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005115 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005116 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005118
John McCall60d7b3a2010-08-24 06:29:42 +00005119 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005120 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005121 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregorb98b1992009-08-11 05:31:07 +00005123 if (!getDerived().AlwaysRebuild() &&
5124 LHS.get() == E->getLHS() &&
5125 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005126 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregorb98b1992009-08-11 05:31:07 +00005128 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005129 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130}
5131
Mike Stump1eb44332009-09-09 15:08:12 +00005132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005134TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005135 CompoundAssignOperator *E) {
5136 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005137}
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Douglas Gregorb98b1992009-08-11 05:31:07 +00005139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005140ExprResult
John McCall454feb92009-12-08 09:21:05 +00005141TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005142 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005145
John McCall60d7b3a2010-08-24 06:29:42 +00005146 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005147 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005148 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005149
John McCall60d7b3a2010-08-24 06:29:42 +00005150 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005152 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregorb98b1992009-08-11 05:31:07 +00005154 if (!getDerived().AlwaysRebuild() &&
5155 Cond.get() == E->getCond() &&
5156 LHS.get() == E->getLHS() &&
5157 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005158 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005159
John McCall9ae2f072010-08-23 23:25:46 +00005160 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005161 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005162 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005163 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005164 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165}
Mike Stump1eb44332009-09-09 15:08:12 +00005166
5167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005168ExprResult
John McCall454feb92009-12-08 09:21:05 +00005169TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005170 // Implicit casts are eliminated during transformation, since they
5171 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005172 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005173}
Mike Stump1eb44332009-09-09 15:08:12 +00005174
Douglas Gregorb98b1992009-08-11 05:31:07 +00005175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005176ExprResult
John McCall454feb92009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005178 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5179 if (!Type)
5180 return ExprError();
5181
John McCall60d7b3a2010-08-24 06:29:42 +00005182 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005183 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005185 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregorb98b1992009-08-11 05:31:07 +00005187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005188 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005189 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005190 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005191
John McCall9d125032010-01-15 18:39:57 +00005192 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005193 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005194 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005195 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196}
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005199ExprResult
John McCall454feb92009-12-08 09:21:05 +00005200TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005201 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5202 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5203 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005205
John McCall60d7b3a2010-08-24 06:29:42 +00005206 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005207 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005211 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005212 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005213 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214
John McCall1d7d8d62010-01-19 22:33:45 +00005215 // Note: the expression type doesn't necessarily match the
5216 // type-as-written, but that's okay, because it should always be
5217 // derivable from the initializer.
5218
John McCall42f56b52010-01-18 19:35:47 +00005219 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005221 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005222}
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Douglas Gregorb98b1992009-08-11 05:31:07 +00005224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005225ExprResult
John McCall454feb92009-12-08 09:21:05 +00005226TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005227 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005228 if (Base.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() &&
5232 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005233 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005236 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005237 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005238 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 E->getAccessorLoc(),
5240 E->getAccessor());
5241}
Mike Stump1eb44332009-09-09 15:08:12 +00005242
Douglas Gregorb98b1992009-08-11 05:31:07 +00005243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005244ExprResult
John McCall454feb92009-12-08 09:21:05 +00005245TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005246 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005247
John McCallca0408f2010-08-23 06:44:23 +00005248 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005249 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5250 Inits, &InitChanged))
5251 return ExprError();
5252
Douglas Gregorb98b1992009-08-11 05:31:07 +00005253 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005254 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005255
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005257 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005258}
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005261ExprResult
John McCall454feb92009-12-08 09:21:05 +00005262TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005263 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005266 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005271 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272 bool ExprChanged = false;
5273 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5274 DEnd = E->designators_end();
5275 D != DEnd; ++D) {
5276 if (D->isFieldDesignator()) {
5277 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5278 D->getDotLoc(),
5279 D->getFieldLoc()));
5280 continue;
5281 }
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregorb98b1992009-08-11 05:31:07 +00005283 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005284 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005285 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005286 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005287
5288 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005289 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Douglas Gregorb98b1992009-08-11 05:31:07 +00005291 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5292 ArrayExprs.push_back(Index.release());
5293 continue;
5294 }
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005297 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005298 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5299 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005301
John McCall60d7b3a2010-08-24 06:29:42 +00005302 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005303 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
5306 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307 End.get(),
5308 D->getLBracketLoc(),
5309 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregorb98b1992009-08-11 05:31:07 +00005311 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5312 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregorb98b1992009-08-11 05:31:07 +00005314 ArrayExprs.push_back(Start.release());
5315 ArrayExprs.push_back(End.release());
5316 }
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318 if (!getDerived().AlwaysRebuild() &&
5319 Init.get() == E->getInit() &&
5320 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005321 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregorb98b1992009-08-11 05:31:07 +00005323 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5324 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005325 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005326}
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregorb98b1992009-08-11 05:31:07 +00005328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005329ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005330TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005331 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005332 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005333
Douglas Gregor5557b252009-10-28 00:29:27 +00005334 // FIXME: Will we ever have proper type location here? Will we actually
5335 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005336 QualType T = getDerived().TransformType(E->getType());
5337 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregorb98b1992009-08-11 05:31:07 +00005340 if (!getDerived().AlwaysRebuild() &&
5341 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005342 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Douglas Gregorb98b1992009-08-11 05:31:07 +00005344 return getDerived().RebuildImplicitValueInitExpr(T);
5345}
Mike Stump1eb44332009-09-09 15:08:12 +00005346
Douglas Gregorb98b1992009-08-11 05:31:07 +00005347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005348ExprResult
John McCall454feb92009-12-08 09:21:05 +00005349TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005350 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5351 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005353
John McCall60d7b3a2010-08-24 06:29:42 +00005354 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005355 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005357
Douglas Gregorb98b1992009-08-11 05:31:07 +00005358 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005359 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005360 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005361 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005362
John McCall9ae2f072010-08-23 23:25:46 +00005363 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005364 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005365}
5366
5367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005368ExprResult
John McCall454feb92009-12-08 09:21:05 +00005369TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005370 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005371 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005372 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5373 &ArgumentChanged))
5374 return ExprError();
5375
Douglas Gregorb98b1992009-08-11 05:31:07 +00005376 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5377 move_arg(Inits),
5378 E->getRParenLoc());
5379}
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregorb98b1992009-08-11 05:31:07 +00005381/// \brief Transform an address-of-label expression.
5382///
5383/// By default, the transformation of an address-of-label expression always
5384/// rebuilds the expression, so that the label identifier can be resolved to
5385/// the corresponding label statement by semantic analysis.
5386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005387ExprResult
John McCall454feb92009-12-08 09:21:05 +00005388TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005389 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5390 E->getLabel());
5391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
5393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394ExprResult
John McCall454feb92009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005396 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005397 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5398 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005400
Douglas Gregorb98b1992009-08-11 05:31:07 +00005401 if (!getDerived().AlwaysRebuild() &&
5402 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005403 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005404
5405 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005406 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005407 E->getRParenLoc());
5408}
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregorb98b1992009-08-11 05:31:07 +00005410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411ExprResult
John McCall454feb92009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005413 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005414 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005416
John McCall60d7b3a2010-08-24 06:29:42 +00005417 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005418 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005420
John McCall60d7b3a2010-08-24 06:29:42 +00005421 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005422 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005423 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005424
Douglas Gregorb98b1992009-08-11 05:31:07 +00005425 if (!getDerived().AlwaysRebuild() &&
5426 Cond.get() == E->getCond() &&
5427 LHS.get() == E->getLHS() &&
5428 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005429 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005430
Douglas Gregorb98b1992009-08-11 05:31:07 +00005431 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005432 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005433 E->getRParenLoc());
5434}
Mike Stump1eb44332009-09-09 15:08:12 +00005435
Douglas Gregorb98b1992009-08-11 05:31:07 +00005436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005437ExprResult
John McCall454feb92009-12-08 09:21:05 +00005438TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005439 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005440}
5441
5442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005443ExprResult
John McCall454feb92009-12-08 09:21:05 +00005444TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005445 switch (E->getOperator()) {
5446 case OO_New:
5447 case OO_Delete:
5448 case OO_Array_New:
5449 case OO_Array_Delete:
5450 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005451 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005452
Douglas Gregor668d6d92009-12-13 20:44:55 +00005453 case OO_Call: {
5454 // This is a call to an object's operator().
5455 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5456
5457 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005458 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005459 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005460 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005461
5462 // FIXME: Poor location information
5463 SourceLocation FakeLParenLoc
5464 = SemaRef.PP.getLocForEndOfToken(
5465 static_cast<Expr *>(Object.get())->getLocEnd());
5466
5467 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005468 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005469 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5470 Args))
5471 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005472
John McCall9ae2f072010-08-23 23:25:46 +00005473 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005474 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005475 E->getLocEnd());
5476 }
5477
5478#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5479 case OO_##Name:
5480#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5481#include "clang/Basic/OperatorKinds.def"
5482 case OO_Subscript:
5483 // Handled below.
5484 break;
5485
5486 case OO_Conditional:
5487 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005488 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005489
5490 case OO_None:
5491 case NUM_OVERLOADED_OPERATORS:
5492 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005493 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005494 }
5495
John McCall60d7b3a2010-08-24 06:29:42 +00005496 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005497 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005499
John McCall60d7b3a2010-08-24 06:29:42 +00005500 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005503
John McCall60d7b3a2010-08-24 06:29:42 +00005504 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005505 if (E->getNumArgs() == 2) {
5506 Second = getDerived().TransformExpr(E->getArg(1));
5507 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005508 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509 }
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregorb98b1992009-08-11 05:31:07 +00005511 if (!getDerived().AlwaysRebuild() &&
5512 Callee.get() == E->getCallee() &&
5513 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005514 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005515 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5518 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005519 Callee.get(),
5520 First.get(),
5521 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005522}
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregorb98b1992009-08-11 05:31:07 +00005524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005525ExprResult
John McCall454feb92009-12-08 09:21:05 +00005526TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5527 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528}
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregorb98b1992009-08-11 05:31:07 +00005530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005531ExprResult
John McCall454feb92009-12-08 09:21:05 +00005532TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005533 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5534 if (!Type)
5535 return ExprError();
5536
John McCall60d7b3a2010-08-24 06:29:42 +00005537 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005538 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005539 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005540 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005541
Douglas Gregorb98b1992009-08-11 05:31:07 +00005542 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005543 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005544 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005545 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregorb98b1992009-08-11 05:31:07 +00005547 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005548 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005549 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5550 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5551 SourceLocation FakeRParenLoc
5552 = SemaRef.PP.getLocForEndOfToken(
5553 E->getSubExpr()->getSourceRange().getEnd());
5554 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005555 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005557 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005558 FakeRAngleLoc,
5559 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005560 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561 FakeRParenLoc);
5562}
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005565ExprResult
John McCall454feb92009-12-08 09:21:05 +00005566TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5567 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005568}
Mike Stump1eb44332009-09-09 15:08:12 +00005569
5570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005571ExprResult
John McCall454feb92009-12-08 09:21:05 +00005572TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5573 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005574}
5575
Douglas Gregorb98b1992009-08-11 05:31:07 +00005576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005577ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005578TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005579 CXXReinterpretCastExpr *E) {
5580 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581}
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005584ExprResult
John McCall454feb92009-12-08 09:21:05 +00005585TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5586 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587}
Mike Stump1eb44332009-09-09 15:08:12 +00005588
Douglas Gregorb98b1992009-08-11 05:31:07 +00005589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005590ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005592 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005593 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5594 if (!Type)
5595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005596
John McCall60d7b3a2010-08-24 06:29:42 +00005597 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005598 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005599 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005601
Douglas Gregorb98b1992009-08-11 05:31:07 +00005602 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005603 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005605 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005606
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005607 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005609 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005610 E->getRParenLoc());
5611}
Mike Stump1eb44332009-09-09 15:08:12 +00005612
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005614ExprResult
John McCall454feb92009-12-08 09:21:05 +00005615TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005617 TypeSourceInfo *TInfo
5618 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5619 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005620 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Douglas Gregorb98b1992009-08-11 05:31:07 +00005622 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005623 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005624 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005625
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005626 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5627 E->getLocStart(),
5628 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629 E->getLocEnd());
5630 }
Mike Stump1eb44332009-09-09 15:08:12 +00005631
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632 // We don't know whether the expression is potentially evaluated until
5633 // after we perform semantic analysis, so the expression is potentially
5634 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005635 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005636 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005637
John McCall60d7b3a2010-08-24 06:29:42 +00005638 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005639 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005640 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005641
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 if (!getDerived().AlwaysRebuild() &&
5643 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005644 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005645
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005646 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5647 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005648 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649 E->getLocEnd());
5650}
5651
5652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005653ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005654TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5655 if (E->isTypeOperand()) {
5656 TypeSourceInfo *TInfo
5657 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5658 if (!TInfo)
5659 return ExprError();
5660
5661 if (!getDerived().AlwaysRebuild() &&
5662 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005663 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005664
5665 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5666 E->getLocStart(),
5667 TInfo,
5668 E->getLocEnd());
5669 }
5670
5671 // We don't know whether the expression is potentially evaluated until
5672 // after we perform semantic analysis, so the expression is potentially
5673 // potentially evaluated.
5674 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5675
5676 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5677 if (SubExpr.isInvalid())
5678 return ExprError();
5679
5680 if (!getDerived().AlwaysRebuild() &&
5681 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005682 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005683
5684 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5685 E->getLocStart(),
5686 SubExpr.get(),
5687 E->getLocEnd());
5688}
5689
5690template<typename Derived>
5691ExprResult
John McCall454feb92009-12-08 09:21:05 +00005692TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005693 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694}
Mike Stump1eb44332009-09-09 15:08:12 +00005695
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005697ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005699 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005700 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005701}
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005704ExprResult
John McCall454feb92009-12-08 09:21:05 +00005705TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005706 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5707 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5708 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005710 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005711 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005712
Douglas Gregor828a1972010-01-07 23:12:05 +00005713 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714}
Mike Stump1eb44332009-09-09 15:08:12 +00005715
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005717ExprResult
John McCall454feb92009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005719 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005721 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005722
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723 if (!getDerived().AlwaysRebuild() &&
5724 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005725 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005726
John McCall9ae2f072010-08-23 23:25:46 +00005727 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728}
Mike Stump1eb44332009-09-09 15:08:12 +00005729
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005731ExprResult
John McCall454feb92009-12-08 09:21:05 +00005732TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005733 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005734 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5735 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005737 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005738
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005739 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005741 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005742
Douglas Gregor036aed12009-12-23 23:03:06 +00005743 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744}
Mike Stump1eb44332009-09-09 15:08:12 +00005745
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005747ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005748TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5749 CXXScalarValueInitExpr *E) {
5750 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5751 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005752 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005753
Douglas Gregorb98b1992009-08-11 05:31:07 +00005754 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005755 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005756 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005757
Douglas Gregorab6677e2010-09-08 00:15:04 +00005758 return getDerived().RebuildCXXScalarValueInitExpr(T,
5759 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005760 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761}
Mike Stump1eb44332009-09-09 15:08:12 +00005762
Douglas Gregorb98b1992009-08-11 05:31:07 +00005763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005764ExprResult
John McCall454feb92009-12-08 09:21:05 +00005765TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005766 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005767 TypeSourceInfo *AllocTypeInfo
5768 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5769 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005770 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005771
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005773 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005776
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 // Transform the placement arguments (if any).
5778 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005779 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005780 if (getDerived().TransformExprs(E->getPlacementArgs(),
5781 E->getNumPlacementArgs(), true,
5782 PlacementArgs, &ArgumentChanged))
5783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregor43959a92009-08-20 07:17:43 +00005785 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005786 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005787 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5788 ConstructorArgs, &ArgumentChanged))
5789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005790
Douglas Gregor1af74512010-02-26 00:38:10 +00005791 // Transform constructor, new operator, and delete operator.
5792 CXXConstructorDecl *Constructor = 0;
5793 if (E->getConstructor()) {
5794 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005795 getDerived().TransformDecl(E->getLocStart(),
5796 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005797 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005798 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005799 }
5800
5801 FunctionDecl *OperatorNew = 0;
5802 if (E->getOperatorNew()) {
5803 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005804 getDerived().TransformDecl(E->getLocStart(),
5805 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005806 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005807 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005808 }
5809
5810 FunctionDecl *OperatorDelete = 0;
5811 if (E->getOperatorDelete()) {
5812 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005813 getDerived().TransformDecl(E->getLocStart(),
5814 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005815 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005816 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005817 }
Sean Huntc3021132010-05-05 15:23:54 +00005818
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005820 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005821 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005822 Constructor == E->getConstructor() &&
5823 OperatorNew == E->getOperatorNew() &&
5824 OperatorDelete == E->getOperatorDelete() &&
5825 !ArgumentChanged) {
5826 // Mark any declarations we need as referenced.
5827 // FIXME: instantiation-specific.
5828 if (Constructor)
5829 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5830 if (OperatorNew)
5831 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5832 if (OperatorDelete)
5833 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005834 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005835 }
Mike Stump1eb44332009-09-09 15:08:12 +00005836
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005837 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005838 if (!ArraySize.get()) {
5839 // If no array size was specified, but the new expression was
5840 // instantiated with an array type (e.g., "new T" where T is
5841 // instantiated with "int[4]"), extract the outer bound from the
5842 // array type as our array size. We do this with constant and
5843 // dependently-sized array types.
5844 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5845 if (!ArrayT) {
5846 // Do nothing
5847 } else if (const ConstantArrayType *ConsArrayT
5848 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005849 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005850 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5851 ConsArrayT->getSize(),
5852 SemaRef.Context.getSizeType(),
5853 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005854 AllocType = ConsArrayT->getElementType();
5855 } else if (const DependentSizedArrayType *DepArrayT
5856 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5857 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005858 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005859 AllocType = DepArrayT->getElementType();
5860 }
5861 }
5862 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005863
Douglas Gregorb98b1992009-08-11 05:31:07 +00005864 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5865 E->isGlobalNew(),
5866 /*FIXME:*/E->getLocStart(),
5867 move_arg(PlacementArgs),
5868 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00005869 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005870 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005871 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00005872 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005873 /*FIXME:*/E->getLocStart(),
5874 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00005875 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005876}
Mike Stump1eb44332009-09-09 15:08:12 +00005877
Douglas Gregorb98b1992009-08-11 05:31:07 +00005878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005879ExprResult
John McCall454feb92009-12-08 09:21:05 +00005880TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005881 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005883 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005884
Douglas Gregor1af74512010-02-26 00:38:10 +00005885 // Transform the delete operator, if known.
5886 FunctionDecl *OperatorDelete = 0;
5887 if (E->getOperatorDelete()) {
5888 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005889 getDerived().TransformDecl(E->getLocStart(),
5890 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005891 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005892 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005893 }
Sean Huntc3021132010-05-05 15:23:54 +00005894
Douglas Gregorb98b1992009-08-11 05:31:07 +00005895 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005896 Operand.get() == E->getArgument() &&
5897 OperatorDelete == E->getOperatorDelete()) {
5898 // Mark any declarations we need as referenced.
5899 // FIXME: instantiation-specific.
5900 if (OperatorDelete)
5901 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00005902
5903 if (!E->getArgument()->isTypeDependent()) {
5904 QualType Destroyed = SemaRef.Context.getBaseElementType(
5905 E->getDestroyedType());
5906 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5907 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5908 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5909 SemaRef.LookupDestructor(Record));
5910 }
5911 }
5912
John McCall3fa5cae2010-10-26 07:05:15 +00005913 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005914 }
Mike Stump1eb44332009-09-09 15:08:12 +00005915
Douglas Gregorb98b1992009-08-11 05:31:07 +00005916 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5917 E->isGlobalDelete(),
5918 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00005919 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005920}
Mike Stump1eb44332009-09-09 15:08:12 +00005921
Douglas Gregorb98b1992009-08-11 05:31:07 +00005922template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005923ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00005924TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00005925 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005926 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00005927 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005928 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005929
John McCallb3d87482010-08-24 05:47:05 +00005930 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005931 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00005932 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005933 E->getOperatorLoc(),
5934 E->isArrow()? tok::arrow : tok::period,
5935 ObjectTypePtr,
5936 MayBePseudoDestructor);
5937 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005938 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005939
John McCallb3d87482010-08-24 05:47:05 +00005940 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00005941 NestedNameSpecifier *Qualifier = E->getQualifier();
5942 if (Qualifier) {
5943 Qualifier
5944 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5945 E->getQualifierRange(),
5946 ObjectType);
5947 if (!Qualifier)
5948 return ExprError();
5949 }
Mike Stump1eb44332009-09-09 15:08:12 +00005950
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005951 PseudoDestructorTypeStorage Destroyed;
5952 if (E->getDestroyedTypeInfo()) {
5953 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00005954 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5955 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005956 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005957 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005958 Destroyed = DestroyedTypeInfo;
5959 } else if (ObjectType->isDependentType()) {
5960 // We aren't likely to be able to resolve the identifier down to a type
5961 // now anyway, so just retain the identifier.
5962 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5963 E->getDestroyedTypeLoc());
5964 } else {
5965 // Look for a destructor known with the given name.
5966 CXXScopeSpec SS;
5967 if (Qualifier) {
5968 SS.setScopeRep(Qualifier);
5969 SS.setRange(E->getQualifierRange());
5970 }
Sean Huntc3021132010-05-05 15:23:54 +00005971
John McCallb3d87482010-08-24 05:47:05 +00005972 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005973 *E->getDestroyedTypeIdentifier(),
5974 E->getDestroyedTypeLoc(),
5975 /*Scope=*/0,
5976 SS, ObjectTypePtr,
5977 false);
5978 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005979 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005980
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005981 Destroyed
5982 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5983 E->getDestroyedTypeLoc());
5984 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005985
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005986 TypeSourceInfo *ScopeTypeInfo = 0;
5987 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00005988 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005989 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005990 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00005991 }
Sean Huntc3021132010-05-05 15:23:54 +00005992
John McCall9ae2f072010-08-23 23:25:46 +00005993 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005994 E->getOperatorLoc(),
5995 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00005996 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005997 E->getQualifierRange(),
5998 ScopeTypeInfo,
5999 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006000 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006001 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006002}
Mike Stump1eb44332009-09-09 15:08:12 +00006003
Douglas Gregora71d8192009-09-04 17:36:40 +00006004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006005ExprResult
John McCallba135432009-11-21 08:51:07 +00006006TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006007 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006008 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6009
6010 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6011 Sema::LookupOrdinaryName);
6012
6013 // Transform all the decls.
6014 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6015 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006016 NamedDecl *InstD = static_cast<NamedDecl*>(
6017 getDerived().TransformDecl(Old->getNameLoc(),
6018 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006019 if (!InstD) {
6020 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6021 // This can happen because of dependent hiding.
6022 if (isa<UsingShadowDecl>(*I))
6023 continue;
6024 else
John McCallf312b1e2010-08-26 23:41:50 +00006025 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006026 }
John McCallf7a1a742009-11-24 19:00:30 +00006027
6028 // Expand using declarations.
6029 if (isa<UsingDecl>(InstD)) {
6030 UsingDecl *UD = cast<UsingDecl>(InstD);
6031 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6032 E = UD->shadow_end(); I != E; ++I)
6033 R.addDecl(*I);
6034 continue;
6035 }
6036
6037 R.addDecl(InstD);
6038 }
6039
6040 // Resolve a kind, but don't do any further analysis. If it's
6041 // ambiguous, the callee needs to deal with it.
6042 R.resolveKind();
6043
6044 // Rebuild the nested-name qualifier, if present.
6045 CXXScopeSpec SS;
6046 NestedNameSpecifier *Qualifier = 0;
6047 if (Old->getQualifier()) {
6048 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006049 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006050 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006051 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006052
John McCallf7a1a742009-11-24 19:00:30 +00006053 SS.setScopeRep(Qualifier);
6054 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006055 }
6056
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006057 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006058 CXXRecordDecl *NamingClass
6059 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6060 Old->getNameLoc(),
6061 Old->getNamingClass()));
6062 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006063 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006064
Douglas Gregor66c45152010-04-27 16:10:10 +00006065 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006066 }
6067
6068 // If we have no template arguments, it's a normal declaration name.
6069 if (!Old->hasExplicitTemplateArgs())
6070 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6071
6072 // If we have template arguments, rebuild them, then rebuild the
6073 // templateid expression.
6074 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006075 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6076 Old->getNumTemplateArgs(),
6077 TransArgs))
6078 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006079
6080 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6081 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082}
Mike Stump1eb44332009-09-09 15:08:12 +00006083
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006085ExprResult
John McCall454feb92009-12-08 09:21:05 +00006086TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006087 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6088 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006089 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006090
Douglas Gregorb98b1992009-08-11 05:31:07 +00006091 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006092 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006093 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006094
Mike Stump1eb44332009-09-09 15:08:12 +00006095 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097 T,
6098 E->getLocEnd());
6099}
Mike Stump1eb44332009-09-09 15:08:12 +00006100
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006102ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006103TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6104 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6105 if (!LhsT)
6106 return ExprError();
6107
6108 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6109 if (!RhsT)
6110 return ExprError();
6111
6112 if (!getDerived().AlwaysRebuild() &&
6113 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6114 return SemaRef.Owned(E);
6115
6116 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6117 E->getLocStart(),
6118 LhsT, RhsT,
6119 E->getLocEnd());
6120}
6121
6122template<typename Derived>
6123ExprResult
John McCall865d4472009-11-19 22:55:06 +00006124TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006125 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006127 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006128 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006130 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006131
John McCall43fed0d2010-11-12 08:19:04 +00006132 // TODO: If this is a conversion-function-id, verify that the
6133 // destination type name (if present) resolves the same way after
6134 // instantiation as it did in the local scope.
6135
Abramo Bagnara25777432010-08-11 22:01:17 +00006136 DeclarationNameInfo NameInfo
6137 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6138 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006139 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006140
John McCallf7a1a742009-11-24 19:00:30 +00006141 if (!E->hasExplicitTemplateArgs()) {
6142 if (!getDerived().AlwaysRebuild() &&
6143 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006144 // Note: it is sufficient to compare the Name component of NameInfo:
6145 // if name has not changed, DNLoc has not changed either.
6146 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006148
John McCallf7a1a742009-11-24 19:00:30 +00006149 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6150 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006151 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006152 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006153 }
John McCalld5532b62009-11-23 01:53:49 +00006154
6155 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006156 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6157 E->getNumTemplateArgs(),
6158 TransArgs))
6159 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160
John McCallf7a1a742009-11-24 19:00:30 +00006161 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6162 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006163 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006164 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165}
6166
6167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006168ExprResult
John McCall454feb92009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006170 // CXXConstructExprs are always implicit, so when we have a
6171 // 1-argument construction we just transform that argument.
6172 if (E->getNumArgs() == 1 ||
6173 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6174 return getDerived().TransformExpr(E->getArg(0));
6175
Douglas Gregorb98b1992009-08-11 05:31:07 +00006176 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6177
6178 QualType T = getDerived().TransformType(E->getType());
6179 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006180 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181
6182 CXXConstructorDecl *Constructor
6183 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006184 getDerived().TransformDecl(E->getLocStart(),
6185 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006187 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006188
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006190 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006191 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6192 &ArgumentChanged))
6193 return ExprError();
6194
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 if (!getDerived().AlwaysRebuild() &&
6196 T == E->getType() &&
6197 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006198 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006199 // Mark the constructor as referenced.
6200 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006201 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006202 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006203 }
Mike Stump1eb44332009-09-09 15:08:12 +00006204
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006205 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6206 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006207 move_arg(Args),
6208 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006209 E->getConstructionKind(),
6210 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211}
Mike Stump1eb44332009-09-09 15:08:12 +00006212
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213/// \brief Transform a C++ temporary-binding expression.
6214///
Douglas Gregor51326552009-12-24 18:51:59 +00006215/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6216/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006218ExprResult
John McCall454feb92009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006220 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221}
Mike Stump1eb44332009-09-09 15:08:12 +00006222
John McCall4765fa02010-12-06 08:20:24 +00006223/// \brief Transform a C++ expression that contains cleanups that should
6224/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225///
John McCall4765fa02010-12-06 08:20:24 +00006226/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006227/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006229ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006230TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006231 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232}
Mike Stump1eb44332009-09-09 15:08:12 +00006233
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006235ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006237 CXXTemporaryObjectExpr *E) {
6238 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6239 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006240 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006241
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242 CXXConstructorDecl *Constructor
6243 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006244 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006245 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006247 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006248
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006250 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006252 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6253 &ArgumentChanged))
6254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006257 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006259 !ArgumentChanged) {
6260 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006261 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006262 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006263 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006264
6265 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6266 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006268 E->getLocEnd());
6269}
Mike Stump1eb44332009-09-09 15:08:12 +00006270
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006272ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006273TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006274 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006275 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6276 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006278
Douglas Gregorb98b1992009-08-11 05:31:07 +00006279 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006280 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006281 Args.reserve(E->arg_size());
6282 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6283 &ArgumentChanged))
6284 return ExprError();
6285
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006287 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006289 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006290
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006292 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 E->getLParenLoc(),
6294 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 E->getRParenLoc());
6296}
Mike Stump1eb44332009-09-09 15:08:12 +00006297
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006299ExprResult
John McCall865d4472009-11-19 22:55:06 +00006300TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006301 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006303 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006304 Expr *OldBase;
6305 QualType BaseType;
6306 QualType ObjectType;
6307 if (!E->isImplicitAccess()) {
6308 OldBase = E->getBase();
6309 Base = getDerived().TransformExpr(OldBase);
6310 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006312
John McCallaa81e162009-12-01 22:10:20 +00006313 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006314 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006315 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006316 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006317 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006318 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006319 ObjectTy,
6320 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006321 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006322 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006323
John McCallb3d87482010-08-24 05:47:05 +00006324 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006325 BaseType = ((Expr*) Base.get())->getType();
6326 } else {
6327 OldBase = 0;
6328 BaseType = getDerived().TransformType(E->getBaseType());
6329 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6330 }
Mike Stump1eb44332009-09-09 15:08:12 +00006331
Douglas Gregor6cd21982009-10-20 05:58:46 +00006332 // Transform the first part of the nested-name-specifier that qualifies
6333 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006334 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006335 = getDerived().TransformFirstQualifierInScope(
6336 E->getFirstQualifierFoundInScope(),
6337 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006338
Douglas Gregora38c6872009-09-03 16:14:30 +00006339 NestedNameSpecifier *Qualifier = 0;
6340 if (E->getQualifier()) {
6341 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6342 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006343 ObjectType,
6344 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006345 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006346 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006347 }
Mike Stump1eb44332009-09-09 15:08:12 +00006348
John McCall43fed0d2010-11-12 08:19:04 +00006349 // TODO: If this is a conversion-function-id, verify that the
6350 // destination type name (if present) resolves the same way after
6351 // instantiation as it did in the local scope.
6352
Abramo Bagnara25777432010-08-11 22:01:17 +00006353 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006354 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006355 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006357
John McCallaa81e162009-12-01 22:10:20 +00006358 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006359 // This is a reference to a member without an explicitly-specified
6360 // template argument list. Optimize for this common case.
6361 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006362 Base.get() == OldBase &&
6363 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006364 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006365 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006366 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006367 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006368
John McCall9ae2f072010-08-23 23:25:46 +00006369 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006370 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006371 E->isArrow(),
6372 E->getOperatorLoc(),
6373 Qualifier,
6374 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006375 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006376 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006377 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006378 }
6379
John McCalld5532b62009-11-23 01:53:49 +00006380 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006381 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6382 E->getNumTemplateArgs(),
6383 TransArgs))
6384 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006385
John McCall9ae2f072010-08-23 23:25:46 +00006386 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006387 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 E->isArrow(),
6389 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006390 Qualifier,
6391 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006392 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006393 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006394 &TransArgs);
6395}
6396
6397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006398ExprResult
John McCall454feb92009-12-08 09:21:05 +00006399TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006400 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006401 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006402 QualType BaseType;
6403 if (!Old->isImplicitAccess()) {
6404 Base = getDerived().TransformExpr(Old->getBase());
6405 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006407 BaseType = ((Expr*) Base.get())->getType();
6408 } else {
6409 BaseType = getDerived().TransformType(Old->getBaseType());
6410 }
John McCall129e2df2009-11-30 22:42:35 +00006411
6412 NestedNameSpecifier *Qualifier = 0;
6413 if (Old->getQualifier()) {
6414 Qualifier
6415 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006416 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006417 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006418 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006419 }
6420
Abramo Bagnara25777432010-08-11 22:01:17 +00006421 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006422 Sema::LookupOrdinaryName);
6423
6424 // Transform all the decls.
6425 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6426 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006427 NamedDecl *InstD = static_cast<NamedDecl*>(
6428 getDerived().TransformDecl(Old->getMemberLoc(),
6429 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006430 if (!InstD) {
6431 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6432 // This can happen because of dependent hiding.
6433 if (isa<UsingShadowDecl>(*I))
6434 continue;
6435 else
John McCallf312b1e2010-08-26 23:41:50 +00006436 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006437 }
John McCall129e2df2009-11-30 22:42:35 +00006438
6439 // Expand using declarations.
6440 if (isa<UsingDecl>(InstD)) {
6441 UsingDecl *UD = cast<UsingDecl>(InstD);
6442 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6443 E = UD->shadow_end(); I != E; ++I)
6444 R.addDecl(*I);
6445 continue;
6446 }
6447
6448 R.addDecl(InstD);
6449 }
6450
6451 R.resolveKind();
6452
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006453 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006454 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006455 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006456 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006457 Old->getMemberLoc(),
6458 Old->getNamingClass()));
6459 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006460 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006461
Douglas Gregor66c45152010-04-27 16:10:10 +00006462 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006463 }
Sean Huntc3021132010-05-05 15:23:54 +00006464
John McCall129e2df2009-11-30 22:42:35 +00006465 TemplateArgumentListInfo TransArgs;
6466 if (Old->hasExplicitTemplateArgs()) {
6467 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6468 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006469 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6470 Old->getNumTemplateArgs(),
6471 TransArgs))
6472 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006473 }
John McCallc2233c52010-01-15 08:34:02 +00006474
6475 // FIXME: to do this check properly, we will need to preserve the
6476 // first-qualifier-in-scope here, just in case we had a dependent
6477 // base (and therefore couldn't do the check) and a
6478 // nested-name-qualifier (and therefore could do the lookup).
6479 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006480
John McCall9ae2f072010-08-23 23:25:46 +00006481 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006482 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006483 Old->getOperatorLoc(),
6484 Old->isArrow(),
6485 Qualifier,
6486 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006487 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006488 R,
6489 (Old->hasExplicitTemplateArgs()
6490 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491}
6492
6493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006495TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6496 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6497 if (SubExpr.isInvalid())
6498 return ExprError();
6499
6500 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006501 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006502
6503 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6504}
6505
6506template<typename Derived>
6507ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006508TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6509 llvm_unreachable("pack expansion expression in unhandled context");
6510 return ExprError();
6511}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006512
6513template<typename Derived>
6514ExprResult
6515TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6516 // If E is not value-dependent, then nothing will change when we transform it.
6517 // Note: This is an instantiation-centric view.
6518 if (!E->isValueDependent())
6519 return SemaRef.Owned(E);
6520
6521 // Note: None of the implementations of TryExpandParameterPacks can ever
6522 // produce a diagnostic when given only a single unexpanded parameter pack,
6523 // so
6524 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6525 bool ShouldExpand = false;
6526 unsigned NumExpansions = 0;
6527 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6528 &Unexpanded, 1,
6529 ShouldExpand, NumExpansions))
6530 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006531
Douglas Gregoree8aff02011-01-04 17:33:58 +00006532 if (!ShouldExpand)
6533 return SemaRef.Owned(E);
6534
6535 // We now know the length of the parameter pack, so build a new expression
6536 // that stores that length.
6537 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6538 E->getPackLoc(), E->getRParenLoc(),
6539 NumExpansions);
6540}
6541
Douglas Gregorbe230c32011-01-03 17:17:50 +00006542template<typename Derived>
6543ExprResult
John McCall454feb92009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006545 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546}
6547
Mike Stump1eb44332009-09-09 15:08:12 +00006548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006549ExprResult
John McCall454feb92009-12-08 09:21:05 +00006550TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006551 TypeSourceInfo *EncodedTypeInfo
6552 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6553 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006555
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006557 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006558 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559
6560 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006561 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 E->getRParenLoc());
6563}
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006566ExprResult
John McCall454feb92009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006568 // Transform arguments.
6569 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006570 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006571 Args.reserve(E->getNumArgs());
6572 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6573 &ArgChanged))
6574 return ExprError();
6575
Douglas Gregor92e986e2010-04-22 16:44:27 +00006576 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6577 // Class message: transform the receiver type.
6578 TypeSourceInfo *ReceiverTypeInfo
6579 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6580 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006581 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006582
Douglas Gregor92e986e2010-04-22 16:44:27 +00006583 // If nothing changed, just retain the existing message send.
6584 if (!getDerived().AlwaysRebuild() &&
6585 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006587
6588 // Build a new class message send.
6589 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6590 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006591 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006592 E->getMethodDecl(),
6593 E->getLeftLoc(),
6594 move_arg(Args),
6595 E->getRightLoc());
6596 }
6597
6598 // Instance message: transform the receiver
6599 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6600 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006601 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006602 = getDerived().TransformExpr(E->getInstanceReceiver());
6603 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006604 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006605
6606 // If nothing changed, just retain the existing message send.
6607 if (!getDerived().AlwaysRebuild() &&
6608 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006609 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006610
Douglas Gregor92e986e2010-04-22 16:44:27 +00006611 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006612 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006613 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006614 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006615 E->getMethodDecl(),
6616 E->getLeftLoc(),
6617 move_arg(Args),
6618 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619}
6620
Mike Stump1eb44332009-09-09 15:08:12 +00006621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006622ExprResult
John McCall454feb92009-12-08 09:21:05 +00006623TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006624 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625}
6626
Mike Stump1eb44332009-09-09 15:08:12 +00006627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006628ExprResult
John McCall454feb92009-12-08 09:21:05 +00006629TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006630 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631}
6632
Mike Stump1eb44332009-09-09 15:08:12 +00006633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
John McCall454feb92009-12-08 09:21:05 +00006635TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006636 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006637 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006638 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006639 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006640
6641 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006642
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006643 // If nothing changed, just retain the existing expression.
6644 if (!getDerived().AlwaysRebuild() &&
6645 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006646 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006647
John McCall9ae2f072010-08-23 23:25:46 +00006648 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006649 E->getLocation(),
6650 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651}
6652
Mike Stump1eb44332009-09-09 15:08:12 +00006653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006654ExprResult
John McCall454feb92009-12-08 09:21:05 +00006655TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006656 // 'super' and types never change. Property never changes. Just
6657 // retain the existing expression.
6658 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006659 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006660
Douglas Gregore3303542010-04-26 20:47:02 +00006661 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006662 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006663 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006664 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006665
Douglas Gregore3303542010-04-26 20:47:02 +00006666 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006667
Douglas Gregore3303542010-04-26 20:47:02 +00006668 // If nothing changed, just retain the existing expression.
6669 if (!getDerived().AlwaysRebuild() &&
6670 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006671 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672
John McCall12f78a62010-12-02 01:19:52 +00006673 if (E->isExplicitProperty())
6674 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6675 E->getExplicitProperty(),
6676 E->getLocation());
6677
6678 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6679 E->getType(),
6680 E->getImplicitPropertyGetter(),
6681 E->getImplicitPropertySetter(),
6682 E->getLocation());
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>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006688 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006689 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006690 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006691 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006692
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006693 // If nothing changed, just retain the existing expression.
6694 if (!getDerived().AlwaysRebuild() &&
6695 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006696 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006697
John McCall9ae2f072010-08-23 23:25:46 +00006698 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006699 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700}
6701
Mike Stump1eb44332009-09-09 15:08:12 +00006702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006703ExprResult
John McCall454feb92009-12-08 09:21:05 +00006704TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006706 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006707 SubExprs.reserve(E->getNumSubExprs());
6708 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6709 SubExprs, &ArgumentChanged))
6710 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
6713 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006714 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006715
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6717 move_arg(SubExprs),
6718 E->getRParenLoc());
6719}
6720
Mike Stump1eb44332009-09-09 15:08:12 +00006721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006722ExprResult
John McCall454feb92009-12-08 09:21:05 +00006723TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006724 SourceLocation CaretLoc(E->getExprLoc());
6725
6726 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6727 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6728 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6729 llvm::SmallVector<ParmVarDecl*, 4> Params;
6730 llvm::SmallVector<QualType, 4> ParamTypes;
6731
6732 // Parameter substitution.
6733 const BlockDecl *BD = E->getBlockDecl();
6734 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6735 EN = BD->param_end(); P != EN; ++P) {
6736 ParmVarDecl *OldParm = (*P);
6737 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6738 QualType NewType = NewParm->getType();
6739 Params.push_back(NewParm);
6740 ParamTypes.push_back(NewParm->getType());
6741 }
6742
6743 const FunctionType *BExprFunctionType = E->getFunctionType();
6744 QualType BExprResultType = BExprFunctionType->getResultType();
6745 if (!BExprResultType.isNull()) {
6746 if (!BExprResultType->isDependentType())
6747 CurBlock->ReturnType = BExprResultType;
6748 else if (BExprResultType != SemaRef.Context.DependentTy)
6749 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6750 }
John McCall711c52b2011-01-05 12:14:39 +00006751
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006752 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6753 CurBlock->ReturnType,
6754 ParamTypes.data(),
6755 ParamTypes.size(),
6756 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006757 0,
6758 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006759 CurBlock->FunctionType = FunctionType;
John McCall711c52b2011-01-05 12:14:39 +00006760
6761 // Set the parameters on the block decl.
6762 if (!Params.empty())
6763 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6764
6765 // Transform the body
6766 StmtResult Body = getDerived().TransformStmt(E->getBody());
6767 if (Body.isInvalid())
6768 return ExprError();
6769
John McCall9ae2f072010-08-23 23:25:46 +00006770 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771}
6772
Mike Stump1eb44332009-09-09 15:08:12 +00006773template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006774ExprResult
John McCall454feb92009-12-08 09:21:05 +00006775TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006776 NestedNameSpecifier *Qualifier = 0;
6777
6778 ValueDecl *ND
6779 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6780 E->getDecl()));
6781 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006782 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006783
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006784 if (!getDerived().AlwaysRebuild() &&
6785 ND == E->getDecl()) {
6786 // Mark it referenced in the new context regardless.
6787 // FIXME: this is a bit instantiation-specific.
6788 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6789
John McCall3fa5cae2010-10-26 07:05:15 +00006790 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006791 }
6792
Abramo Bagnara25777432010-08-11 22:01:17 +00006793 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006794 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006795 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796}
Mike Stump1eb44332009-09-09 15:08:12 +00006797
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006799// Type reconstruction
6800//===----------------------------------------------------------------------===//
6801
Mike Stump1eb44332009-09-09 15:08:12 +00006802template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006803QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6804 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006805 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006806 getDerived().getBaseEntity());
6807}
6808
Mike Stump1eb44332009-09-09 15:08:12 +00006809template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006810QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6811 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006812 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006813 getDerived().getBaseEntity());
6814}
6815
Mike Stump1eb44332009-09-09 15:08:12 +00006816template<typename Derived>
6817QualType
John McCall85737a72009-10-30 00:06:24 +00006818TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6819 bool WrittenAsLValue,
6820 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006821 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006822 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006823}
6824
6825template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006826QualType
John McCall85737a72009-10-30 00:06:24 +00006827TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6828 QualType ClassType,
6829 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006830 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006831 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006832}
6833
6834template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006835QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006836TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6837 ArrayType::ArraySizeModifier SizeMod,
6838 const llvm::APInt *Size,
6839 Expr *SizeExpr,
6840 unsigned IndexTypeQuals,
6841 SourceRange BracketsRange) {
6842 if (SizeExpr || !Size)
6843 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6844 IndexTypeQuals, BracketsRange,
6845 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006846
6847 QualType Types[] = {
6848 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6849 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6850 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006851 };
6852 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6853 QualType SizeType;
6854 for (unsigned I = 0; I != NumTypes; ++I)
6855 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6856 SizeType = Types[I];
6857 break;
6858 }
Mike Stump1eb44332009-09-09 15:08:12 +00006859
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006860 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6861 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006862 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006863 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006864 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006865}
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregor577f75a2009-08-04 16:50:30 +00006867template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006868QualType
6869TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006870 ArrayType::ArraySizeModifier SizeMod,
6871 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00006872 unsigned IndexTypeQuals,
6873 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006874 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00006875 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006876}
6877
6878template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006879QualType
Mike Stump1eb44332009-09-09 15:08:12 +00006880TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006881 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00006882 unsigned IndexTypeQuals,
6883 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006884 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00006885 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006886}
Mike Stump1eb44332009-09-09 15:08:12 +00006887
Douglas Gregor577f75a2009-08-04 16:50:30 +00006888template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006889QualType
6890TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006891 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006892 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006893 unsigned IndexTypeQuals,
6894 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006895 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006896 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006897 IndexTypeQuals, BracketsRange);
6898}
6899
6900template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006901QualType
6902TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006903 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00006904 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006905 unsigned IndexTypeQuals,
6906 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00006907 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00006908 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006909 IndexTypeQuals, BracketsRange);
6910}
6911
6912template<typename Derived>
6913QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00006914 unsigned NumElements,
6915 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00006916 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00006917 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006918}
Mike Stump1eb44332009-09-09 15:08:12 +00006919
Douglas Gregor577f75a2009-08-04 16:50:30 +00006920template<typename Derived>
6921QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6922 unsigned NumElements,
6923 SourceLocation AttributeLoc) {
6924 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6925 NumElements, true);
6926 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006927 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6928 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00006929 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006930}
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Douglas Gregor577f75a2009-08-04 16:50:30 +00006932template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006933QualType
6934TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00006935 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006936 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00006937 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006938}
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregor577f75a2009-08-04 16:50:30 +00006940template<typename Derived>
6941QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00006942 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006943 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00006944 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00006945 unsigned Quals,
6946 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00006947 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006948 Quals,
6949 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006950 getDerived().getBaseEntity(),
6951 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006952}
Mike Stump1eb44332009-09-09 15:08:12 +00006953
Douglas Gregor577f75a2009-08-04 16:50:30 +00006954template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00006955QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6956 return SemaRef.Context.getFunctionNoProtoType(T);
6957}
6958
6959template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00006960QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6961 assert(D && "no decl found");
6962 if (D->isInvalidDecl()) return QualType();
6963
Douglas Gregor92e986e2010-04-22 16:44:27 +00006964 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00006965 TypeDecl *Ty;
6966 if (isa<UsingDecl>(D)) {
6967 UsingDecl *Using = cast<UsingDecl>(D);
6968 assert(Using->isTypeName() &&
6969 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6970
6971 // A valid resolved using typename decl points to exactly one type decl.
6972 assert(++Using->shadow_begin() == Using->shadow_end());
6973 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00006974
John McCalled976492009-12-04 22:46:56 +00006975 } else {
6976 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6977 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6978 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6979 }
6980
6981 return SemaRef.Context.getTypeDeclType(Ty);
6982}
6983
6984template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006985QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6986 SourceLocation Loc) {
6987 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006988}
6989
6990template<typename Derived>
6991QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6992 return SemaRef.Context.getTypeOfType(Underlying);
6993}
6994
6995template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00006996QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6997 SourceLocation Loc) {
6998 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00006999}
7000
7001template<typename Derived>
7002QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007003 TemplateName Template,
7004 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007005 const TemplateArgumentListInfo &TemplateArgs) {
7006 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007007}
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Douglas Gregordcee1a12009-08-06 05:28:30 +00007009template<typename Derived>
7010NestedNameSpecifier *
7011TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7012 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007013 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007014 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007015 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007016 CXXScopeSpec SS;
7017 // FIXME: The source location information is all wrong.
7018 SS.setRange(Range);
7019 SS.setScopeRep(Prefix);
7020 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007021 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007022 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007023 ObjectType,
7024 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007025 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007026}
7027
7028template<typename Derived>
7029NestedNameSpecifier *
7030TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7031 SourceRange Range,
7032 NamespaceDecl *NS) {
7033 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7034}
7035
7036template<typename Derived>
7037NestedNameSpecifier *
7038TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7039 SourceRange Range,
7040 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007041 QualType T) {
7042 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007043 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007044 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007045 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7046 T.getTypePtr());
7047 }
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Douglas Gregordcee1a12009-08-06 05:28:30 +00007049 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7050 return 0;
7051}
Mike Stump1eb44332009-09-09 15:08:12 +00007052
Douglas Gregord1067e52009-08-06 06:41:21 +00007053template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007054TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007055TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7056 bool TemplateKW,
7057 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007058 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007059 Template);
7060}
7061
7062template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007063TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007064TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007065 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007066 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007067 QualType ObjectType,
7068 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007069 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007070 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007071 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007072 UnqualifiedId Name;
7073 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007074 Sema::TemplateTy Template;
7075 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7076 /*FIXME:*/getDerived().getBaseLocation(),
7077 SS,
7078 Name,
John McCallb3d87482010-08-24 05:47:05 +00007079 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007080 /*EnteringContext=*/false,
7081 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007082 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007083}
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007086TemplateName
7087TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7088 OverloadedOperatorKind Operator,
7089 QualType ObjectType) {
7090 CXXScopeSpec SS;
7091 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7092 SS.setScopeRep(Qualifier);
7093 UnqualifiedId Name;
7094 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7095 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7096 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007097 Sema::TemplateTy Template;
7098 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007099 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007100 SS,
7101 Name,
John McCallb3d87482010-08-24 05:47:05 +00007102 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007103 /*EnteringContext=*/false,
7104 Template);
7105 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007106}
Sean Huntc3021132010-05-05 15:23:54 +00007107
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007109ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7111 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007112 Expr *OrigCallee,
7113 Expr *First,
7114 Expr *Second) {
7115 Expr *Callee = OrigCallee->IgnoreParenCasts();
7116 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007119 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007120 if (!First->getType()->isOverloadableType() &&
7121 !Second->getType()->isOverloadableType())
7122 return getSema().CreateBuiltinArraySubscriptExpr(First,
7123 Callee->getLocStart(),
7124 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007125 } else if (Op == OO_Arrow) {
7126 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007127 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7128 } else if (Second == 0 || isPostIncDec) {
7129 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130 // The argument is not of overloadable type, so try to create a
7131 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007132 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007134
John McCall9ae2f072010-08-23 23:25:46 +00007135 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136 }
7137 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007138 if (!First->getType()->isOverloadableType() &&
7139 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140 // Neither of the arguments is an overloadable type, so try to
7141 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007142 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007143 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007144 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148 return move(Result);
7149 }
7150 }
Mike Stump1eb44332009-09-09 15:08:12 +00007151
7152 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007154 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007155
John McCall9ae2f072010-08-23 23:25:46 +00007156 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007157 assert(ULE->requiresADL());
7158
7159 // FIXME: Do we have to check
7160 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007161 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007162 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007163 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007164 }
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007167 Expr *Args[2] = { First, Second };
7168 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170 // Create the overloaded operator invocation for unary operators.
7171 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007172 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007174 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 }
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Sebastian Redlf322ed62009-10-29 20:17:01 +00007177 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007178 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007179 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007180 First,
7181 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007182
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007184 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007185 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7187 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007188 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Mike Stump1eb44332009-09-09 15:08:12 +00007190 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191}
Mike Stump1eb44332009-09-09 15:08:12 +00007192
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007194ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007195TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007196 SourceLocation OperatorLoc,
7197 bool isArrow,
7198 NestedNameSpecifier *Qualifier,
7199 SourceRange QualifierRange,
7200 TypeSourceInfo *ScopeType,
7201 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007202 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007203 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007204 CXXScopeSpec SS;
7205 if (Qualifier) {
7206 SS.setRange(QualifierRange);
7207 SS.setScopeRep(Qualifier);
7208 }
7209
John McCall9ae2f072010-08-23 23:25:46 +00007210 QualType BaseType = Base->getType();
7211 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007212 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007213 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007214 !BaseType->getAs<PointerType>()->getPointeeType()
7215 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007216 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007217 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007218 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007219 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007220 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007221 /*FIXME?*/true);
7222 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007223
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007224 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007225 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7226 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7227 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7228 NameInfo.setNamedTypeInfo(DestroyedType);
7229
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007230 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007231
John McCall9ae2f072010-08-23 23:25:46 +00007232 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007233 OperatorLoc, isArrow,
7234 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007235 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007236 /*TemplateArgs*/ 0);
7237}
7238
Douglas Gregor577f75a2009-08-04 16:50:30 +00007239} // end namespace clang
7240
7241#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H