blob: 25ead7bba5f655f263d96a3735b7d08b391fdcbc [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 Gregora7fc9012011-01-05 18:58:31 +00002126 return TemplateArgumentLoc(TemplateArgument(
2127 Pattern.getArgument().getAsTemplate(),
2128 true),
2129 Pattern.getTemplateQualifierRange(),
2130 Pattern.getTemplateNameLoc(),
2131 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002132
2133 case TemplateArgument::Null:
2134 case TemplateArgument::Integral:
2135 case TemplateArgument::Declaration:
2136 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002137 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002138 llvm_unreachable("Pack expansion pattern has no parameter packs");
2139
2140 case TemplateArgument::Type:
2141 if (TypeSourceInfo *Expansion
2142 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2143 EllipsisLoc))
2144 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2145 Expansion);
2146 break;
2147 }
2148
2149 return TemplateArgumentLoc();
2150 }
2151
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002152 /// \brief Build a new expression pack expansion.
2153 ///
2154 /// By default, performs semantic analysis to build a new pack expansion
2155 /// for an expression. Subclasses may override this routine to provide
2156 /// different behavior.
2157 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2158 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2159 }
2160
John McCall43fed0d2010-11-12 08:19:04 +00002161private:
2162 QualType TransformTypeInObjectScope(QualType T,
2163 QualType ObjectType,
2164 NamedDecl *FirstQualifierInScope,
2165 NestedNameSpecifier *Prefix);
2166
2167 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2168 QualType ObjectType,
2169 NamedDecl *FirstQualifierInScope,
2170 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002171};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172
Douglas Gregor43959a92009-08-20 07:17:43 +00002173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002174StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002175 if (!S)
2176 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002177
Douglas Gregor43959a92009-08-20 07:17:43 +00002178 switch (S->getStmtClass()) {
2179 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002180
Douglas Gregor43959a92009-08-20 07:17:43 +00002181 // Transform individual statement nodes
2182#define STMT(Node, Parent) \
2183 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2184#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002185#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002186
Douglas Gregor43959a92009-08-20 07:17:43 +00002187 // Transform expressions by calling TransformExpr.
2188#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002189#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002190#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002191#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002192 {
John McCall60d7b3a2010-08-24 06:29:42 +00002193 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002194 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002195 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002196
John McCall9ae2f072010-08-23 23:25:46 +00002197 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002198 }
Mike Stump1eb44332009-09-09 15:08:12 +00002199 }
2200
John McCall3fa5cae2010-10-26 07:05:15 +00002201 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002202}
Mike Stump1eb44332009-09-09 15:08:12 +00002203
2204
Douglas Gregor670444e2009-08-04 22:27:00 +00002205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002206ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002207 if (!E)
2208 return SemaRef.Owned(E);
2209
2210 switch (E->getStmtClass()) {
2211 case Stmt::NoStmtClass: break;
2212#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002213#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002214#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002215 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002216#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002217 }
2218
John McCall3fa5cae2010-10-26 07:05:15 +00002219 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002220}
2221
2222template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002223bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2224 unsigned NumInputs,
2225 bool IsCall,
2226 llvm::SmallVectorImpl<Expr *> &Outputs,
2227 bool *ArgChanged) {
2228 for (unsigned I = 0; I != NumInputs; ++I) {
2229 // If requested, drop call arguments that need to be dropped.
2230 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2231 if (ArgChanged)
2232 *ArgChanged = true;
2233
2234 break;
2235 }
2236
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002237 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2238 Expr *Pattern = Expansion->getPattern();
2239
2240 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2241 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2242 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2243
2244 // Determine whether the set of unexpanded parameter packs can and should
2245 // be expanded.
2246 bool Expand = true;
2247 unsigned NumExpansions = 0;
2248 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2249 Pattern->getSourceRange(),
2250 Unexpanded.data(),
2251 Unexpanded.size(),
2252 Expand, NumExpansions))
2253 return true;
2254
2255 if (!Expand) {
2256 // The transform has determined that we should perform a simple
2257 // transformation on the pack expansion, producing another pack
2258 // expansion.
2259 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2260 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2261 if (OutPattern.isInvalid())
2262 return true;
2263
2264 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2265 Expansion->getEllipsisLoc());
2266 if (Out.isInvalid())
2267 return true;
2268
2269 if (ArgChanged)
2270 *ArgChanged = true;
2271 Outputs.push_back(Out.get());
2272 continue;
2273 }
2274
2275 // The transform has determined that we should perform an elementwise
2276 // expansion of the pattern. Do so.
2277 for (unsigned I = 0; I != NumExpansions; ++I) {
2278 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2279 ExprResult Out = getDerived().TransformExpr(Pattern);
2280 if (Out.isInvalid())
2281 return true;
2282
2283 if (ArgChanged)
2284 *ArgChanged = true;
2285 Outputs.push_back(Out.get());
2286 }
2287
2288 continue;
2289 }
2290
Douglas Gregoraa165f82011-01-03 19:04:46 +00002291 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2292 if (Result.isInvalid())
2293 return true;
2294
2295 if (Result.get() != Inputs[I] && ArgChanged)
2296 *ArgChanged = true;
2297
2298 Outputs.push_back(Result.get());
2299 }
2300
2301 return false;
2302}
2303
2304template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002305NestedNameSpecifier *
2306TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002307 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002308 QualType ObjectType,
2309 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002310 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002311
Douglas Gregor43959a92009-08-20 07:17:43 +00002312 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002313 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002314 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002315 ObjectType,
2316 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002317 if (!Prefix)
2318 return 0;
2319 }
Mike Stump1eb44332009-09-09 15:08:12 +00002320
Douglas Gregordcee1a12009-08-06 05:28:30 +00002321 switch (NNS->getKind()) {
2322 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002323 if (Prefix) {
2324 // The object type and qualifier-in-scope really apply to the
2325 // leftmost entity.
2326 ObjectType = QualType();
2327 FirstQualifierInScope = 0;
2328 }
2329
Mike Stump1eb44332009-09-09 15:08:12 +00002330 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002331 "Identifier nested-name-specifier with no prefix or object type");
2332 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2333 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002334 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002335
2336 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002337 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002338 ObjectType,
2339 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002340
Douglas Gregordcee1a12009-08-06 05:28:30 +00002341 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002342 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002343 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002344 getDerived().TransformDecl(Range.getBegin(),
2345 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002346 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002347 Prefix == NNS->getPrefix() &&
2348 NS == NNS->getAsNamespace())
2349 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002350
Douglas Gregordcee1a12009-08-06 05:28:30 +00002351 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2352 }
Mike Stump1eb44332009-09-09 15:08:12 +00002353
Douglas Gregordcee1a12009-08-06 05:28:30 +00002354 case NestedNameSpecifier::Global:
2355 // There is no meaningful transformation that one could perform on the
2356 // global scope.
2357 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002358
Douglas Gregordcee1a12009-08-06 05:28:30 +00002359 case NestedNameSpecifier::TypeSpecWithTemplate:
2360 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002361 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002362 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2363 ObjectType,
2364 FirstQualifierInScope,
2365 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002366 if (T.isNull())
2367 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002368
Douglas Gregordcee1a12009-08-06 05:28:30 +00002369 if (!getDerived().AlwaysRebuild() &&
2370 Prefix == NNS->getPrefix() &&
2371 T == QualType(NNS->getAsType(), 0))
2372 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002373
2374 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2375 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002376 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002377 }
2378 }
Mike Stump1eb44332009-09-09 15:08:12 +00002379
Douglas Gregordcee1a12009-08-06 05:28:30 +00002380 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002381 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002382}
2383
2384template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002385DeclarationNameInfo
2386TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002387::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002388 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002389 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002390 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002391
2392 switch (Name.getNameKind()) {
2393 case DeclarationName::Identifier:
2394 case DeclarationName::ObjCZeroArgSelector:
2395 case DeclarationName::ObjCOneArgSelector:
2396 case DeclarationName::ObjCMultiArgSelector:
2397 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002398 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002399 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002400 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002401
Douglas Gregor81499bb2009-09-03 22:13:48 +00002402 case DeclarationName::CXXConstructorName:
2403 case DeclarationName::CXXDestructorName:
2404 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002405 TypeSourceInfo *NewTInfo;
2406 CanQualType NewCanTy;
2407 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002408 NewTInfo = getDerived().TransformType(OldTInfo);
2409 if (!NewTInfo)
2410 return DeclarationNameInfo();
2411 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002412 }
2413 else {
2414 NewTInfo = 0;
2415 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002416 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002417 if (NewT.isNull())
2418 return DeclarationNameInfo();
2419 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2420 }
Mike Stump1eb44332009-09-09 15:08:12 +00002421
Abramo Bagnara25777432010-08-11 22:01:17 +00002422 DeclarationName NewName
2423 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2424 NewCanTy);
2425 DeclarationNameInfo NewNameInfo(NameInfo);
2426 NewNameInfo.setName(NewName);
2427 NewNameInfo.setNamedTypeInfo(NewTInfo);
2428 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002429 }
Mike Stump1eb44332009-09-09 15:08:12 +00002430 }
2431
Abramo Bagnara25777432010-08-11 22:01:17 +00002432 assert(0 && "Unknown name kind.");
2433 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002434}
2435
2436template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002437TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002438TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002439 QualType ObjectType,
2440 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002441 SourceLocation Loc = getDerived().getBaseLocation();
2442
Douglas Gregord1067e52009-08-06 06:41:21 +00002443 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002444 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002445 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002446 /*FIXME*/ SourceRange(Loc),
2447 ObjectType,
2448 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002449 if (!NNS)
2450 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002451
Douglas Gregord1067e52009-08-06 06:41:21 +00002452 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002453 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002454 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002455 if (!TransTemplate)
2456 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002457
Douglas Gregord1067e52009-08-06 06:41:21 +00002458 if (!getDerived().AlwaysRebuild() &&
2459 NNS == QTN->getQualifier() &&
2460 TransTemplate == Template)
2461 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002462
Douglas Gregord1067e52009-08-06 06:41:21 +00002463 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2464 TransTemplate);
2465 }
Mike Stump1eb44332009-09-09 15:08:12 +00002466
John McCallf7a1a742009-11-24 19:00:30 +00002467 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002468 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002469 }
Mike Stump1eb44332009-09-09 15:08:12 +00002470
Douglas Gregord1067e52009-08-06 06:41:21 +00002471 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002472 NestedNameSpecifier *NNS = DTN->getQualifier();
2473 if (NNS) {
2474 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2475 /*FIXME:*/SourceRange(Loc),
2476 ObjectType,
2477 FirstQualifierInScope);
2478 if (!NNS) return TemplateName();
2479
2480 // These apply to the scope specifier, not the template.
2481 ObjectType = QualType();
2482 FirstQualifierInScope = 0;
2483 }
Mike Stump1eb44332009-09-09 15:08:12 +00002484
Douglas Gregord1067e52009-08-06 06:41:21 +00002485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002486 NNS == DTN->getQualifier() &&
2487 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002488 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002489
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002490 if (DTN->isIdentifier()) {
2491 // FIXME: Bad range
2492 SourceRange QualifierRange(getDerived().getBaseLocation());
2493 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2494 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002495 ObjectType,
2496 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002497 }
Sean Huntc3021132010-05-05 15:23:54 +00002498
2499 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002500 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002501 }
Mike Stump1eb44332009-09-09 15:08:12 +00002502
Douglas Gregord1067e52009-08-06 06:41:21 +00002503 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002504 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002505 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002506 if (!TransTemplate)
2507 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002508
Douglas Gregord1067e52009-08-06 06:41:21 +00002509 if (!getDerived().AlwaysRebuild() &&
2510 TransTemplate == Template)
2511 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002512
Douglas Gregord1067e52009-08-06 06:41:21 +00002513 return TemplateName(TransTemplate);
2514 }
Mike Stump1eb44332009-09-09 15:08:12 +00002515
John McCallf7a1a742009-11-24 19:00:30 +00002516 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002517 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002518 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002519}
2520
2521template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002522void TreeTransform<Derived>::InventTemplateArgumentLoc(
2523 const TemplateArgument &Arg,
2524 TemplateArgumentLoc &Output) {
2525 SourceLocation Loc = getDerived().getBaseLocation();
2526 switch (Arg.getKind()) {
2527 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002528 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002529 break;
2530
2531 case TemplateArgument::Type:
2532 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002533 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002534
John McCall833ca992009-10-29 08:12:44 +00002535 break;
2536
Douglas Gregor788cd062009-11-11 01:00:40 +00002537 case TemplateArgument::Template:
2538 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2539 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002540
2541 case TemplateArgument::TemplateExpansion:
2542 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2543 break;
2544
John McCall833ca992009-10-29 08:12:44 +00002545 case TemplateArgument::Expression:
2546 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2547 break;
2548
2549 case TemplateArgument::Declaration:
2550 case TemplateArgument::Integral:
2551 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002552 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002553 break;
2554 }
2555}
2556
2557template<typename Derived>
2558bool TreeTransform<Derived>::TransformTemplateArgument(
2559 const TemplateArgumentLoc &Input,
2560 TemplateArgumentLoc &Output) {
2561 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002562 switch (Arg.getKind()) {
2563 case TemplateArgument::Null:
2564 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002565 Output = Input;
2566 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002567
Douglas Gregor670444e2009-08-04 22:27:00 +00002568 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002569 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002570 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002571 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002572
2573 DI = getDerived().TransformType(DI);
2574 if (!DI) return true;
2575
2576 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2577 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002578 }
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregor670444e2009-08-04 22:27:00 +00002580 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002581 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002582 DeclarationName Name;
2583 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2584 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002585 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002586 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002587 if (!D) return true;
2588
John McCall828bff22009-10-29 18:45:58 +00002589 Expr *SourceExpr = Input.getSourceDeclExpression();
2590 if (SourceExpr) {
2591 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002592 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002593 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002594 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002595 }
2596
2597 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002598 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002599 }
Mike Stump1eb44332009-09-09 15:08:12 +00002600
Douglas Gregor788cd062009-11-11 01:00:40 +00002601 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002602 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002603 TemplateName Template
2604 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2605 if (Template.isNull())
2606 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002607
Douglas Gregor788cd062009-11-11 01:00:40 +00002608 Output = TemplateArgumentLoc(TemplateArgument(Template),
2609 Input.getTemplateQualifierRange(),
2610 Input.getTemplateNameLoc());
2611 return false;
2612 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002613
2614 case TemplateArgument::TemplateExpansion:
2615 llvm_unreachable("Caller should expand pack expansions");
2616
Douglas Gregor670444e2009-08-04 22:27:00 +00002617 case TemplateArgument::Expression: {
2618 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002619 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002620 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002621
John McCall833ca992009-10-29 08:12:44 +00002622 Expr *InputExpr = Input.getSourceExpression();
2623 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2624
John McCall60d7b3a2010-08-24 06:29:42 +00002625 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002626 = getDerived().TransformExpr(InputExpr);
2627 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002628 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002629 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002630 }
Mike Stump1eb44332009-09-09 15:08:12 +00002631
Douglas Gregor670444e2009-08-04 22:27:00 +00002632 case TemplateArgument::Pack: {
2633 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2634 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002635 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002636 AEnd = Arg.pack_end();
2637 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002638
John McCall833ca992009-10-29 08:12:44 +00002639 // FIXME: preserve source information here when we start
2640 // caring about parameter packs.
2641
John McCall828bff22009-10-29 18:45:58 +00002642 TemplateArgumentLoc InputArg;
2643 TemplateArgumentLoc OutputArg;
2644 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2645 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002646 return true;
2647
John McCall828bff22009-10-29 18:45:58 +00002648 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002649 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002650
2651 TemplateArgument *TransformedArgsPtr
2652 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2653 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2654 TransformedArgsPtr);
2655 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2656 TransformedArgs.size()),
2657 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002658 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002659 }
2660 }
Mike Stump1eb44332009-09-09 15:08:12 +00002661
Douglas Gregor670444e2009-08-04 22:27:00 +00002662 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002663 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002664}
2665
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002666/// \brief Iterator adaptor that invents template argument location information
2667/// for each of the template arguments in its underlying iterator.
2668template<typename Derived, typename InputIterator>
2669class TemplateArgumentLocInventIterator {
2670 TreeTransform<Derived> &Self;
2671 InputIterator Iter;
2672
2673public:
2674 typedef TemplateArgumentLoc value_type;
2675 typedef TemplateArgumentLoc reference;
2676 typedef typename std::iterator_traits<InputIterator>::difference_type
2677 difference_type;
2678 typedef std::input_iterator_tag iterator_category;
2679
2680 class pointer {
2681 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002682
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002683 public:
2684 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2685
2686 const TemplateArgumentLoc *operator->() const { return &Arg; }
2687 };
2688
2689 TemplateArgumentLocInventIterator() { }
2690
2691 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2692 InputIterator Iter)
2693 : Self(Self), Iter(Iter) { }
2694
2695 TemplateArgumentLocInventIterator &operator++() {
2696 ++Iter;
2697 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002698 }
2699
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002700 TemplateArgumentLocInventIterator operator++(int) {
2701 TemplateArgumentLocInventIterator Old(*this);
2702 ++(*this);
2703 return Old;
2704 }
2705
2706 reference operator*() const {
2707 TemplateArgumentLoc Result;
2708 Self.InventTemplateArgumentLoc(*Iter, Result);
2709 return Result;
2710 }
2711
2712 pointer operator->() const { return pointer(**this); }
2713
2714 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2715 const TemplateArgumentLocInventIterator &Y) {
2716 return X.Iter == Y.Iter;
2717 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002718
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002719 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2720 const TemplateArgumentLocInventIterator &Y) {
2721 return X.Iter != Y.Iter;
2722 }
2723};
2724
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002725template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002726template<typename InputIterator>
2727bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2728 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002729 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002730 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002731 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002732 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002733
2734 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2735 // Unpack argument packs, which we translate them into separate
2736 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002737 // FIXME: We could do much better if we could guarantee that the
2738 // TemplateArgumentLocInfo for the pack expansion would be usable for
2739 // all of the template arguments in the argument pack.
2740 typedef TemplateArgumentLocInventIterator<Derived,
2741 TemplateArgument::pack_iterator>
2742 PackLocIterator;
2743 if (TransformTemplateArguments(PackLocIterator(*this,
2744 In.getArgument().pack_begin()),
2745 PackLocIterator(*this,
2746 In.getArgument().pack_end()),
2747 Outputs))
2748 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002749
2750 continue;
2751 }
2752
2753 if (In.getArgument().isPackExpansion()) {
2754 // We have a pack expansion, for which we will be substituting into
2755 // the pattern.
2756 SourceLocation Ellipsis;
2757 TemplateArgumentLoc Pattern
2758 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2759
2760 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2761 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2762 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2763
2764 // Determine whether the set of unexpanded parameter packs can and should
2765 // be expanded.
2766 bool Expand = true;
2767 unsigned NumExpansions = 0;
2768 if (getDerived().TryExpandParameterPacks(Ellipsis,
2769 Pattern.getSourceRange(),
2770 Unexpanded.data(),
2771 Unexpanded.size(),
2772 Expand, NumExpansions))
2773 return true;
2774
2775 if (!Expand) {
2776 // The transform has determined that we should perform a simple
2777 // transformation on the pack expansion, producing another pack
2778 // expansion.
2779 TemplateArgumentLoc OutPattern;
2780 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2781 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2782 return true;
2783
2784 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2785 if (Out.getArgument().isNull())
2786 return true;
2787
2788 Outputs.addArgument(Out);
2789 continue;
2790 }
2791
2792 // The transform has determined that we should perform an elementwise
2793 // expansion of the pattern. Do so.
2794 for (unsigned I = 0; I != NumExpansions; ++I) {
2795 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2796
2797 if (getDerived().TransformTemplateArgument(Pattern, Out))
2798 return true;
2799
2800 Outputs.addArgument(Out);
2801 }
2802
2803 continue;
2804 }
2805
2806 // The simple case:
2807 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002808 return true;
2809
2810 Outputs.addArgument(Out);
2811 }
2812
2813 return false;
2814
2815}
2816
Douglas Gregor577f75a2009-08-04 16:50:30 +00002817//===----------------------------------------------------------------------===//
2818// Type transformation
2819//===----------------------------------------------------------------------===//
2820
2821template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002822QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002823 if (getDerived().AlreadyTransformed(T))
2824 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002825
John McCalla2becad2009-10-21 00:40:46 +00002826 // Temporary workaround. All of these transformations should
2827 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002828 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002829 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002830
John McCall43fed0d2010-11-12 08:19:04 +00002831 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002832
John McCalla2becad2009-10-21 00:40:46 +00002833 if (!NewDI)
2834 return QualType();
2835
2836 return NewDI->getType();
2837}
2838
2839template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002840TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002841 if (getDerived().AlreadyTransformed(DI->getType()))
2842 return DI;
2843
2844 TypeLocBuilder TLB;
2845
2846 TypeLoc TL = DI->getTypeLoc();
2847 TLB.reserve(TL.getFullDataSize());
2848
John McCall43fed0d2010-11-12 08:19:04 +00002849 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002850 if (Result.isNull())
2851 return 0;
2852
John McCalla93c9342009-12-07 02:54:59 +00002853 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002854}
2855
2856template<typename Derived>
2857QualType
John McCall43fed0d2010-11-12 08:19:04 +00002858TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002859 switch (T.getTypeLocClass()) {
2860#define ABSTRACT_TYPELOC(CLASS, PARENT)
2861#define TYPELOC(CLASS, PARENT) \
2862 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002863 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002864#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002865 }
Mike Stump1eb44332009-09-09 15:08:12 +00002866
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002867 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002868 return QualType();
2869}
2870
2871/// FIXME: By default, this routine adds type qualifiers only to types
2872/// that can have qualifiers, and silently suppresses those qualifiers
2873/// that are not permitted (e.g., qualifiers on reference or function
2874/// types). This is the right thing for template instantiation, but
2875/// probably not for other clients.
2876template<typename Derived>
2877QualType
2878TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002879 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002880 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002881
John McCall43fed0d2010-11-12 08:19:04 +00002882 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002883 if (Result.isNull())
2884 return QualType();
2885
2886 // Silently suppress qualifiers if the result type can't be qualified.
2887 // FIXME: this is the right thing for template instantiation, but
2888 // probably not for other clients.
2889 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002890 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002891
John McCall28654742010-06-05 06:41:15 +00002892 if (!Quals.empty()) {
2893 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2894 TLB.push<QualifiedTypeLoc>(Result);
2895 // No location information to preserve.
2896 }
John McCalla2becad2009-10-21 00:40:46 +00002897
2898 return Result;
2899}
2900
John McCall43fed0d2010-11-12 08:19:04 +00002901/// \brief Transforms a type that was written in a scope specifier,
2902/// given an object type, the results of unqualified lookup, and
2903/// an already-instantiated prefix.
2904///
2905/// The object type is provided iff the scope specifier qualifies the
2906/// member of a dependent member-access expression. The prefix is
2907/// provided iff the the scope specifier in which this appears has a
2908/// prefix.
2909///
2910/// This is private to TreeTransform.
2911template<typename Derived>
2912QualType
2913TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2914 QualType ObjectType,
2915 NamedDecl *UnqualLookup,
2916 NestedNameSpecifier *Prefix) {
2917 if (getDerived().AlreadyTransformed(T))
2918 return T;
2919
2920 TypeSourceInfo *TSI =
2921 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2922
2923 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2924 UnqualLookup, Prefix);
2925 if (!TSI) return QualType();
2926 return TSI->getType();
2927}
2928
2929template<typename Derived>
2930TypeSourceInfo *
2931TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2932 QualType ObjectType,
2933 NamedDecl *UnqualLookup,
2934 NestedNameSpecifier *Prefix) {
2935 // TODO: in some cases, we might be some verification to do here.
2936 if (ObjectType.isNull())
2937 return getDerived().TransformType(TSI);
2938
2939 QualType T = TSI->getType();
2940 if (getDerived().AlreadyTransformed(T))
2941 return TSI;
2942
2943 TypeLocBuilder TLB;
2944 QualType Result;
2945
2946 if (isa<TemplateSpecializationType>(T)) {
2947 TemplateSpecializationTypeLoc TL
2948 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2949
2950 TemplateName Template =
2951 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2952 ObjectType, UnqualLookup);
2953 if (Template.isNull()) return 0;
2954
2955 Result = getDerived()
2956 .TransformTemplateSpecializationType(TLB, TL, Template);
2957 } else if (isa<DependentTemplateSpecializationType>(T)) {
2958 DependentTemplateSpecializationTypeLoc TL
2959 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2960
2961 Result = getDerived()
2962 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2963 } else {
2964 // Nothing special needs to be done for these.
2965 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2966 }
2967
2968 if (Result.isNull()) return 0;
2969 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2970}
2971
John McCalla2becad2009-10-21 00:40:46 +00002972template <class TyLoc> static inline
2973QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2974 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2975 NewT.setNameLoc(T.getNameLoc());
2976 return T.getType();
2977}
2978
John McCalla2becad2009-10-21 00:40:46 +00002979template<typename Derived>
2980QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002981 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002982 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2983 NewT.setBuiltinLoc(T.getBuiltinLoc());
2984 if (T.needsExtraLocalData())
2985 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2986 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002987}
Mike Stump1eb44332009-09-09 15:08:12 +00002988
Douglas Gregor577f75a2009-08-04 16:50:30 +00002989template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002990QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002991 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002992 // FIXME: recurse?
2993 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002994}
Mike Stump1eb44332009-09-09 15:08:12 +00002995
Douglas Gregor577f75a2009-08-04 16:50:30 +00002996template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002997QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002998 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00002999 QualType PointeeType
3000 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003001 if (PointeeType.isNull())
3002 return QualType();
3003
3004 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003005 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003006 // A dependent pointer type 'T *' has is being transformed such
3007 // that an Objective-C class type is being replaced for 'T'. The
3008 // resulting pointer type is an ObjCObjectPointerType, not a
3009 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003010 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003011
John McCallc12c5bb2010-05-15 11:32:37 +00003012 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3013 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003014 return Result;
3015 }
John McCall43fed0d2010-11-12 08:19:04 +00003016
Douglas Gregor92e986e2010-04-22 16:44:27 +00003017 if (getDerived().AlwaysRebuild() ||
3018 PointeeType != TL.getPointeeLoc().getType()) {
3019 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3020 if (Result.isNull())
3021 return QualType();
3022 }
Sean Huntc3021132010-05-05 15:23:54 +00003023
Douglas Gregor92e986e2010-04-22 16:44:27 +00003024 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3025 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003026 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003027}
Mike Stump1eb44332009-09-09 15:08:12 +00003028
3029template<typename Derived>
3030QualType
John McCalla2becad2009-10-21 00:40:46 +00003031TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003032 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003033 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003034 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3035 if (PointeeType.isNull())
3036 return QualType();
3037
3038 QualType Result = TL.getType();
3039 if (getDerived().AlwaysRebuild() ||
3040 PointeeType != TL.getPointeeLoc().getType()) {
3041 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003042 TL.getSigilLoc());
3043 if (Result.isNull())
3044 return QualType();
3045 }
3046
Douglas Gregor39968ad2010-04-22 16:50:51 +00003047 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003048 NewT.setSigilLoc(TL.getSigilLoc());
3049 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003050}
3051
John McCall85737a72009-10-30 00:06:24 +00003052/// Transforms a reference type. Note that somewhat paradoxically we
3053/// don't care whether the type itself is an l-value type or an r-value
3054/// type; we only care if the type was *written* as an l-value type
3055/// or an r-value type.
3056template<typename Derived>
3057QualType
3058TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003059 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003060 const ReferenceType *T = TL.getTypePtr();
3061
3062 // Note that this works with the pointee-as-written.
3063 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3064 if (PointeeType.isNull())
3065 return QualType();
3066
3067 QualType Result = TL.getType();
3068 if (getDerived().AlwaysRebuild() ||
3069 PointeeType != T->getPointeeTypeAsWritten()) {
3070 Result = getDerived().RebuildReferenceType(PointeeType,
3071 T->isSpelledAsLValue(),
3072 TL.getSigilLoc());
3073 if (Result.isNull())
3074 return QualType();
3075 }
3076
3077 // r-value references can be rebuilt as l-value references.
3078 ReferenceTypeLoc NewTL;
3079 if (isa<LValueReferenceType>(Result))
3080 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3081 else
3082 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3083 NewTL.setSigilLoc(TL.getSigilLoc());
3084
3085 return Result;
3086}
3087
Mike Stump1eb44332009-09-09 15:08:12 +00003088template<typename Derived>
3089QualType
John McCalla2becad2009-10-21 00:40:46 +00003090TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003091 LValueReferenceTypeLoc TL) {
3092 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003093}
3094
Mike Stump1eb44332009-09-09 15:08:12 +00003095template<typename Derived>
3096QualType
John McCalla2becad2009-10-21 00:40:46 +00003097TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003098 RValueReferenceTypeLoc TL) {
3099 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003100}
Mike Stump1eb44332009-09-09 15:08:12 +00003101
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003103QualType
John McCalla2becad2009-10-21 00:40:46 +00003104TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003105 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003106 MemberPointerType *T = TL.getTypePtr();
3107
3108 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003109 if (PointeeType.isNull())
3110 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003111
John McCalla2becad2009-10-21 00:40:46 +00003112 // TODO: preserve source information for this.
3113 QualType ClassType
3114 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003115 if (ClassType.isNull())
3116 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003117
John McCalla2becad2009-10-21 00:40:46 +00003118 QualType Result = TL.getType();
3119 if (getDerived().AlwaysRebuild() ||
3120 PointeeType != T->getPointeeType() ||
3121 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003122 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3123 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003124 if (Result.isNull())
3125 return QualType();
3126 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003127
John McCalla2becad2009-10-21 00:40:46 +00003128 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3129 NewTL.setSigilLoc(TL.getSigilLoc());
3130
3131 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003132}
3133
Mike Stump1eb44332009-09-09 15:08:12 +00003134template<typename Derived>
3135QualType
John McCalla2becad2009-10-21 00:40:46 +00003136TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003137 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003138 ConstantArrayType *T = TL.getTypePtr();
3139 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003140 if (ElementType.isNull())
3141 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003142
John McCalla2becad2009-10-21 00:40:46 +00003143 QualType Result = TL.getType();
3144 if (getDerived().AlwaysRebuild() ||
3145 ElementType != T->getElementType()) {
3146 Result = getDerived().RebuildConstantArrayType(ElementType,
3147 T->getSizeModifier(),
3148 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003149 T->getIndexTypeCVRQualifiers(),
3150 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003151 if (Result.isNull())
3152 return QualType();
3153 }
Sean Huntc3021132010-05-05 15:23:54 +00003154
John McCalla2becad2009-10-21 00:40:46 +00003155 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3156 NewTL.setLBracketLoc(TL.getLBracketLoc());
3157 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003158
John McCalla2becad2009-10-21 00:40:46 +00003159 Expr *Size = TL.getSizeExpr();
3160 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003161 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003162 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3163 }
3164 NewTL.setSizeExpr(Size);
3165
3166 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003167}
Mike Stump1eb44332009-09-09 15:08:12 +00003168
Douglas Gregor577f75a2009-08-04 16:50:30 +00003169template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003170QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003171 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003172 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003173 IncompleteArrayType *T = TL.getTypePtr();
3174 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003175 if (ElementType.isNull())
3176 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003177
John McCalla2becad2009-10-21 00:40:46 +00003178 QualType Result = TL.getType();
3179 if (getDerived().AlwaysRebuild() ||
3180 ElementType != T->getElementType()) {
3181 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003182 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003183 T->getIndexTypeCVRQualifiers(),
3184 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003185 if (Result.isNull())
3186 return QualType();
3187 }
Sean Huntc3021132010-05-05 15:23:54 +00003188
John McCalla2becad2009-10-21 00:40:46 +00003189 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3190 NewTL.setLBracketLoc(TL.getLBracketLoc());
3191 NewTL.setRBracketLoc(TL.getRBracketLoc());
3192 NewTL.setSizeExpr(0);
3193
3194 return Result;
3195}
3196
3197template<typename Derived>
3198QualType
3199TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003200 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003201 VariableArrayType *T = TL.getTypePtr();
3202 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3203 if (ElementType.isNull())
3204 return QualType();
3205
3206 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003207 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003208
John McCall60d7b3a2010-08-24 06:29:42 +00003209 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003210 = getDerived().TransformExpr(T->getSizeExpr());
3211 if (SizeResult.isInvalid())
3212 return QualType();
3213
John McCall9ae2f072010-08-23 23:25:46 +00003214 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003215
3216 QualType Result = TL.getType();
3217 if (getDerived().AlwaysRebuild() ||
3218 ElementType != T->getElementType() ||
3219 Size != T->getSizeExpr()) {
3220 Result = getDerived().RebuildVariableArrayType(ElementType,
3221 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003222 Size,
John McCalla2becad2009-10-21 00:40:46 +00003223 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003224 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003225 if (Result.isNull())
3226 return QualType();
3227 }
Sean Huntc3021132010-05-05 15:23:54 +00003228
John McCalla2becad2009-10-21 00:40:46 +00003229 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3230 NewTL.setLBracketLoc(TL.getLBracketLoc());
3231 NewTL.setRBracketLoc(TL.getRBracketLoc());
3232 NewTL.setSizeExpr(Size);
3233
3234 return Result;
3235}
3236
3237template<typename Derived>
3238QualType
3239TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003240 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003241 DependentSizedArrayType *T = TL.getTypePtr();
3242 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3243 if (ElementType.isNull())
3244 return QualType();
3245
3246 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003247 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003248
John McCall60d7b3a2010-08-24 06:29:42 +00003249 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003250 = getDerived().TransformExpr(T->getSizeExpr());
3251 if (SizeResult.isInvalid())
3252 return QualType();
3253
3254 Expr *Size = static_cast<Expr*>(SizeResult.get());
3255
3256 QualType Result = TL.getType();
3257 if (getDerived().AlwaysRebuild() ||
3258 ElementType != T->getElementType() ||
3259 Size != T->getSizeExpr()) {
3260 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3261 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003262 Size,
John McCalla2becad2009-10-21 00:40:46 +00003263 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003264 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003265 if (Result.isNull())
3266 return QualType();
3267 }
3268 else SizeResult.take();
3269
3270 // We might have any sort of array type now, but fortunately they
3271 // all have the same location layout.
3272 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3273 NewTL.setLBracketLoc(TL.getLBracketLoc());
3274 NewTL.setRBracketLoc(TL.getRBracketLoc());
3275 NewTL.setSizeExpr(Size);
3276
3277 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003278}
Mike Stump1eb44332009-09-09 15:08:12 +00003279
3280template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003281QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003282 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003283 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003284 DependentSizedExtVectorType *T = TL.getTypePtr();
3285
3286 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003287 QualType ElementType = getDerived().TransformType(T->getElementType());
3288 if (ElementType.isNull())
3289 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003290
Douglas Gregor670444e2009-08-04 22:27:00 +00003291 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003292 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003293
John McCall60d7b3a2010-08-24 06:29:42 +00003294 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003295 if (Size.isInvalid())
3296 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003297
John McCalla2becad2009-10-21 00:40:46 +00003298 QualType Result = TL.getType();
3299 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003300 ElementType != T->getElementType() ||
3301 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003302 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003303 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003304 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003305 if (Result.isNull())
3306 return QualType();
3307 }
John McCalla2becad2009-10-21 00:40:46 +00003308
3309 // Result might be dependent or not.
3310 if (isa<DependentSizedExtVectorType>(Result)) {
3311 DependentSizedExtVectorTypeLoc NewTL
3312 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3313 NewTL.setNameLoc(TL.getNameLoc());
3314 } else {
3315 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3316 NewTL.setNameLoc(TL.getNameLoc());
3317 }
3318
3319 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003320}
Mike Stump1eb44332009-09-09 15:08:12 +00003321
3322template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003323QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003324 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003325 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003326 QualType ElementType = getDerived().TransformType(T->getElementType());
3327 if (ElementType.isNull())
3328 return QualType();
3329
John McCalla2becad2009-10-21 00:40:46 +00003330 QualType Result = TL.getType();
3331 if (getDerived().AlwaysRebuild() ||
3332 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003333 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003334 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003335 if (Result.isNull())
3336 return QualType();
3337 }
Sean Huntc3021132010-05-05 15:23:54 +00003338
John McCalla2becad2009-10-21 00:40:46 +00003339 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3340 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003341
John McCalla2becad2009-10-21 00:40:46 +00003342 return Result;
3343}
3344
3345template<typename Derived>
3346QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003347 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003348 VectorType *T = TL.getTypePtr();
3349 QualType ElementType = getDerived().TransformType(T->getElementType());
3350 if (ElementType.isNull())
3351 return QualType();
3352
3353 QualType Result = TL.getType();
3354 if (getDerived().AlwaysRebuild() ||
3355 ElementType != T->getElementType()) {
3356 Result = getDerived().RebuildExtVectorType(ElementType,
3357 T->getNumElements(),
3358 /*FIXME*/ SourceLocation());
3359 if (Result.isNull())
3360 return QualType();
3361 }
Sean Huntc3021132010-05-05 15:23:54 +00003362
John McCalla2becad2009-10-21 00:40:46 +00003363 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3364 NewTL.setNameLoc(TL.getNameLoc());
3365
3366 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003367}
Mike Stump1eb44332009-09-09 15:08:12 +00003368
3369template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003370ParmVarDecl *
3371TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3372 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3373 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3374 if (!NewDI)
3375 return 0;
3376
3377 if (NewDI == OldDI)
3378 return OldParm;
3379 else
3380 return ParmVarDecl::Create(SemaRef.Context,
3381 OldParm->getDeclContext(),
3382 OldParm->getLocation(),
3383 OldParm->getIdentifier(),
3384 NewDI->getType(),
3385 NewDI,
3386 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003387 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003388 /* DefArg */ NULL);
3389}
3390
3391template<typename Derived>
3392bool TreeTransform<Derived>::
3393 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3394 llvm::SmallVectorImpl<QualType> &PTypes,
3395 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3396 FunctionProtoType *T = TL.getTypePtr();
3397
3398 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003399 if (ParmVarDecl *OldParm = TL.getArg(i)) {
3400 if (OldParm->isParameterPack()) {
3401 // We have a function parameter pack that may need to be expanded.
3402 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003403
Douglas Gregor603cfb42011-01-05 23:12:31 +00003404 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003405 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3406 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3407 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3408 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003409
3410 // Determine whether we should expand the parameter packs.
3411 bool ShouldExpand = false;
3412 unsigned NumExpansions = 0;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003413 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3414 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003415 Unexpanded.data(),
3416 Unexpanded.size(),
3417 ShouldExpand, NumExpansions)) {
3418 return true;
3419 }
3420
3421 if (ShouldExpand) {
3422 // Expand the function parameter pack into multiple, separate
3423 // parameters.
3424 for (unsigned I = 0; I != NumExpansions; ++I) {
3425 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3426 ParmVarDecl *NewParm
3427 = getDerived().TransformFunctionTypeParam(OldParm);
3428 if (!NewParm)
3429 return true;
3430
3431 PTypes.push_back(NewParm->getType());
3432 PVars.push_back(NewParm);
3433 }
3434
3435 // We're done with the pack expansion.
3436 continue;
3437 }
3438
3439 // We'll substitute the parameter now without expanding the pack
3440 // expansion.
3441 }
3442
3443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3444 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
John McCall21ef0fa2010-03-11 09:03:00 +00003445 if (!NewParm)
3446 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003447
3448 PTypes.push_back(NewParm->getType());
3449 PVars.push_back(NewParm);
3450 continue;
3451 }
John McCall21ef0fa2010-03-11 09:03:00 +00003452
3453 // Deal with the possibility that we don't have a parameter
3454 // declaration for this parameter.
Douglas Gregor603cfb42011-01-05 23:12:31 +00003455 QualType OldType = T->getArgType(i);
3456 bool IsPackExpansion = false;
3457 if (const PackExpansionType *Expansion
3458 = dyn_cast<PackExpansionType>(OldType)) {
3459 // We have a function parameter pack that may need to be expanded.
3460 QualType Pattern = Expansion->getPattern();
3461 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3462 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3463
3464 // Determine whether we should expand the parameter packs.
3465 bool ShouldExpand = false;
3466 unsigned NumExpansions = 0;
3467 if (getDerived().TryExpandParameterPacks(TL.getBeginLoc(), SourceRange(),
3468 Unexpanded.data(),
3469 Unexpanded.size(),
3470 ShouldExpand, NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003471 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003472 }
3473
3474 if (ShouldExpand) {
3475 // Expand the function parameter pack into multiple, separate
3476 // parameters.
3477 for (unsigned I = 0; I != NumExpansions; ++I) {
3478 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3479 QualType NewType = getDerived().TransformType(Pattern);
3480 if (NewType.isNull())
3481 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003482
Douglas Gregor603cfb42011-01-05 23:12:31 +00003483 PTypes.push_back(NewType);
3484 PVars.push_back(0);
3485 }
3486
3487 // We're done with the pack expansion.
3488 continue;
3489 }
3490
3491 // We'll substitute the parameter now without expanding the pack
3492 // expansion.
3493 OldType = Expansion->getPattern();
3494 IsPackExpansion = true;
3495 }
3496
3497 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3498 QualType NewType = getDerived().TransformType(OldType);
3499 if (NewType.isNull())
3500 return true;
3501
3502 if (IsPackExpansion)
3503 NewType = getSema().Context.getPackExpansionType(NewType);
3504
John McCall21ef0fa2010-03-11 09:03:00 +00003505 PTypes.push_back(NewType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003506 PVars.push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003507 }
3508
3509 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003510 }
John McCall21ef0fa2010-03-11 09:03:00 +00003511
3512template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003513QualType
John McCalla2becad2009-10-21 00:40:46 +00003514TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003515 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003516 // Transform the parameters and return type.
3517 //
3518 // We instantiate in source order, with the return type first followed by
3519 // the parameters, because users tend to expect this (even if they shouldn't
3520 // rely on it!).
3521 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003522 // When the function has a trailing return type, we instantiate the
3523 // parameters before the return type, since the return type can then refer
3524 // to the parameters themselves (via decltype, sizeof, etc.).
3525 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003526 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003527 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003528 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003529
Douglas Gregordab60ad2010-10-01 18:44:50 +00003530 QualType ResultType;
3531
3532 if (TL.getTrailingReturn()) {
3533 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3534 return QualType();
3535
3536 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3537 if (ResultType.isNull())
3538 return QualType();
3539 }
3540 else {
3541 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3542 if (ResultType.isNull())
3543 return QualType();
3544
3545 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3546 return QualType();
3547 }
3548
John McCalla2becad2009-10-21 00:40:46 +00003549 QualType Result = TL.getType();
3550 if (getDerived().AlwaysRebuild() ||
3551 ResultType != T->getResultType() ||
3552 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3553 Result = getDerived().RebuildFunctionProtoType(ResultType,
3554 ParamTypes.data(),
3555 ParamTypes.size(),
3556 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003557 T->getTypeQuals(),
3558 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003559 if (Result.isNull())
3560 return QualType();
3561 }
Mike Stump1eb44332009-09-09 15:08:12 +00003562
John McCalla2becad2009-10-21 00:40:46 +00003563 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3564 NewTL.setLParenLoc(TL.getLParenLoc());
3565 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003566 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003567 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3568 NewTL.setArg(i, ParamDecls[i]);
3569
3570 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003571}
Mike Stump1eb44332009-09-09 15:08:12 +00003572
Douglas Gregor577f75a2009-08-04 16:50:30 +00003573template<typename Derived>
3574QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003575 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003576 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003577 FunctionNoProtoType *T = TL.getTypePtr();
3578 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3579 if (ResultType.isNull())
3580 return QualType();
3581
3582 QualType Result = TL.getType();
3583 if (getDerived().AlwaysRebuild() ||
3584 ResultType != T->getResultType())
3585 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3586
3587 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3588 NewTL.setLParenLoc(TL.getLParenLoc());
3589 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003590 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003591
3592 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003593}
Mike Stump1eb44332009-09-09 15:08:12 +00003594
John McCalled976492009-12-04 22:46:56 +00003595template<typename Derived> QualType
3596TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003597 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003598 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003599 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003600 if (!D)
3601 return QualType();
3602
3603 QualType Result = TL.getType();
3604 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3605 Result = getDerived().RebuildUnresolvedUsingType(D);
3606 if (Result.isNull())
3607 return QualType();
3608 }
3609
3610 // We might get an arbitrary type spec type back. We should at
3611 // least always get a type spec type, though.
3612 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3613 NewTL.setNameLoc(TL.getNameLoc());
3614
3615 return Result;
3616}
3617
Douglas Gregor577f75a2009-08-04 16:50:30 +00003618template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003619QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003620 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003621 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003622 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003623 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3624 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003625 if (!Typedef)
3626 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003627
John McCalla2becad2009-10-21 00:40:46 +00003628 QualType Result = TL.getType();
3629 if (getDerived().AlwaysRebuild() ||
3630 Typedef != T->getDecl()) {
3631 Result = getDerived().RebuildTypedefType(Typedef);
3632 if (Result.isNull())
3633 return QualType();
3634 }
Mike Stump1eb44332009-09-09 15:08:12 +00003635
John McCalla2becad2009-10-21 00:40:46 +00003636 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3637 NewTL.setNameLoc(TL.getNameLoc());
3638
3639 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003640}
Mike Stump1eb44332009-09-09 15:08:12 +00003641
Douglas Gregor577f75a2009-08-04 16:50:30 +00003642template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003643QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003644 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003645 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003647
John McCall60d7b3a2010-08-24 06:29:42 +00003648 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003649 if (E.isInvalid())
3650 return QualType();
3651
John McCalla2becad2009-10-21 00:40:46 +00003652 QualType Result = TL.getType();
3653 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003654 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003655 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003656 if (Result.isNull())
3657 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003658 }
John McCalla2becad2009-10-21 00:40:46 +00003659 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003660
John McCalla2becad2009-10-21 00:40:46 +00003661 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003662 NewTL.setTypeofLoc(TL.getTypeofLoc());
3663 NewTL.setLParenLoc(TL.getLParenLoc());
3664 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003665
3666 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003667}
Mike Stump1eb44332009-09-09 15:08:12 +00003668
3669template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003670QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003671 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003672 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3673 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3674 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003675 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003676
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003678 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3679 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003680 if (Result.isNull())
3681 return QualType();
3682 }
Mike Stump1eb44332009-09-09 15:08:12 +00003683
John McCalla2becad2009-10-21 00:40:46 +00003684 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003685 NewTL.setTypeofLoc(TL.getTypeofLoc());
3686 NewTL.setLParenLoc(TL.getLParenLoc());
3687 NewTL.setRParenLoc(TL.getRParenLoc());
3688 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003689
3690 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003691}
Mike Stump1eb44332009-09-09 15:08:12 +00003692
3693template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003694QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003695 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003696 DecltypeType *T = TL.getTypePtr();
3697
Douglas Gregor670444e2009-08-04 22:27:00 +00003698 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003699 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003700
John McCall60d7b3a2010-08-24 06:29:42 +00003701 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003702 if (E.isInvalid())
3703 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003704
John McCalla2becad2009-10-21 00:40:46 +00003705 QualType Result = TL.getType();
3706 if (getDerived().AlwaysRebuild() ||
3707 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003708 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003709 if (Result.isNull())
3710 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003711 }
John McCalla2becad2009-10-21 00:40:46 +00003712 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003713
John McCalla2becad2009-10-21 00:40:46 +00003714 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3715 NewTL.setNameLoc(TL.getNameLoc());
3716
3717 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718}
3719
3720template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003721QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003722 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003723 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003725 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3726 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003727 if (!Record)
3728 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003729
John McCalla2becad2009-10-21 00:40:46 +00003730 QualType Result = TL.getType();
3731 if (getDerived().AlwaysRebuild() ||
3732 Record != T->getDecl()) {
3733 Result = getDerived().RebuildRecordType(Record);
3734 if (Result.isNull())
3735 return QualType();
3736 }
Mike Stump1eb44332009-09-09 15:08:12 +00003737
John McCalla2becad2009-10-21 00:40:46 +00003738 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3739 NewTL.setNameLoc(TL.getNameLoc());
3740
3741 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742}
Mike Stump1eb44332009-09-09 15:08:12 +00003743
3744template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003745QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003746 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003747 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003748 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003749 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3750 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003751 if (!Enum)
3752 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003753
John McCalla2becad2009-10-21 00:40:46 +00003754 QualType Result = TL.getType();
3755 if (getDerived().AlwaysRebuild() ||
3756 Enum != T->getDecl()) {
3757 Result = getDerived().RebuildEnumType(Enum);
3758 if (Result.isNull())
3759 return QualType();
3760 }
Mike Stump1eb44332009-09-09 15:08:12 +00003761
John McCalla2becad2009-10-21 00:40:46 +00003762 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3763 NewTL.setNameLoc(TL.getNameLoc());
3764
3765 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003766}
John McCall7da24312009-09-05 00:15:47 +00003767
John McCall3cb0ebd2010-03-10 03:28:59 +00003768template<typename Derived>
3769QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3770 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003771 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003772 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3773 TL.getTypePtr()->getDecl());
3774 if (!D) return QualType();
3775
3776 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3777 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3778 return T;
3779}
3780
Douglas Gregor577f75a2009-08-04 16:50:30 +00003781template<typename Derived>
3782QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003783 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003784 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003785 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003786}
3787
Mike Stump1eb44332009-09-09 15:08:12 +00003788template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003789QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003790 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003791 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003792 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003793}
3794
3795template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003796QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003797 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003798 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003799 const TemplateSpecializationType *T = TL.getTypePtr();
3800
Mike Stump1eb44332009-09-09 15:08:12 +00003801 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003802 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003803 if (Template.isNull())
3804 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003805
John McCall43fed0d2010-11-12 08:19:04 +00003806 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3807}
3808
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003809namespace {
3810 /// \brief Simple iterator that traverses the template arguments in a
3811 /// container that provides a \c getArgLoc() member function.
3812 ///
3813 /// This iterator is intended to be used with the iterator form of
3814 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3815 template<typename ArgLocContainer>
3816 class TemplateArgumentLocContainerIterator {
3817 ArgLocContainer *Container;
3818 unsigned Index;
3819
3820 public:
3821 typedef TemplateArgumentLoc value_type;
3822 typedef TemplateArgumentLoc reference;
3823 typedef int difference_type;
3824 typedef std::input_iterator_tag iterator_category;
3825
3826 class pointer {
3827 TemplateArgumentLoc Arg;
3828
3829 public:
3830 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3831
3832 const TemplateArgumentLoc *operator->() const {
3833 return &Arg;
3834 }
3835 };
3836
3837
3838 TemplateArgumentLocContainerIterator() {}
3839
3840 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3841 unsigned Index)
3842 : Container(&Container), Index(Index) { }
3843
3844 TemplateArgumentLocContainerIterator &operator++() {
3845 ++Index;
3846 return *this;
3847 }
3848
3849 TemplateArgumentLocContainerIterator operator++(int) {
3850 TemplateArgumentLocContainerIterator Old(*this);
3851 ++(*this);
3852 return Old;
3853 }
3854
3855 TemplateArgumentLoc operator*() const {
3856 return Container->getArgLoc(Index);
3857 }
3858
3859 pointer operator->() const {
3860 return pointer(Container->getArgLoc(Index));
3861 }
3862
3863 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003864 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003865 return X.Container == Y.Container && X.Index == Y.Index;
3866 }
3867
3868 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003869 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003870 return !(X == Y);
3871 }
3872 };
3873}
3874
3875
John McCall43fed0d2010-11-12 08:19:04 +00003876template <typename Derived>
3877QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3878 TypeLocBuilder &TLB,
3879 TemplateSpecializationTypeLoc TL,
3880 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00003881 TemplateArgumentListInfo NewTemplateArgs;
3882 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3883 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003884 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3885 ArgIterator;
3886 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3887 ArgIterator(TL, TL.getNumArgs()),
3888 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003889 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003890
John McCall833ca992009-10-29 08:12:44 +00003891 // FIXME: maybe don't rebuild if all the template arguments are the same.
3892
3893 QualType Result =
3894 getDerived().RebuildTemplateSpecializationType(Template,
3895 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00003896 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003897
3898 if (!Result.isNull()) {
3899 TemplateSpecializationTypeLoc NewTL
3900 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3901 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3902 NewTL.setLAngleLoc(TL.getLAngleLoc());
3903 NewTL.setRAngleLoc(TL.getRAngleLoc());
3904 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3905 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003906 }
Mike Stump1eb44332009-09-09 15:08:12 +00003907
John McCall833ca992009-10-29 08:12:44 +00003908 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003909}
Mike Stump1eb44332009-09-09 15:08:12 +00003910
3911template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003912QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003913TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003914 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003915 ElaboratedType *T = TL.getTypePtr();
3916
3917 NestedNameSpecifier *NNS = 0;
3918 // NOTE: the qualifier in an ElaboratedType is optional.
3919 if (T->getQualifier() != 0) {
3920 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00003921 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003922 if (!NNS)
3923 return QualType();
3924 }
Mike Stump1eb44332009-09-09 15:08:12 +00003925
John McCall43fed0d2010-11-12 08:19:04 +00003926 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3927 if (NamedT.isNull())
3928 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00003929
John McCalla2becad2009-10-21 00:40:46 +00003930 QualType Result = TL.getType();
3931 if (getDerived().AlwaysRebuild() ||
3932 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003933 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00003934 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3935 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00003936 if (Result.isNull())
3937 return QualType();
3938 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003939
Abramo Bagnara465d41b2010-05-11 21:36:43 +00003940 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00003941 NewTL.setKeywordLoc(TL.getKeywordLoc());
3942 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00003943
3944 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003945}
Mike Stump1eb44332009-09-09 15:08:12 +00003946
3947template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00003948QualType TreeTransform<Derived>::TransformAttributedType(
3949 TypeLocBuilder &TLB,
3950 AttributedTypeLoc TL) {
3951 const AttributedType *oldType = TL.getTypePtr();
3952 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
3953 if (modifiedType.isNull())
3954 return QualType();
3955
3956 QualType result = TL.getType();
3957
3958 // FIXME: dependent operand expressions?
3959 if (getDerived().AlwaysRebuild() ||
3960 modifiedType != oldType->getModifiedType()) {
3961 // TODO: this is really lame; we should really be rebuilding the
3962 // equivalent type from first principles.
3963 QualType equivalentType
3964 = getDerived().TransformType(oldType->getEquivalentType());
3965 if (equivalentType.isNull())
3966 return QualType();
3967 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
3968 modifiedType,
3969 equivalentType);
3970 }
3971
3972 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
3973 newTL.setAttrNameLoc(TL.getAttrNameLoc());
3974 if (TL.hasAttrOperand())
3975 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
3976 if (TL.hasAttrExprOperand())
3977 newTL.setAttrExprOperand(TL.getAttrExprOperand());
3978 else if (TL.hasAttrEnumOperand())
3979 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
3980
3981 return result;
3982}
3983
3984template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00003985QualType
3986TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3987 ParenTypeLoc TL) {
3988 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3989 if (Inner.isNull())
3990 return QualType();
3991
3992 QualType Result = TL.getType();
3993 if (getDerived().AlwaysRebuild() ||
3994 Inner != TL.getInnerLoc().getType()) {
3995 Result = getDerived().RebuildParenType(Inner);
3996 if (Result.isNull())
3997 return QualType();
3998 }
3999
4000 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4001 NewTL.setLParenLoc(TL.getLParenLoc());
4002 NewTL.setRParenLoc(TL.getRParenLoc());
4003 return Result;
4004}
4005
4006template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004007QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004008 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00004009 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004010
Douglas Gregor577f75a2009-08-04 16:50:30 +00004011 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004012 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004013 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004014 if (!NNS)
4015 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004016
John McCall33500952010-06-11 00:33:02 +00004017 QualType Result
4018 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4019 T->getIdentifier(),
4020 TL.getKeywordLoc(),
4021 TL.getQualifierRange(),
4022 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004023 if (Result.isNull())
4024 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004025
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004026 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4027 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004028 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4029
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004030 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4031 NewTL.setKeywordLoc(TL.getKeywordLoc());
4032 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004033 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004034 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4035 NewTL.setKeywordLoc(TL.getKeywordLoc());
4036 NewTL.setQualifierRange(TL.getQualifierRange());
4037 NewTL.setNameLoc(TL.getNameLoc());
4038 }
John McCalla2becad2009-10-21 00:40:46 +00004039 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004040}
Mike Stump1eb44332009-09-09 15:08:12 +00004041
Douglas Gregor577f75a2009-08-04 16:50:30 +00004042template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004043QualType TreeTransform<Derived>::
4044 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004045 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00004046 DependentTemplateSpecializationType *T = TL.getTypePtr();
4047
4048 NestedNameSpecifier *NNS
4049 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004050 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004051 if (!NNS)
4052 return QualType();
4053
John McCall43fed0d2010-11-12 08:19:04 +00004054 return getDerived()
4055 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4056}
4057
4058template<typename Derived>
4059QualType TreeTransform<Derived>::
4060 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4061 DependentTemplateSpecializationTypeLoc TL,
4062 NestedNameSpecifier *NNS) {
4063 DependentTemplateSpecializationType *T = TL.getTypePtr();
4064
John McCall33500952010-06-11 00:33:02 +00004065 TemplateArgumentListInfo NewTemplateArgs;
4066 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4067 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004068
4069 typedef TemplateArgumentLocContainerIterator<
4070 DependentTemplateSpecializationTypeLoc> ArgIterator;
4071 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4072 ArgIterator(TL, TL.getNumArgs()),
4073 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004074 return QualType();
John McCall33500952010-06-11 00:33:02 +00004075
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004076 QualType Result
4077 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4078 NNS,
4079 TL.getQualifierRange(),
4080 T->getIdentifier(),
4081 TL.getNameLoc(),
4082 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004083 if (Result.isNull())
4084 return QualType();
4085
4086 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4087 QualType NamedT = ElabT->getNamedType();
4088
4089 // Copy information relevant to the template specialization.
4090 TemplateSpecializationTypeLoc NamedTL
4091 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4092 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4093 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4094 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4095 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4096
4097 // Copy information relevant to the elaborated type.
4098 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4099 NewTL.setKeywordLoc(TL.getKeywordLoc());
4100 NewTL.setQualifierRange(TL.getQualifierRange());
4101 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004102 TypeLoc NewTL(Result, TL.getOpaqueData());
4103 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004104 }
4105 return Result;
4106}
4107
4108template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004109QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4110 PackExpansionTypeLoc TL) {
Douglas Gregor1d65ebb2011-01-05 19:06:29 +00004111 llvm_unreachable("Caller must expansion pack expansion types");
Douglas Gregor7536dd52010-12-20 02:24:11 +00004112 return QualType();
4113}
4114
4115template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004116QualType
4117TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004118 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004119 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004120 TLB.pushFullCopy(TL);
4121 return TL.getType();
4122}
4123
4124template<typename Derived>
4125QualType
4126TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004127 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004128 // ObjCObjectType is never dependent.
4129 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004130 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004131}
Mike Stump1eb44332009-09-09 15:08:12 +00004132
4133template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004134QualType
4135TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004136 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004137 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004138 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004139 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004140}
4141
Douglas Gregor577f75a2009-08-04 16:50:30 +00004142//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004143// Statement transformation
4144//===----------------------------------------------------------------------===//
4145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004146StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004147TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004148 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004149}
4150
4151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004152StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004153TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4154 return getDerived().TransformCompoundStmt(S, false);
4155}
4156
4157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004158StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004159TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004160 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004161 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004162 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004163 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004164 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4165 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004166 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004167 if (Result.isInvalid()) {
4168 // Immediately fail if this was a DeclStmt, since it's very
4169 // likely that this will cause problems for future statements.
4170 if (isa<DeclStmt>(*B))
4171 return StmtError();
4172
4173 // Otherwise, just keep processing substatements and fail later.
4174 SubStmtInvalid = true;
4175 continue;
4176 }
Mike Stump1eb44332009-09-09 15:08:12 +00004177
Douglas Gregor43959a92009-08-20 07:17:43 +00004178 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4179 Statements.push_back(Result.takeAs<Stmt>());
4180 }
Mike Stump1eb44332009-09-09 15:08:12 +00004181
John McCall7114cba2010-08-27 19:56:05 +00004182 if (SubStmtInvalid)
4183 return StmtError();
4184
Douglas Gregor43959a92009-08-20 07:17:43 +00004185 if (!getDerived().AlwaysRebuild() &&
4186 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004187 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004188
4189 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4190 move_arg(Statements),
4191 S->getRBracLoc(),
4192 IsStmtExpr);
4193}
Mike Stump1eb44332009-09-09 15:08:12 +00004194
Douglas Gregor43959a92009-08-20 07:17:43 +00004195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004196StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004197TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004198 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004199 {
4200 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004201 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004202
Eli Friedman264c1f82009-11-19 03:14:00 +00004203 // Transform the left-hand case value.
4204 LHS = getDerived().TransformExpr(S->getLHS());
4205 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004206 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004207
Eli Friedman264c1f82009-11-19 03:14:00 +00004208 // Transform the right-hand case value (for the GNU case-range extension).
4209 RHS = getDerived().TransformExpr(S->getRHS());
4210 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004211 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004212 }
Mike Stump1eb44332009-09-09 15:08:12 +00004213
Douglas Gregor43959a92009-08-20 07:17:43 +00004214 // Build the case statement.
4215 // Case statements are always rebuilt so that they will attached to their
4216 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004217 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004218 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004219 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004220 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004221 S->getColonLoc());
4222 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004223 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004224
Douglas Gregor43959a92009-08-20 07:17:43 +00004225 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004226 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004227 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004228 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004229
Douglas Gregor43959a92009-08-20 07:17:43 +00004230 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004231 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004232}
4233
4234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004235StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004236TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004237 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004238 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004239 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004240 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004241
Douglas Gregor43959a92009-08-20 07:17:43 +00004242 // Default statements are always rebuilt
4243 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004244 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004245}
Mike Stump1eb44332009-09-09 15:08:12 +00004246
Douglas Gregor43959a92009-08-20 07:17:43 +00004247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004248StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004249TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004250 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004251 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004252 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004253
Douglas Gregor43959a92009-08-20 07:17:43 +00004254 // FIXME: Pass the real colon location in.
4255 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4256 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004257 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004258}
Mike Stump1eb44332009-09-09 15:08:12 +00004259
Douglas Gregor43959a92009-08-20 07:17:43 +00004260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004261StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004262TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004263 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004264 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004265 VarDecl *ConditionVar = 0;
4266 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004267 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004268 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004269 getDerived().TransformDefinition(
4270 S->getConditionVariable()->getLocation(),
4271 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004272 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004273 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004274 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004275 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004276
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004277 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004278 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004279
4280 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004281 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004282 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4283 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004284 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004285 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004286
John McCall9ae2f072010-08-23 23:25:46 +00004287 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004288 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004289 }
Sean Huntc3021132010-05-05 15:23:54 +00004290
John McCall9ae2f072010-08-23 23:25:46 +00004291 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4292 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004293 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004294
Douglas Gregor43959a92009-08-20 07:17:43 +00004295 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004296 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004297 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004298 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004299
Douglas Gregor43959a92009-08-20 07:17:43 +00004300 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004301 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004302 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004303 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004304
Douglas Gregor43959a92009-08-20 07:17:43 +00004305 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004306 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004307 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004308 Then.get() == S->getThen() &&
4309 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004310 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004311
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004312 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004313 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004314 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004315}
4316
4317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004318StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004319TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004320 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004321 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004322 VarDecl *ConditionVar = 0;
4323 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004324 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004325 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004326 getDerived().TransformDefinition(
4327 S->getConditionVariable()->getLocation(),
4328 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004329 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004330 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004331 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004332 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004333
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004334 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004335 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004336 }
Mike Stump1eb44332009-09-09 15:08:12 +00004337
Douglas Gregor43959a92009-08-20 07:17:43 +00004338 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004339 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004340 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004341 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004342 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004343 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
Douglas Gregor43959a92009-08-20 07:17:43 +00004345 // Transform the body of the switch statement.
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 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004351 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4352 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004353}
Mike Stump1eb44332009-09-09 15:08:12 +00004354
Douglas Gregor43959a92009-08-20 07:17:43 +00004355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004356StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004357TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004358 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004359 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004360 VarDecl *ConditionVar = 0;
4361 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004362 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004363 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004364 getDerived().TransformDefinition(
4365 S->getConditionVariable()->getLocation(),
4366 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004367 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004368 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004369 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004370 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004371
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004372 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004373 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004374
4375 if (S->getCond()) {
4376 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004377 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4378 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004379 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004380 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004381 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004382 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004383 }
Mike Stump1eb44332009-09-09 15:08:12 +00004384
John McCall9ae2f072010-08-23 23:25:46 +00004385 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4386 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004387 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004388
Douglas Gregor43959a92009-08-20 07:17:43 +00004389 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004390 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004391 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004392 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004393
Douglas Gregor43959a92009-08-20 07:17:43 +00004394 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004395 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004396 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004397 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004398 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004399
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004400 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004401 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004402}
Mike Stump1eb44332009-09-09 15:08:12 +00004403
Douglas Gregor43959a92009-08-20 07:17:43 +00004404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004405StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004406TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004407 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004408 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004409 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004410 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004411
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004412 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004413 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004414 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004415 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004416
Douglas Gregor43959a92009-08-20 07:17:43 +00004417 if (!getDerived().AlwaysRebuild() &&
4418 Cond.get() == S->getCond() &&
4419 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004420 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004421
John McCall9ae2f072010-08-23 23:25:46 +00004422 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4423 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004424 S->getRParenLoc());
4425}
Mike Stump1eb44332009-09-09 15:08:12 +00004426
Douglas Gregor43959a92009-08-20 07:17:43 +00004427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004428StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004429TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004430 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004431 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004432 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004433 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004434
Douglas Gregor43959a92009-08-20 07:17:43 +00004435 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004436 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004437 VarDecl *ConditionVar = 0;
4438 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004439 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004440 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004441 getDerived().TransformDefinition(
4442 S->getConditionVariable()->getLocation(),
4443 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004444 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004445 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004446 } else {
4447 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004448
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004449 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004450 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004451
4452 if (S->getCond()) {
4453 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004454 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4455 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004456 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004457 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004458
John McCall9ae2f072010-08-23 23:25:46 +00004459 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004460 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004461 }
Mike Stump1eb44332009-09-09 15:08:12 +00004462
John McCall9ae2f072010-08-23 23:25:46 +00004463 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4464 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004465 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004466
Douglas Gregor43959a92009-08-20 07:17:43 +00004467 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004468 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004469 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004470 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004471
John McCall9ae2f072010-08-23 23:25:46 +00004472 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4473 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004474 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004475
Douglas Gregor43959a92009-08-20 07:17:43 +00004476 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004477 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004478 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004479 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004480
Douglas Gregor43959a92009-08-20 07:17:43 +00004481 if (!getDerived().AlwaysRebuild() &&
4482 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004483 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004484 Inc.get() == S->getInc() &&
4485 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004486 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004487
Douglas Gregor43959a92009-08-20 07:17:43 +00004488 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004489 Init.get(), FullCond, ConditionVar,
4490 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004491}
4492
4493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004494StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004495TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004496 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004497 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004498 S->getLabel());
4499}
4500
4501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004502StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004503TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004504 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004505 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004506 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004507
Douglas Gregor43959a92009-08-20 07:17:43 +00004508 if (!getDerived().AlwaysRebuild() &&
4509 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004510 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004511
4512 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004513 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004514}
4515
4516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004517StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004518TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004519 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004520}
Mike Stump1eb44332009-09-09 15:08:12 +00004521
Douglas Gregor43959a92009-08-20 07:17:43 +00004522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004523StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004524TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004525 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004526}
Mike Stump1eb44332009-09-09 15:08:12 +00004527
Douglas Gregor43959a92009-08-20 07:17:43 +00004528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004529StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004530TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004531 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004532 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004533 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004534
Mike Stump1eb44332009-09-09 15:08:12 +00004535 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004536 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004537 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004538}
Mike Stump1eb44332009-09-09 15:08:12 +00004539
Douglas Gregor43959a92009-08-20 07:17:43 +00004540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004541StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004542TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004543 bool DeclChanged = false;
4544 llvm::SmallVector<Decl *, 4> Decls;
4545 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4546 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004547 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4548 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004549 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004550 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004551
Douglas Gregor43959a92009-08-20 07:17:43 +00004552 if (Transformed != *D)
4553 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004554
Douglas Gregor43959a92009-08-20 07:17:43 +00004555 Decls.push_back(Transformed);
4556 }
Mike Stump1eb44332009-09-09 15:08:12 +00004557
Douglas Gregor43959a92009-08-20 07:17:43 +00004558 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004559 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004560
4561 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004562 S->getStartLoc(), S->getEndLoc());
4563}
Mike Stump1eb44332009-09-09 15:08:12 +00004564
Douglas Gregor43959a92009-08-20 07:17:43 +00004565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004566StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004567TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004568 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004569 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004570}
4571
4572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004573StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004574TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004575
John McCallca0408f2010-08-23 06:44:23 +00004576 ASTOwningVector<Expr*> Constraints(getSema());
4577 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004578 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004579
John McCall60d7b3a2010-08-24 06:29:42 +00004580 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004581 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004582
4583 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004584
Anders Carlsson703e3942010-01-24 05:50:09 +00004585 // Go through the outputs.
4586 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004587 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004588
Anders Carlsson703e3942010-01-24 05:50:09 +00004589 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004590 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004591
Anders Carlsson703e3942010-01-24 05:50:09 +00004592 // Transform the output expr.
4593 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004594 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004595 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004596 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004597
Anders Carlsson703e3942010-01-24 05:50:09 +00004598 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004599
John McCall9ae2f072010-08-23 23:25:46 +00004600 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004601 }
Sean Huntc3021132010-05-05 15:23:54 +00004602
Anders Carlsson703e3942010-01-24 05:50:09 +00004603 // Go through the inputs.
4604 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004605 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004606
Anders Carlsson703e3942010-01-24 05:50:09 +00004607 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004608 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004609
Anders Carlsson703e3942010-01-24 05:50:09 +00004610 // Transform the input expr.
4611 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004612 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004613 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004614 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004615
Anders Carlsson703e3942010-01-24 05:50:09 +00004616 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004617
John McCall9ae2f072010-08-23 23:25:46 +00004618 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004619 }
Sean Huntc3021132010-05-05 15:23:54 +00004620
Anders Carlsson703e3942010-01-24 05:50:09 +00004621 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004622 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004623
4624 // Go through the clobbers.
4625 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004626 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004627
4628 // No need to transform the asm string literal.
4629 AsmString = SemaRef.Owned(S->getAsmString());
4630
4631 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4632 S->isSimple(),
4633 S->isVolatile(),
4634 S->getNumOutputs(),
4635 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004636 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004637 move_arg(Constraints),
4638 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004639 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004640 move_arg(Clobbers),
4641 S->getRParenLoc(),
4642 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004643}
4644
4645
4646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004647StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004648TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004649 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004650 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004651 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004652 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004653
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004654 // Transform the @catch statements (if present).
4655 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004656 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004657 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004658 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004659 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004660 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004661 if (Catch.get() != S->getCatchStmt(I))
4662 AnyCatchChanged = true;
4663 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004664 }
Sean Huntc3021132010-05-05 15:23:54 +00004665
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004666 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004667 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004668 if (S->getFinallyStmt()) {
4669 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4670 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004671 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004672 }
4673
4674 // If nothing changed, just retain this statement.
4675 if (!getDerived().AlwaysRebuild() &&
4676 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004677 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004678 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004679 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004680
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004681 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004682 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4683 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004684}
Mike Stump1eb44332009-09-09 15:08:12 +00004685
Douglas Gregor43959a92009-08-20 07:17:43 +00004686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004687StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004688TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004689 // Transform the @catch parameter, if there is one.
4690 VarDecl *Var = 0;
4691 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4692 TypeSourceInfo *TSInfo = 0;
4693 if (FromVar->getTypeSourceInfo()) {
4694 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4695 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004696 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004697 }
Sean Huntc3021132010-05-05 15:23:54 +00004698
Douglas Gregorbe270a02010-04-26 17:57:08 +00004699 QualType T;
4700 if (TSInfo)
4701 T = TSInfo->getType();
4702 else {
4703 T = getDerived().TransformType(FromVar->getType());
4704 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004705 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004706 }
Sean Huntc3021132010-05-05 15:23:54 +00004707
Douglas Gregorbe270a02010-04-26 17:57:08 +00004708 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4709 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004710 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004711 }
Sean Huntc3021132010-05-05 15:23:54 +00004712
John McCall60d7b3a2010-08-24 06:29:42 +00004713 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004714 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004715 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004716
4717 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004718 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004719 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004720}
Mike Stump1eb44332009-09-09 15:08:12 +00004721
Douglas Gregor43959a92009-08-20 07:17:43 +00004722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004723StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004724TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004725 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004726 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004727 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004728 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004729
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004730 // If nothing changed, just retain this statement.
4731 if (!getDerived().AlwaysRebuild() &&
4732 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004733 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004734
4735 // Build a new statement.
4736 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004737 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004738}
Mike Stump1eb44332009-09-09 15:08:12 +00004739
Douglas Gregor43959a92009-08-20 07:17:43 +00004740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004741StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004742TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004743 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004744 if (S->getThrowExpr()) {
4745 Operand = getDerived().TransformExpr(S->getThrowExpr());
4746 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004747 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004748 }
Sean Huntc3021132010-05-05 15:23:54 +00004749
Douglas Gregord1377b22010-04-22 21:44:01 +00004750 if (!getDerived().AlwaysRebuild() &&
4751 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004752 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004753
John McCall9ae2f072010-08-23 23:25:46 +00004754 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004755}
Mike Stump1eb44332009-09-09 15:08:12 +00004756
Douglas Gregor43959a92009-08-20 07:17:43 +00004757template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004758StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004759TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004760 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004761 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004762 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004763 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004764 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004765
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004766 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004767 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004768 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004769 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004770
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004771 // If nothing change, just retain the current statement.
4772 if (!getDerived().AlwaysRebuild() &&
4773 Object.get() == S->getSynchExpr() &&
4774 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004775 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004776
4777 // Build a new statement.
4778 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004779 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004780}
4781
4782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004783StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004784TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004785 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004786 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004787 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004788 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004789 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004790
Douglas Gregorc3203e72010-04-22 23:10:45 +00004791 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004792 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004793 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004794 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004795
Douglas Gregorc3203e72010-04-22 23:10:45 +00004796 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004797 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004798 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004799 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004800
Douglas Gregorc3203e72010-04-22 23:10:45 +00004801 // If nothing changed, just retain this statement.
4802 if (!getDerived().AlwaysRebuild() &&
4803 Element.get() == S->getElement() &&
4804 Collection.get() == S->getCollection() &&
4805 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004806 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004807
Douglas Gregorc3203e72010-04-22 23:10:45 +00004808 // Build a new statement.
4809 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4810 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004811 Element.get(),
4812 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004813 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004814 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004815}
4816
4817
4818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004819StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004820TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4821 // Transform the exception declaration, if any.
4822 VarDecl *Var = 0;
4823 if (S->getExceptionDecl()) {
4824 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004825 TypeSourceInfo *T = getDerived().TransformType(
4826 ExceptionDecl->getTypeSourceInfo());
4827 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004828 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004829
Douglas Gregor83cb9422010-09-09 17:09:21 +00004830 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004831 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004832 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004833 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004834 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004835 }
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregor43959a92009-08-20 07:17:43 +00004837 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004838 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004839 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004840 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004841
Douglas Gregor43959a92009-08-20 07:17:43 +00004842 if (!getDerived().AlwaysRebuild() &&
4843 !Var &&
4844 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004845 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004846
4847 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4848 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004849 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004850}
Mike Stump1eb44332009-09-09 15:08:12 +00004851
Douglas Gregor43959a92009-08-20 07:17:43 +00004852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004853StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004854TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4855 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004856 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004857 = getDerived().TransformCompoundStmt(S->getTryBlock());
4858 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004859 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004860
Douglas Gregor43959a92009-08-20 07:17:43 +00004861 // Transform the handlers.
4862 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004863 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004864 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004865 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004866 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4867 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004868 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004869
Douglas Gregor43959a92009-08-20 07:17:43 +00004870 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4871 Handlers.push_back(Handler.takeAs<Stmt>());
4872 }
Mike Stump1eb44332009-09-09 15:08:12 +00004873
Douglas Gregor43959a92009-08-20 07:17:43 +00004874 if (!getDerived().AlwaysRebuild() &&
4875 TryBlock.get() == S->getTryBlock() &&
4876 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004877 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004878
John McCall9ae2f072010-08-23 23:25:46 +00004879 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004880 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004881}
Mike Stump1eb44332009-09-09 15:08:12 +00004882
Douglas Gregor43959a92009-08-20 07:17:43 +00004883//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004884// Expression transformation
4885//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004887ExprResult
John McCall454feb92009-12-08 09:21:05 +00004888TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004889 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004890}
Mike Stump1eb44332009-09-09 15:08:12 +00004891
4892template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004893ExprResult
John McCall454feb92009-12-08 09:21:05 +00004894TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00004895 NestedNameSpecifier *Qualifier = 0;
4896 if (E->getQualifier()) {
4897 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004898 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00004899 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00004900 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00004901 }
John McCalldbd872f2009-12-08 09:08:17 +00004902
4903 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004904 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4905 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004906 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00004907 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004908
John McCallec8045d2010-08-17 21:27:17 +00004909 DeclarationNameInfo NameInfo = E->getNameInfo();
4910 if (NameInfo.getName()) {
4911 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4912 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00004913 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00004914 }
Abramo Bagnara25777432010-08-11 22:01:17 +00004915
4916 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00004917 Qualifier == E->getQualifier() &&
4918 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00004919 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00004920 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004921
4922 // Mark it referenced in the new context regardless.
4923 // FIXME: this is a bit instantiation-specific.
4924 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4925
John McCall3fa5cae2010-10-26 07:05:15 +00004926 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00004927 }
John McCalldbd872f2009-12-08 09:08:17 +00004928
4929 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00004930 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00004931 TemplateArgs = &TransArgs;
4932 TransArgs.setLAngleLoc(E->getLAngleLoc());
4933 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00004934 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4935 E->getNumTemplateArgs(),
4936 TransArgs))
4937 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00004938 }
4939
Douglas Gregora2813ce2009-10-23 18:54:35 +00004940 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00004941 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004942}
Mike Stump1eb44332009-09-09 15:08:12 +00004943
Douglas Gregorb98b1992009-08-11 05:31:07 +00004944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004945ExprResult
John McCall454feb92009-12-08 09:21:05 +00004946TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004947 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004948}
Mike Stump1eb44332009-09-09 15:08:12 +00004949
Douglas Gregorb98b1992009-08-11 05:31:07 +00004950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004951ExprResult
John McCall454feb92009-12-08 09:21:05 +00004952TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004953 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004954}
Mike Stump1eb44332009-09-09 15:08:12 +00004955
Douglas Gregorb98b1992009-08-11 05:31:07 +00004956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004957ExprResult
John McCall454feb92009-12-08 09:21:05 +00004958TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004959 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004960}
Mike Stump1eb44332009-09-09 15:08:12 +00004961
Douglas Gregorb98b1992009-08-11 05:31:07 +00004962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004963ExprResult
John McCall454feb92009-12-08 09:21:05 +00004964TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004965 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004966}
Mike Stump1eb44332009-09-09 15:08:12 +00004967
Douglas Gregorb98b1992009-08-11 05:31:07 +00004968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004969ExprResult
John McCall454feb92009-12-08 09:21:05 +00004970TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00004971 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004972}
4973
4974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004975ExprResult
John McCall454feb92009-12-08 09:21:05 +00004976TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004977 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004978 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregorb98b1992009-08-11 05:31:07 +00004981 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004982 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004983
John McCall9ae2f072010-08-23 23:25:46 +00004984 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004985 E->getRParen());
4986}
4987
Mike Stump1eb44332009-09-09 15:08:12 +00004988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004989ExprResult
John McCall454feb92009-12-08 09:21:05 +00004990TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00004991 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004992 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Douglas Gregorb98b1992009-08-11 05:31:07 +00004995 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004997
Douglas Gregorb98b1992009-08-11 05:31:07 +00004998 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4999 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005000 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005001}
Mike Stump1eb44332009-09-09 15:08:12 +00005002
Douglas Gregorb98b1992009-08-11 05:31:07 +00005003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005004ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005005TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5006 // Transform the type.
5007 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5008 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005009 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005010
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005011 // Transform all of the components into components similar to what the
5012 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005013 // FIXME: It would be slightly more efficient in the non-dependent case to
5014 // just map FieldDecls, rather than requiring the rebuilder to look for
5015 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005016 // template code that we don't care.
5017 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005018 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005019 typedef OffsetOfExpr::OffsetOfNode Node;
5020 llvm::SmallVector<Component, 4> Components;
5021 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5022 const Node &ON = E->getComponent(I);
5023 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005024 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005025 Comp.LocStart = ON.getRange().getBegin();
5026 Comp.LocEnd = ON.getRange().getEnd();
5027 switch (ON.getKind()) {
5028 case Node::Array: {
5029 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005030 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005031 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005032 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005033
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005034 ExprChanged = ExprChanged || Index.get() != FromIndex;
5035 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005036 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005037 break;
5038 }
Sean Huntc3021132010-05-05 15:23:54 +00005039
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005040 case Node::Field:
5041 case Node::Identifier:
5042 Comp.isBrackets = false;
5043 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005044 if (!Comp.U.IdentInfo)
5045 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005046
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005047 break;
Sean Huntc3021132010-05-05 15:23:54 +00005048
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005049 case Node::Base:
5050 // Will be recomputed during the rebuild.
5051 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005052 }
Sean Huntc3021132010-05-05 15:23:54 +00005053
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005054 Components.push_back(Comp);
5055 }
Sean Huntc3021132010-05-05 15:23:54 +00005056
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005057 // If nothing changed, retain the existing expression.
5058 if (!getDerived().AlwaysRebuild() &&
5059 Type == E->getTypeSourceInfo() &&
5060 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005061 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005062
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005063 // Build a new offsetof expression.
5064 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5065 Components.data(), Components.size(),
5066 E->getRParenLoc());
5067}
5068
5069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005070ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005071TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5072 assert(getDerived().AlreadyTransformed(E->getType()) &&
5073 "opaque value expression requires transformation");
5074 return SemaRef.Owned(E);
5075}
5076
5077template<typename Derived>
5078ExprResult
John McCall454feb92009-12-08 09:21:05 +00005079TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005081 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005082
John McCalla93c9342009-12-07 02:54:59 +00005083 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005084 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005085 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005086
John McCall5ab75172009-11-04 07:28:41 +00005087 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005088 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005089
John McCall5ab75172009-11-04 07:28:41 +00005090 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005091 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092 E->getSourceRange());
5093 }
Mike Stump1eb44332009-09-09 15:08:12 +00005094
John McCall60d7b3a2010-08-24 06:29:42 +00005095 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005096 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097 // C++0x [expr.sizeof]p1:
5098 // The operand is either an expression, which is an unevaluated operand
5099 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005100 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005101
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5103 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005104 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005105
Douglas Gregorb98b1992009-08-11 05:31:07 +00005106 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005107 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005108 }
Mike Stump1eb44332009-09-09 15:08:12 +00005109
John McCall9ae2f072010-08-23 23:25:46 +00005110 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005111 E->isSizeOf(),
5112 E->getSourceRange());
5113}
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005116ExprResult
John McCall454feb92009-12-08 09:21:05 +00005117TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005118 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005121
John McCall60d7b3a2010-08-24 06:29:42 +00005122 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005123 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005124 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005125
5126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127 if (!getDerived().AlwaysRebuild() &&
5128 LHS.get() == E->getLHS() &&
5129 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005130 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005131
John McCall9ae2f072010-08-23 23:25:46 +00005132 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005133 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005134 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005135 E->getRBracketLoc());
5136}
Mike Stump1eb44332009-09-09 15:08:12 +00005137
5138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005139ExprResult
John McCall454feb92009-12-08 09:21:05 +00005140TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005141 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005142 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145
5146 // Transform arguments.
5147 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005148 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005149 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5150 &ArgChanged))
5151 return ExprError();
5152
Douglas Gregorb98b1992009-08-11 05:31:07 +00005153 if (!getDerived().AlwaysRebuild() &&
5154 Callee.get() == E->getCallee() &&
5155 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005156 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Douglas Gregorb98b1992009-08-11 05:31:07 +00005158 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005159 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005160 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005161 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005162 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163 E->getRParenLoc());
5164}
Mike Stump1eb44332009-09-09 15:08:12 +00005165
5166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005167ExprResult
John McCall454feb92009-12-08 09:21:05 +00005168TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005169 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005170 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005171 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005172
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005173 NestedNameSpecifier *Qualifier = 0;
5174 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005175 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005176 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005177 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005178 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005179 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005180 }
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Eli Friedmanf595cc42009-12-04 06:40:45 +00005182 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005183 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5184 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005185 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
John McCall6bb80172010-03-30 21:47:33 +00005188 NamedDecl *FoundDecl = E->getFoundDecl();
5189 if (FoundDecl == E->getMemberDecl()) {
5190 FoundDecl = Member;
5191 } else {
5192 FoundDecl = cast_or_null<NamedDecl>(
5193 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5194 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005195 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005196 }
5197
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198 if (!getDerived().AlwaysRebuild() &&
5199 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005200 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005201 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005202 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005203 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005204
Anders Carlsson1f240322009-12-22 05:24:09 +00005205 // Mark it referenced in the new context regardless.
5206 // FIXME: this is a bit instantiation-specific.
5207 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005208 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005209 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005210
John McCalld5532b62009-11-23 01:53:49 +00005211 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005212 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005213 TransArgs.setLAngleLoc(E->getLAngleLoc());
5214 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005215 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5216 E->getNumTemplateArgs(),
5217 TransArgs))
5218 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005219 }
Sean Huntc3021132010-05-05 15:23:54 +00005220
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221 // FIXME: Bogus source location for the operator
5222 SourceLocation FakeOperatorLoc
5223 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5224
John McCallc2233c52010-01-15 08:34:02 +00005225 // FIXME: to do this check properly, we will need to preserve the
5226 // first-qualifier-in-scope here, just in case we had a dependent
5227 // base (and therefore couldn't do the check) and a
5228 // nested-name-qualifier (and therefore could do the lookup).
5229 NamedDecl *FirstQualifierInScope = 0;
5230
John McCall9ae2f072010-08-23 23:25:46 +00005231 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005232 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005233 Qualifier,
5234 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005235 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005236 Member,
John McCall6bb80172010-03-30 21:47:33 +00005237 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005238 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005239 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005240 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005241}
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>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
John McCall60d7b3a2010-08-24 06:29:42 +00005250 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregorb98b1992009-08-11 05:31:07 +00005254 if (!getDerived().AlwaysRebuild() &&
5255 LHS.get() == E->getLHS() &&
5256 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005257 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005260 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005261}
5262
Mike Stump1eb44332009-09-09 15:08:12 +00005263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005264ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005266 CompoundAssignOperator *E) {
5267 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005268}
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005271ExprResult
John McCall454feb92009-12-08 09:21:05 +00005272TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005273 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005275 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005276
John McCall60d7b3a2010-08-24 06:29:42 +00005277 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005278 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005280
John McCall60d7b3a2010-08-24 06:29:42 +00005281 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregorb98b1992009-08-11 05:31:07 +00005285 if (!getDerived().AlwaysRebuild() &&
5286 Cond.get() == E->getCond() &&
5287 LHS.get() == E->getLHS() &&
5288 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005289 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005290
John McCall9ae2f072010-08-23 23:25:46 +00005291 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005292 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005293 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005294 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005295 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296}
Mike Stump1eb44332009-09-09 15:08:12 +00005297
5298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005299ExprResult
John McCall454feb92009-12-08 09:21:05 +00005300TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005301 // Implicit casts are eliminated during transformation, since they
5302 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005303 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005304}
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregorb98b1992009-08-11 05:31:07 +00005306template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005307ExprResult
John McCall454feb92009-12-08 09:21:05 +00005308TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005309 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5310 if (!Type)
5311 return ExprError();
5312
John McCall60d7b3a2010-08-24 06:29:42 +00005313 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005314 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005315 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregorb98b1992009-08-11 05:31:07 +00005318 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005319 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005320 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005321 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005322
John McCall9d125032010-01-15 18:39:57 +00005323 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005324 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005325 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005326 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005327}
Mike Stump1eb44332009-09-09 15:08:12 +00005328
Douglas Gregorb98b1992009-08-11 05:31:07 +00005329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005330ExprResult
John McCall454feb92009-12-08 09:21:05 +00005331TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005332 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5333 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5334 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005335 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005336
John McCall60d7b3a2010-08-24 06:29:42 +00005337 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005338 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005340
Douglas Gregorb98b1992009-08-11 05:31:07 +00005341 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005342 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005343 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005344 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005345
John McCall1d7d8d62010-01-19 22:33:45 +00005346 // Note: the expression type doesn't necessarily match the
5347 // type-as-written, but that's okay, because it should always be
5348 // derivable from the initializer.
5349
John McCall42f56b52010-01-18 19:35:47 +00005350 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005351 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005352 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005353}
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregorb98b1992009-08-11 05:31:07 +00005355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005356ExprResult
John McCall454feb92009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005358 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005359 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregorb98b1992009-08-11 05:31:07 +00005362 if (!getDerived().AlwaysRebuild() &&
5363 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005364 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregorb98b1992009-08-11 05:31:07 +00005366 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005367 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005368 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005369 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005370 E->getAccessorLoc(),
5371 E->getAccessor());
5372}
Mike Stump1eb44332009-09-09 15:08:12 +00005373
Douglas Gregorb98b1992009-08-11 05:31:07 +00005374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005375ExprResult
John McCall454feb92009-12-08 09:21:05 +00005376TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005377 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005378
John McCallca0408f2010-08-23 06:44:23 +00005379 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005380 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5381 Inits, &InitChanged))
5382 return ExprError();
5383
Douglas Gregorb98b1992009-08-11 05:31:07 +00005384 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005385 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005386
Douglas Gregorb98b1992009-08-11 05:31:07 +00005387 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005388 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005389}
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Douglas Gregorb98b1992009-08-11 05:31:07 +00005391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005392ExprResult
John McCall454feb92009-12-08 09:21:05 +00005393TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005398 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005400
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005402 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005403 bool ExprChanged = false;
5404 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5405 DEnd = E->designators_end();
5406 D != DEnd; ++D) {
5407 if (D->isFieldDesignator()) {
5408 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5409 D->getDotLoc(),
5410 D->getFieldLoc()));
5411 continue;
5412 }
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregorb98b1992009-08-11 05:31:07 +00005414 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005415 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005416 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005417 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005418
5419 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005420 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregorb98b1992009-08-11 05:31:07 +00005422 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5423 ArrayExprs.push_back(Index.release());
5424 continue;
5425 }
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregorb98b1992009-08-11 05:31:07 +00005427 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005428 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005429 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5430 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005432
John McCall60d7b3a2010-08-24 06:29:42 +00005433 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005434 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005436
5437 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005438 End.get(),
5439 D->getLBracketLoc(),
5440 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregorb98b1992009-08-11 05:31:07 +00005442 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5443 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445 ArrayExprs.push_back(Start.release());
5446 ArrayExprs.push_back(End.release());
5447 }
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregorb98b1992009-08-11 05:31:07 +00005449 if (!getDerived().AlwaysRebuild() &&
5450 Init.get() == E->getInit() &&
5451 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005452 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005453
Douglas Gregorb98b1992009-08-11 05:31:07 +00005454 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5455 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005456 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005457}
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregorb98b1992009-08-11 05:31:07 +00005459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005460ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005461TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005462 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005463 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005464
Douglas Gregor5557b252009-10-28 00:29:27 +00005465 // FIXME: Will we ever have proper type location here? Will we actually
5466 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005467 QualType T = getDerived().TransformType(E->getType());
5468 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005470
Douglas Gregorb98b1992009-08-11 05:31:07 +00005471 if (!getDerived().AlwaysRebuild() &&
5472 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005473 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregorb98b1992009-08-11 05:31:07 +00005475 return getDerived().RebuildImplicitValueInitExpr(T);
5476}
Mike Stump1eb44332009-09-09 15:08:12 +00005477
Douglas Gregorb98b1992009-08-11 05:31:07 +00005478template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005479ExprResult
John McCall454feb92009-12-08 09:21:05 +00005480TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005481 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5482 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005484
John McCall60d7b3a2010-08-24 06:29:42 +00005485 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005486 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005488
Douglas Gregorb98b1992009-08-11 05:31:07 +00005489 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005490 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005491 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005492 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005493
John McCall9ae2f072010-08-23 23:25:46 +00005494 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005495 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005496}
5497
5498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499ExprResult
John McCall454feb92009-12-08 09:21:05 +00005500TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005502 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005503 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5504 &ArgumentChanged))
5505 return ExprError();
5506
Douglas Gregorb98b1992009-08-11 05:31:07 +00005507 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5508 move_arg(Inits),
5509 E->getRParenLoc());
5510}
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregorb98b1992009-08-11 05:31:07 +00005512/// \brief Transform an address-of-label expression.
5513///
5514/// By default, the transformation of an address-of-label expression always
5515/// rebuilds the expression, so that the label identifier can be resolved to
5516/// the corresponding label statement by semantic analysis.
5517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518ExprResult
John McCall454feb92009-12-08 09:21:05 +00005519TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005520 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5521 E->getLabel());
5522}
Mike Stump1eb44332009-09-09 15:08:12 +00005523
5524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005525ExprResult
John McCall454feb92009-12-08 09:21:05 +00005526TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005527 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5529 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregorb98b1992009-08-11 05:31:07 +00005532 if (!getDerived().AlwaysRebuild() &&
5533 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005534 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005535
5536 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005537 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005538 E->getRParenLoc());
5539}
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregorb98b1992009-08-11 05:31:07 +00005541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005542ExprResult
John McCall454feb92009-12-08 09:21:05 +00005543TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005544 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005547
John McCall60d7b3a2010-08-24 06:29:42 +00005548 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005549 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005551
John McCall60d7b3a2010-08-24 06:29:42 +00005552 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 if (!getDerived().AlwaysRebuild() &&
5557 Cond.get() == E->getCond() &&
5558 LHS.get() == E->getLHS() &&
5559 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005560 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005563 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564 E->getRParenLoc());
5565}
Mike Stump1eb44332009-09-09 15:08:12 +00005566
Douglas Gregorb98b1992009-08-11 05:31:07 +00005567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005568ExprResult
John McCall454feb92009-12-08 09:21:05 +00005569TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005570 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005571}
5572
5573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005574ExprResult
John McCall454feb92009-12-08 09:21:05 +00005575TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005576 switch (E->getOperator()) {
5577 case OO_New:
5578 case OO_Delete:
5579 case OO_Array_New:
5580 case OO_Array_Delete:
5581 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005582 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005583
Douglas Gregor668d6d92009-12-13 20:44:55 +00005584 case OO_Call: {
5585 // This is a call to an object's operator().
5586 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5587
5588 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005589 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005590 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005591 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005592
5593 // FIXME: Poor location information
5594 SourceLocation FakeLParenLoc
5595 = SemaRef.PP.getLocForEndOfToken(
5596 static_cast<Expr *>(Object.get())->getLocEnd());
5597
5598 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005599 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005600 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5601 Args))
5602 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005603
John McCall9ae2f072010-08-23 23:25:46 +00005604 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005605 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005606 E->getLocEnd());
5607 }
5608
5609#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5610 case OO_##Name:
5611#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5612#include "clang/Basic/OperatorKinds.def"
5613 case OO_Subscript:
5614 // Handled below.
5615 break;
5616
5617 case OO_Conditional:
5618 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005619 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005620
5621 case OO_None:
5622 case NUM_OVERLOADED_OPERATORS:
5623 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005624 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005625 }
5626
John McCall60d7b3a2010-08-24 06:29:42 +00005627 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005628 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005630
John McCall60d7b3a2010-08-24 06:29:42 +00005631 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005633 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005634
John McCall60d7b3a2010-08-24 06:29:42 +00005635 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005636 if (E->getNumArgs() == 2) {
5637 Second = getDerived().TransformExpr(E->getArg(1));
5638 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 }
Mike Stump1eb44332009-09-09 15:08:12 +00005641
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 if (!getDerived().AlwaysRebuild() &&
5643 Callee.get() == E->getCallee() &&
5644 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005645 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005646 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005647
Douglas Gregorb98b1992009-08-11 05:31:07 +00005648 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5649 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005650 Callee.get(),
5651 First.get(),
5652 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653}
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregorb98b1992009-08-11 05:31:07 +00005655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005656ExprResult
John McCall454feb92009-12-08 09:21:05 +00005657TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5658 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005659}
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005662ExprResult
John McCall454feb92009-12-08 09:21:05 +00005663TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005664 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5665 if (!Type)
5666 return ExprError();
5667
John McCall60d7b3a2010-08-24 06:29:42 +00005668 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005669 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005674 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005676 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005677
Douglas Gregorb98b1992009-08-11 05:31:07 +00005678 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005679 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5681 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5682 SourceLocation FakeRParenLoc
5683 = SemaRef.PP.getLocForEndOfToken(
5684 E->getSubExpr()->getSourceRange().getEnd());
5685 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005686 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005687 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005688 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005689 FakeRAngleLoc,
5690 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005691 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005692 FakeRParenLoc);
5693}
Mike Stump1eb44332009-09-09 15:08:12 +00005694
Douglas Gregorb98b1992009-08-11 05:31:07 +00005695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005696ExprResult
John McCall454feb92009-12-08 09:21:05 +00005697TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5698 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005699}
Mike Stump1eb44332009-09-09 15:08:12 +00005700
5701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005702ExprResult
John McCall454feb92009-12-08 09:21:05 +00005703TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5704 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005705}
5706
Douglas Gregorb98b1992009-08-11 05:31:07 +00005707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005708ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005710 CXXReinterpretCastExpr *E) {
5711 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712}
Mike Stump1eb44332009-09-09 15:08:12 +00005713
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005715ExprResult
John McCall454feb92009-12-08 09:21:05 +00005716TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5717 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005718}
Mike Stump1eb44332009-09-09 15:08:12 +00005719
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005721ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005723 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005724 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5725 if (!Type)
5726 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005727
John McCall60d7b3a2010-08-24 06:29:42 +00005728 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005729 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005732
Douglas Gregorb98b1992009-08-11 05:31:07 +00005733 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005734 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005735 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005736 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005737
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005738 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005739 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005740 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005741 E->getRParenLoc());
5742}
Mike Stump1eb44332009-09-09 15:08:12 +00005743
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005745ExprResult
John McCall454feb92009-12-08 09:21:05 +00005746TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005747 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005748 TypeSourceInfo *TInfo
5749 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5750 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005752
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005754 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005755 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005756
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005757 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5758 E->getLocStart(),
5759 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760 E->getLocEnd());
5761 }
Mike Stump1eb44332009-09-09 15:08:12 +00005762
Douglas Gregorb98b1992009-08-11 05:31:07 +00005763 // We don't know whether the expression is potentially evaluated until
5764 // after we perform semantic analysis, so the expression is potentially
5765 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005766 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005767 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005768
John McCall60d7b3a2010-08-24 06:29:42 +00005769 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005772
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773 if (!getDerived().AlwaysRebuild() &&
5774 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005775 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005776
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005777 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5778 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005779 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780 E->getLocEnd());
5781}
5782
5783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005784ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005785TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5786 if (E->isTypeOperand()) {
5787 TypeSourceInfo *TInfo
5788 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5789 if (!TInfo)
5790 return ExprError();
5791
5792 if (!getDerived().AlwaysRebuild() &&
5793 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005794 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005795
5796 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5797 E->getLocStart(),
5798 TInfo,
5799 E->getLocEnd());
5800 }
5801
5802 // We don't know whether the expression is potentially evaluated until
5803 // after we perform semantic analysis, so the expression is potentially
5804 // potentially evaluated.
5805 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5806
5807 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5808 if (SubExpr.isInvalid())
5809 return ExprError();
5810
5811 if (!getDerived().AlwaysRebuild() &&
5812 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005813 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005814
5815 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5816 E->getLocStart(),
5817 SubExpr.get(),
5818 E->getLocEnd());
5819}
5820
5821template<typename Derived>
5822ExprResult
John McCall454feb92009-12-08 09:21:05 +00005823TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005824 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005825}
Mike Stump1eb44332009-09-09 15:08:12 +00005826
Douglas Gregorb98b1992009-08-11 05:31:07 +00005827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005828ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005829TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005830 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005831 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005832}
Mike Stump1eb44332009-09-09 15:08:12 +00005833
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005835ExprResult
John McCall454feb92009-12-08 09:21:05 +00005836TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005837 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5838 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5839 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005840
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005841 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005842 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor828a1972010-01-07 23:12:05 +00005844 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005845}
Mike Stump1eb44332009-09-09 15:08:12 +00005846
Douglas Gregorb98b1992009-08-11 05:31:07 +00005847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005848ExprResult
John McCall454feb92009-12-08 09:21:05 +00005849TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005850 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005851 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005852 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregorb98b1992009-08-11 05:31:07 +00005854 if (!getDerived().AlwaysRebuild() &&
5855 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005856 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005857
John McCall9ae2f072010-08-23 23:25:46 +00005858 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005859}
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005862ExprResult
John McCall454feb92009-12-08 09:21:05 +00005863TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005864 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005865 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5866 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005867 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005870 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005872 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregor036aed12009-12-23 23:03:06 +00005874 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005875}
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005878ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005879TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5880 CXXScalarValueInitExpr *E) {
5881 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5882 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005883 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005884
Douglas Gregorb98b1992009-08-11 05:31:07 +00005885 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005886 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Douglas Gregorab6677e2010-09-08 00:15:04 +00005889 return getDerived().RebuildCXXScalarValueInitExpr(T,
5890 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00005891 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005892}
Mike Stump1eb44332009-09-09 15:08:12 +00005893
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005895ExprResult
John McCall454feb92009-12-08 09:21:05 +00005896TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005898 TypeSourceInfo *AllocTypeInfo
5899 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5900 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005902
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00005904 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005905 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005907
Douglas Gregorb98b1992009-08-11 05:31:07 +00005908 // Transform the placement arguments (if any).
5909 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005910 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005911 if (getDerived().TransformExprs(E->getPlacementArgs(),
5912 E->getNumPlacementArgs(), true,
5913 PlacementArgs, &ArgumentChanged))
5914 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005915
Douglas Gregor43959a92009-08-20 07:17:43 +00005916 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00005917 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005918 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5919 ConstructorArgs, &ArgumentChanged))
5920 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005921
Douglas Gregor1af74512010-02-26 00:38:10 +00005922 // Transform constructor, new operator, and delete operator.
5923 CXXConstructorDecl *Constructor = 0;
5924 if (E->getConstructor()) {
5925 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005926 getDerived().TransformDecl(E->getLocStart(),
5927 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005928 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00005929 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005930 }
5931
5932 FunctionDecl *OperatorNew = 0;
5933 if (E->getOperatorNew()) {
5934 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005935 getDerived().TransformDecl(E->getLocStart(),
5936 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005937 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00005938 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005939 }
5940
5941 FunctionDecl *OperatorDelete = 0;
5942 if (E->getOperatorDelete()) {
5943 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005944 getDerived().TransformDecl(E->getLocStart(),
5945 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00005946 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00005947 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00005948 }
Sean Huntc3021132010-05-05 15:23:54 +00005949
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005951 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00005953 Constructor == E->getConstructor() &&
5954 OperatorNew == E->getOperatorNew() &&
5955 OperatorDelete == E->getOperatorDelete() &&
5956 !ArgumentChanged) {
5957 // Mark any declarations we need as referenced.
5958 // FIXME: instantiation-specific.
5959 if (Constructor)
5960 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5961 if (OperatorNew)
5962 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5963 if (OperatorDelete)
5964 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00005965 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00005966 }
Mike Stump1eb44332009-09-09 15:08:12 +00005967
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005968 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005969 if (!ArraySize.get()) {
5970 // If no array size was specified, but the new expression was
5971 // instantiated with an array type (e.g., "new T" where T is
5972 // instantiated with "int[4]"), extract the outer bound from the
5973 // array type as our array size. We do this with constant and
5974 // dependently-sized array types.
5975 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5976 if (!ArrayT) {
5977 // Do nothing
5978 } else if (const ConstantArrayType *ConsArrayT
5979 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00005980 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00005981 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5982 ConsArrayT->getSize(),
5983 SemaRef.Context.getSizeType(),
5984 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005985 AllocType = ConsArrayT->getElementType();
5986 } else if (const DependentSizedArrayType *DepArrayT
5987 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5988 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00005989 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00005990 AllocType = DepArrayT->getElementType();
5991 }
5992 }
5993 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00005994
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5996 E->isGlobalNew(),
5997 /*FIXME:*/E->getLocStart(),
5998 move_arg(PlacementArgs),
5999 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006000 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006002 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006003 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004 /*FIXME:*/E->getLocStart(),
6005 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006006 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006007}
Mike Stump1eb44332009-09-09 15:08:12 +00006008
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006010ExprResult
John McCall454feb92009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006012 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006013 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006015
Douglas Gregor1af74512010-02-26 00:38:10 +00006016 // Transform the delete operator, if known.
6017 FunctionDecl *OperatorDelete = 0;
6018 if (E->getOperatorDelete()) {
6019 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006020 getDerived().TransformDecl(E->getLocStart(),
6021 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006022 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006023 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006024 }
Sean Huntc3021132010-05-05 15:23:54 +00006025
Douglas Gregorb98b1992009-08-11 05:31:07 +00006026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006027 Operand.get() == E->getArgument() &&
6028 OperatorDelete == E->getOperatorDelete()) {
6029 // Mark any declarations we need as referenced.
6030 // FIXME: instantiation-specific.
6031 if (OperatorDelete)
6032 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006033
6034 if (!E->getArgument()->isTypeDependent()) {
6035 QualType Destroyed = SemaRef.Context.getBaseElementType(
6036 E->getDestroyedType());
6037 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6038 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6039 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6040 SemaRef.LookupDestructor(Record));
6041 }
6042 }
6043
John McCall3fa5cae2010-10-26 07:05:15 +00006044 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006045 }
Mike Stump1eb44332009-09-09 15:08:12 +00006046
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6048 E->isGlobalDelete(),
6049 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006050 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051}
Mike Stump1eb44332009-09-09 15:08:12 +00006052
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006054ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006055TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006056 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006057 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006058 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006060
John McCallb3d87482010-08-24 05:47:05 +00006061 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006062 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006063 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006064 E->getOperatorLoc(),
6065 E->isArrow()? tok::arrow : tok::period,
6066 ObjectTypePtr,
6067 MayBePseudoDestructor);
6068 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006069 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006070
John McCallb3d87482010-08-24 05:47:05 +00006071 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006072 NestedNameSpecifier *Qualifier = E->getQualifier();
6073 if (Qualifier) {
6074 Qualifier
6075 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6076 E->getQualifierRange(),
6077 ObjectType);
6078 if (!Qualifier)
6079 return ExprError();
6080 }
Mike Stump1eb44332009-09-09 15:08:12 +00006081
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006082 PseudoDestructorTypeStorage Destroyed;
6083 if (E->getDestroyedTypeInfo()) {
6084 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006085 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6086 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006087 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006088 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006089 Destroyed = DestroyedTypeInfo;
6090 } else if (ObjectType->isDependentType()) {
6091 // We aren't likely to be able to resolve the identifier down to a type
6092 // now anyway, so just retain the identifier.
6093 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6094 E->getDestroyedTypeLoc());
6095 } else {
6096 // Look for a destructor known with the given name.
6097 CXXScopeSpec SS;
6098 if (Qualifier) {
6099 SS.setScopeRep(Qualifier);
6100 SS.setRange(E->getQualifierRange());
6101 }
Sean Huntc3021132010-05-05 15:23:54 +00006102
John McCallb3d87482010-08-24 05:47:05 +00006103 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006104 *E->getDestroyedTypeIdentifier(),
6105 E->getDestroyedTypeLoc(),
6106 /*Scope=*/0,
6107 SS, ObjectTypePtr,
6108 false);
6109 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006110 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006111
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006112 Destroyed
6113 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6114 E->getDestroyedTypeLoc());
6115 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006116
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006117 TypeSourceInfo *ScopeTypeInfo = 0;
6118 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006119 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006120 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006121 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006122 }
Sean Huntc3021132010-05-05 15:23:54 +00006123
John McCall9ae2f072010-08-23 23:25:46 +00006124 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006125 E->getOperatorLoc(),
6126 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006127 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006128 E->getQualifierRange(),
6129 ScopeTypeInfo,
6130 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006131 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006132 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006133}
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregora71d8192009-09-04 17:36:40 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCallba135432009-11-21 08:51:07 +00006137TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006138 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006139 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6140
6141 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6142 Sema::LookupOrdinaryName);
6143
6144 // Transform all the decls.
6145 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6146 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006147 NamedDecl *InstD = static_cast<NamedDecl*>(
6148 getDerived().TransformDecl(Old->getNameLoc(),
6149 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006150 if (!InstD) {
6151 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6152 // This can happen because of dependent hiding.
6153 if (isa<UsingShadowDecl>(*I))
6154 continue;
6155 else
John McCallf312b1e2010-08-26 23:41:50 +00006156 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006157 }
John McCallf7a1a742009-11-24 19:00:30 +00006158
6159 // Expand using declarations.
6160 if (isa<UsingDecl>(InstD)) {
6161 UsingDecl *UD = cast<UsingDecl>(InstD);
6162 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6163 E = UD->shadow_end(); I != E; ++I)
6164 R.addDecl(*I);
6165 continue;
6166 }
6167
6168 R.addDecl(InstD);
6169 }
6170
6171 // Resolve a kind, but don't do any further analysis. If it's
6172 // ambiguous, the callee needs to deal with it.
6173 R.resolveKind();
6174
6175 // Rebuild the nested-name qualifier, if present.
6176 CXXScopeSpec SS;
6177 NestedNameSpecifier *Qualifier = 0;
6178 if (Old->getQualifier()) {
6179 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006180 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006181 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006182 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006183
John McCallf7a1a742009-11-24 19:00:30 +00006184 SS.setScopeRep(Qualifier);
6185 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006186 }
6187
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006188 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006189 CXXRecordDecl *NamingClass
6190 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6191 Old->getNameLoc(),
6192 Old->getNamingClass()));
6193 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006194 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006195
Douglas Gregor66c45152010-04-27 16:10:10 +00006196 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006197 }
6198
6199 // If we have no template arguments, it's a normal declaration name.
6200 if (!Old->hasExplicitTemplateArgs())
6201 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6202
6203 // If we have template arguments, rebuild them, then rebuild the
6204 // templateid expression.
6205 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006206 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6207 Old->getNumTemplateArgs(),
6208 TransArgs))
6209 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006210
6211 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6212 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213}
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006216ExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006218 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6219 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006223 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006224 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006225
Mike Stump1eb44332009-09-09 15:08:12 +00006226 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 T,
6229 E->getLocEnd());
6230}
Mike Stump1eb44332009-09-09 15:08:12 +00006231
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006234TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6235 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6236 if (!LhsT)
6237 return ExprError();
6238
6239 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6240 if (!RhsT)
6241 return ExprError();
6242
6243 if (!getDerived().AlwaysRebuild() &&
6244 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6245 return SemaRef.Owned(E);
6246
6247 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6248 E->getLocStart(),
6249 LhsT, RhsT,
6250 E->getLocEnd());
6251}
6252
6253template<typename Derived>
6254ExprResult
John McCall865d4472009-11-19 22:55:06 +00006255TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006256 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006258 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006259 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006262
John McCall43fed0d2010-11-12 08:19:04 +00006263 // TODO: If this is a conversion-function-id, verify that the
6264 // destination type name (if present) resolves the same way after
6265 // instantiation as it did in the local scope.
6266
Abramo Bagnara25777432010-08-11 22:01:17 +00006267 DeclarationNameInfo NameInfo
6268 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6269 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006270 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006271
John McCallf7a1a742009-11-24 19:00:30 +00006272 if (!E->hasExplicitTemplateArgs()) {
6273 if (!getDerived().AlwaysRebuild() &&
6274 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006275 // Note: it is sufficient to compare the Name component of NameInfo:
6276 // if name has not changed, DNLoc has not changed either.
6277 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006278 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006279
John McCallf7a1a742009-11-24 19:00:30 +00006280 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6281 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006282 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006283 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006284 }
John McCalld5532b62009-11-23 01:53:49 +00006285
6286 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006287 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6288 E->getNumTemplateArgs(),
6289 TransArgs))
6290 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291
John McCallf7a1a742009-11-24 19:00:30 +00006292 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6293 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006294 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006295 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296}
6297
6298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006299ExprResult
John McCall454feb92009-12-08 09:21:05 +00006300TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006301 // CXXConstructExprs are always implicit, so when we have a
6302 // 1-argument construction we just transform that argument.
6303 if (E->getNumArgs() == 1 ||
6304 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6305 return getDerived().TransformExpr(E->getArg(0));
6306
Douglas Gregorb98b1992009-08-11 05:31:07 +00006307 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6308
6309 QualType T = getDerived().TransformType(E->getType());
6310 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006311 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312
6313 CXXConstructorDecl *Constructor
6314 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006315 getDerived().TransformDecl(E->getLocStart(),
6316 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006318 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006319
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006321 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006322 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6323 &ArgumentChanged))
6324 return ExprError();
6325
Douglas Gregorb98b1992009-08-11 05:31:07 +00006326 if (!getDerived().AlwaysRebuild() &&
6327 T == E->getType() &&
6328 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006329 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006330 // Mark the constructor as referenced.
6331 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006332 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006333 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006334 }
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006336 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6337 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006338 move_arg(Args),
6339 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006340 E->getConstructionKind(),
6341 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342}
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344/// \brief Transform a C++ temporary-binding expression.
6345///
Douglas Gregor51326552009-12-24 18:51:59 +00006346/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6347/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006349ExprResult
John McCall454feb92009-12-08 09:21:05 +00006350TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006351 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352}
Mike Stump1eb44332009-09-09 15:08:12 +00006353
John McCall4765fa02010-12-06 08:20:24 +00006354/// \brief Transform a C++ expression that contains cleanups that should
6355/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356///
John McCall4765fa02010-12-06 08:20:24 +00006357/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006358/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006360ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006361TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006362 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363}
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006366ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006368 CXXTemporaryObjectExpr *E) {
6369 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6370 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006371 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 CXXConstructorDecl *Constructor
6374 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006375 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006376 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006378 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006379
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006381 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006383 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6384 &ArgumentChanged))
6385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006386
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006388 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006390 !ArgumentChanged) {
6391 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006392 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006393 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006394 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006395
6396 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6397 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 E->getLocEnd());
6400}
Mike Stump1eb44332009-09-09 15:08:12 +00006401
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006403ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006405 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006406 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6407 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006408 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006409
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006411 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006412 Args.reserve(E->arg_size());
6413 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6414 &ArgumentChanged))
6415 return ExprError();
6416
Douglas Gregorb98b1992009-08-11 05:31:07 +00006417 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006418 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006421
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006423 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 E->getLParenLoc(),
6425 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426 E->getRParenLoc());
6427}
Mike Stump1eb44332009-09-09 15:08:12 +00006428
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006430ExprResult
John McCall865d4472009-11-19 22:55:06 +00006431TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006432 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006434 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006435 Expr *OldBase;
6436 QualType BaseType;
6437 QualType ObjectType;
6438 if (!E->isImplicitAccess()) {
6439 OldBase = E->getBase();
6440 Base = getDerived().TransformExpr(OldBase);
6441 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006442 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006443
John McCallaa81e162009-12-01 22:10:20 +00006444 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006445 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006446 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006447 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006448 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006449 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006450 ObjectTy,
6451 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006452 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006453 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006454
John McCallb3d87482010-08-24 05:47:05 +00006455 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006456 BaseType = ((Expr*) Base.get())->getType();
6457 } else {
6458 OldBase = 0;
6459 BaseType = getDerived().TransformType(E->getBaseType());
6460 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6461 }
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Douglas Gregor6cd21982009-10-20 05:58:46 +00006463 // Transform the first part of the nested-name-specifier that qualifies
6464 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006465 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006466 = getDerived().TransformFirstQualifierInScope(
6467 E->getFirstQualifierFoundInScope(),
6468 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregora38c6872009-09-03 16:14:30 +00006470 NestedNameSpecifier *Qualifier = 0;
6471 if (E->getQualifier()) {
6472 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6473 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006474 ObjectType,
6475 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006476 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006477 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006478 }
Mike Stump1eb44332009-09-09 15:08:12 +00006479
John McCall43fed0d2010-11-12 08:19:04 +00006480 // TODO: If this is a conversion-function-id, verify that the
6481 // destination type name (if present) resolves the same way after
6482 // instantiation as it did in the local scope.
6483
Abramo Bagnara25777432010-08-11 22:01:17 +00006484 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006485 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006486 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006488
John McCallaa81e162009-12-01 22:10:20 +00006489 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006490 // This is a reference to a member without an explicitly-specified
6491 // template argument list. Optimize for this common case.
6492 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006493 Base.get() == OldBase &&
6494 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006495 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006496 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006497 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006499
John McCall9ae2f072010-08-23 23:25:46 +00006500 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006501 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006502 E->isArrow(),
6503 E->getOperatorLoc(),
6504 Qualifier,
6505 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006506 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006507 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006508 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006509 }
6510
John McCalld5532b62009-11-23 01:53:49 +00006511 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006512 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6513 E->getNumTemplateArgs(),
6514 TransArgs))
6515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
John McCall9ae2f072010-08-23 23:25:46 +00006517 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006518 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 E->isArrow(),
6520 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006521 Qualifier,
6522 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006523 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006524 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006525 &TransArgs);
6526}
6527
6528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006529ExprResult
John McCall454feb92009-12-08 09:21:05 +00006530TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006531 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006532 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006533 QualType BaseType;
6534 if (!Old->isImplicitAccess()) {
6535 Base = getDerived().TransformExpr(Old->getBase());
6536 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006537 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006538 BaseType = ((Expr*) Base.get())->getType();
6539 } else {
6540 BaseType = getDerived().TransformType(Old->getBaseType());
6541 }
John McCall129e2df2009-11-30 22:42:35 +00006542
6543 NestedNameSpecifier *Qualifier = 0;
6544 if (Old->getQualifier()) {
6545 Qualifier
6546 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006547 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006548 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006549 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006550 }
6551
Abramo Bagnara25777432010-08-11 22:01:17 +00006552 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006553 Sema::LookupOrdinaryName);
6554
6555 // Transform all the decls.
6556 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6557 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006558 NamedDecl *InstD = static_cast<NamedDecl*>(
6559 getDerived().TransformDecl(Old->getMemberLoc(),
6560 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006561 if (!InstD) {
6562 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6563 // This can happen because of dependent hiding.
6564 if (isa<UsingShadowDecl>(*I))
6565 continue;
6566 else
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006568 }
John McCall129e2df2009-11-30 22:42:35 +00006569
6570 // Expand using declarations.
6571 if (isa<UsingDecl>(InstD)) {
6572 UsingDecl *UD = cast<UsingDecl>(InstD);
6573 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6574 E = UD->shadow_end(); I != E; ++I)
6575 R.addDecl(*I);
6576 continue;
6577 }
6578
6579 R.addDecl(InstD);
6580 }
6581
6582 R.resolveKind();
6583
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006584 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006585 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006586 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006587 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006588 Old->getMemberLoc(),
6589 Old->getNamingClass()));
6590 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006591 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006592
Douglas Gregor66c45152010-04-27 16:10:10 +00006593 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006594 }
Sean Huntc3021132010-05-05 15:23:54 +00006595
John McCall129e2df2009-11-30 22:42:35 +00006596 TemplateArgumentListInfo TransArgs;
6597 if (Old->hasExplicitTemplateArgs()) {
6598 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6599 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006600 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6601 Old->getNumTemplateArgs(),
6602 TransArgs))
6603 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006604 }
John McCallc2233c52010-01-15 08:34:02 +00006605
6606 // FIXME: to do this check properly, we will need to preserve the
6607 // first-qualifier-in-scope here, just in case we had a dependent
6608 // base (and therefore couldn't do the check) and a
6609 // nested-name-qualifier (and therefore could do the lookup).
6610 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006611
John McCall9ae2f072010-08-23 23:25:46 +00006612 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006613 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006614 Old->getOperatorLoc(),
6615 Old->isArrow(),
6616 Qualifier,
6617 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006618 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006619 R,
6620 (Old->hasExplicitTemplateArgs()
6621 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622}
6623
6624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006625ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006626TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6627 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6628 if (SubExpr.isInvalid())
6629 return ExprError();
6630
6631 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006632 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006633
6634 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6635}
6636
6637template<typename Derived>
6638ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006639TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6640 llvm_unreachable("pack expansion expression in unhandled context");
6641 return ExprError();
6642}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006643
6644template<typename Derived>
6645ExprResult
6646TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6647 // If E is not value-dependent, then nothing will change when we transform it.
6648 // Note: This is an instantiation-centric view.
6649 if (!E->isValueDependent())
6650 return SemaRef.Owned(E);
6651
6652 // Note: None of the implementations of TryExpandParameterPacks can ever
6653 // produce a diagnostic when given only a single unexpanded parameter pack,
6654 // so
6655 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6656 bool ShouldExpand = false;
6657 unsigned NumExpansions = 0;
6658 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6659 &Unexpanded, 1,
6660 ShouldExpand, NumExpansions))
6661 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006662
Douglas Gregoree8aff02011-01-04 17:33:58 +00006663 if (!ShouldExpand)
6664 return SemaRef.Owned(E);
6665
6666 // We now know the length of the parameter pack, so build a new expression
6667 // that stores that length.
6668 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6669 E->getPackLoc(), E->getRParenLoc(),
6670 NumExpansions);
6671}
6672
Douglas Gregorbe230c32011-01-03 17:17:50 +00006673template<typename Derived>
6674ExprResult
John McCall454feb92009-12-08 09:21:05 +00006675TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006676 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677}
6678
Mike Stump1eb44332009-09-09 15:08:12 +00006679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006680ExprResult
John McCall454feb92009-12-08 09:21:05 +00006681TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006682 TypeSourceInfo *EncodedTypeInfo
6683 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6684 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006688 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006689 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690
6691 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006692 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 E->getRParenLoc());
6694}
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006697ExprResult
John McCall454feb92009-12-08 09:21:05 +00006698TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006699 // Transform arguments.
6700 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006701 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006702 Args.reserve(E->getNumArgs());
6703 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6704 &ArgChanged))
6705 return ExprError();
6706
Douglas Gregor92e986e2010-04-22 16:44:27 +00006707 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6708 // Class message: transform the receiver type.
6709 TypeSourceInfo *ReceiverTypeInfo
6710 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6711 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006712 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006713
Douglas Gregor92e986e2010-04-22 16:44:27 +00006714 // If nothing changed, just retain the existing message send.
6715 if (!getDerived().AlwaysRebuild() &&
6716 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006717 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006718
6719 // Build a new class message send.
6720 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6721 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006722 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006723 E->getMethodDecl(),
6724 E->getLeftLoc(),
6725 move_arg(Args),
6726 E->getRightLoc());
6727 }
6728
6729 // Instance message: transform the receiver
6730 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6731 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006732 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006733 = getDerived().TransformExpr(E->getInstanceReceiver());
6734 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006735 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006736
6737 // If nothing changed, just retain the existing message send.
6738 if (!getDerived().AlwaysRebuild() &&
6739 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006740 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006741
Douglas Gregor92e986e2010-04-22 16:44:27 +00006742 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006743 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006744 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006745 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006746 E->getMethodDecl(),
6747 E->getLeftLoc(),
6748 move_arg(Args),
6749 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750}
6751
Mike Stump1eb44332009-09-09 15:08:12 +00006752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006753ExprResult
John McCall454feb92009-12-08 09:21:05 +00006754TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006755 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756}
6757
Mike Stump1eb44332009-09-09 15:08:12 +00006758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006759ExprResult
John McCall454feb92009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762}
6763
Mike Stump1eb44332009-09-09 15:08:12 +00006764template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006765ExprResult
John McCall454feb92009-12-08 09:21:05 +00006766TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006767 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006768 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006769 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006770 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006771
6772 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006773
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006774 // If nothing changed, just retain the existing expression.
6775 if (!getDerived().AlwaysRebuild() &&
6776 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006777 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006778
John McCall9ae2f072010-08-23 23:25:46 +00006779 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006780 E->getLocation(),
6781 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782}
6783
Mike Stump1eb44332009-09-09 15:08:12 +00006784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006787 // 'super' and types never change. Property never changes. Just
6788 // retain the existing expression.
6789 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006790 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006791
Douglas Gregore3303542010-04-26 20:47:02 +00006792 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006793 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006794 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006795 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006796
Douglas Gregore3303542010-04-26 20:47:02 +00006797 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006798
Douglas Gregore3303542010-04-26 20:47:02 +00006799 // If nothing changed, just retain the existing expression.
6800 if (!getDerived().AlwaysRebuild() &&
6801 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006802 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803
John McCall12f78a62010-12-02 01:19:52 +00006804 if (E->isExplicitProperty())
6805 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6806 E->getExplicitProperty(),
6807 E->getLocation());
6808
6809 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6810 E->getType(),
6811 E->getImplicitPropertyGetter(),
6812 E->getImplicitPropertySetter(),
6813 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814}
6815
Mike Stump1eb44332009-09-09 15:08:12 +00006816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006817ExprResult
John McCall454feb92009-12-08 09:21:05 +00006818TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006819 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006820 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006821 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006822 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006823
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006824 // If nothing changed, just retain the existing expression.
6825 if (!getDerived().AlwaysRebuild() &&
6826 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006827 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006828
John McCall9ae2f072010-08-23 23:25:46 +00006829 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006830 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831}
6832
Mike Stump1eb44332009-09-09 15:08:12 +00006833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006834ExprResult
John McCall454feb92009-12-08 09:21:05 +00006835TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006837 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006838 SubExprs.reserve(E->getNumSubExprs());
6839 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6840 SubExprs, &ArgumentChanged))
6841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006842
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 if (!getDerived().AlwaysRebuild() &&
6844 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006845 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006846
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6848 move_arg(SubExprs),
6849 E->getRParenLoc());
6850}
6851
Mike Stump1eb44332009-09-09 15:08:12 +00006852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006853ExprResult
John McCall454feb92009-12-08 09:21:05 +00006854TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006855 SourceLocation CaretLoc(E->getExprLoc());
6856
6857 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6858 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6859 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6860 llvm::SmallVector<ParmVarDecl*, 4> Params;
6861 llvm::SmallVector<QualType, 4> ParamTypes;
6862
6863 // Parameter substitution.
6864 const BlockDecl *BD = E->getBlockDecl();
6865 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6866 EN = BD->param_end(); P != EN; ++P) {
6867 ParmVarDecl *OldParm = (*P);
6868 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6869 QualType NewType = NewParm->getType();
6870 Params.push_back(NewParm);
6871 ParamTypes.push_back(NewParm->getType());
6872 }
6873
6874 const FunctionType *BExprFunctionType = E->getFunctionType();
6875 QualType BExprResultType = BExprFunctionType->getResultType();
6876 if (!BExprResultType.isNull()) {
6877 if (!BExprResultType->isDependentType())
6878 CurBlock->ReturnType = BExprResultType;
6879 else if (BExprResultType != SemaRef.Context.DependentTy)
6880 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6881 }
John McCall711c52b2011-01-05 12:14:39 +00006882
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006883 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6884 CurBlock->ReturnType,
6885 ParamTypes.data(),
6886 ParamTypes.size(),
6887 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00006888 0,
6889 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006890 CurBlock->FunctionType = FunctionType;
John McCall711c52b2011-01-05 12:14:39 +00006891
6892 // Set the parameters on the block decl.
6893 if (!Params.empty())
6894 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6895
6896 // Transform the body
6897 StmtResult Body = getDerived().TransformStmt(E->getBody());
6898 if (Body.isInvalid())
6899 return ExprError();
6900
John McCall9ae2f072010-08-23 23:25:46 +00006901 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902}
6903
Mike Stump1eb44332009-09-09 15:08:12 +00006904template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006905ExprResult
John McCall454feb92009-12-08 09:21:05 +00006906TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006907 NestedNameSpecifier *Qualifier = 0;
6908
6909 ValueDecl *ND
6910 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6911 E->getDecl()));
6912 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006913 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00006914
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006915 if (!getDerived().AlwaysRebuild() &&
6916 ND == E->getDecl()) {
6917 // Mark it referenced in the new context regardless.
6918 // FIXME: this is a bit instantiation-specific.
6919 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6920
John McCall3fa5cae2010-10-26 07:05:15 +00006921 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006922 }
6923
Abramo Bagnara25777432010-08-11 22:01:17 +00006924 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006925 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006926 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927}
Mike Stump1eb44332009-09-09 15:08:12 +00006928
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00006930// Type reconstruction
6931//===----------------------------------------------------------------------===//
6932
Mike Stump1eb44332009-09-09 15:08:12 +00006933template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006934QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6935 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006936 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006937 getDerived().getBaseEntity());
6938}
6939
Mike Stump1eb44332009-09-09 15:08:12 +00006940template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00006941QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6942 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00006943 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006944 getDerived().getBaseEntity());
6945}
6946
Mike Stump1eb44332009-09-09 15:08:12 +00006947template<typename Derived>
6948QualType
John McCall85737a72009-10-30 00:06:24 +00006949TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6950 bool WrittenAsLValue,
6951 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006952 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00006953 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006954}
6955
6956template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006957QualType
John McCall85737a72009-10-30 00:06:24 +00006958TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6959 QualType ClassType,
6960 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00006961 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00006962 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006963}
6964
6965template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006966QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00006967TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6968 ArrayType::ArraySizeModifier SizeMod,
6969 const llvm::APInt *Size,
6970 Expr *SizeExpr,
6971 unsigned IndexTypeQuals,
6972 SourceRange BracketsRange) {
6973 if (SizeExpr || !Size)
6974 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6975 IndexTypeQuals, BracketsRange,
6976 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00006977
6978 QualType Types[] = {
6979 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6980 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6981 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00006982 };
6983 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6984 QualType SizeType;
6985 for (unsigned I = 0; I != NumTypes; ++I)
6986 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6987 SizeType = Types[I];
6988 break;
6989 }
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006991 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6992 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006993 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00006994 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00006995 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00006996}
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Douglas Gregor577f75a2009-08-04 16:50:30 +00006998template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00006999QualType
7000TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007001 ArrayType::ArraySizeModifier SizeMod,
7002 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007003 unsigned IndexTypeQuals,
7004 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007005 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007006 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007007}
7008
7009template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007010QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007011TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007012 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007013 unsigned IndexTypeQuals,
7014 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007015 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007016 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007017}
Mike Stump1eb44332009-09-09 15:08:12 +00007018
Douglas Gregor577f75a2009-08-04 16:50:30 +00007019template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007020QualType
7021TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007022 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007023 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007024 unsigned IndexTypeQuals,
7025 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007026 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007027 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007028 IndexTypeQuals, BracketsRange);
7029}
7030
7031template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007032QualType
7033TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007034 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007035 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007036 unsigned IndexTypeQuals,
7037 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007038 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007039 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007040 IndexTypeQuals, BracketsRange);
7041}
7042
7043template<typename Derived>
7044QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007045 unsigned NumElements,
7046 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007047 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007048 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007049}
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregor577f75a2009-08-04 16:50:30 +00007051template<typename Derived>
7052QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7053 unsigned NumElements,
7054 SourceLocation AttributeLoc) {
7055 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7056 NumElements, true);
7057 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007058 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7059 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007060 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007061}
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregor577f75a2009-08-04 16:50:30 +00007063template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007064QualType
7065TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007066 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007067 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007068 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007069}
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Douglas Gregor577f75a2009-08-04 16:50:30 +00007071template<typename Derived>
7072QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007073 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007074 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007075 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007076 unsigned Quals,
7077 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007078 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007079 Quals,
7080 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007081 getDerived().getBaseEntity(),
7082 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007083}
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregor577f75a2009-08-04 16:50:30 +00007085template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007086QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7087 return SemaRef.Context.getFunctionNoProtoType(T);
7088}
7089
7090template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007091QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7092 assert(D && "no decl found");
7093 if (D->isInvalidDecl()) return QualType();
7094
Douglas Gregor92e986e2010-04-22 16:44:27 +00007095 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007096 TypeDecl *Ty;
7097 if (isa<UsingDecl>(D)) {
7098 UsingDecl *Using = cast<UsingDecl>(D);
7099 assert(Using->isTypeName() &&
7100 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7101
7102 // A valid resolved using typename decl points to exactly one type decl.
7103 assert(++Using->shadow_begin() == Using->shadow_end());
7104 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007105
John McCalled976492009-12-04 22:46:56 +00007106 } else {
7107 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7108 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7109 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7110 }
7111
7112 return SemaRef.Context.getTypeDeclType(Ty);
7113}
7114
7115template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007116QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7117 SourceLocation Loc) {
7118 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007119}
7120
7121template<typename Derived>
7122QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7123 return SemaRef.Context.getTypeOfType(Underlying);
7124}
7125
7126template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007127QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7128 SourceLocation Loc) {
7129 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007130}
7131
7132template<typename Derived>
7133QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007134 TemplateName Template,
7135 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007136 const TemplateArgumentListInfo &TemplateArgs) {
7137 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
Douglas Gregordcee1a12009-08-06 05:28:30 +00007140template<typename Derived>
7141NestedNameSpecifier *
7142TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7143 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007144 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007145 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007146 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007147 CXXScopeSpec SS;
7148 // FIXME: The source location information is all wrong.
7149 SS.setRange(Range);
7150 SS.setScopeRep(Prefix);
7151 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007152 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007153 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007154 ObjectType,
7155 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007156 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007157}
7158
7159template<typename Derived>
7160NestedNameSpecifier *
7161TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7162 SourceRange Range,
7163 NamespaceDecl *NS) {
7164 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7165}
7166
7167template<typename Derived>
7168NestedNameSpecifier *
7169TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7170 SourceRange Range,
7171 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007172 QualType T) {
7173 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007174 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007175 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007176 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7177 T.getTypePtr());
7178 }
Mike Stump1eb44332009-09-09 15:08:12 +00007179
Douglas Gregordcee1a12009-08-06 05:28:30 +00007180 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7181 return 0;
7182}
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregord1067e52009-08-06 06:41:21 +00007184template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007185TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007186TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7187 bool TemplateKW,
7188 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007189 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007190 Template);
7191}
7192
7193template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007194TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007195TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007196 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007197 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007198 QualType ObjectType,
7199 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007200 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007201 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007202 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007203 UnqualifiedId Name;
7204 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007205 Sema::TemplateTy Template;
7206 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7207 /*FIXME:*/getDerived().getBaseLocation(),
7208 SS,
7209 Name,
John McCallb3d87482010-08-24 05:47:05 +00007210 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007211 /*EnteringContext=*/false,
7212 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007213 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007214}
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007217TemplateName
7218TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7219 OverloadedOperatorKind Operator,
7220 QualType ObjectType) {
7221 CXXScopeSpec SS;
7222 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7223 SS.setScopeRep(Qualifier);
7224 UnqualifiedId Name;
7225 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7226 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7227 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007228 Sema::TemplateTy Template;
7229 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007230 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007231 SS,
7232 Name,
John McCallb3d87482010-08-24 05:47:05 +00007233 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007234 /*EnteringContext=*/false,
7235 Template);
7236 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007237}
Sean Huntc3021132010-05-05 15:23:54 +00007238
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007240ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007241TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7242 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007243 Expr *OrigCallee,
7244 Expr *First,
7245 Expr *Second) {
7246 Expr *Callee = OrigCallee->IgnoreParenCasts();
7247 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007248
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007250 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007251 if (!First->getType()->isOverloadableType() &&
7252 !Second->getType()->isOverloadableType())
7253 return getSema().CreateBuiltinArraySubscriptExpr(First,
7254 Callee->getLocStart(),
7255 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007256 } else if (Op == OO_Arrow) {
7257 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007258 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7259 } else if (Second == 0 || isPostIncDec) {
7260 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261 // The argument is not of overloadable type, so try to create a
7262 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007263 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007265
John McCall9ae2f072010-08-23 23:25:46 +00007266 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 }
7268 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007269 if (!First->getType()->isOverloadableType() &&
7270 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007271 // Neither of the arguments is an overloadable type, so try to
7272 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007273 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007274 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007275 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007278
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279 return move(Result);
7280 }
7281 }
Mike Stump1eb44332009-09-09 15:08:12 +00007282
7283 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007284 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007285 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007286
John McCall9ae2f072010-08-23 23:25:46 +00007287 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007288 assert(ULE->requiresADL());
7289
7290 // FIXME: Do we have to check
7291 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007292 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007293 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007294 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007295 }
Mike Stump1eb44332009-09-09 15:08:12 +00007296
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007298 Expr *Args[2] = { First, Second };
7299 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301 // Create the overloaded operator invocation for unary operators.
7302 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007303 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007305 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306 }
Mike Stump1eb44332009-09-09 15:08:12 +00007307
Sebastian Redlf322ed62009-10-29 20:17:01 +00007308 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007309 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007310 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007311 First,
7312 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007313
Douglas Gregorb98b1992009-08-11 05:31:07 +00007314 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007315 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007316 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7318 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007319 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007320
Mike Stump1eb44332009-09-09 15:08:12 +00007321 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322}
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007325ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007326TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007327 SourceLocation OperatorLoc,
7328 bool isArrow,
7329 NestedNameSpecifier *Qualifier,
7330 SourceRange QualifierRange,
7331 TypeSourceInfo *ScopeType,
7332 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007333 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007334 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007335 CXXScopeSpec SS;
7336 if (Qualifier) {
7337 SS.setRange(QualifierRange);
7338 SS.setScopeRep(Qualifier);
7339 }
7340
John McCall9ae2f072010-08-23 23:25:46 +00007341 QualType BaseType = Base->getType();
7342 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007343 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007344 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007345 !BaseType->getAs<PointerType>()->getPointeeType()
7346 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007347 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007348 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007349 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007350 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007351 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007352 /*FIXME?*/true);
7353 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007354
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007355 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007356 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7357 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7358 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7359 NameInfo.setNamedTypeInfo(DestroyedType);
7360
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007361 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007362
John McCall9ae2f072010-08-23 23:25:46 +00007363 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007364 OperatorLoc, isArrow,
7365 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007366 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007367 /*TemplateArgs*/ 0);
7368}
7369
Douglas Gregor577f75a2009-08-04 16:50:30 +00007370} // end namespace clang
7371
7372#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H