blob: 12eba2979995a66467c560562d100de4201f59f7 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +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.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
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//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCall781472f2010-08-25 08:40:02 +000039using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor577f75a2009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump1eb44332009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump1eb44332009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregor577f75a2009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000113
Mike Stump1eb44332009-09-09 15:08:12 +0000114public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Douglas Gregor577f75a2009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 }
125
John McCall60d7b3a2010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000128
Douglas Gregor577f75a2009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000132
Douglas Gregor577f75a2009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Douglas Gregor577f75a2009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregorb98b1992009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000177 }
Mike Stump1eb44332009-09-09 15:08:12 +0000178
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump1eb44332009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregor6eef5192009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Sean Huntc3021132010-05-05 15:23:54 +0000204
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregord3731192011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregor12c9c002011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregor577f75a2009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCalla2becad2009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
John McCalla2becad2009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 ///
John McCalla2becad2009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall43fed0d2010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000304 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Douglas Gregoraa165f82011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Douglas Gregor6cd21982009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Sean Huntc3021132010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000377 }
Sean Huntc3021132010-05-05 15:23:54 +0000378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregor81499bb2009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregorfcc12532010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCalla93c9342009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000534
John McCall43fed0d2010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000536
John McCall60d7b3a2010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Douglas Gregor43959a92009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
John McCall85737a72009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 ///
John McCall85737a72009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 ///
John McCall85737a72009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000671
John McCalla2becad2009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCalled976492009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCall7da24312009-09-05 00:15:47 +0000693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Sean Huntca63c202011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump1eb44332009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Richard Smith34b41d92011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregor577f75a2009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000808
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCall56138762010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregor40336422010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Sean Huntc3021132010-05-05 15:23:54 +0000840
Douglas Gregor40336422010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Sean Huntc3021132010-05-05 15:23:54 +0000844
Douglas Gregor40336422010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000849
Douglas Gregor40336422010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000872 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Richard Trieubbf34c02011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000894 }
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000906 }
907
Douglas Gregord1067e52009-08-06 06:41:21 +0000908 /// \brief Build a new template name given a nested name specifier, a flag
909 /// indicating whether the "template" keyword was provided, and the template
910 /// that the template name refers to.
911 ///
912 /// By default, builds the new template name directly. Subclasses may override
913 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000915 bool TemplateKW,
916 TemplateDecl *Template);
917
Douglas Gregord1067e52009-08-06 06:41:21 +0000918 /// \brief Build a new template name given a nested name specifier and the
919 /// name that is referred to as a template.
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000925 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926 const IdentifierInfo &Name,
927 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000928 QualType ObjectType,
929 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000930
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000931 /// \brief Build a new template name given a nested name specifier and the
932 /// overloaded operator name that is referred to as a template.
933 ///
934 /// By default, performs semantic analysis to determine whether the name can
935 /// be resolved to a specific template, then builds the appropriate kind of
936 /// template name. Subclasses may override this routine to provide different
937 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000938 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000939 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000940 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000941 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000942
943 /// \brief Build a new template name given a template template parameter pack
944 /// and the
945 ///
946 /// By default, performs semantic analysis to determine whether the name can
947 /// be resolved to a specific template, then builds the appropriate kind of
948 /// template name. Subclasses may override this routine to provide different
949 /// behavior.
950 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
951 const TemplateArgument &ArgPack) {
952 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
953 }
954
Douglas Gregor43959a92009-08-20 07:17:43 +0000955 /// \brief Build a new compound statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000959 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000960 MultiStmtArg Statements,
961 SourceLocation RBraceLoc,
962 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000963 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000964 IsStmtExpr);
965 }
966
967 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000972 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000974 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000975 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000976 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000977 ColonLoc);
978 }
Mike Stump1eb44332009-09-09 15:08:12 +0000979
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 /// \brief Attach the body to a new case statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000984 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000985 getSema().ActOnCaseStmtBody(S, Body);
986 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 /// \brief Build a new default statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000993 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000994 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000995 Stmt *SubStmt) {
996 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000997 /*CurScope=*/0);
998 }
Mike Stump1eb44332009-09-09 15:08:12 +0000999
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 /// \brief Build a new label statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001004 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1005 SourceLocation ColonLoc, Stmt *SubStmt) {
1006 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 }
Mike Stump1eb44332009-09-09 15:08:12 +00001008
Douglas Gregor43959a92009-08-20 07:17:43 +00001009 /// \brief Build a new "if" statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001013 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001014 VarDecl *CondVar, Stmt *Then,
1015 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001016 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 }
Mike Stump1eb44332009-09-09 15:08:12 +00001018
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 /// \brief Start building a new switch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001023 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001024 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001025 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001026 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 }
Mike Stump1eb44332009-09-09 15:08:12 +00001028
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 /// \brief Attach the body to the switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001034 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001035 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new while statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001042 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1043 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001044 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 /// \brief Build a new do-while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001051 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001052 SourceLocation WhileLoc, SourceLocation LParenLoc,
1053 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001054 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1055 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 }
1057
1058 /// \brief Build a new for statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001062 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063 Stmt *Init, Sema::FullExprArg Cond,
1064 VarDecl *CondVar, Sema::FullExprArg Inc,
1065 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001066 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001067 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001068 }
Mike Stump1eb44332009-09-09 15:08:12 +00001069
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 /// \brief Build a new goto statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001074 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001076 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 }
1078
1079 /// \brief Build a new indirect goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001083 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001084 SourceLocation StarLoc,
1085 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001086 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 /// \brief Build a new return statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001093 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001094 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 }
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 /// \brief Build a new declaration statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001101 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001102 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001104 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 }
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Anders Carlsson703e3942010-01-24 05:50:09 +00001108 /// \brief Build a new inline asm statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001112 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001113 bool IsSimple,
1114 bool IsVolatile,
1115 unsigned NumOutputs,
1116 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001117 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001118 MultiExprArg Constraints,
1119 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001120 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001121 MultiExprArg Clobbers,
1122 SourceLocation RParenLoc,
1123 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001124 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001125 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001126 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001127 RParenLoc, MSAsm);
1128 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001129
1130 /// \brief Build a new Objective-C @try statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001134 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001135 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001136 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001137 Stmt *Finally) {
1138 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1139 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001140 }
1141
Douglas Gregorbe270a02010-04-26 17:57:08 +00001142 /// \brief Rebuild an Objective-C exception declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new declaration.
1145 /// Subclasses may override this routine to provide different behavior.
1146 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001148 return getSema().BuildObjCExceptionDecl(TInfo, T,
1149 ExceptionDecl->getInnerLocStart(),
1150 ExceptionDecl->getLocation(),
1151 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001152 }
Sean Huntc3021132010-05-05 15:23:54 +00001153
Douglas Gregorbe270a02010-04-26 17:57:08 +00001154 /// \brief Build a new Objective-C @catch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001159 SourceLocation RParenLoc,
1160 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001161 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001162 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001163 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001164 }
Sean Huntc3021132010-05-05 15:23:54 +00001165
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001166 /// \brief Build a new Objective-C @finally statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001170 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001171 Stmt *Body) {
1172 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001173 }
Sean Huntc3021132010-05-05 15:23:54 +00001174
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001175 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001180 Expr *Operand) {
1181 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001182 }
Sean Huntc3021132010-05-05 15:23:54 +00001183
John McCall07524032011-07-27 21:50:02 +00001184 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
1188 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1189 Expr *object) {
1190 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1191 }
1192
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001193 /// \brief Build a new Objective-C @synchronized statement.
1194 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001198 Expr *Object, Stmt *Body) {
1199 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001200 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001201
John McCallf85e1932011-06-15 23:02:42 +00001202 /// \brief Build a new Objective-C @autoreleasepool statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
1206 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1207 Stmt *Body) {
1208 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1209 }
John McCall990567c2011-07-27 01:07:15 +00001210
1211 /// \brief Build the collection operand to a new Objective-C fast
1212 /// enumeration statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
1216 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1217 Expr *collection) {
1218 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1219 }
John McCallf85e1932011-06-15 23:02:42 +00001220
Douglas Gregorc3203e72010-04-22 23:10:45 +00001221 /// \brief Build a new Objective-C fast enumeration statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001226 SourceLocation LParenLoc,
1227 Stmt *Element,
1228 Expr *Collection,
1229 SourceLocation RParenLoc,
1230 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001231 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Element,
1233 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001234 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001236 }
Sean Huntc3021132010-05-05 15:23:54 +00001237
Douglas Gregor43959a92009-08-20 07:17:43 +00001238 /// \brief Build a new C++ exception declaration.
1239 ///
1240 /// By default, performs semantic analysis to build the new decaration.
1241 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001242 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001243 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001244 SourceLocation StartLoc,
1245 SourceLocation IdLoc,
1246 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001247 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1248 StartLoc, IdLoc, Id);
1249 if (Var)
1250 getSema().CurContext->addDecl(Var);
1251 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001252 }
1253
1254 /// \brief Build a new C++ catch statement.
1255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001258 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001259 VarDecl *ExceptionDecl,
1260 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001261 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1262 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001263 }
Mike Stump1eb44332009-09-09 15:08:12 +00001264
Douglas Gregor43959a92009-08-20 07:17:43 +00001265 /// \brief Build a new C++ try statement.
1266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001269 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001270 Stmt *TryBlock,
1271 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001272 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001273 }
Mike Stump1eb44332009-09-09 15:08:12 +00001274
Richard Smithad762fc2011-04-14 22:09:26 +00001275 /// \brief Build a new C++0x range-based for statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
1279 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1280 SourceLocation ColonLoc,
1281 Stmt *Range, Stmt *BeginEnd,
1282 Expr *Cond, Expr *Inc,
1283 Stmt *LoopVar,
1284 SourceLocation RParenLoc) {
1285 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1286 Cond, Inc, LoopVar, RParenLoc);
1287 }
1288
1289 /// \brief Attach body to a C++0x range-based for statement.
1290 ///
1291 /// By default, performs semantic analysis to finish the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
1293 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1294 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1295 }
1296
John Wiegley28bbe4b2011-04-28 01:08:34 +00001297 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1298 SourceLocation TryLoc,
1299 Stmt *TryBlock,
1300 Stmt *Handler) {
1301 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1302 }
1303
1304 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1305 Expr *FilterExpr,
1306 Stmt *Block) {
1307 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1308 }
1309
1310 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1311 Stmt *Block) {
1312 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1313 }
1314
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 /// \brief Build a new expression that references a declaration.
1316 ///
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001319 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001320 LookupResult &R,
1321 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001322 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1323 }
1324
1325
1326 /// \brief Build a new expression that references a declaration.
1327 ///
1328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001330 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001331 ValueDecl *VD,
1332 const DeclarationNameInfo &NameInfo,
1333 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001334 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001335 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001336
1337 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001338
1339 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001343 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001346 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001348 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 }
1350
Douglas Gregora71d8192009-09-04 17:36:40 +00001351 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001352 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001355 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001356 SourceLocation OperatorLoc,
1357 bool isArrow,
1358 CXXScopeSpec &SS,
1359 TypeSourceInfo *ScopeType,
1360 SourceLocation CCLoc,
1361 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001362 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001363
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001365 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001368 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001369 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001370 Expr *SubExpr) {
1371 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 }
Mike Stump1eb44332009-09-09 15:08:12 +00001373
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001374 /// \brief Build a new builtin offsetof expression.
1375 ///
1376 /// By default, performs semantic analysis to build the new expression.
1377 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001378 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001379 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001380 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001381 unsigned NumComponents,
1382 SourceLocation RParenLoc) {
1383 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1384 NumComponents, RParenLoc);
1385 }
Sean Huntc3021132010-05-05 15:23:54 +00001386
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001387 /// \brief Build a new sizeof, alignof or vec_step expression with a
1388 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001389 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001392 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1393 SourceLocation OpLoc,
1394 UnaryExprOrTypeTrait ExprKind,
1395 SourceRange R) {
1396 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 }
1398
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001399 /// \brief Build a new sizeof, alignof or vec step expression with an
1400 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001401 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001404 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1405 UnaryExprOrTypeTrait ExprKind,
1406 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001407 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001408 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001411
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 return move(Result);
1413 }
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001416 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001419 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001421 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001423 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1424 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 RBracketLoc);
1426 }
1427
1428 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001429 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001432 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001434 SourceLocation RParenLoc,
1435 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001436 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001437 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001441 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001444 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001445 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001446 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001447 const DeclarationNameInfo &MemberNameInfo,
1448 ValueDecl *Member,
1449 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001450 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001451 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001452 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001453 // We have a reference to an unnamed field. This is always the
1454 // base of an anonymous struct/union member access, i.e. the
1455 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001456 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001457 assert(Member->getType()->isRecordType() &&
1458 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001459
John Wiegley429bb272011-04-08 18:41:53 +00001460 ExprResult BaseResult =
1461 getSema().PerformObjectMemberConversion(Base,
1462 QualifierLoc.getNestedNameSpecifier(),
1463 FoundDecl, Member);
1464 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001465 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001466 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001467 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001468 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001469 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001470 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001471 cast<FieldDecl>(Member)->getType(),
1472 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001473 return getSema().Owned(ME);
1474 }
Mike Stump1eb44332009-09-09 15:08:12 +00001475
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001476 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001477 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001478
John Wiegley429bb272011-04-08 18:41:53 +00001479 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1480 if (BaseResult.isInvalid())
1481 return ExprError();
1482 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001483 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001484
John McCall6bb80172010-03-30 21:47:33 +00001485 // FIXME: this involves duplicating earlier analysis in a lot of
1486 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001487 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001488 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001489 R.resolveKind();
1490
John McCall9ae2f072010-08-23 23:25:46 +00001491 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001492 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001493 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 }
Mike Stump1eb44332009-09-09 15:08:12 +00001495
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001497 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001501 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001502 Expr *LHS, Expr *RHS) {
1503 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 }
1505
1506 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001507 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001510 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001511 SourceLocation QuestionLoc,
1512 Expr *LHS,
1513 SourceLocation ColonLoc,
1514 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001515 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1516 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 }
1518
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001520 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001523 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001524 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001526 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001527 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001528 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 }
Mike Stump1eb44332009-09-09 15:08:12 +00001530
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001532 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001535 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001536 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001538 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001539 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001540 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 }
Mike Stump1eb44332009-09-09 15:08:12 +00001542
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001544 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001547 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 SourceLocation OpLoc,
1549 SourceLocation AccessorLoc,
1550 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001551
John McCall129e2df2009-11-30 22:42:35 +00001552 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001553 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001554 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001555 OpLoc, /*IsArrow*/ false,
1556 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001557 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001558 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 }
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001562 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001565 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001566 MultiExprArg Inits,
1567 SourceLocation RBraceLoc,
1568 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001570 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1571 if (Result.isInvalid() || ResultTy->isDependentType())
1572 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001573
Douglas Gregore48319a2009-11-09 17:16:50 +00001574 // Patch in the result type we were given, which may have been computed
1575 // when the initial InitListExpr was built.
1576 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1577 ILE->setType(ResultTy);
1578 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 }
Mike Stump1eb44332009-09-09 15:08:12 +00001580
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001582 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 MultiExprArg ArrayExprs,
1587 SourceLocation EqualOrColonLoc,
1588 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001589 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001590 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001594 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001595
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 ArrayExprs.release();
1597 return move(Result);
1598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001601 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// By default, builds the implicit value initialization without performing
1603 /// any semantic analysis. Subclasses may override this routine to provide
1604 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001605 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001614 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001615 SourceLocation RParenLoc) {
1616 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001617 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001618 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 }
1620
1621 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001622 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001625 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 MultiExprArg SubExprs,
1627 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001628 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001629 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001633 ///
1634 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 /// rather than attempting to map the label statement itself.
1636 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001637 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001638 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001639 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 }
Mike Stump1eb44332009-09-09 15:08:12 +00001641
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001643 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001646 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001647 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001649 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 }
Mike Stump1eb44332009-09-09 15:08:12 +00001651
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 /// \brief Build a new __builtin_choose_expr expression.
1653 ///
1654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001656 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001657 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 SourceLocation RParenLoc) {
1659 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001660 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 RParenLoc);
1662 }
Mike Stump1eb44332009-09-09 15:08:12 +00001663
Peter Collingbournef111d932011-04-15 00:35:48 +00001664 /// \brief Build a new generic selection expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
1668 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1669 SourceLocation DefaultLoc,
1670 SourceLocation RParenLoc,
1671 Expr *ControllingExpr,
1672 TypeSourceInfo **Types,
1673 Expr **Exprs,
1674 unsigned NumAssocs) {
1675 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1676 ControllingExpr, Types, Exprs,
1677 NumAssocs);
1678 }
1679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new overloaded operator call expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// The semantic analysis provides the behavior of template instantiation,
1684 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001685 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// argument-dependent lookup, etc. Subclasses may override this routine to
1687 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 Expr *Callee,
1691 Expr *First,
1692 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001693
1694 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// reinterpret_cast.
1696 ///
1697 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001698 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001700 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 Stmt::StmtClass Class,
1702 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001703 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 SourceLocation RAngleLoc,
1705 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001706 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 SourceLocation RParenLoc) {
1708 switch (Class) {
1709 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001710 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001711 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713
1714 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001715 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001716 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001718
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001720 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001721 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001722 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 default:
1731 assert(false && "Invalid C++ named cast");
1732 break;
1733 }
Mike Stump1eb44332009-09-09 15:08:12 +00001734
John McCallf312b1e2010-08-26 23:41:50 +00001735 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 }
Mike Stump1eb44332009-09-09 15:08:12 +00001737
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 /// \brief Build a new C++ static_cast expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001742 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001744 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 SourceLocation RAngleLoc,
1746 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001747 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001749 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001750 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001751 SourceRange(LAngleLoc, RAngleLoc),
1752 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 }
1754
1755 /// \brief Build a new C++ dynamic_cast expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001759 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001761 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 SourceLocation RAngleLoc,
1763 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001766 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001767 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001768 SourceRange(LAngleLoc, RAngleLoc),
1769 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 }
1771
1772 /// \brief Build a new C++ reinterpret_cast expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001778 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 SourceLocation RAngleLoc,
1780 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001781 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001783 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001784 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001785 SourceRange(LAngleLoc, RAngleLoc),
1786 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ const_cast expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001795 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 SourceLocation RAngleLoc,
1797 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001800 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001801 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001802 SourceRange(LAngleLoc, RAngleLoc),
1803 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 }
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 /// \brief Build a new C++ functional-style cast expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001810 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1811 SourceLocation LParenLoc,
1812 Expr *Sub,
1813 SourceLocation RParenLoc) {
1814 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001815 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 RParenLoc);
1817 }
Mike Stump1eb44332009-09-09 15:08:12 +00001818
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 /// \brief Build a new C++ typeid(type) expression.
1820 ///
1821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001823 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001824 SourceLocation TypeidLoc,
1825 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001827 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001828 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Francois Pichet01b7c302010-09-08 12:20:18 +00001831
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 /// \brief Build a new C++ typeid(expr) expression.
1833 ///
1834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001837 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001838 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001840 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001841 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001842 }
1843
Francois Pichet01b7c302010-09-08 12:20:18 +00001844 /// \brief Build a new C++ __uuidof(type) expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
1848 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1849 SourceLocation TypeidLoc,
1850 TypeSourceInfo *Operand,
1851 SourceLocation RParenLoc) {
1852 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1853 RParenLoc);
1854 }
1855
1856 /// \brief Build a new C++ __uuidof(expr) expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
1860 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1861 SourceLocation TypeidLoc,
1862 Expr *Operand,
1863 SourceLocation RParenLoc) {
1864 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1865 RParenLoc);
1866 }
1867
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 /// \brief Build a new C++ "this" expression.
1869 ///
1870 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001871 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001873 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001874 QualType ThisType,
1875 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001877 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1878 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 }
1880
1881 /// \brief Build a new C++ throw expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001885 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1886 bool IsThrownVariableInScope) {
1887 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 }
1889
1890 /// \brief Build a new C++ default-argument expression.
1891 ///
1892 /// By default, builds a new default-argument expression, which does not
1893 /// require any semantic analysis. Subclasses may override this routine to
1894 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001895 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001896 ParmVarDecl *Param) {
1897 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1898 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
1900
1901 /// \brief Build a new C++ zero-initialization expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001905 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1906 SourceLocation LParenLoc,
1907 SourceLocation RParenLoc) {
1908 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001909 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001910 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 }
Mike Stump1eb44332009-09-09 15:08:12 +00001912
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 /// \brief Build a new C++ "new" expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001917 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001918 bool UseGlobal,
1919 SourceLocation PlacementLParen,
1920 MultiExprArg PlacementArgs,
1921 SourceLocation PlacementRParen,
1922 SourceRange TypeIdParens,
1923 QualType AllocatedType,
1924 TypeSourceInfo *AllocatedTypeInfo,
1925 Expr *ArraySize,
1926 SourceLocation ConstructorLParen,
1927 MultiExprArg ConstructorArgs,
1928 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001929 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 PlacementLParen,
1931 move(PlacementArgs),
1932 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001933 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001934 AllocatedType,
1935 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001936 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 ConstructorLParen,
1938 move(ConstructorArgs),
1939 ConstructorRParen);
1940 }
Mike Stump1eb44332009-09-09 15:08:12 +00001941
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 /// \brief Build a new C++ "delete" expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001946 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 bool IsGlobalDelete,
1948 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001949 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001951 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 }
Mike Stump1eb44332009-09-09 15:08:12 +00001953
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 /// \brief Build a new unary type trait expression.
1955 ///
1956 /// By default, performs semantic analysis to build the new expression.
1957 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001958 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001959 SourceLocation StartLoc,
1960 TypeSourceInfo *T,
1961 SourceLocation RParenLoc) {
1962 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 }
1964
Francois Pichet6ad6f282010-12-07 00:08:36 +00001965 /// \brief Build a new binary type trait expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
1969 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1970 SourceLocation StartLoc,
1971 TypeSourceInfo *LhsT,
1972 TypeSourceInfo *RhsT,
1973 SourceLocation RParenLoc) {
1974 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1975 }
1976
John Wiegley21ff2e52011-04-28 00:16:57 +00001977 /// \brief Build a new array type trait expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
1981 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1982 SourceLocation StartLoc,
1983 TypeSourceInfo *TSInfo,
1984 Expr *DimExpr,
1985 SourceLocation RParenLoc) {
1986 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1987 }
1988
John Wiegley55262202011-04-25 06:54:41 +00001989 /// \brief Build a new expression trait expression.
1990 ///
1991 /// By default, performs semantic analysis to build the new expression.
1992 /// Subclasses may override this routine to provide different behavior.
1993 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1994 SourceLocation StartLoc,
1995 Expr *Queried,
1996 SourceLocation RParenLoc) {
1997 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1998 }
1999
Mike Stump1eb44332009-09-09 15:08:12 +00002000 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002001 /// expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002005 ExprResult RebuildDependentScopeDeclRefExpr(
2006 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002007 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002008 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002010 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002011
2012 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002013 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002014 *TemplateArgs);
2015
Abramo Bagnara25777432010-08-11 22:01:17 +00002016 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 }
2018
2019 /// \brief Build a new template-id expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002023 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002024 LookupResult &R,
2025 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002026 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002027 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 }
2029
2030 /// \brief Build a new object-construction expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002034 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002035 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 CXXConstructorDecl *Constructor,
2037 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002038 MultiExprArg Args,
2039 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002040 CXXConstructExpr::ConstructionKind ConstructKind,
2041 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002042 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002043 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002044 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002045 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002046
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002047 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002048 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00002049 RequiresZeroInit, ConstructKind,
2050 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002051 }
2052
2053 /// \brief Build a new object-construction expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002057 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2058 SourceLocation LParenLoc,
2059 MultiExprArg Args,
2060 SourceLocation RParenLoc) {
2061 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002062 LParenLoc,
2063 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 RParenLoc);
2065 }
2066
2067 /// \brief Build a new object-construction expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002071 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2072 SourceLocation LParenLoc,
2073 MultiExprArg Args,
2074 SourceLocation RParenLoc) {
2075 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 LParenLoc,
2077 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002078 RParenLoc);
2079 }
Mike Stump1eb44332009-09-09 15:08:12 +00002080
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 /// \brief Build a new member reference expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002085 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002086 QualType BaseType,
2087 bool IsArrow,
2088 SourceLocation OperatorLoc,
2089 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002090 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002091 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002092 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002094 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002095
John McCall9ae2f072010-08-23 23:25:46 +00002096 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002097 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002098 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002099 MemberNameInfo,
2100 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002101 }
2102
John McCall129e2df2009-11-30 22:42:35 +00002103 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002104 ///
2105 /// By default, performs semantic analysis to build the new expression.
2106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002107 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002108 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002109 SourceLocation OperatorLoc,
2110 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002111 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002112 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002113 LookupResult &R,
2114 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002115 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002116 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002117
John McCall9ae2f072010-08-23 23:25:46 +00002118 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002119 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002120 SS, FirstQualifierInScope,
2121 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002122 }
Mike Stump1eb44332009-09-09 15:08:12 +00002123
Sebastian Redl2e156222010-09-10 20:55:43 +00002124 /// \brief Build a new noexcept expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
2128 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2129 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2130 }
2131
Douglas Gregoree8aff02011-01-04 17:33:58 +00002132 /// \brief Build a new expression to compute the length of a parameter pack.
2133 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2134 SourceLocation PackLoc,
2135 SourceLocation RParenLoc,
2136 unsigned Length) {
2137 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2138 OperatorLoc, Pack, PackLoc,
2139 RParenLoc, Length);
2140 }
2141
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 /// \brief Build a new Objective-C @encode expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002146 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002147 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002148 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002149 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002151 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002152
Douglas Gregor92e986e2010-04-22 16:44:27 +00002153 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002154 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002155 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002156 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002157 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002158 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002159 MultiExprArg Args,
2160 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002161 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2162 ReceiverTypeInfo->getType(),
2163 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002164 Sel, Method, LBracLoc, SelectorLoc,
2165 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002166 }
2167
2168 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002169 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002170 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002171 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002172 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002173 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002174 MultiExprArg Args,
2175 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002176 return SemaRef.BuildInstanceMessage(Receiver,
2177 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002178 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002179 Sel, Method, LBracLoc, SelectorLoc,
2180 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002181 }
2182
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002183 /// \brief Build a new Objective-C ivar reference expression.
2184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002187 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002188 SourceLocation IvarLoc,
2189 bool IsArrow, bool IsFreeIvar) {
2190 // FIXME: We lose track of the IsFreeIvar bit.
2191 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002192 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002193 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2194 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002195 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002196 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002197 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002198 false);
John Wiegley429bb272011-04-08 18:41:53 +00002199 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002200 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002201
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002202 if (Result.get())
2203 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002204
John Wiegley429bb272011-04-08 18:41:53 +00002205 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002206 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002207 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002208 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002209 /*TemplateArgs=*/0);
2210 }
Douglas Gregore3303542010-04-26 20:47:02 +00002211
2212 /// \brief Build a new Objective-C property reference expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002216 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002217 ObjCPropertyDecl *Property,
2218 SourceLocation PropertyLoc) {
2219 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002220 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002221 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2222 Sema::LookupMemberName);
2223 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002224 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002225 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002226 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002227 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002228 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002229
Douglas Gregore3303542010-04-26 20:47:02 +00002230 if (Result.get())
2231 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002232
John Wiegley429bb272011-04-08 18:41:53 +00002233 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002234 /*FIXME:*/PropertyLoc, IsArrow,
2235 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002236 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002237 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002238 /*TemplateArgs=*/0);
2239 }
Sean Huntc3021132010-05-05 15:23:54 +00002240
John McCall12f78a62010-12-02 01:19:52 +00002241 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002242 ///
2243 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002244 /// Subclasses may override this routine to provide different behavior.
2245 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2246 ObjCMethodDecl *Getter,
2247 ObjCMethodDecl *Setter,
2248 SourceLocation PropertyLoc) {
2249 // Since these expressions can only be value-dependent, we do not
2250 // need to perform semantic analysis again.
2251 return Owned(
2252 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2253 VK_LValue, OK_ObjCProperty,
2254 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002255 }
2256
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002257 /// \brief Build a new Objective-C "isa" expression.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002261 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002262 bool IsArrow) {
2263 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002264 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002265 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2266 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002267 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002268 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002269 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002270 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002271 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002272
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002273 if (Result.get())
2274 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002275
John Wiegley429bb272011-04-08 18:41:53 +00002276 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002277 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002278 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002279 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002280 /*TemplateArgs=*/0);
2281 }
Sean Huntc3021132010-05-05 15:23:54 +00002282
Douglas Gregorb98b1992009-08-11 05:31:07 +00002283 /// \brief Build a new shuffle vector expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002287 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002288 MultiExprArg SubExprs,
2289 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002290 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002291 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002292 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2293 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2294 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2295 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002296
Douglas Gregorb98b1992009-08-11 05:31:07 +00002297 // Build a reference to the __builtin_shufflevector builtin
2298 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002299 ExprResult Callee
2300 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2301 VK_LValue, BuiltinLoc));
2302 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2303 if (Callee.isInvalid())
2304 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002305
2306 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002307 unsigned NumSubExprs = SubExprs.size();
2308 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002309 ExprResult TheCall = SemaRef.Owned(
2310 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002311 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002312 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002313 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002314 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002315
Douglas Gregorb98b1992009-08-11 05:31:07 +00002316 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002317 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002318 }
John McCall43fed0d2010-11-12 08:19:04 +00002319
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002320 /// \brief Build a new template argument pack expansion.
2321 ///
2322 /// By default, performs semantic analysis to build a new pack expansion
2323 /// for a template argument. Subclasses may override this routine to provide
2324 /// different behavior.
2325 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002326 SourceLocation EllipsisLoc,
2327 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002328 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002329 case TemplateArgument::Expression: {
2330 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002331 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2332 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002333 if (Result.isInvalid())
2334 return TemplateArgumentLoc();
2335
2336 return TemplateArgumentLoc(Result.get(), Result.get());
2337 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002338
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002339 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002340 return TemplateArgumentLoc(TemplateArgument(
2341 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002342 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002343 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002344 Pattern.getTemplateNameLoc(),
2345 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002346
2347 case TemplateArgument::Null:
2348 case TemplateArgument::Integral:
2349 case TemplateArgument::Declaration:
2350 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002351 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002352 llvm_unreachable("Pack expansion pattern has no parameter packs");
2353
2354 case TemplateArgument::Type:
2355 if (TypeSourceInfo *Expansion
2356 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002357 EllipsisLoc,
2358 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002359 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2360 Expansion);
2361 break;
2362 }
2363
2364 return TemplateArgumentLoc();
2365 }
2366
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002367 /// \brief Build a new expression pack expansion.
2368 ///
2369 /// By default, performs semantic analysis to build a new pack expansion
2370 /// for an expression. Subclasses may override this routine to provide
2371 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002372 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2373 llvm::Optional<unsigned> NumExpansions) {
2374 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002375 }
2376
John McCall43fed0d2010-11-12 08:19:04 +00002377private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002378 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2379 QualType ObjectType,
2380 NamedDecl *FirstQualifierInScope,
2381 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002382
2383 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2384 QualType ObjectType,
2385 NamedDecl *FirstQualifierInScope,
2386 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002387};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002388
Douglas Gregor43959a92009-08-20 07:17:43 +00002389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002390StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002391 if (!S)
2392 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002393
Douglas Gregor43959a92009-08-20 07:17:43 +00002394 switch (S->getStmtClass()) {
2395 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002396
Douglas Gregor43959a92009-08-20 07:17:43 +00002397 // Transform individual statement nodes
2398#define STMT(Node, Parent) \
2399 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002400#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002401#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002402#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002403
Douglas Gregor43959a92009-08-20 07:17:43 +00002404 // Transform expressions by calling TransformExpr.
2405#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002406#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002407#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002408#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002409 {
John McCall60d7b3a2010-08-24 06:29:42 +00002410 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002411 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002412 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002413
John McCall9ae2f072010-08-23 23:25:46 +00002414 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002415 }
Mike Stump1eb44332009-09-09 15:08:12 +00002416 }
2417
John McCall3fa5cae2010-10-26 07:05:15 +00002418 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002419}
Mike Stump1eb44332009-09-09 15:08:12 +00002420
2421
Douglas Gregor670444e2009-08-04 22:27:00 +00002422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002423ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 if (!E)
2425 return SemaRef.Owned(E);
2426
2427 switch (E->getStmtClass()) {
2428 case Stmt::NoStmtClass: break;
2429#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002430#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002431#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002432 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002433#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002434 }
2435
John McCall3fa5cae2010-10-26 07:05:15 +00002436 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002437}
2438
2439template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002440bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2441 unsigned NumInputs,
2442 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002443 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002444 bool *ArgChanged) {
2445 for (unsigned I = 0; I != NumInputs; ++I) {
2446 // If requested, drop call arguments that need to be dropped.
2447 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2448 if (ArgChanged)
2449 *ArgChanged = true;
2450
2451 break;
2452 }
2453
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002454 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2455 Expr *Pattern = Expansion->getPattern();
2456
Chris Lattner686775d2011-07-20 06:58:45 +00002457 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002458 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2459 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2460
2461 // Determine whether the set of unexpanded parameter packs can and should
2462 // be expanded.
2463 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002464 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002465 llvm::Optional<unsigned> OrigNumExpansions
2466 = Expansion->getNumExpansions();
2467 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002468 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2469 Pattern->getSourceRange(),
2470 Unexpanded.data(),
2471 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002472 Expand, RetainExpansion,
2473 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002474 return true;
2475
2476 if (!Expand) {
2477 // The transform has determined that we should perform a simple
2478 // transformation on the pack expansion, producing another pack
2479 // expansion.
2480 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2481 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2482 if (OutPattern.isInvalid())
2483 return true;
2484
2485 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002486 Expansion->getEllipsisLoc(),
2487 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002488 if (Out.isInvalid())
2489 return true;
2490
2491 if (ArgChanged)
2492 *ArgChanged = true;
2493 Outputs.push_back(Out.get());
2494 continue;
2495 }
John McCallc8fc90a2011-07-06 07:30:07 +00002496
2497 // Record right away that the argument was changed. This needs
2498 // to happen even if the array expands to nothing.
2499 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500
2501 // The transform has determined that we should perform an elementwise
2502 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002503 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2505 ExprResult Out = getDerived().TransformExpr(Pattern);
2506 if (Out.isInvalid())
2507 return true;
2508
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002509 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002510 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2511 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002512 if (Out.isInvalid())
2513 return true;
2514 }
2515
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002516 Outputs.push_back(Out.get());
2517 }
2518
2519 continue;
2520 }
2521
Douglas Gregoraa165f82011-01-03 19:04:46 +00002522 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2523 if (Result.isInvalid())
2524 return true;
2525
2526 if (Result.get() != Inputs[I] && ArgChanged)
2527 *ArgChanged = true;
2528
2529 Outputs.push_back(Result.get());
2530 }
2531
2532 return false;
2533}
2534
2535template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002536NestedNameSpecifierLoc
2537TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2538 NestedNameSpecifierLoc NNS,
2539 QualType ObjectType,
2540 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002541 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002542 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2543 Qualifier = Qualifier.getPrefix())
2544 Qualifiers.push_back(Qualifier);
2545
2546 CXXScopeSpec SS;
2547 while (!Qualifiers.empty()) {
2548 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2549 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2550
2551 switch (QNNS->getKind()) {
2552 case NestedNameSpecifier::Identifier:
2553 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2554 *QNNS->getAsIdentifier(),
2555 Q.getLocalBeginLoc(),
2556 Q.getLocalEndLoc(),
2557 ObjectType, false, SS,
2558 FirstQualifierInScope, false))
2559 return NestedNameSpecifierLoc();
2560
2561 break;
2562
2563 case NestedNameSpecifier::Namespace: {
2564 NamespaceDecl *NS
2565 = cast_or_null<NamespaceDecl>(
2566 getDerived().TransformDecl(
2567 Q.getLocalBeginLoc(),
2568 QNNS->getAsNamespace()));
2569 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2570 break;
2571 }
2572
2573 case NestedNameSpecifier::NamespaceAlias: {
2574 NamespaceAliasDecl *Alias
2575 = cast_or_null<NamespaceAliasDecl>(
2576 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2577 QNNS->getAsNamespaceAlias()));
2578 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2579 Q.getLocalEndLoc());
2580 break;
2581 }
2582
2583 case NestedNameSpecifier::Global:
2584 // There is no meaningful transformation that one could perform on the
2585 // global scope.
2586 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2587 break;
2588
2589 case NestedNameSpecifier::TypeSpecWithTemplate:
2590 case NestedNameSpecifier::TypeSpec: {
2591 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2592 FirstQualifierInScope, SS);
2593
2594 if (!TL)
2595 return NestedNameSpecifierLoc();
2596
2597 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2598 (SemaRef.getLangOptions().CPlusPlus0x &&
2599 TL.getType()->isEnumeralType())) {
2600 assert(!TL.getType().hasLocalQualifiers() &&
2601 "Can't get cv-qualifiers here");
2602 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2603 Q.getLocalEndLoc());
2604 break;
2605 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002606 // If the nested-name-specifier is an invalid type def, don't emit an
2607 // error because a previous error should have already been emitted.
2608 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2609 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2610 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2611 << TL.getType() << SS.getRange();
2612 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002613 return NestedNameSpecifierLoc();
2614 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002615 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002616
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002617 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002618 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002619 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002620 }
2621
2622 // Don't rebuild the nested-name-specifier if we don't have to.
2623 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2624 !getDerived().AlwaysRebuild())
2625 return NNS;
2626
2627 // If we can re-use the source-location data from the original
2628 // nested-name-specifier, do so.
2629 if (SS.location_size() == NNS.getDataLength() &&
2630 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2631 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2632
2633 // Allocate new nested-name-specifier location information.
2634 return SS.getWithLocInContext(SemaRef.Context);
2635}
2636
2637template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002638DeclarationNameInfo
2639TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002640::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002641 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002642 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002643 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002644
2645 switch (Name.getNameKind()) {
2646 case DeclarationName::Identifier:
2647 case DeclarationName::ObjCZeroArgSelector:
2648 case DeclarationName::ObjCOneArgSelector:
2649 case DeclarationName::ObjCMultiArgSelector:
2650 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002651 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002652 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002653 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002654
Douglas Gregor81499bb2009-09-03 22:13:48 +00002655 case DeclarationName::CXXConstructorName:
2656 case DeclarationName::CXXDestructorName:
2657 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002658 TypeSourceInfo *NewTInfo;
2659 CanQualType NewCanTy;
2660 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002661 NewTInfo = getDerived().TransformType(OldTInfo);
2662 if (!NewTInfo)
2663 return DeclarationNameInfo();
2664 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002665 }
2666 else {
2667 NewTInfo = 0;
2668 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002669 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002670 if (NewT.isNull())
2671 return DeclarationNameInfo();
2672 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2673 }
Mike Stump1eb44332009-09-09 15:08:12 +00002674
Abramo Bagnara25777432010-08-11 22:01:17 +00002675 DeclarationName NewName
2676 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2677 NewCanTy);
2678 DeclarationNameInfo NewNameInfo(NameInfo);
2679 NewNameInfo.setName(NewName);
2680 NewNameInfo.setNamedTypeInfo(NewTInfo);
2681 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002682 }
Mike Stump1eb44332009-09-09 15:08:12 +00002683 }
2684
Abramo Bagnara25777432010-08-11 22:01:17 +00002685 assert(0 && "Unknown name kind.");
2686 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002687}
2688
2689template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002690TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002691TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2692 TemplateName Name,
2693 SourceLocation NameLoc,
2694 QualType ObjectType,
2695 NamedDecl *FirstQualifierInScope) {
2696 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2697 TemplateDecl *Template = QTN->getTemplateDecl();
2698 assert(Template && "qualified template name must refer to a template");
2699
2700 TemplateDecl *TransTemplate
2701 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2702 Template));
2703 if (!TransTemplate)
2704 return TemplateName();
2705
2706 if (!getDerived().AlwaysRebuild() &&
2707 SS.getScopeRep() == QTN->getQualifier() &&
2708 TransTemplate == Template)
2709 return Name;
2710
2711 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2712 TransTemplate);
2713 }
2714
2715 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2716 if (SS.getScopeRep()) {
2717 // These apply to the scope specifier, not the template.
2718 ObjectType = QualType();
2719 FirstQualifierInScope = 0;
2720 }
2721
2722 if (!getDerived().AlwaysRebuild() &&
2723 SS.getScopeRep() == DTN->getQualifier() &&
2724 ObjectType.isNull())
2725 return Name;
2726
2727 if (DTN->isIdentifier()) {
2728 return getDerived().RebuildTemplateName(SS,
2729 *DTN->getIdentifier(),
2730 NameLoc,
2731 ObjectType,
2732 FirstQualifierInScope);
2733 }
2734
2735 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2736 ObjectType);
2737 }
2738
2739 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2740 TemplateDecl *TransTemplate
2741 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2742 Template));
2743 if (!TransTemplate)
2744 return TemplateName();
2745
2746 if (!getDerived().AlwaysRebuild() &&
2747 TransTemplate == Template)
2748 return Name;
2749
2750 return TemplateName(TransTemplate);
2751 }
2752
2753 if (SubstTemplateTemplateParmPackStorage *SubstPack
2754 = Name.getAsSubstTemplateTemplateParmPack()) {
2755 TemplateTemplateParmDecl *TransParam
2756 = cast_or_null<TemplateTemplateParmDecl>(
2757 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2758 if (!TransParam)
2759 return TemplateName();
2760
2761 if (!getDerived().AlwaysRebuild() &&
2762 TransParam == SubstPack->getParameterPack())
2763 return Name;
2764
2765 return getDerived().RebuildTemplateName(TransParam,
2766 SubstPack->getArgumentPack());
2767 }
2768
2769 // These should be getting filtered out before they reach the AST.
2770 llvm_unreachable("overloaded function decl survived to here");
2771 return TemplateName();
2772}
2773
2774template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002775void TreeTransform<Derived>::InventTemplateArgumentLoc(
2776 const TemplateArgument &Arg,
2777 TemplateArgumentLoc &Output) {
2778 SourceLocation Loc = getDerived().getBaseLocation();
2779 switch (Arg.getKind()) {
2780 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002781 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002782 break;
2783
2784 case TemplateArgument::Type:
2785 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002786 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002787
John McCall833ca992009-10-29 08:12:44 +00002788 break;
2789
Douglas Gregor788cd062009-11-11 01:00:40 +00002790 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002791 case TemplateArgument::TemplateExpansion: {
2792 NestedNameSpecifierLocBuilder Builder;
2793 TemplateName Template = Arg.getAsTemplate();
2794 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2795 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2796 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2797 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2798
2799 if (Arg.getKind() == TemplateArgument::Template)
2800 Output = TemplateArgumentLoc(Arg,
2801 Builder.getWithLocInContext(SemaRef.Context),
2802 Loc);
2803 else
2804 Output = TemplateArgumentLoc(Arg,
2805 Builder.getWithLocInContext(SemaRef.Context),
2806 Loc, Loc);
2807
Douglas Gregor788cd062009-11-11 01:00:40 +00002808 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002809 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002810
John McCall833ca992009-10-29 08:12:44 +00002811 case TemplateArgument::Expression:
2812 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2813 break;
2814
2815 case TemplateArgument::Declaration:
2816 case TemplateArgument::Integral:
2817 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002818 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002819 break;
2820 }
2821}
2822
2823template<typename Derived>
2824bool TreeTransform<Derived>::TransformTemplateArgument(
2825 const TemplateArgumentLoc &Input,
2826 TemplateArgumentLoc &Output) {
2827 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002828 switch (Arg.getKind()) {
2829 case TemplateArgument::Null:
2830 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002831 Output = Input;
2832 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002833
Douglas Gregor670444e2009-08-04 22:27:00 +00002834 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002835 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002836 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002837 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002838
2839 DI = getDerived().TransformType(DI);
2840 if (!DI) return true;
2841
2842 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2843 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002844 }
Mike Stump1eb44332009-09-09 15:08:12 +00002845
Douglas Gregor670444e2009-08-04 22:27:00 +00002846 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002847 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002848 DeclarationName Name;
2849 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2850 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002851 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002852 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002853 if (!D) return true;
2854
John McCall828bff22009-10-29 18:45:58 +00002855 Expr *SourceExpr = Input.getSourceDeclExpression();
2856 if (SourceExpr) {
2857 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002858 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002859 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002860 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002861 }
2862
2863 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002864 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002865 }
Mike Stump1eb44332009-09-09 15:08:12 +00002866
Douglas Gregor788cd062009-11-11 01:00:40 +00002867 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002868 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2869 if (QualifierLoc) {
2870 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2871 if (!QualifierLoc)
2872 return true;
2873 }
2874
Douglas Gregor1d752d72011-03-02 18:46:51 +00002875 CXXScopeSpec SS;
2876 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002877 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002878 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2879 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002880 if (Template.isNull())
2881 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002882
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002883 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002884 Input.getTemplateNameLoc());
2885 return false;
2886 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002887
2888 case TemplateArgument::TemplateExpansion:
2889 llvm_unreachable("Caller should expand pack expansions");
2890
Douglas Gregor670444e2009-08-04 22:27:00 +00002891 case TemplateArgument::Expression: {
2892 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002893 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002894 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002895
John McCall833ca992009-10-29 08:12:44 +00002896 Expr *InputExpr = Input.getSourceExpression();
2897 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2898
Chris Lattner223de242011-04-25 20:37:58 +00002899 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002900 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002901 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002902 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002903 }
Mike Stump1eb44332009-09-09 15:08:12 +00002904
Douglas Gregor670444e2009-08-04 22:27:00 +00002905 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002906 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002907 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002908 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002909 AEnd = Arg.pack_end();
2910 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002911
John McCall833ca992009-10-29 08:12:44 +00002912 // FIXME: preserve source information here when we start
2913 // caring about parameter packs.
2914
John McCall828bff22009-10-29 18:45:58 +00002915 TemplateArgumentLoc InputArg;
2916 TemplateArgumentLoc OutputArg;
2917 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2918 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002919 return true;
2920
John McCall828bff22009-10-29 18:45:58 +00002921 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002922 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002923
2924 TemplateArgument *TransformedArgsPtr
2925 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2926 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2927 TransformedArgsPtr);
2928 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2929 TransformedArgs.size()),
2930 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002931 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002932 }
2933 }
Mike Stump1eb44332009-09-09 15:08:12 +00002934
Douglas Gregor670444e2009-08-04 22:27:00 +00002935 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002936 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002937}
2938
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002939/// \brief Iterator adaptor that invents template argument location information
2940/// for each of the template arguments in its underlying iterator.
2941template<typename Derived, typename InputIterator>
2942class TemplateArgumentLocInventIterator {
2943 TreeTransform<Derived> &Self;
2944 InputIterator Iter;
2945
2946public:
2947 typedef TemplateArgumentLoc value_type;
2948 typedef TemplateArgumentLoc reference;
2949 typedef typename std::iterator_traits<InputIterator>::difference_type
2950 difference_type;
2951 typedef std::input_iterator_tag iterator_category;
2952
2953 class pointer {
2954 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002955
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002956 public:
2957 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2958
2959 const TemplateArgumentLoc *operator->() const { return &Arg; }
2960 };
2961
2962 TemplateArgumentLocInventIterator() { }
2963
2964 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2965 InputIterator Iter)
2966 : Self(Self), Iter(Iter) { }
2967
2968 TemplateArgumentLocInventIterator &operator++() {
2969 ++Iter;
2970 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002971 }
2972
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002973 TemplateArgumentLocInventIterator operator++(int) {
2974 TemplateArgumentLocInventIterator Old(*this);
2975 ++(*this);
2976 return Old;
2977 }
2978
2979 reference operator*() const {
2980 TemplateArgumentLoc Result;
2981 Self.InventTemplateArgumentLoc(*Iter, Result);
2982 return Result;
2983 }
2984
2985 pointer operator->() const { return pointer(**this); }
2986
2987 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2988 const TemplateArgumentLocInventIterator &Y) {
2989 return X.Iter == Y.Iter;
2990 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002991
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002992 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2993 const TemplateArgumentLocInventIterator &Y) {
2994 return X.Iter != Y.Iter;
2995 }
2996};
2997
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002998template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002999template<typename InputIterator>
3000bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3001 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003002 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003003 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003004 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003005 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003006
3007 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3008 // Unpack argument packs, which we translate them into separate
3009 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003010 // FIXME: We could do much better if we could guarantee that the
3011 // TemplateArgumentLocInfo for the pack expansion would be usable for
3012 // all of the template arguments in the argument pack.
3013 typedef TemplateArgumentLocInventIterator<Derived,
3014 TemplateArgument::pack_iterator>
3015 PackLocIterator;
3016 if (TransformTemplateArguments(PackLocIterator(*this,
3017 In.getArgument().pack_begin()),
3018 PackLocIterator(*this,
3019 In.getArgument().pack_end()),
3020 Outputs))
3021 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003022
3023 continue;
3024 }
3025
3026 if (In.getArgument().isPackExpansion()) {
3027 // We have a pack expansion, for which we will be substituting into
3028 // the pattern.
3029 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003030 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003031 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003032 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3033 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003034
Chris Lattner686775d2011-07-20 06:58:45 +00003035 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003036 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3037 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3038
3039 // Determine whether the set of unexpanded parameter packs can and should
3040 // be expanded.
3041 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003042 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003043 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003044 if (getDerived().TryExpandParameterPacks(Ellipsis,
3045 Pattern.getSourceRange(),
3046 Unexpanded.data(),
3047 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003048 Expand,
3049 RetainExpansion,
3050 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003051 return true;
3052
3053 if (!Expand) {
3054 // The transform has determined that we should perform a simple
3055 // transformation on the pack expansion, producing another pack
3056 // expansion.
3057 TemplateArgumentLoc OutPattern;
3058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3059 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3060 return true;
3061
Douglas Gregorcded4f62011-01-14 17:04:44 +00003062 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3063 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003064 if (Out.getArgument().isNull())
3065 return true;
3066
3067 Outputs.addArgument(Out);
3068 continue;
3069 }
3070
3071 // The transform has determined that we should perform an elementwise
3072 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003073 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003074 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3075
3076 if (getDerived().TransformTemplateArgument(Pattern, Out))
3077 return true;
3078
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003079 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003080 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3081 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003082 if (Out.getArgument().isNull())
3083 return true;
3084 }
3085
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003086 Outputs.addArgument(Out);
3087 }
3088
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003089 // If we're supposed to retain a pack expansion, do so by temporarily
3090 // forgetting the partially-substituted parameter pack.
3091 if (RetainExpansion) {
3092 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3093
3094 if (getDerived().TransformTemplateArgument(Pattern, Out))
3095 return true;
3096
Douglas Gregorcded4f62011-01-14 17:04:44 +00003097 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3098 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003099 if (Out.getArgument().isNull())
3100 return true;
3101
3102 Outputs.addArgument(Out);
3103 }
Douglas Gregord3731192011-01-10 07:32:04 +00003104
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003105 continue;
3106 }
3107
3108 // The simple case:
3109 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003110 return true;
3111
3112 Outputs.addArgument(Out);
3113 }
3114
3115 return false;
3116
3117}
3118
Douglas Gregor577f75a2009-08-04 16:50:30 +00003119//===----------------------------------------------------------------------===//
3120// Type transformation
3121//===----------------------------------------------------------------------===//
3122
3123template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003124QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003125 if (getDerived().AlreadyTransformed(T))
3126 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003127
John McCalla2becad2009-10-21 00:40:46 +00003128 // Temporary workaround. All of these transformations should
3129 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003130 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3131 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003132
John McCall43fed0d2010-11-12 08:19:04 +00003133 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003134
John McCalla2becad2009-10-21 00:40:46 +00003135 if (!NewDI)
3136 return QualType();
3137
3138 return NewDI->getType();
3139}
3140
3141template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003142TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003143 if (getDerived().AlreadyTransformed(DI->getType()))
3144 return DI;
3145
3146 TypeLocBuilder TLB;
3147
3148 TypeLoc TL = DI->getTypeLoc();
3149 TLB.reserve(TL.getFullDataSize());
3150
John McCall43fed0d2010-11-12 08:19:04 +00003151 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003152 if (Result.isNull())
3153 return 0;
3154
John McCalla93c9342009-12-07 02:54:59 +00003155 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003156}
3157
3158template<typename Derived>
3159QualType
John McCall43fed0d2010-11-12 08:19:04 +00003160TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003161 switch (T.getTypeLocClass()) {
3162#define ABSTRACT_TYPELOC(CLASS, PARENT)
3163#define TYPELOC(CLASS, PARENT) \
3164 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003165 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003166#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003167 }
Mike Stump1eb44332009-09-09 15:08:12 +00003168
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003169 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003170 return QualType();
3171}
3172
3173/// FIXME: By default, this routine adds type qualifiers only to types
3174/// that can have qualifiers, and silently suppresses those qualifiers
3175/// that are not permitted (e.g., qualifiers on reference or function
3176/// types). This is the right thing for template instantiation, but
3177/// probably not for other clients.
3178template<typename Derived>
3179QualType
3180TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003181 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003182 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003183
John McCall43fed0d2010-11-12 08:19:04 +00003184 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003185 if (Result.isNull())
3186 return QualType();
3187
3188 // Silently suppress qualifiers if the result type can't be qualified.
3189 // FIXME: this is the right thing for template instantiation, but
3190 // probably not for other clients.
3191 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003192 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003193
John McCallf85e1932011-06-15 23:02:42 +00003194 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003195 // resulting type.
3196 if (Quals.hasObjCLifetime()) {
3197 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3198 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003199 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003200 // Objective-C ARC:
3201 // A lifetime qualifier applied to a substituted template parameter
3202 // overrides the lifetime qualifier from the template argument.
3203 if (const SubstTemplateTypeParmType *SubstTypeParam
3204 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3205 QualType Replacement = SubstTypeParam->getReplacementType();
3206 Qualifiers Qs = Replacement.getQualifiers();
3207 Qs.removeObjCLifetime();
3208 Replacement
3209 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3210 Qs);
3211 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3212 SubstTypeParam->getReplacedParameter(),
3213 Replacement);
3214 TLB.TypeWasModifiedSafely(Result);
3215 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003216 // Otherwise, complain about the addition of a qualifier to an
3217 // already-qualified type.
3218 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003219 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003220 << Result << R;
3221
Douglas Gregore559ca12011-06-17 22:11:49 +00003222 Quals.removeObjCLifetime();
3223 }
3224 }
3225 }
John McCall28654742010-06-05 06:41:15 +00003226 if (!Quals.empty()) {
3227 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3228 TLB.push<QualifiedTypeLoc>(Result);
3229 // No location information to preserve.
3230 }
John McCalla2becad2009-10-21 00:40:46 +00003231
3232 return Result;
3233}
3234
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003235template<typename Derived>
3236TypeLoc
3237TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3238 QualType ObjectType,
3239 NamedDecl *UnqualLookup,
3240 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003241 QualType T = TL.getType();
3242 if (getDerived().AlreadyTransformed(T))
3243 return TL;
3244
3245 TypeLocBuilder TLB;
3246 QualType Result;
3247
3248 if (isa<TemplateSpecializationType>(T)) {
3249 TemplateSpecializationTypeLoc SpecTL
3250 = cast<TemplateSpecializationTypeLoc>(TL);
3251
3252 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003253 getDerived().TransformTemplateName(SS,
3254 SpecTL.getTypePtr()->getTemplateName(),
3255 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003256 ObjectType, UnqualLookup);
3257 if (Template.isNull())
3258 return TypeLoc();
3259
3260 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3261 Template);
3262 } else if (isa<DependentTemplateSpecializationType>(T)) {
3263 DependentTemplateSpecializationTypeLoc SpecTL
3264 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3265
Douglas Gregora88f09f2011-02-28 17:23:35 +00003266 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003267 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003268 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003269 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003270 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003271 if (Template.isNull())
3272 return TypeLoc();
3273
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003274 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003275 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003276 Template,
3277 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003278 } else {
3279 // Nothing special needs to be done for these.
3280 Result = getDerived().TransformType(TLB, TL);
3281 }
3282
3283 if (Result.isNull())
3284 return TypeLoc();
3285
3286 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3287}
3288
Douglas Gregorb71d8212011-03-02 18:32:08 +00003289template<typename Derived>
3290TypeSourceInfo *
3291TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3292 QualType ObjectType,
3293 NamedDecl *UnqualLookup,
3294 CXXScopeSpec &SS) {
3295 // FIXME: Painfully copy-paste from the above!
3296
3297 QualType T = TSInfo->getType();
3298 if (getDerived().AlreadyTransformed(T))
3299 return TSInfo;
3300
3301 TypeLocBuilder TLB;
3302 QualType Result;
3303
3304 TypeLoc TL = TSInfo->getTypeLoc();
3305 if (isa<TemplateSpecializationType>(T)) {
3306 TemplateSpecializationTypeLoc SpecTL
3307 = cast<TemplateSpecializationTypeLoc>(TL);
3308
3309 TemplateName Template
3310 = getDerived().TransformTemplateName(SS,
3311 SpecTL.getTypePtr()->getTemplateName(),
3312 SpecTL.getTemplateNameLoc(),
3313 ObjectType, UnqualLookup);
3314 if (Template.isNull())
3315 return 0;
3316
3317 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3318 Template);
3319 } else if (isa<DependentTemplateSpecializationType>(T)) {
3320 DependentTemplateSpecializationTypeLoc SpecTL
3321 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3322
3323 TemplateName Template
3324 = getDerived().RebuildTemplateName(SS,
3325 *SpecTL.getTypePtr()->getIdentifier(),
3326 SpecTL.getNameLoc(),
3327 ObjectType, UnqualLookup);
3328 if (Template.isNull())
3329 return 0;
3330
3331 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3332 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003333 Template,
3334 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003335 } else {
3336 // Nothing special needs to be done for these.
3337 Result = getDerived().TransformType(TLB, TL);
3338 }
3339
3340 if (Result.isNull())
3341 return 0;
3342
3343 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3344}
3345
John McCalla2becad2009-10-21 00:40:46 +00003346template <class TyLoc> static inline
3347QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3348 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3349 NewT.setNameLoc(T.getNameLoc());
3350 return T.getType();
3351}
3352
John McCalla2becad2009-10-21 00:40:46 +00003353template<typename Derived>
3354QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003355 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003356 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3357 NewT.setBuiltinLoc(T.getBuiltinLoc());
3358 if (T.needsExtraLocalData())
3359 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3360 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003361}
Mike Stump1eb44332009-09-09 15:08:12 +00003362
Douglas Gregor577f75a2009-08-04 16:50:30 +00003363template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003364QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003365 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003366 // FIXME: recurse?
3367 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003368}
Mike Stump1eb44332009-09-09 15:08:12 +00003369
Douglas Gregor577f75a2009-08-04 16:50:30 +00003370template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003371QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003372 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003373 QualType PointeeType
3374 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003375 if (PointeeType.isNull())
3376 return QualType();
3377
3378 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003379 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003380 // A dependent pointer type 'T *' has is being transformed such
3381 // that an Objective-C class type is being replaced for 'T'. The
3382 // resulting pointer type is an ObjCObjectPointerType, not a
3383 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003384 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003385
John McCallc12c5bb2010-05-15 11:32:37 +00003386 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3387 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003388 return Result;
3389 }
John McCall43fed0d2010-11-12 08:19:04 +00003390
Douglas Gregor92e986e2010-04-22 16:44:27 +00003391 if (getDerived().AlwaysRebuild() ||
3392 PointeeType != TL.getPointeeLoc().getType()) {
3393 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3394 if (Result.isNull())
3395 return QualType();
3396 }
John McCallf85e1932011-06-15 23:02:42 +00003397
3398 // Objective-C ARC can add lifetime qualifiers to the type that we're
3399 // pointing to.
3400 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3401
Douglas Gregor92e986e2010-04-22 16:44:27 +00003402 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3403 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003404 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003405}
Mike Stump1eb44332009-09-09 15:08:12 +00003406
3407template<typename Derived>
3408QualType
John McCalla2becad2009-10-21 00:40:46 +00003409TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003410 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003411 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003412 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3413 if (PointeeType.isNull())
3414 return QualType();
3415
3416 QualType Result = TL.getType();
3417 if (getDerived().AlwaysRebuild() ||
3418 PointeeType != TL.getPointeeLoc().getType()) {
3419 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003420 TL.getSigilLoc());
3421 if (Result.isNull())
3422 return QualType();
3423 }
3424
Douglas Gregor39968ad2010-04-22 16:50:51 +00003425 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003426 NewT.setSigilLoc(TL.getSigilLoc());
3427 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003428}
3429
John McCall85737a72009-10-30 00:06:24 +00003430/// Transforms a reference type. Note that somewhat paradoxically we
3431/// don't care whether the type itself is an l-value type or an r-value
3432/// type; we only care if the type was *written* as an l-value type
3433/// or an r-value type.
3434template<typename Derived>
3435QualType
3436TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003437 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003438 const ReferenceType *T = TL.getTypePtr();
3439
3440 // Note that this works with the pointee-as-written.
3441 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3442 if (PointeeType.isNull())
3443 return QualType();
3444
3445 QualType Result = TL.getType();
3446 if (getDerived().AlwaysRebuild() ||
3447 PointeeType != T->getPointeeTypeAsWritten()) {
3448 Result = getDerived().RebuildReferenceType(PointeeType,
3449 T->isSpelledAsLValue(),
3450 TL.getSigilLoc());
3451 if (Result.isNull())
3452 return QualType();
3453 }
3454
John McCallf85e1932011-06-15 23:02:42 +00003455 // Objective-C ARC can add lifetime qualifiers to the type that we're
3456 // referring to.
3457 TLB.TypeWasModifiedSafely(
3458 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3459
John McCall85737a72009-10-30 00:06:24 +00003460 // r-value references can be rebuilt as l-value references.
3461 ReferenceTypeLoc NewTL;
3462 if (isa<LValueReferenceType>(Result))
3463 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3464 else
3465 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3466 NewTL.setSigilLoc(TL.getSigilLoc());
3467
3468 return Result;
3469}
3470
Mike Stump1eb44332009-09-09 15:08:12 +00003471template<typename Derived>
3472QualType
John McCalla2becad2009-10-21 00:40:46 +00003473TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003474 LValueReferenceTypeLoc TL) {
3475 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003476}
3477
Mike Stump1eb44332009-09-09 15:08:12 +00003478template<typename Derived>
3479QualType
John McCalla2becad2009-10-21 00:40:46 +00003480TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003481 RValueReferenceTypeLoc TL) {
3482 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003483}
Mike Stump1eb44332009-09-09 15:08:12 +00003484
Douglas Gregor577f75a2009-08-04 16:50:30 +00003485template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003486QualType
John McCalla2becad2009-10-21 00:40:46 +00003487TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003488 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003489 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003490 if (PointeeType.isNull())
3491 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003492
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003493 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3494 TypeSourceInfo* NewClsTInfo = 0;
3495 if (OldClsTInfo) {
3496 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3497 if (!NewClsTInfo)
3498 return QualType();
3499 }
3500
3501 const MemberPointerType *T = TL.getTypePtr();
3502 QualType OldClsType = QualType(T->getClass(), 0);
3503 QualType NewClsType;
3504 if (NewClsTInfo)
3505 NewClsType = NewClsTInfo->getType();
3506 else {
3507 NewClsType = getDerived().TransformType(OldClsType);
3508 if (NewClsType.isNull())
3509 return QualType();
3510 }
Mike Stump1eb44332009-09-09 15:08:12 +00003511
John McCalla2becad2009-10-21 00:40:46 +00003512 QualType Result = TL.getType();
3513 if (getDerived().AlwaysRebuild() ||
3514 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003515 NewClsType != OldClsType) {
3516 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003517 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003518 if (Result.isNull())
3519 return QualType();
3520 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521
John McCalla2becad2009-10-21 00:40:46 +00003522 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3523 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003524 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003525
3526 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003527}
3528
Mike Stump1eb44332009-09-09 15:08:12 +00003529template<typename Derived>
3530QualType
John McCalla2becad2009-10-21 00:40:46 +00003531TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003532 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003533 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003534 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535 if (ElementType.isNull())
3536 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003537
John McCalla2becad2009-10-21 00:40:46 +00003538 QualType Result = TL.getType();
3539 if (getDerived().AlwaysRebuild() ||
3540 ElementType != T->getElementType()) {
3541 Result = getDerived().RebuildConstantArrayType(ElementType,
3542 T->getSizeModifier(),
3543 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003544 T->getIndexTypeCVRQualifiers(),
3545 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003546 if (Result.isNull())
3547 return QualType();
3548 }
Sean Huntc3021132010-05-05 15:23:54 +00003549
John McCalla2becad2009-10-21 00:40:46 +00003550 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3551 NewTL.setLBracketLoc(TL.getLBracketLoc());
3552 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003553
John McCalla2becad2009-10-21 00:40:46 +00003554 Expr *Size = TL.getSizeExpr();
3555 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003556 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003557 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3558 }
3559 NewTL.setSizeExpr(Size);
3560
3561 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003562}
Mike Stump1eb44332009-09-09 15:08:12 +00003563
Douglas Gregor577f75a2009-08-04 16:50:30 +00003564template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003565QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003566 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003567 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003568 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003569 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570 if (ElementType.isNull())
3571 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003572
John McCalla2becad2009-10-21 00:40:46 +00003573 QualType Result = TL.getType();
3574 if (getDerived().AlwaysRebuild() ||
3575 ElementType != T->getElementType()) {
3576 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003578 T->getIndexTypeCVRQualifiers(),
3579 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003580 if (Result.isNull())
3581 return QualType();
3582 }
Sean Huntc3021132010-05-05 15:23:54 +00003583
John McCalla2becad2009-10-21 00:40:46 +00003584 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3585 NewTL.setLBracketLoc(TL.getLBracketLoc());
3586 NewTL.setRBracketLoc(TL.getRBracketLoc());
3587 NewTL.setSizeExpr(0);
3588
3589 return Result;
3590}
3591
3592template<typename Derived>
3593QualType
3594TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003595 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003596 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003597 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3598 if (ElementType.isNull())
3599 return QualType();
3600
3601 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003602 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003603
John McCall60d7b3a2010-08-24 06:29:42 +00003604 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003605 = getDerived().TransformExpr(T->getSizeExpr());
3606 if (SizeResult.isInvalid())
3607 return QualType();
3608
John McCall9ae2f072010-08-23 23:25:46 +00003609 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003610
3611 QualType Result = TL.getType();
3612 if (getDerived().AlwaysRebuild() ||
3613 ElementType != T->getElementType() ||
3614 Size != T->getSizeExpr()) {
3615 Result = getDerived().RebuildVariableArrayType(ElementType,
3616 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003617 Size,
John McCalla2becad2009-10-21 00:40:46 +00003618 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003619 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003620 if (Result.isNull())
3621 return QualType();
3622 }
Sean Huntc3021132010-05-05 15:23:54 +00003623
John McCalla2becad2009-10-21 00:40:46 +00003624 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3625 NewTL.setLBracketLoc(TL.getLBracketLoc());
3626 NewTL.setRBracketLoc(TL.getRBracketLoc());
3627 NewTL.setSizeExpr(Size);
3628
3629 return Result;
3630}
3631
3632template<typename Derived>
3633QualType
3634TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003635 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003636 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003637 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3638 if (ElementType.isNull())
3639 return QualType();
3640
3641 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003642 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003643
John McCall3b657512011-01-19 10:06:00 +00003644 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3645 Expr *origSize = TL.getSizeExpr();
3646 if (!origSize) origSize = T->getSizeExpr();
3647
3648 ExprResult sizeResult
3649 = getDerived().TransformExpr(origSize);
3650 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003651 return QualType();
3652
John McCall3b657512011-01-19 10:06:00 +00003653 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003654
3655 QualType Result = TL.getType();
3656 if (getDerived().AlwaysRebuild() ||
3657 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003658 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003659 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3660 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003661 size,
John McCalla2becad2009-10-21 00:40:46 +00003662 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003663 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003664 if (Result.isNull())
3665 return QualType();
3666 }
John McCalla2becad2009-10-21 00:40:46 +00003667
3668 // We might have any sort of array type now, but fortunately they
3669 // all have the same location layout.
3670 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3671 NewTL.setLBracketLoc(TL.getLBracketLoc());
3672 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003673 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003674
3675 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
Mike Stump1eb44332009-09-09 15:08:12 +00003677
3678template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003679QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003680 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003681 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003682 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003683
3684 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685 QualType ElementType = getDerived().TransformType(T->getElementType());
3686 if (ElementType.isNull())
3687 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003688
Douglas Gregor670444e2009-08-04 22:27:00 +00003689 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003690 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003691
John McCall60d7b3a2010-08-24 06:29:42 +00003692 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003693 if (Size.isInvalid())
3694 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003695
John McCalla2becad2009-10-21 00:40:46 +00003696 QualType Result = TL.getType();
3697 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003698 ElementType != T->getElementType() ||
3699 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003700 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003701 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003702 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003703 if (Result.isNull())
3704 return QualType();
3705 }
John McCalla2becad2009-10-21 00:40:46 +00003706
3707 // Result might be dependent or not.
3708 if (isa<DependentSizedExtVectorType>(Result)) {
3709 DependentSizedExtVectorTypeLoc NewTL
3710 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3711 NewTL.setNameLoc(TL.getNameLoc());
3712 } else {
3713 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3714 NewTL.setNameLoc(TL.getNameLoc());
3715 }
3716
3717 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718}
Mike Stump1eb44332009-09-09 15:08:12 +00003719
3720template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003721QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003722 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003723 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724 QualType ElementType = getDerived().TransformType(T->getElementType());
3725 if (ElementType.isNull())
3726 return QualType();
3727
John McCalla2becad2009-10-21 00:40:46 +00003728 QualType Result = TL.getType();
3729 if (getDerived().AlwaysRebuild() ||
3730 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003731 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003732 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003733 if (Result.isNull())
3734 return QualType();
3735 }
Sean Huntc3021132010-05-05 15:23:54 +00003736
John McCalla2becad2009-10-21 00:40:46 +00003737 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3738 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003739
John McCalla2becad2009-10-21 00:40:46 +00003740 return Result;
3741}
3742
3743template<typename Derived>
3744QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003745 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003746 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003747 QualType ElementType = getDerived().TransformType(T->getElementType());
3748 if (ElementType.isNull())
3749 return QualType();
3750
3751 QualType Result = TL.getType();
3752 if (getDerived().AlwaysRebuild() ||
3753 ElementType != T->getElementType()) {
3754 Result = getDerived().RebuildExtVectorType(ElementType,
3755 T->getNumElements(),
3756 /*FIXME*/ SourceLocation());
3757 if (Result.isNull())
3758 return QualType();
3759 }
Sean Huntc3021132010-05-05 15:23:54 +00003760
John McCalla2becad2009-10-21 00:40:46 +00003761 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3762 NewTL.setNameLoc(TL.getNameLoc());
3763
3764 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003765}
Mike Stump1eb44332009-09-09 15:08:12 +00003766
3767template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003768ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003769TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003770 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003771 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003772 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003773 TypeSourceInfo *NewDI = 0;
3774
3775 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3776 // If we're substituting into a pack expansion type and we know the
3777 TypeLoc OldTL = OldDI->getTypeLoc();
3778 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3779
3780 TypeLocBuilder TLB;
3781 TypeLoc NewTL = OldDI->getTypeLoc();
3782 TLB.reserve(NewTL.getFullDataSize());
3783
3784 QualType Result = getDerived().TransformType(TLB,
3785 OldExpansionTL.getPatternLoc());
3786 if (Result.isNull())
3787 return 0;
3788
3789 Result = RebuildPackExpansionType(Result,
3790 OldExpansionTL.getPatternLoc().getSourceRange(),
3791 OldExpansionTL.getEllipsisLoc(),
3792 NumExpansions);
3793 if (Result.isNull())
3794 return 0;
3795
3796 PackExpansionTypeLoc NewExpansionTL
3797 = TLB.push<PackExpansionTypeLoc>(Result);
3798 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3799 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3800 } else
3801 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003802 if (!NewDI)
3803 return 0;
3804
John McCallfb44de92011-05-01 22:35:37 +00003805 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003806 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003807
3808 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3809 OldParm->getDeclContext(),
3810 OldParm->getInnerLocStart(),
3811 OldParm->getLocation(),
3812 OldParm->getIdentifier(),
3813 NewDI->getType(),
3814 NewDI,
3815 OldParm->getStorageClass(),
3816 OldParm->getStorageClassAsWritten(),
3817 /* DefArg */ NULL);
3818 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3819 OldParm->getFunctionScopeIndex() + indexAdjustment);
3820 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003821}
3822
3823template<typename Derived>
3824bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003825 TransformFunctionTypeParams(SourceLocation Loc,
3826 ParmVarDecl **Params, unsigned NumParams,
3827 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003828 SmallVectorImpl<QualType> &OutParamTypes,
3829 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003830 int indexAdjustment = 0;
3831
Douglas Gregora009b592011-01-07 00:20:55 +00003832 for (unsigned i = 0; i != NumParams; ++i) {
3833 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003834 assert(OldParm->getFunctionScopeIndex() == i);
3835
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003836 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003837 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003838 if (OldParm->isParameterPack()) {
3839 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003840 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003841
Douglas Gregor603cfb42011-01-05 23:12:31 +00003842 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003843 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3844 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3845 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3846 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003847 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3848
Douglas Gregor603cfb42011-01-05 23:12:31 +00003849 // Determine whether we should expand the parameter packs.
3850 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003851 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003852 llvm::Optional<unsigned> OrigNumExpansions
3853 = ExpansionTL.getTypePtr()->getNumExpansions();
3854 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003855 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3856 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003857 Unexpanded.data(),
3858 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003859 ShouldExpand,
3860 RetainExpansion,
3861 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003862 return true;
3863 }
3864
3865 if (ShouldExpand) {
3866 // Expand the function parameter pack into multiple, separate
3867 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003868 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003869 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003870 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3871 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003872 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003873 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003874 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003875 if (!NewParm)
3876 return true;
3877
Douglas Gregora009b592011-01-07 00:20:55 +00003878 OutParamTypes.push_back(NewParm->getType());
3879 if (PVars)
3880 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003881 }
Douglas Gregord3731192011-01-10 07:32:04 +00003882
3883 // If we're supposed to retain a pack expansion, do so by temporarily
3884 // forgetting the partially-substituted parameter pack.
3885 if (RetainExpansion) {
3886 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3887 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003888 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003889 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003890 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003891 if (!NewParm)
3892 return true;
3893
3894 OutParamTypes.push_back(NewParm->getType());
3895 if (PVars)
3896 PVars->push_back(NewParm);
3897 }
3898
John McCallfb44de92011-05-01 22:35:37 +00003899 // The next parameter should have the same adjustment as the
3900 // last thing we pushed, but we post-incremented indexAdjustment
3901 // on every push. Also, if we push nothing, the adjustment should
3902 // go down by one.
3903 indexAdjustment--;
3904
Douglas Gregor603cfb42011-01-05 23:12:31 +00003905 // We're done with the pack expansion.
3906 continue;
3907 }
3908
3909 // We'll substitute the parameter now without expanding the pack
3910 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3912 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003913 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003914 NumExpansions);
3915 } else {
3916 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003917 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003918 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003919 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003920
John McCall21ef0fa2010-03-11 09:03:00 +00003921 if (!NewParm)
3922 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003923
Douglas Gregora009b592011-01-07 00:20:55 +00003924 OutParamTypes.push_back(NewParm->getType());
3925 if (PVars)
3926 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003927 continue;
3928 }
John McCall21ef0fa2010-03-11 09:03:00 +00003929
3930 // Deal with the possibility that we don't have a parameter
3931 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003932 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003933 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003934 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003935 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003936 if (const PackExpansionType *Expansion
3937 = dyn_cast<PackExpansionType>(OldType)) {
3938 // We have a function parameter pack that may need to be expanded.
3939 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003940 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003941 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3942
3943 // Determine whether we should expand the parameter packs.
3944 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003945 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003946 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003947 Unexpanded.data(),
3948 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003949 ShouldExpand,
3950 RetainExpansion,
3951 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003952 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003953 }
3954
3955 if (ShouldExpand) {
3956 // Expand the function parameter pack into multiple, separate
3957 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003958 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003959 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3960 QualType NewType = getDerived().TransformType(Pattern);
3961 if (NewType.isNull())
3962 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003963
Douglas Gregora009b592011-01-07 00:20:55 +00003964 OutParamTypes.push_back(NewType);
3965 if (PVars)
3966 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003967 }
3968
3969 // We're done with the pack expansion.
3970 continue;
3971 }
3972
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003973 // If we're supposed to retain a pack expansion, do so by temporarily
3974 // forgetting the partially-substituted parameter pack.
3975 if (RetainExpansion) {
3976 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3977 QualType NewType = getDerived().TransformType(Pattern);
3978 if (NewType.isNull())
3979 return true;
3980
3981 OutParamTypes.push_back(NewType);
3982 if (PVars)
3983 PVars->push_back(0);
3984 }
Douglas Gregord3731192011-01-10 07:32:04 +00003985
Douglas Gregor603cfb42011-01-05 23:12:31 +00003986 // We'll substitute the parameter now without expanding the pack
3987 // expansion.
3988 OldType = Expansion->getPattern();
3989 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003990 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3991 NewType = getDerived().TransformType(OldType);
3992 } else {
3993 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003994 }
3995
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 if (NewType.isNull())
3997 return true;
3998
3999 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004000 NewType = getSema().Context.getPackExpansionType(NewType,
4001 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002
Douglas Gregora009b592011-01-07 00:20:55 +00004003 OutParamTypes.push_back(NewType);
4004 if (PVars)
4005 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004006 }
4007
John McCallfb44de92011-05-01 22:35:37 +00004008#ifndef NDEBUG
4009 if (PVars) {
4010 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4011 if (ParmVarDecl *parm = (*PVars)[i])
4012 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004013 }
John McCallfb44de92011-05-01 22:35:37 +00004014#endif
4015
4016 return false;
4017}
John McCall21ef0fa2010-03-11 09:03:00 +00004018
4019template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004020QualType
John McCalla2becad2009-10-21 00:40:46 +00004021TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004022 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004023 // Transform the parameters and return type.
4024 //
4025 // We instantiate in source order, with the return type first followed by
4026 // the parameters, because users tend to expect this (even if they shouldn't
4027 // rely on it!).
4028 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004029 // When the function has a trailing return type, we instantiate the
4030 // parameters before the return type, since the return type can then refer
4031 // to the parameters themselves (via decltype, sizeof, etc.).
4032 //
Chris Lattner686775d2011-07-20 06:58:45 +00004033 SmallVector<QualType, 4> ParamTypes;
4034 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004035 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004036
Douglas Gregordab60ad2010-10-01 18:44:50 +00004037 QualType ResultType;
4038
4039 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004040 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4041 TL.getParmArray(),
4042 TL.getNumArgs(),
4043 TL.getTypePtr()->arg_type_begin(),
4044 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004045 return QualType();
4046
4047 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4048 if (ResultType.isNull())
4049 return QualType();
4050 }
4051 else {
4052 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4053 if (ResultType.isNull())
4054 return QualType();
4055
Douglas Gregora009b592011-01-07 00:20:55 +00004056 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4057 TL.getParmArray(),
4058 TL.getNumArgs(),
4059 TL.getTypePtr()->arg_type_begin(),
4060 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004061 return QualType();
4062 }
4063
John McCalla2becad2009-10-21 00:40:46 +00004064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004067 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004068 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4069 Result = getDerived().RebuildFunctionProtoType(ResultType,
4070 ParamTypes.data(),
4071 ParamTypes.size(),
4072 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004073 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004074 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004075 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004076 if (Result.isNull())
4077 return QualType();
4078 }
Mike Stump1eb44332009-09-09 15:08:12 +00004079
John McCalla2becad2009-10-21 00:40:46 +00004080 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004081 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4082 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004083 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004084 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4085 NewTL.setArg(i, ParamDecls[i]);
4086
4087 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004088}
Mike Stump1eb44332009-09-09 15:08:12 +00004089
Douglas Gregor577f75a2009-08-04 16:50:30 +00004090template<typename Derived>
4091QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004092 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004093 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004094 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004095 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4096 if (ResultType.isNull())
4097 return QualType();
4098
4099 QualType Result = TL.getType();
4100 if (getDerived().AlwaysRebuild() ||
4101 ResultType != T->getResultType())
4102 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4103
4104 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004105 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4106 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004107 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004108
4109 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004110}
Mike Stump1eb44332009-09-09 15:08:12 +00004111
John McCalled976492009-12-04 22:46:56 +00004112template<typename Derived> QualType
4113TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004114 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004115 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004116 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004117 if (!D)
4118 return QualType();
4119
4120 QualType Result = TL.getType();
4121 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4122 Result = getDerived().RebuildUnresolvedUsingType(D);
4123 if (Result.isNull())
4124 return QualType();
4125 }
4126
4127 // We might get an arbitrary type spec type back. We should at
4128 // least always get a type spec type, though.
4129 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4130 NewTL.setNameLoc(TL.getNameLoc());
4131
4132 return Result;
4133}
4134
Douglas Gregor577f75a2009-08-04 16:50:30 +00004135template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004136QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004137 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004138 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004139 TypedefNameDecl *Typedef
4140 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4141 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004142 if (!Typedef)
4143 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004144
John McCalla2becad2009-10-21 00:40:46 +00004145 QualType Result = TL.getType();
4146 if (getDerived().AlwaysRebuild() ||
4147 Typedef != T->getDecl()) {
4148 Result = getDerived().RebuildTypedefType(Typedef);
4149 if (Result.isNull())
4150 return QualType();
4151 }
Mike Stump1eb44332009-09-09 15:08:12 +00004152
John McCalla2becad2009-10-21 00:40:46 +00004153 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4154 NewTL.setNameLoc(TL.getNameLoc());
4155
4156 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004157}
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregor577f75a2009-08-04 16:50:30 +00004159template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004160QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004161 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004162 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004163 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004164
John McCall60d7b3a2010-08-24 06:29:42 +00004165 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004166 if (E.isInvalid())
4167 return QualType();
4168
John McCalla2becad2009-10-21 00:40:46 +00004169 QualType Result = TL.getType();
4170 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004171 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004172 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004173 if (Result.isNull())
4174 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004175 }
John McCalla2becad2009-10-21 00:40:46 +00004176 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004177
John McCalla2becad2009-10-21 00:40:46 +00004178 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004179 NewTL.setTypeofLoc(TL.getTypeofLoc());
4180 NewTL.setLParenLoc(TL.getLParenLoc());
4181 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004182
4183 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004184}
Mike Stump1eb44332009-09-09 15:08:12 +00004185
4186template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004187QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004188 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004189 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4190 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4191 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004192 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004193
John McCalla2becad2009-10-21 00:40:46 +00004194 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004195 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4196 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004197 if (Result.isNull())
4198 return QualType();
4199 }
Mike Stump1eb44332009-09-09 15:08:12 +00004200
John McCalla2becad2009-10-21 00:40:46 +00004201 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004202 NewTL.setTypeofLoc(TL.getTypeofLoc());
4203 NewTL.setLParenLoc(TL.getLParenLoc());
4204 NewTL.setRParenLoc(TL.getRParenLoc());
4205 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004206
4207 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004208}
Mike Stump1eb44332009-09-09 15:08:12 +00004209
4210template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004211QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004212 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004213 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004214
Douglas Gregor670444e2009-08-04 22:27:00 +00004215 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004216 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004217
John McCall60d7b3a2010-08-24 06:29:42 +00004218 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004219 if (E.isInvalid())
4220 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004221
John McCalla2becad2009-10-21 00:40:46 +00004222 QualType Result = TL.getType();
4223 if (getDerived().AlwaysRebuild() ||
4224 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004225 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004226 if (Result.isNull())
4227 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004228 }
John McCalla2becad2009-10-21 00:40:46 +00004229 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004230
John McCalla2becad2009-10-21 00:40:46 +00004231 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4232 NewTL.setNameLoc(TL.getNameLoc());
4233
4234 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004235}
4236
4237template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004238QualType TreeTransform<Derived>::TransformUnaryTransformType(
4239 TypeLocBuilder &TLB,
4240 UnaryTransformTypeLoc TL) {
4241 QualType Result = TL.getType();
4242 if (Result->isDependentType()) {
4243 const UnaryTransformType *T = TL.getTypePtr();
4244 QualType NewBase =
4245 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4246 Result = getDerived().RebuildUnaryTransformType(NewBase,
4247 T->getUTTKind(),
4248 TL.getKWLoc());
4249 if (Result.isNull())
4250 return QualType();
4251 }
4252
4253 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4254 NewTL.setKWLoc(TL.getKWLoc());
4255 NewTL.setParensRange(TL.getParensRange());
4256 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4257 return Result;
4258}
4259
4260template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004261QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4262 AutoTypeLoc TL) {
4263 const AutoType *T = TL.getTypePtr();
4264 QualType OldDeduced = T->getDeducedType();
4265 QualType NewDeduced;
4266 if (!OldDeduced.isNull()) {
4267 NewDeduced = getDerived().TransformType(OldDeduced);
4268 if (NewDeduced.isNull())
4269 return QualType();
4270 }
4271
4272 QualType Result = TL.getType();
4273 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4274 Result = getDerived().RebuildAutoType(NewDeduced);
4275 if (Result.isNull())
4276 return QualType();
4277 }
4278
4279 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4280 NewTL.setNameLoc(TL.getNameLoc());
4281
4282 return Result;
4283}
4284
4285template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004286QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004287 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004288 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004289 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004290 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4291 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004292 if (!Record)
4293 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004294
John McCalla2becad2009-10-21 00:40:46 +00004295 QualType Result = TL.getType();
4296 if (getDerived().AlwaysRebuild() ||
4297 Record != T->getDecl()) {
4298 Result = getDerived().RebuildRecordType(Record);
4299 if (Result.isNull())
4300 return QualType();
4301 }
Mike Stump1eb44332009-09-09 15:08:12 +00004302
John McCalla2becad2009-10-21 00:40:46 +00004303 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4304 NewTL.setNameLoc(TL.getNameLoc());
4305
4306 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004307}
Mike Stump1eb44332009-09-09 15:08:12 +00004308
4309template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004310QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004311 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004312 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004313 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004314 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4315 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004316 if (!Enum)
4317 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004318
John McCalla2becad2009-10-21 00:40:46 +00004319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() ||
4321 Enum != T->getDecl()) {
4322 Result = getDerived().RebuildEnumType(Enum);
4323 if (Result.isNull())
4324 return QualType();
4325 }
Mike Stump1eb44332009-09-09 15:08:12 +00004326
John McCalla2becad2009-10-21 00:40:46 +00004327 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4328 NewTL.setNameLoc(TL.getNameLoc());
4329
4330 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004331}
John McCall7da24312009-09-05 00:15:47 +00004332
John McCall3cb0ebd2010-03-10 03:28:59 +00004333template<typename Derived>
4334QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4335 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004336 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004337 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4338 TL.getTypePtr()->getDecl());
4339 if (!D) return QualType();
4340
4341 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4342 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4343 return T;
4344}
4345
Douglas Gregor577f75a2009-08-04 16:50:30 +00004346template<typename Derived>
4347QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004348 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004349 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004350 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004351}
4352
Mike Stump1eb44332009-09-09 15:08:12 +00004353template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004354QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004355 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004356 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004357 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4358
4359 // Substitute into the replacement type, which itself might involve something
4360 // that needs to be transformed. This only tends to occur with default
4361 // template arguments of template template parameters.
4362 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4363 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4364 if (Replacement.isNull())
4365 return QualType();
4366
4367 // Always canonicalize the replacement type.
4368 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4369 QualType Result
4370 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4371 Replacement);
4372
4373 // Propagate type-source information.
4374 SubstTemplateTypeParmTypeLoc NewTL
4375 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4376 NewTL.setNameLoc(TL.getNameLoc());
4377 return Result;
4378
John McCall49a832b2009-10-18 09:09:24 +00004379}
4380
4381template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004382QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4383 TypeLocBuilder &TLB,
4384 SubstTemplateTypeParmPackTypeLoc TL) {
4385 return TransformTypeSpecType(TLB, TL);
4386}
4387
4388template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004389QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004390 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004391 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004392 const TemplateSpecializationType *T = TL.getTypePtr();
4393
Douglas Gregor1d752d72011-03-02 18:46:51 +00004394 // The nested-name-specifier never matters in a TemplateSpecializationType,
4395 // because we can't have a dependent nested-name-specifier anyway.
4396 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004397 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004398 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4399 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004400 if (Template.isNull())
4401 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004402
John McCall43fed0d2010-11-12 08:19:04 +00004403 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4404}
4405
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004406namespace {
4407 /// \brief Simple iterator that traverses the template arguments in a
4408 /// container that provides a \c getArgLoc() member function.
4409 ///
4410 /// This iterator is intended to be used with the iterator form of
4411 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4412 template<typename ArgLocContainer>
4413 class TemplateArgumentLocContainerIterator {
4414 ArgLocContainer *Container;
4415 unsigned Index;
4416
4417 public:
4418 typedef TemplateArgumentLoc value_type;
4419 typedef TemplateArgumentLoc reference;
4420 typedef int difference_type;
4421 typedef std::input_iterator_tag iterator_category;
4422
4423 class pointer {
4424 TemplateArgumentLoc Arg;
4425
4426 public:
4427 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4428
4429 const TemplateArgumentLoc *operator->() const {
4430 return &Arg;
4431 }
4432 };
4433
4434
4435 TemplateArgumentLocContainerIterator() {}
4436
4437 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4438 unsigned Index)
4439 : Container(&Container), Index(Index) { }
4440
4441 TemplateArgumentLocContainerIterator &operator++() {
4442 ++Index;
4443 return *this;
4444 }
4445
4446 TemplateArgumentLocContainerIterator operator++(int) {
4447 TemplateArgumentLocContainerIterator Old(*this);
4448 ++(*this);
4449 return Old;
4450 }
4451
4452 TemplateArgumentLoc operator*() const {
4453 return Container->getArgLoc(Index);
4454 }
4455
4456 pointer operator->() const {
4457 return pointer(Container->getArgLoc(Index));
4458 }
4459
4460 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004461 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004462 return X.Container == Y.Container && X.Index == Y.Index;
4463 }
4464
4465 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004466 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004467 return !(X == Y);
4468 }
4469 };
4470}
4471
4472
John McCall43fed0d2010-11-12 08:19:04 +00004473template <typename Derived>
4474QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4475 TypeLocBuilder &TLB,
4476 TemplateSpecializationTypeLoc TL,
4477 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004478 TemplateArgumentListInfo NewTemplateArgs;
4479 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4480 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004481 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4482 ArgIterator;
4483 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4484 ArgIterator(TL, TL.getNumArgs()),
4485 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004486 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCall833ca992009-10-29 08:12:44 +00004488 // FIXME: maybe don't rebuild if all the template arguments are the same.
4489
4490 QualType Result =
4491 getDerived().RebuildTemplateSpecializationType(Template,
4492 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004493 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004494
4495 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004496 // Specializations of template template parameters are represented as
4497 // TemplateSpecializationTypes, and substitution of type alias templates
4498 // within a dependent context can transform them into
4499 // DependentTemplateSpecializationTypes.
4500 if (isa<DependentTemplateSpecializationType>(Result)) {
4501 DependentTemplateSpecializationTypeLoc NewTL
4502 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4503 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4504 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4505 NewTL.setNameLoc(TL.getTemplateNameLoc());
4506 NewTL.setLAngleLoc(TL.getLAngleLoc());
4507 NewTL.setRAngleLoc(TL.getRAngleLoc());
4508 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4509 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4510 return Result;
4511 }
4512
John McCall833ca992009-10-29 08:12:44 +00004513 TemplateSpecializationTypeLoc NewTL
4514 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4515 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4516 NewTL.setLAngleLoc(TL.getLAngleLoc());
4517 NewTL.setRAngleLoc(TL.getRAngleLoc());
4518 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4519 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004520 }
Mike Stump1eb44332009-09-09 15:08:12 +00004521
John McCall833ca992009-10-29 08:12:44 +00004522 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004523}
Mike Stump1eb44332009-09-09 15:08:12 +00004524
Douglas Gregora88f09f2011-02-28 17:23:35 +00004525template <typename Derived>
4526QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4527 TypeLocBuilder &TLB,
4528 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004529 TemplateName Template,
4530 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004531 TemplateArgumentListInfo NewTemplateArgs;
4532 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4533 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4534 typedef TemplateArgumentLocContainerIterator<
4535 DependentTemplateSpecializationTypeLoc> ArgIterator;
4536 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4537 ArgIterator(TL, TL.getNumArgs()),
4538 NewTemplateArgs))
4539 return QualType();
4540
4541 // FIXME: maybe don't rebuild if all the template arguments are the same.
4542
4543 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4544 QualType Result
4545 = getSema().Context.getDependentTemplateSpecializationType(
4546 TL.getTypePtr()->getKeyword(),
4547 DTN->getQualifier(),
4548 DTN->getIdentifier(),
4549 NewTemplateArgs);
4550
4551 DependentTemplateSpecializationTypeLoc NewTL
4552 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4553 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004554
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004555 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004556 NewTL.setNameLoc(TL.getNameLoc());
4557 NewTL.setLAngleLoc(TL.getLAngleLoc());
4558 NewTL.setRAngleLoc(TL.getRAngleLoc());
4559 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4560 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4561 return Result;
4562 }
4563
4564 QualType Result
4565 = getDerived().RebuildTemplateSpecializationType(Template,
4566 TL.getNameLoc(),
4567 NewTemplateArgs);
4568
4569 if (!Result.isNull()) {
4570 /// FIXME: Wrap this in an elaborated-type-specifier?
4571 TemplateSpecializationTypeLoc NewTL
4572 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4573 NewTL.setTemplateNameLoc(TL.getNameLoc());
4574 NewTL.setLAngleLoc(TL.getLAngleLoc());
4575 NewTL.setRAngleLoc(TL.getRAngleLoc());
4576 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4577 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4578 }
4579
4580 return Result;
4581}
4582
Mike Stump1eb44332009-09-09 15:08:12 +00004583template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004584QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004585TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004586 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004587 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004588
Douglas Gregor9e876872011-03-01 18:12:44 +00004589 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004590 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004591 if (TL.getQualifierLoc()) {
4592 QualifierLoc
4593 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4594 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004595 return QualType();
4596 }
Mike Stump1eb44332009-09-09 15:08:12 +00004597
John McCall43fed0d2010-11-12 08:19:04 +00004598 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4599 if (NamedT.isNull())
4600 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004601
Richard Smith3e4c6c42011-05-05 21:57:07 +00004602 // C++0x [dcl.type.elab]p2:
4603 // If the identifier resolves to a typedef-name or the simple-template-id
4604 // resolves to an alias template specialization, the
4605 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004606 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4607 if (const TemplateSpecializationType *TST =
4608 NamedT->getAs<TemplateSpecializationType>()) {
4609 TemplateName Template = TST->getTemplateName();
4610 if (TypeAliasTemplateDecl *TAT =
4611 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4612 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4613 diag::err_tag_reference_non_tag) << 4;
4614 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4615 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004616 }
4617 }
4618
John McCalla2becad2009-10-21 00:40:46 +00004619 QualType Result = TL.getType();
4620 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004621 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004622 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004623 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004624 T->getKeyword(),
4625 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004626 if (Result.isNull())
4627 return QualType();
4628 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004629
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004630 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004631 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004632 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004633 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004634}
Mike Stump1eb44332009-09-09 15:08:12 +00004635
4636template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004637QualType TreeTransform<Derived>::TransformAttributedType(
4638 TypeLocBuilder &TLB,
4639 AttributedTypeLoc TL) {
4640 const AttributedType *oldType = TL.getTypePtr();
4641 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4642 if (modifiedType.isNull())
4643 return QualType();
4644
4645 QualType result = TL.getType();
4646
4647 // FIXME: dependent operand expressions?
4648 if (getDerived().AlwaysRebuild() ||
4649 modifiedType != oldType->getModifiedType()) {
4650 // TODO: this is really lame; we should really be rebuilding the
4651 // equivalent type from first principles.
4652 QualType equivalentType
4653 = getDerived().TransformType(oldType->getEquivalentType());
4654 if (equivalentType.isNull())
4655 return QualType();
4656 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4657 modifiedType,
4658 equivalentType);
4659 }
4660
4661 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4662 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4663 if (TL.hasAttrOperand())
4664 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4665 if (TL.hasAttrExprOperand())
4666 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4667 else if (TL.hasAttrEnumOperand())
4668 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4669
4670 return result;
4671}
4672
4673template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004674QualType
4675TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4676 ParenTypeLoc TL) {
4677 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4678 if (Inner.isNull())
4679 return QualType();
4680
4681 QualType Result = TL.getType();
4682 if (getDerived().AlwaysRebuild() ||
4683 Inner != TL.getInnerLoc().getType()) {
4684 Result = getDerived().RebuildParenType(Inner);
4685 if (Result.isNull())
4686 return QualType();
4687 }
4688
4689 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4690 NewTL.setLParenLoc(TL.getLParenLoc());
4691 NewTL.setRParenLoc(TL.getRParenLoc());
4692 return Result;
4693}
4694
4695template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004696QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004697 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004698 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004699
Douglas Gregor2494dd02011-03-01 01:34:45 +00004700 NestedNameSpecifierLoc QualifierLoc
4701 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4702 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004703 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004704
John McCall33500952010-06-11 00:33:02 +00004705 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004706 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004707 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004708 QualifierLoc,
4709 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004710 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004711 if (Result.isNull())
4712 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004713
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004714 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4715 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004716 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4717
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004718 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4719 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004720 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004721 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004722 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4723 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004724 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004725 NewTL.setNameLoc(TL.getNameLoc());
4726 }
John McCalla2becad2009-10-21 00:40:46 +00004727 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004728}
Mike Stump1eb44332009-09-09 15:08:12 +00004729
Douglas Gregor577f75a2009-08-04 16:50:30 +00004730template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004731QualType TreeTransform<Derived>::
4732 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004733 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004734 NestedNameSpecifierLoc QualifierLoc;
4735 if (TL.getQualifierLoc()) {
4736 QualifierLoc
4737 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4738 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004739 return QualType();
4740 }
4741
John McCall43fed0d2010-11-12 08:19:04 +00004742 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004743 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004744}
4745
4746template<typename Derived>
4747QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004748TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4749 DependentTemplateSpecializationTypeLoc TL,
4750 NestedNameSpecifierLoc QualifierLoc) {
4751 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4752
4753 TemplateArgumentListInfo NewTemplateArgs;
4754 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4755 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4756
4757 typedef TemplateArgumentLocContainerIterator<
4758 DependentTemplateSpecializationTypeLoc> ArgIterator;
4759 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4760 ArgIterator(TL, TL.getNumArgs()),
4761 NewTemplateArgs))
4762 return QualType();
4763
4764 QualType Result
4765 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4766 QualifierLoc,
4767 T->getIdentifier(),
4768 TL.getNameLoc(),
4769 NewTemplateArgs);
4770 if (Result.isNull())
4771 return QualType();
4772
4773 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4774 QualType NamedT = ElabT->getNamedType();
4775
4776 // Copy information relevant to the template specialization.
4777 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004778 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004779 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004780 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4781 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004782 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004783 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004784
4785 // Copy information relevant to the elaborated type.
4786 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4787 NewTL.setKeywordLoc(TL.getKeywordLoc());
4788 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004789 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4790 DependentTemplateSpecializationTypeLoc SpecTL
4791 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004792 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004793 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004794 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004795 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4796 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004797 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004798 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004799 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004800 TemplateSpecializationTypeLoc SpecTL
4801 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004802 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004803 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4804 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004805 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004806 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004807 }
4808 return Result;
4809}
4810
4811template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004812QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4813 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004814 QualType Pattern
4815 = getDerived().TransformType(TLB, TL.getPatternLoc());
4816 if (Pattern.isNull())
4817 return QualType();
4818
4819 QualType Result = TL.getType();
4820 if (getDerived().AlwaysRebuild() ||
4821 Pattern != TL.getPatternLoc().getType()) {
4822 Result = getDerived().RebuildPackExpansionType(Pattern,
4823 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004824 TL.getEllipsisLoc(),
4825 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004826 if (Result.isNull())
4827 return QualType();
4828 }
4829
4830 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4831 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4832 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004833}
4834
4835template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004836QualType
4837TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004838 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004839 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004840 TLB.pushFullCopy(TL);
4841 return TL.getType();
4842}
4843
4844template<typename Derived>
4845QualType
4846TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004847 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004848 // ObjCObjectType is never dependent.
4849 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004850 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004851}
Mike Stump1eb44332009-09-09 15:08:12 +00004852
4853template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004854QualType
4855TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004856 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004857 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004858 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004859 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004860}
4861
Douglas Gregor577f75a2009-08-04 16:50:30 +00004862//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004863// Statement transformation
4864//===----------------------------------------------------------------------===//
4865template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004866StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004867TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004868 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004869}
4870
4871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004872StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004873TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4874 return getDerived().TransformCompoundStmt(S, false);
4875}
4876
4877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004878StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004879TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004880 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004881 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004882 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004883 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004884 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4885 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004886 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004887 if (Result.isInvalid()) {
4888 // Immediately fail if this was a DeclStmt, since it's very
4889 // likely that this will cause problems for future statements.
4890 if (isa<DeclStmt>(*B))
4891 return StmtError();
4892
4893 // Otherwise, just keep processing substatements and fail later.
4894 SubStmtInvalid = true;
4895 continue;
4896 }
Mike Stump1eb44332009-09-09 15:08:12 +00004897
Douglas Gregor43959a92009-08-20 07:17:43 +00004898 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4899 Statements.push_back(Result.takeAs<Stmt>());
4900 }
Mike Stump1eb44332009-09-09 15:08:12 +00004901
John McCall7114cba2010-08-27 19:56:05 +00004902 if (SubStmtInvalid)
4903 return StmtError();
4904
Douglas Gregor43959a92009-08-20 07:17:43 +00004905 if (!getDerived().AlwaysRebuild() &&
4906 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004907 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004908
4909 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4910 move_arg(Statements),
4911 S->getRBracLoc(),
4912 IsStmtExpr);
4913}
Mike Stump1eb44332009-09-09 15:08:12 +00004914
Douglas Gregor43959a92009-08-20 07:17:43 +00004915template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004916StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004917TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004918 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004919 {
4920 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004921 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004922
Eli Friedman264c1f82009-11-19 03:14:00 +00004923 // Transform the left-hand case value.
4924 LHS = getDerived().TransformExpr(S->getLHS());
4925 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004926 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004927
Eli Friedman264c1f82009-11-19 03:14:00 +00004928 // Transform the right-hand case value (for the GNU case-range extension).
4929 RHS = getDerived().TransformExpr(S->getRHS());
4930 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004931 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004932 }
Mike Stump1eb44332009-09-09 15:08:12 +00004933
Douglas Gregor43959a92009-08-20 07:17:43 +00004934 // Build the case statement.
4935 // Case statements are always rebuilt so that they will attached to their
4936 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004937 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004938 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004939 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004940 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004941 S->getColonLoc());
4942 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004943 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004944
Douglas Gregor43959a92009-08-20 07:17:43 +00004945 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004946 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004947 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004948 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004949
Douglas Gregor43959a92009-08-20 07:17:43 +00004950 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004951 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004952}
4953
4954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004955StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004956TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004957 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004958 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004959 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004960 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004961
Douglas Gregor43959a92009-08-20 07:17:43 +00004962 // Default statements are always rebuilt
4963 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004964 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004965}
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregor43959a92009-08-20 07:17:43 +00004967template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004968StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004969TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004970 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004971 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004972 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004973
Chris Lattner57ad3782011-02-17 20:34:02 +00004974 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4975 S->getDecl());
4976 if (!LD)
4977 return StmtError();
4978
4979
Douglas Gregor43959a92009-08-20 07:17:43 +00004980 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004981 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004982 cast<LabelDecl>(LD), SourceLocation(),
4983 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004984}
Mike Stump1eb44332009-09-09 15:08:12 +00004985
Douglas Gregor43959a92009-08-20 07:17:43 +00004986template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004987StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004988TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004989 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004990 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004991 VarDecl *ConditionVar = 0;
4992 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004993 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004994 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004995 getDerived().TransformDefinition(
4996 S->getConditionVariable()->getLocation(),
4997 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004998 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004999 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005000 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005001 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005002
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005003 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005004 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005005
5006 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005007 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005008 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5009 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005010 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005011 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005012
John McCall9ae2f072010-08-23 23:25:46 +00005013 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005014 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005015 }
Sean Huntc3021132010-05-05 15:23:54 +00005016
John McCall9ae2f072010-08-23 23:25:46 +00005017 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5018 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005019 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005020
Douglas Gregor43959a92009-08-20 07:17:43 +00005021 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005022 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005023 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005024 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005025
Douglas Gregor43959a92009-08-20 07:17:43 +00005026 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005027 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005028 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005029 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005030
Douglas Gregor43959a92009-08-20 07:17:43 +00005031 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005032 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005033 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005034 Then.get() == S->getThen() &&
5035 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005036 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005037
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005038 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005039 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005040 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005041}
5042
5043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005044StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005045TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005046 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005047 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005048 VarDecl *ConditionVar = 0;
5049 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005050 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005051 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005052 getDerived().TransformDefinition(
5053 S->getConditionVariable()->getLocation(),
5054 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005055 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005056 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005057 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005058 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005059
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005060 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005061 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005062 }
Mike Stump1eb44332009-09-09 15:08:12 +00005063
Douglas Gregor43959a92009-08-20 07:17:43 +00005064 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005065 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005066 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005067 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005068 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005069 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005070
Douglas Gregor43959a92009-08-20 07:17:43 +00005071 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005072 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005073 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005074 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregor43959a92009-08-20 07:17:43 +00005076 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005077 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5078 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005079}
Mike Stump1eb44332009-09-09 15:08:12 +00005080
Douglas Gregor43959a92009-08-20 07:17:43 +00005081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005082StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005083TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005084 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005085 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005086 VarDecl *ConditionVar = 0;
5087 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005088 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005089 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005090 getDerived().TransformDefinition(
5091 S->getConditionVariable()->getLocation(),
5092 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005093 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005094 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005095 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005096 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005097
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005098 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005099 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005100
5101 if (S->getCond()) {
5102 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005103 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5104 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005105 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005106 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005107 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005108 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005109 }
Mike Stump1eb44332009-09-09 15:08:12 +00005110
John McCall9ae2f072010-08-23 23:25:46 +00005111 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5112 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005113 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005116 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005118 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005121 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005122 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005124 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005125
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005126 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005127 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005128}
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregor43959a92009-08-20 07:17:43 +00005130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005131StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005132TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005134 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005135 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005136 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005138 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005139 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005140 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005141 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005142
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 if (!getDerived().AlwaysRebuild() &&
5144 Cond.get() == S->getCond() &&
5145 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005146 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005147
John McCall9ae2f072010-08-23 23:25:46 +00005148 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5149 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 S->getRParenLoc());
5151}
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005154StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005155TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005156 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005157 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005159 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005162 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005163 VarDecl *ConditionVar = 0;
5164 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005165 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005166 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005167 getDerived().TransformDefinition(
5168 S->getConditionVariable()->getLocation(),
5169 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005170 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005171 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005172 } else {
5173 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005174
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005175 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005176 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005177
5178 if (S->getCond()) {
5179 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005180 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5181 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005182 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005184
John McCall9ae2f072010-08-23 23:25:46 +00005185 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005186 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005187 }
Mike Stump1eb44332009-09-09 15:08:12 +00005188
John McCall9ae2f072010-08-23 23:25:46 +00005189 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5190 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005191 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005192
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005194 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005196 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005197
John McCall9ae2f072010-08-23 23:25:46 +00005198 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5199 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005200 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005201
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005203 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005205 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005206
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 if (!getDerived().AlwaysRebuild() &&
5208 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005209 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 Inc.get() == S->getInc() &&
5211 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005212 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005215 Init.get(), FullCond, ConditionVar,
5216 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005217}
5218
5219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005220StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005221TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005222 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5223 S->getLabel());
5224 if (!LD)
5225 return StmtError();
5226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005228 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005229 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005230}
5231
5232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005233StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005234TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005235 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005236 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005237 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregor43959a92009-08-20 07:17:43 +00005239 if (!getDerived().AlwaysRebuild() &&
5240 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005241 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005242
5243 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005244 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005245}
5246
5247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005248StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005249TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005250 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005251}
Mike Stump1eb44332009-09-09 15:08:12 +00005252
Douglas Gregor43959a92009-08-20 07:17:43 +00005253template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005254StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005255TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005256 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005257}
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005260StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005261TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005262 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005265
Mike Stump1eb44332009-09-09 15:08:12 +00005266 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005268 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005269}
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregor43959a92009-08-20 07:17:43 +00005271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005272StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005273TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005275 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5277 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005278 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5279 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 if (Transformed != *D)
5284 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005285
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 Decls.push_back(Transformed);
5287 }
Mike Stump1eb44332009-09-09 15:08:12 +00005288
Douglas Gregor43959a92009-08-20 07:17:43 +00005289 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005290 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005291
5292 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 S->getStartLoc(), S->getEndLoc());
5294}
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregor43959a92009-08-20 07:17:43 +00005296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005297StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005298TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005299
John McCallca0408f2010-08-23 06:44:23 +00005300 ASTOwningVector<Expr*> Constraints(getSema());
5301 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005302 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005303
John McCall60d7b3a2010-08-24 06:29:42 +00005304 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005305 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005306
5307 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005308
Anders Carlsson703e3942010-01-24 05:50:09 +00005309 // Go through the outputs.
5310 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005311 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005312
Anders Carlsson703e3942010-01-24 05:50:09 +00005313 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005314 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005315
Anders Carlsson703e3942010-01-24 05:50:09 +00005316 // Transform the output expr.
5317 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005318 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005319 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005320 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005321
Anders Carlsson703e3942010-01-24 05:50:09 +00005322 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005323
John McCall9ae2f072010-08-23 23:25:46 +00005324 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005325 }
Sean Huntc3021132010-05-05 15:23:54 +00005326
Anders Carlsson703e3942010-01-24 05:50:09 +00005327 // Go through the inputs.
5328 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005329 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005330
Anders Carlsson703e3942010-01-24 05:50:09 +00005331 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005332 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005333
Anders Carlsson703e3942010-01-24 05:50:09 +00005334 // Transform the input expr.
5335 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005336 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005337 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005339
Anders Carlsson703e3942010-01-24 05:50:09 +00005340 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005341
John McCall9ae2f072010-08-23 23:25:46 +00005342 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005343 }
Sean Huntc3021132010-05-05 15:23:54 +00005344
Anders Carlsson703e3942010-01-24 05:50:09 +00005345 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005346 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005347
5348 // Go through the clobbers.
5349 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005350 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005351
5352 // No need to transform the asm string literal.
5353 AsmString = SemaRef.Owned(S->getAsmString());
5354
5355 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5356 S->isSimple(),
5357 S->isVolatile(),
5358 S->getNumOutputs(),
5359 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005360 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005361 move_arg(Constraints),
5362 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005363 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005364 move_arg(Clobbers),
5365 S->getRParenLoc(),
5366 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005367}
5368
5369
5370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005372TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005373 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005374 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005375 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005377
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005378 // Transform the @catch statements (if present).
5379 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005380 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005381 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005382 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005383 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005385 if (Catch.get() != S->getCatchStmt(I))
5386 AnyCatchChanged = true;
5387 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005388 }
Sean Huntc3021132010-05-05 15:23:54 +00005389
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005390 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005391 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005392 if (S->getFinallyStmt()) {
5393 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5394 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005396 }
5397
5398 // If nothing changed, just retain this statement.
5399 if (!getDerived().AlwaysRebuild() &&
5400 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005401 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005402 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005403 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005404
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005405 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005406 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5407 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408}
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005413 // Transform the @catch parameter, if there is one.
5414 VarDecl *Var = 0;
5415 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5416 TypeSourceInfo *TSInfo = 0;
5417 if (FromVar->getTypeSourceInfo()) {
5418 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5419 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005421 }
Sean Huntc3021132010-05-05 15:23:54 +00005422
Douglas Gregorbe270a02010-04-26 17:57:08 +00005423 QualType T;
5424 if (TSInfo)
5425 T = TSInfo->getType();
5426 else {
5427 T = getDerived().TransformType(FromVar->getType());
5428 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005429 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005430 }
Sean Huntc3021132010-05-05 15:23:54 +00005431
Douglas Gregorbe270a02010-04-26 17:57:08 +00005432 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5433 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005434 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005435 }
Sean Huntc3021132010-05-05 15:23:54 +00005436
John McCall60d7b3a2010-08-24 06:29:42 +00005437 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005438 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005439 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005440
5441 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005442 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005443 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005444}
Mike Stump1eb44332009-09-09 15:08:12 +00005445
Douglas Gregor43959a92009-08-20 07:17:43 +00005446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005447StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005448TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005449 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005450 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005451 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005453
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005454 // If nothing changed, just retain this statement.
5455 if (!getDerived().AlwaysRebuild() &&
5456 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005457 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005458
5459 // Build a new statement.
5460 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005461 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005462}
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005465StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005466TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005467 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005468 if (S->getThrowExpr()) {
5469 Operand = getDerived().TransformExpr(S->getThrowExpr());
5470 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005472 }
Sean Huntc3021132010-05-05 15:23:54 +00005473
Douglas Gregord1377b22010-04-22 21:44:01 +00005474 if (!getDerived().AlwaysRebuild() &&
5475 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005476 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005477
John McCall9ae2f072010-08-23 23:25:46 +00005478 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005479}
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregor43959a92009-08-20 07:17:43 +00005481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005482StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005483TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005484 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005485 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005486 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005487 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005489 Object =
5490 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5491 Object.get());
5492 if (Object.isInvalid())
5493 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005494
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005495 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005496 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005497 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005499
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005500 // If nothing change, just retain the current statement.
5501 if (!getDerived().AlwaysRebuild() &&
5502 Object.get() == S->getSynchExpr() &&
5503 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005504 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005505
5506 // Build a new statement.
5507 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005508 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005509}
5510
5511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005513TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5514 ObjCAutoreleasePoolStmt *S) {
5515 // Transform the body.
5516 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5517 if (Body.isInvalid())
5518 return StmtError();
5519
5520 // If nothing changed, just retain this statement.
5521 if (!getDerived().AlwaysRebuild() &&
5522 Body.get() == S->getSubStmt())
5523 return SemaRef.Owned(S);
5524
5525 // Build a new statement.
5526 return getDerived().RebuildObjCAutoreleasePoolStmt(
5527 S->getAtLoc(), Body.get());
5528}
5529
5530template<typename Derived>
5531StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005532TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005533 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005534 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005535 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005536 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005537 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005538
Douglas Gregorc3203e72010-04-22 23:10:45 +00005539 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005541 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005542 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005543 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5544 Collection.take());
5545 if (Collection.isInvalid())
5546 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005547
Douglas Gregorc3203e72010-04-22 23:10:45 +00005548 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005549 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005550 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005552
Douglas Gregorc3203e72010-04-22 23:10:45 +00005553 // If nothing changed, just retain this statement.
5554 if (!getDerived().AlwaysRebuild() &&
5555 Element.get() == S->getElement() &&
5556 Collection.get() == S->getCollection() &&
5557 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005558 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005559
Douglas Gregorc3203e72010-04-22 23:10:45 +00005560 // Build a new statement.
5561 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5562 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005563 Element.get(),
5564 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005565 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005566 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005567}
5568
5569
5570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005571StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005572TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5573 // Transform the exception declaration, if any.
5574 VarDecl *Var = 0;
5575 if (S->getExceptionDecl()) {
5576 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005577 TypeSourceInfo *T = getDerived().TransformType(
5578 ExceptionDecl->getTypeSourceInfo());
5579 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005580 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005581
Douglas Gregor83cb9422010-09-09 17:09:21 +00005582 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005583 ExceptionDecl->getInnerLocStart(),
5584 ExceptionDecl->getLocation(),
5585 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005586 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005587 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005588 }
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Douglas Gregor43959a92009-08-20 07:17:43 +00005590 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005591 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005592 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 if (!getDerived().AlwaysRebuild() &&
5596 !Var &&
5597 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005598 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005599
5600 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5601 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005602 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005603}
Mike Stump1eb44332009-09-09 15:08:12 +00005604
Douglas Gregor43959a92009-08-20 07:17:43 +00005605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005606StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005607TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5608 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005609 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005610 = getDerived().TransformCompoundStmt(S->getTryBlock());
5611 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005612 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005613
Douglas Gregor43959a92009-08-20 07:17:43 +00005614 // Transform the handlers.
5615 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005616 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005617 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005618 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005619 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5620 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005621 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005622
Douglas Gregor43959a92009-08-20 07:17:43 +00005623 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5624 Handlers.push_back(Handler.takeAs<Stmt>());
5625 }
Mike Stump1eb44332009-09-09 15:08:12 +00005626
Douglas Gregor43959a92009-08-20 07:17:43 +00005627 if (!getDerived().AlwaysRebuild() &&
5628 TryBlock.get() == S->getTryBlock() &&
5629 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005630 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005631
John McCall9ae2f072010-08-23 23:25:46 +00005632 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005633 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005634}
Mike Stump1eb44332009-09-09 15:08:12 +00005635
Richard Smithad762fc2011-04-14 22:09:26 +00005636template<typename Derived>
5637StmtResult
5638TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5639 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5640 if (Range.isInvalid())
5641 return StmtError();
5642
5643 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5644 if (BeginEnd.isInvalid())
5645 return StmtError();
5646
5647 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5648 if (Cond.isInvalid())
5649 return StmtError();
5650
5651 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5652 if (Inc.isInvalid())
5653 return StmtError();
5654
5655 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5656 if (LoopVar.isInvalid())
5657 return StmtError();
5658
5659 StmtResult NewStmt = S;
5660 if (getDerived().AlwaysRebuild() ||
5661 Range.get() != S->getRangeStmt() ||
5662 BeginEnd.get() != S->getBeginEndStmt() ||
5663 Cond.get() != S->getCond() ||
5664 Inc.get() != S->getInc() ||
5665 LoopVar.get() != S->getLoopVarStmt())
5666 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5667 S->getColonLoc(), Range.get(),
5668 BeginEnd.get(), Cond.get(),
5669 Inc.get(), LoopVar.get(),
5670 S->getRParenLoc());
5671
5672 StmtResult Body = getDerived().TransformStmt(S->getBody());
5673 if (Body.isInvalid())
5674 return StmtError();
5675
5676 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5677 // it now so we have a new statement to attach the body to.
5678 if (Body.get() != S->getBody() && NewStmt.get() == S)
5679 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5680 S->getColonLoc(), Range.get(),
5681 BeginEnd.get(), Cond.get(),
5682 Inc.get(), LoopVar.get(),
5683 S->getRParenLoc());
5684
5685 if (NewStmt.get() == S)
5686 return SemaRef.Owned(S);
5687
5688 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5689}
5690
John Wiegley28bbe4b2011-04-28 01:08:34 +00005691template<typename Derived>
5692StmtResult
5693TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5694 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5695 if(TryBlock.isInvalid()) return StmtError();
5696
5697 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5698 if(!getDerived().AlwaysRebuild() &&
5699 TryBlock.get() == S->getTryBlock() &&
5700 Handler.get() == S->getHandler())
5701 return SemaRef.Owned(S);
5702
5703 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5704 S->getTryLoc(),
5705 TryBlock.take(),
5706 Handler.take());
5707}
5708
5709template<typename Derived>
5710StmtResult
5711TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5712 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5713 if(Block.isInvalid()) return StmtError();
5714
5715 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5716 Block.take());
5717}
5718
5719template<typename Derived>
5720StmtResult
5721TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5722 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5723 if(FilterExpr.isInvalid()) return StmtError();
5724
5725 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5726 if(Block.isInvalid()) return StmtError();
5727
5728 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5729 FilterExpr.take(),
5730 Block.take());
5731}
5732
5733template<typename Derived>
5734StmtResult
5735TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5736 if(isa<SEHFinallyStmt>(Handler))
5737 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5738 else
5739 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5740}
5741
Douglas Gregor43959a92009-08-20 07:17:43 +00005742//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005743// Expression transformation
5744//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005746ExprResult
John McCall454feb92009-12-08 09:21:05 +00005747TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005748 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749}
Mike Stump1eb44332009-09-09 15:08:12 +00005750
5751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005752ExprResult
John McCall454feb92009-12-08 09:21:05 +00005753TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005754 NestedNameSpecifierLoc QualifierLoc;
5755 if (E->getQualifierLoc()) {
5756 QualifierLoc
5757 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5758 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005759 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005760 }
John McCalldbd872f2009-12-08 09:08:17 +00005761
5762 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005763 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5764 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005767
John McCallec8045d2010-08-17 21:27:17 +00005768 DeclarationNameInfo NameInfo = E->getNameInfo();
5769 if (NameInfo.getName()) {
5770 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5771 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005772 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005773 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005774
5775 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005776 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005777 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005778 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005779 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005780
5781 // Mark it referenced in the new context regardless.
5782 // FIXME: this is a bit instantiation-specific.
5783 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5784
John McCall3fa5cae2010-10-26 07:05:15 +00005785 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005786 }
John McCalldbd872f2009-12-08 09:08:17 +00005787
5788 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005789 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005790 TemplateArgs = &TransArgs;
5791 TransArgs.setLAngleLoc(E->getLAngleLoc());
5792 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005793 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5794 E->getNumTemplateArgs(),
5795 TransArgs))
5796 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005797 }
5798
Douglas Gregor40d96a62011-02-28 21:54:11 +00005799 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5800 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801}
Mike Stump1eb44332009-09-09 15:08:12 +00005802
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005804ExprResult
John McCall454feb92009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005806 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005807}
Mike Stump1eb44332009-09-09 15:08:12 +00005808
Douglas Gregorb98b1992009-08-11 05:31:07 +00005809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005810ExprResult
John McCall454feb92009-12-08 09:21:05 +00005811TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005812 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005813}
Mike Stump1eb44332009-09-09 15:08:12 +00005814
Douglas Gregorb98b1992009-08-11 05:31:07 +00005815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005816ExprResult
John McCall454feb92009-12-08 09:21:05 +00005817TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819}
Mike Stump1eb44332009-09-09 15:08:12 +00005820
Douglas Gregorb98b1992009-08-11 05:31:07 +00005821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005822ExprResult
John McCall454feb92009-12-08 09:21:05 +00005823TreeTransform<Derived>::TransformStringLiteral(StringLiteral *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
John McCall454feb92009-12-08 09:21:05 +00005829TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005830 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005831}
5832
5833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005834ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005835TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5836 ExprResult ControllingExpr =
5837 getDerived().TransformExpr(E->getControllingExpr());
5838 if (ControllingExpr.isInvalid())
5839 return ExprError();
5840
Chris Lattner686775d2011-07-20 06:58:45 +00005841 SmallVector<Expr *, 4> AssocExprs;
5842 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005843 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5844 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5845 if (TS) {
5846 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5847 if (!AssocType)
5848 return ExprError();
5849 AssocTypes.push_back(AssocType);
5850 } else {
5851 AssocTypes.push_back(0);
5852 }
5853
5854 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5855 if (AssocExpr.isInvalid())
5856 return ExprError();
5857 AssocExprs.push_back(AssocExpr.release());
5858 }
5859
5860 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5861 E->getDefaultLoc(),
5862 E->getRParenLoc(),
5863 ControllingExpr.release(),
5864 AssocTypes.data(),
5865 AssocExprs.data(),
5866 E->getNumAssocs());
5867}
5868
5869template<typename Derived>
5870ExprResult
John McCall454feb92009-12-08 09:21:05 +00005871TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005872 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005873 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005874 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregorb98b1992009-08-11 05:31:07 +00005876 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005877 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005878
John McCall9ae2f072010-08-23 23:25:46 +00005879 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005880 E->getRParen());
5881}
5882
Mike Stump1eb44332009-09-09 15:08:12 +00005883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005884ExprResult
John McCall454feb92009-12-08 09:21:05 +00005885TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005886 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005887 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005889
Douglas Gregorb98b1992009-08-11 05:31:07 +00005890 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005891 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005892
Douglas Gregorb98b1992009-08-11 05:31:07 +00005893 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5894 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005895 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005896}
Mike Stump1eb44332009-09-09 15:08:12 +00005897
Douglas Gregorb98b1992009-08-11 05:31:07 +00005898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005899ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005900TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5901 // Transform the type.
5902 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5903 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005904 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005905
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005906 // Transform all of the components into components similar to what the
5907 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005908 // FIXME: It would be slightly more efficient in the non-dependent case to
5909 // just map FieldDecls, rather than requiring the rebuilder to look for
5910 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005911 // template code that we don't care.
5912 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005913 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005914 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00005915 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005916 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5917 const Node &ON = E->getComponent(I);
5918 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005919 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005920 Comp.LocStart = ON.getSourceRange().getBegin();
5921 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005922 switch (ON.getKind()) {
5923 case Node::Array: {
5924 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005925 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005926 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005927 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005928
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005929 ExprChanged = ExprChanged || Index.get() != FromIndex;
5930 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005931 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005932 break;
5933 }
Sean Huntc3021132010-05-05 15:23:54 +00005934
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005935 case Node::Field:
5936 case Node::Identifier:
5937 Comp.isBrackets = false;
5938 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005939 if (!Comp.U.IdentInfo)
5940 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005941
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005942 break;
Sean Huntc3021132010-05-05 15:23:54 +00005943
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005944 case Node::Base:
5945 // Will be recomputed during the rebuild.
5946 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005947 }
Sean Huntc3021132010-05-05 15:23:54 +00005948
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005949 Components.push_back(Comp);
5950 }
Sean Huntc3021132010-05-05 15:23:54 +00005951
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005952 // If nothing changed, retain the existing expression.
5953 if (!getDerived().AlwaysRebuild() &&
5954 Type == E->getTypeSourceInfo() &&
5955 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005956 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005957
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005958 // Build a new offsetof expression.
5959 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5960 Components.data(), Components.size(),
5961 E->getRParenLoc());
5962}
5963
5964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005965ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005966TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5967 assert(getDerived().AlreadyTransformed(E->getType()) &&
5968 "opaque value expression requires transformation");
5969 return SemaRef.Owned(E);
5970}
5971
5972template<typename Derived>
5973ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005974TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5975 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005977 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005978
John McCalla93c9342009-12-07 02:54:59 +00005979 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005980 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005982
John McCall5ab75172009-11-04 07:28:41 +00005983 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005984 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005985
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005986 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5987 E->getKind(),
5988 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005989 }
Mike Stump1eb44332009-09-09 15:08:12 +00005990
John McCall60d7b3a2010-08-24 06:29:42 +00005991 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005992 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005993 // C++0x [expr.sizeof]p1:
5994 // The operand is either an expression, which is an unevaluated operand
5995 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005996 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005997
Douglas Gregorb98b1992009-08-11 05:31:07 +00005998 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5999 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006000 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006001
Douglas Gregorb98b1992009-08-11 05:31:07 +00006002 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006003 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004 }
Mike Stump1eb44332009-09-09 15:08:12 +00006005
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006006 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6007 E->getOperatorLoc(),
6008 E->getKind(),
6009 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006010}
Mike Stump1eb44332009-09-09 15:08:12 +00006011
Douglas Gregorb98b1992009-08-11 05:31:07 +00006012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006013ExprResult
John McCall454feb92009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006015 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006017 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006018
John McCall60d7b3a2010-08-24 06:29:42 +00006019 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006021 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006022
6023
Douglas Gregorb98b1992009-08-11 05:31:07 +00006024 if (!getDerived().AlwaysRebuild() &&
6025 LHS.get() == E->getLHS() &&
6026 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006027 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006028
John McCall9ae2f072010-08-23 23:25:46 +00006029 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006031 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032 E->getRBracketLoc());
6033}
Mike Stump1eb44332009-09-09 15:08:12 +00006034
6035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006036ExprResult
John McCall454feb92009-12-08 09:21:05 +00006037TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006039 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006040 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006041 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042
6043 // Transform arguments.
6044 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006045 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006046 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6047 &ArgChanged))
6048 return ExprError();
6049
Douglas Gregorb98b1992009-08-11 05:31:07 +00006050 if (!getDerived().AlwaysRebuild() &&
6051 Callee.get() == E->getCallee() &&
6052 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006053 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006056 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006057 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006058 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006060 E->getRParenLoc());
6061}
Mike Stump1eb44332009-09-09 15:08:12 +00006062
6063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006064ExprResult
John McCall454feb92009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006066 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006068 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006069
Douglas Gregor40d96a62011-02-28 21:54:11 +00006070 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006071 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006072 QualifierLoc
6073 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6074
6075 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006076 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006077 }
Mike Stump1eb44332009-09-09 15:08:12 +00006078
Eli Friedmanf595cc42009-12-04 06:40:45 +00006079 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006080 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6081 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006083 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006084
John McCall6bb80172010-03-30 21:47:33 +00006085 NamedDecl *FoundDecl = E->getFoundDecl();
6086 if (FoundDecl == E->getMemberDecl()) {
6087 FoundDecl = Member;
6088 } else {
6089 FoundDecl = cast_or_null<NamedDecl>(
6090 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6091 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006092 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006093 }
6094
Douglas Gregorb98b1992009-08-11 05:31:07 +00006095 if (!getDerived().AlwaysRebuild() &&
6096 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006097 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006098 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006099 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006100 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006101
Anders Carlsson1f240322009-12-22 05:24:09 +00006102 // Mark it referenced in the new context regardless.
6103 // FIXME: this is a bit instantiation-specific.
6104 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006105 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006106 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107
John McCalld5532b62009-11-23 01:53:49 +00006108 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006109 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006110 TransArgs.setLAngleLoc(E->getLAngleLoc());
6111 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006112 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6113 E->getNumTemplateArgs(),
6114 TransArgs))
6115 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006116 }
Sean Huntc3021132010-05-05 15:23:54 +00006117
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118 // FIXME: Bogus source location for the operator
6119 SourceLocation FakeOperatorLoc
6120 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6121
John McCallc2233c52010-01-15 08:34:02 +00006122 // FIXME: to do this check properly, we will need to preserve the
6123 // first-qualifier-in-scope here, just in case we had a dependent
6124 // base (and therefore couldn't do the check) and a
6125 // nested-name-qualifier (and therefore could do the lookup).
6126 NamedDecl *FirstQualifierInScope = 0;
6127
John McCall9ae2f072010-08-23 23:25:46 +00006128 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006130 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006131 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006132 Member,
John McCall6bb80172010-03-30 21:47:33 +00006133 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006134 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006135 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006136 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006142 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006144 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006145
John McCall60d7b3a2010-08-24 06:29:42 +00006146 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006148 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006149
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150 if (!getDerived().AlwaysRebuild() &&
6151 LHS.get() == E->getLHS() &&
6152 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006153 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006154
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006156 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006157}
6158
Mike Stump1eb44332009-09-09 15:08:12 +00006159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006160ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006162 CompoundAssignOperator *E) {
6163 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164}
Mike Stump1eb44332009-09-09 15:08:12 +00006165
Douglas Gregorb98b1992009-08-11 05:31:07 +00006166template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006167ExprResult TreeTransform<Derived>::
6168TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6169 // Just rebuild the common and RHS expressions and see whether we
6170 // get any changes.
6171
6172 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6173 if (commonExpr.isInvalid())
6174 return ExprError();
6175
6176 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6177 if (rhs.isInvalid())
6178 return ExprError();
6179
6180 if (!getDerived().AlwaysRebuild() &&
6181 commonExpr.get() == e->getCommon() &&
6182 rhs.get() == e->getFalseExpr())
6183 return SemaRef.Owned(e);
6184
6185 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6186 e->getQuestionLoc(),
6187 0,
6188 e->getColonLoc(),
6189 rhs.get());
6190}
6191
6192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006195 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006198
John McCall60d7b3a2010-08-24 06:29:42 +00006199 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006201 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006202
John McCall60d7b3a2010-08-24 06:29:42 +00006203 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 if (!getDerived().AlwaysRebuild() &&
6208 Cond.get() == E->getCond() &&
6209 LHS.get() == E->getLHS() &&
6210 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006211 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006212
John McCall9ae2f072010-08-23 23:25:46 +00006213 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006214 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006215 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006216 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006217 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218}
Mike Stump1eb44332009-09-09 15:08:12 +00006219
6220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006221ExprResult
John McCall454feb92009-12-08 09:21:05 +00006222TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006223 // Implicit casts are eliminated during transformation, since they
6224 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006225 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226}
Mike Stump1eb44332009-09-09 15:08:12 +00006227
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006229ExprResult
John McCall454feb92009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006231 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6232 if (!Type)
6233 return ExprError();
6234
John McCall60d7b3a2010-08-24 06:29:42 +00006235 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006236 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006238 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006239
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006241 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006244
John McCall9d125032010-01-15 18:39:57 +00006245 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006246 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006248 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249}
Mike Stump1eb44332009-09-09 15:08:12 +00006250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006252ExprResult
John McCall454feb92009-12-08 09:21:05 +00006253TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006254 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6255 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6256 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006257 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006258
John McCall60d7b3a2010-08-24 06:29:42 +00006259 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006262
Douglas Gregorb98b1992009-08-11 05:31:07 +00006263 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006264 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006265 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006266 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267
John McCall1d7d8d62010-01-19 22:33:45 +00006268 // Note: the expression type doesn't necessarily match the
6269 // type-as-written, but that's okay, because it should always be
6270 // derivable from the initializer.
6271
John McCall42f56b52010-01-18 19:35:47 +00006272 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006273 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006274 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006275}
Mike Stump1eb44332009-09-09 15:08:12 +00006276
Douglas Gregorb98b1992009-08-11 05:31:07 +00006277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006278ExprResult
John McCall454feb92009-12-08 09:21:05 +00006279TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006280 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006281 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006283
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284 if (!getDerived().AlwaysRebuild() &&
6285 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006286 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006287
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006289 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006290 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006291 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006292 E->getAccessorLoc(),
6293 E->getAccessor());
6294}
Mike Stump1eb44332009-09-09 15:08:12 +00006295
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006297ExprResult
John McCall454feb92009-12-08 09:21:05 +00006298TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006300
John McCallca0408f2010-08-23 06:44:23 +00006301 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006302 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6303 Inits, &InitChanged))
6304 return ExprError();
6305
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006307 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006308
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006310 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311}
Mike Stump1eb44332009-09-09 15:08:12 +00006312
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006314ExprResult
John McCall454feb92009-12-08 09:21:05 +00006315TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006317
Douglas Gregor43959a92009-08-20 07:17:43 +00006318 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006319 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006321 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006322
Douglas Gregor43959a92009-08-20 07:17:43 +00006323 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006324 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006325 bool ExprChanged = false;
6326 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6327 DEnd = E->designators_end();
6328 D != DEnd; ++D) {
6329 if (D->isFieldDesignator()) {
6330 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6331 D->getDotLoc(),
6332 D->getFieldLoc()));
6333 continue;
6334 }
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006337 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
6341 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6345 ArrayExprs.push_back(Index.release());
6346 continue;
6347 }
Mike Stump1eb44332009-09-09 15:08:12 +00006348
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006350 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6352 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006353 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006354
John McCall60d7b3a2010-08-24 06:29:42 +00006355 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006358
6359 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 End.get(),
6361 D->getLBracketLoc(),
6362 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006363
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6365 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 ArrayExprs.push_back(Start.release());
6368 ArrayExprs.push_back(End.release());
6369 }
Mike Stump1eb44332009-09-09 15:08:12 +00006370
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 if (!getDerived().AlwaysRebuild() &&
6372 Init.get() == E->getInit() &&
6373 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006374 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6377 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006378 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379}
Mike Stump1eb44332009-09-09 15:08:12 +00006380
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006382ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006384 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006385 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006386
Douglas Gregor5557b252009-10-28 00:29:27 +00006387 // FIXME: Will we ever have proper type location here? Will we actually
6388 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 QualType T = getDerived().TransformType(E->getType());
6390 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (!getDerived().AlwaysRebuild() &&
6394 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006395 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006396
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 return getDerived().RebuildImplicitValueInitExpr(T);
6398}
Mike Stump1eb44332009-09-09 15:08:12 +00006399
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006401ExprResult
John McCall454feb92009-12-08 09:21:05 +00006402TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006403 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6404 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006406
John McCall60d7b3a2010-08-24 06:29:42 +00006407 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006412 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006414 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006415
John McCall9ae2f072010-08-23 23:25:46 +00006416 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006417 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418}
6419
6420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006421ExprResult
John McCall454feb92009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006424 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006425 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6426 &ArgumentChanged))
6427 return ExprError();
6428
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6430 move_arg(Inits),
6431 E->getRParenLoc());
6432}
Mike Stump1eb44332009-09-09 15:08:12 +00006433
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434/// \brief Transform an address-of-label expression.
6435///
6436/// By default, the transformation of an address-of-label expression always
6437/// rebuilds the expression, so that the label identifier can be resolved to
6438/// the corresponding label statement by semantic analysis.
6439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006440ExprResult
John McCall454feb92009-12-08 09:21:05 +00006441TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006442 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6443 E->getLabel());
6444 if (!LD)
6445 return ExprError();
6446
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006448 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449}
Mike Stump1eb44332009-09-09 15:08:12 +00006450
6451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006452ExprResult
John McCall454feb92009-12-08 09:21:05 +00006453TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006454 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6456 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006458
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459 if (!getDerived().AlwaysRebuild() &&
6460 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006461 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006462
6463 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006464 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 E->getRParenLoc());
6466}
Mike Stump1eb44332009-09-09 15:08:12 +00006467
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006469ExprResult
John McCall454feb92009-12-08 09:21:05 +00006470TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006471 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006473 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006474
John McCall60d7b3a2010-08-24 06:29:42 +00006475 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006478
John McCall60d7b3a2010-08-24 06:29:42 +00006479 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 if (!getDerived().AlwaysRebuild() &&
6484 Cond.get() == E->getCond() &&
6485 LHS.get() == E->getLHS() &&
6486 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006490 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 E->getRParenLoc());
6492}
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006495ExprResult
John McCall454feb92009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006497 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498}
6499
6500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006501ExprResult
John McCall454feb92009-12-08 09:21:05 +00006502TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006503 switch (E->getOperator()) {
6504 case OO_New:
6505 case OO_Delete:
6506 case OO_Array_New:
6507 case OO_Array_Delete:
6508 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006509 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006510
Douglas Gregor668d6d92009-12-13 20:44:55 +00006511 case OO_Call: {
6512 // This is a call to an object's operator().
6513 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6514
6515 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006516 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006517 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006518 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006519
6520 // FIXME: Poor location information
6521 SourceLocation FakeLParenLoc
6522 = SemaRef.PP.getLocForEndOfToken(
6523 static_cast<Expr *>(Object.get())->getLocEnd());
6524
6525 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006526 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006527 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6528 Args))
6529 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006530
John McCall9ae2f072010-08-23 23:25:46 +00006531 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006532 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006533 E->getLocEnd());
6534 }
6535
6536#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6537 case OO_##Name:
6538#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6539#include "clang/Basic/OperatorKinds.def"
6540 case OO_Subscript:
6541 // Handled below.
6542 break;
6543
6544 case OO_Conditional:
6545 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006547
6548 case OO_None:
6549 case NUM_OVERLOADED_OPERATORS:
6550 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006551 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006552 }
6553
John McCall60d7b3a2010-08-24 06:29:42 +00006554 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006557
John McCall60d7b3a2010-08-24 06:29:42 +00006558 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006560 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561
John McCall60d7b3a2010-08-24 06:29:42 +00006562 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 if (E->getNumArgs() == 2) {
6564 Second = getDerived().TransformExpr(E->getArg(1));
6565 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 }
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 if (!getDerived().AlwaysRebuild() &&
6570 Callee.get() == E->getCallee() &&
6571 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006572 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006573 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6576 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006577 Callee.get(),
6578 First.get(),
6579 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580}
Mike Stump1eb44332009-09-09 15:08:12 +00006581
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006583ExprResult
John McCall454feb92009-12-08 09:21:05 +00006584TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6585 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586}
Mike Stump1eb44332009-09-09 15:08:12 +00006587
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006589ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006590TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6591 // Transform the callee.
6592 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6593 if (Callee.isInvalid())
6594 return ExprError();
6595
6596 // Transform exec config.
6597 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6598 if (EC.isInvalid())
6599 return ExprError();
6600
6601 // Transform arguments.
6602 bool ArgChanged = false;
6603 ASTOwningVector<Expr*> Args(SemaRef);
6604 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6605 &ArgChanged))
6606 return ExprError();
6607
6608 if (!getDerived().AlwaysRebuild() &&
6609 Callee.get() == E->getCallee() &&
6610 !ArgChanged)
6611 return SemaRef.Owned(E);
6612
6613 // FIXME: Wrong source location information for the '('.
6614 SourceLocation FakeLParenLoc
6615 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6616 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6617 move_arg(Args),
6618 E->getRParenLoc(), EC.get());
6619}
6620
6621template<typename Derived>
6622ExprResult
John McCall454feb92009-12-08 09:21:05 +00006623TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006624 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6625 if (!Type)
6626 return ExprError();
6627
John McCall60d7b3a2010-08-24 06:29:42 +00006628 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006629 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006634 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006636 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006639 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6641 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6642 SourceLocation FakeRParenLoc
6643 = SemaRef.PP.getLocForEndOfToken(
6644 E->getSubExpr()->getSourceRange().getEnd());
6645 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006646 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006648 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 FakeRAngleLoc,
6650 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006651 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 FakeRParenLoc);
6653}
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006656ExprResult
John McCall454feb92009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6658 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659}
Mike Stump1eb44332009-09-09 15:08:12 +00006660
6661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006662ExprResult
John McCall454feb92009-12-08 09:21:05 +00006663TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6664 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006665}
6666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006668ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006670 CXXReinterpretCastExpr *E) {
6671 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672}
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006675ExprResult
John McCall454feb92009-12-08 09:21:05 +00006676TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6677 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678}
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006681ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006683 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006684 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6685 if (!Type)
6686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006687
John McCall60d7b3a2010-08-24 06:29:42 +00006688 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006689 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006691 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006694 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006696 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006698 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006700 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 E->getRParenLoc());
6702}
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006705ExprResult
John McCall454feb92009-12-08 09:21:05 +00006706TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006708 TypeSourceInfo *TInfo
6709 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6710 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006714 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006715 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006717 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6718 E->getLocStart(),
6719 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 E->getLocEnd());
6721 }
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 // We don't know whether the expression is potentially evaluated until
6724 // after we perform semantic analysis, so the expression is potentially
6725 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006726 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006727 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006728
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
6734 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006735 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006737 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6738 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006739 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 E->getLocEnd());
6741}
6742
6743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006744ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006745TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6746 if (E->isTypeOperand()) {
6747 TypeSourceInfo *TInfo
6748 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6749 if (!TInfo)
6750 return ExprError();
6751
6752 if (!getDerived().AlwaysRebuild() &&
6753 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006754 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006755
Douglas Gregor3c52a212011-03-06 17:40:41 +00006756 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006757 E->getLocStart(),
6758 TInfo,
6759 E->getLocEnd());
6760 }
6761
6762 // We don't know whether the expression is potentially evaluated until
6763 // after we perform semantic analysis, so the expression is potentially
6764 // potentially evaluated.
6765 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6766
6767 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6768 if (SubExpr.isInvalid())
6769 return ExprError();
6770
6771 if (!getDerived().AlwaysRebuild() &&
6772 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006773 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006774
6775 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6776 E->getLocStart(),
6777 SubExpr.get(),
6778 E->getLocEnd());
6779}
6780
6781template<typename Derived>
6782ExprResult
John McCall454feb92009-12-08 09:21:05 +00006783TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006784 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785}
Mike Stump1eb44332009-09-09 15:08:12 +00006786
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006788ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006790 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006791 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792}
Mike Stump1eb44332009-09-09 15:08:12 +00006793
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006795ExprResult
John McCall454feb92009-12-08 09:21:05 +00006796TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006797 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006798 QualType T;
6799 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6800 T = MD->getThisType(getSema().Context);
6801 else
6802 T = getSema().Context.getPointerType(
6803 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006804
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006805 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006806 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregor828a1972010-01-07 23:12:05 +00006808 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809}
Mike Stump1eb44332009-09-09 15:08:12 +00006810
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006812ExprResult
John McCall454feb92009-12-08 09:21:05 +00006813TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006814 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006816 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006817
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 if (!getDerived().AlwaysRebuild() &&
6819 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006820 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821
Douglas Gregorbca01b42011-07-06 22:04:06 +00006822 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6823 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824}
Mike Stump1eb44332009-09-09 15:08:12 +00006825
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006827ExprResult
John McCall454feb92009-12-08 09:21:05 +00006828TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006829 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006830 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6831 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006833 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006834
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006835 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006837 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Douglas Gregor036aed12009-12-23 23:03:06 +00006839 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840}
Mike Stump1eb44332009-09-09 15:08:12 +00006841
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006843ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006844TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6845 CXXScalarValueInitExpr *E) {
6846 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6847 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006848 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006851 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006852 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006853
Douglas Gregorab6677e2010-09-08 00:15:04 +00006854 return getDerived().RebuildCXXScalarValueInitExpr(T,
6855 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006856 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857}
Mike Stump1eb44332009-09-09 15:08:12 +00006858
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006860ExprResult
John McCall454feb92009-12-08 09:21:05 +00006861TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006863 TypeSourceInfo *AllocTypeInfo
6864 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6865 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006869 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006872
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873 // Transform the placement arguments (if any).
6874 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006875 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006876 if (getDerived().TransformExprs(E->getPlacementArgs(),
6877 E->getNumPlacementArgs(), true,
6878 PlacementArgs, &ArgumentChanged))
6879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregor43959a92009-08-20 07:17:43 +00006881 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006882 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006883 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6884 ConstructorArgs, &ArgumentChanged))
6885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006886
Douglas Gregor1af74512010-02-26 00:38:10 +00006887 // Transform constructor, new operator, and delete operator.
6888 CXXConstructorDecl *Constructor = 0;
6889 if (E->getConstructor()) {
6890 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006891 getDerived().TransformDecl(E->getLocStart(),
6892 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006893 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006894 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006895 }
6896
6897 FunctionDecl *OperatorNew = 0;
6898 if (E->getOperatorNew()) {
6899 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006900 getDerived().TransformDecl(E->getLocStart(),
6901 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006902 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006903 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006904 }
6905
6906 FunctionDecl *OperatorDelete = 0;
6907 if (E->getOperatorDelete()) {
6908 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006909 getDerived().TransformDecl(E->getLocStart(),
6910 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006911 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006912 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006913 }
Sean Huntc3021132010-05-05 15:23:54 +00006914
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006916 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006918 Constructor == E->getConstructor() &&
6919 OperatorNew == E->getOperatorNew() &&
6920 OperatorDelete == E->getOperatorDelete() &&
6921 !ArgumentChanged) {
6922 // Mark any declarations we need as referenced.
6923 // FIXME: instantiation-specific.
6924 if (Constructor)
6925 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6926 if (OperatorNew)
6927 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6928 if (OperatorDelete)
6929 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00006930
6931 if (E->isArray() && Constructor &&
6932 !E->getAllocatedType()->isDependentType()) {
6933 QualType ElementType
6934 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6935 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6936 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6937 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6938 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6939 }
6940 }
6941 }
6942
John McCall3fa5cae2010-10-26 07:05:15 +00006943 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006944 }
Mike Stump1eb44332009-09-09 15:08:12 +00006945
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006946 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006947 if (!ArraySize.get()) {
6948 // If no array size was specified, but the new expression was
6949 // instantiated with an array type (e.g., "new T" where T is
6950 // instantiated with "int[4]"), extract the outer bound from the
6951 // array type as our array size. We do this with constant and
6952 // dependently-sized array types.
6953 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6954 if (!ArrayT) {
6955 // Do nothing
6956 } else if (const ConstantArrayType *ConsArrayT
6957 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006958 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006959 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6960 ConsArrayT->getSize(),
6961 SemaRef.Context.getSizeType(),
6962 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006963 AllocType = ConsArrayT->getElementType();
6964 } else if (const DependentSizedArrayType *DepArrayT
6965 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6966 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006967 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006968 AllocType = DepArrayT->getElementType();
6969 }
6970 }
6971 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6974 E->isGlobalNew(),
6975 /*FIXME:*/E->getLocStart(),
6976 move_arg(PlacementArgs),
6977 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006978 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006980 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006981 ArraySize.get(),
Douglas Gregord0e8b782011-06-27 16:55:54 +00006982 /*FIXME:*/E->hasInitializer()
6983 ? E->getLocStart()
6984 : SourceLocation(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 move_arg(ConstructorArgs),
Douglas Gregord0e8b782011-06-27 16:55:54 +00006986 /*FIXME:*/E->hasInitializer()
6987 ? E->getLocEnd()
6988 : SourceLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989}
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006992ExprResult
John McCall454feb92009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006994 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006996 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Douglas Gregor1af74512010-02-26 00:38:10 +00006998 // Transform the delete operator, if known.
6999 FunctionDecl *OperatorDelete = 0;
7000 if (E->getOperatorDelete()) {
7001 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007002 getDerived().TransformDecl(E->getLocStart(),
7003 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007004 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007005 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007006 }
Sean Huntc3021132010-05-05 15:23:54 +00007007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007009 Operand.get() == E->getArgument() &&
7010 OperatorDelete == E->getOperatorDelete()) {
7011 // Mark any declarations we need as referenced.
7012 // FIXME: instantiation-specific.
7013 if (OperatorDelete)
7014 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007015
7016 if (!E->getArgument()->isTypeDependent()) {
7017 QualType Destroyed = SemaRef.Context.getBaseElementType(
7018 E->getDestroyedType());
7019 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7020 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7021 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7022 SemaRef.LookupDestructor(Record));
7023 }
7024 }
7025
John McCall3fa5cae2010-10-26 07:05:15 +00007026 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007027 }
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7030 E->isGlobalDelete(),
7031 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007032 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033}
Mike Stump1eb44332009-09-09 15:08:12 +00007034
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007036ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007037TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007038 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007040 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007042
John McCallb3d87482010-08-24 05:47:05 +00007043 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007044 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007045 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007046 E->getOperatorLoc(),
7047 E->isArrow()? tok::arrow : tok::period,
7048 ObjectTypePtr,
7049 MayBePseudoDestructor);
7050 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007051 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007052
John McCallb3d87482010-08-24 05:47:05 +00007053 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007054 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7055 if (QualifierLoc) {
7056 QualifierLoc
7057 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7058 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007059 return ExprError();
7060 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007061 CXXScopeSpec SS;
7062 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007064 PseudoDestructorTypeStorage Destroyed;
7065 if (E->getDestroyedTypeInfo()) {
7066 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007067 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007068 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007069 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007070 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007071 Destroyed = DestroyedTypeInfo;
7072 } else if (ObjectType->isDependentType()) {
7073 // We aren't likely to be able to resolve the identifier down to a type
7074 // now anyway, so just retain the identifier.
7075 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7076 E->getDestroyedTypeLoc());
7077 } else {
7078 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007079 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007080 *E->getDestroyedTypeIdentifier(),
7081 E->getDestroyedTypeLoc(),
7082 /*Scope=*/0,
7083 SS, ObjectTypePtr,
7084 false);
7085 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007086 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007087
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007088 Destroyed
7089 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7090 E->getDestroyedTypeLoc());
7091 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007092
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007093 TypeSourceInfo *ScopeTypeInfo = 0;
7094 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007095 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007096 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007097 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007098 }
Sean Huntc3021132010-05-05 15:23:54 +00007099
John McCall9ae2f072010-08-23 23:25:46 +00007100 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007101 E->getOperatorLoc(),
7102 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007103 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007104 ScopeTypeInfo,
7105 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007106 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007107 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007108}
Mike Stump1eb44332009-09-09 15:08:12 +00007109
Douglas Gregora71d8192009-09-04 17:36:40 +00007110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007111ExprResult
John McCallba135432009-11-21 08:51:07 +00007112TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007113 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007114 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7115 Sema::LookupOrdinaryName);
7116
7117 // Transform all the decls.
7118 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7119 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007120 NamedDecl *InstD = static_cast<NamedDecl*>(
7121 getDerived().TransformDecl(Old->getNameLoc(),
7122 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007123 if (!InstD) {
7124 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7125 // This can happen because of dependent hiding.
7126 if (isa<UsingShadowDecl>(*I))
7127 continue;
7128 else
John McCallf312b1e2010-08-26 23:41:50 +00007129 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007130 }
John McCallf7a1a742009-11-24 19:00:30 +00007131
7132 // Expand using declarations.
7133 if (isa<UsingDecl>(InstD)) {
7134 UsingDecl *UD = cast<UsingDecl>(InstD);
7135 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7136 E = UD->shadow_end(); I != E; ++I)
7137 R.addDecl(*I);
7138 continue;
7139 }
7140
7141 R.addDecl(InstD);
7142 }
7143
7144 // Resolve a kind, but don't do any further analysis. If it's
7145 // ambiguous, the callee needs to deal with it.
7146 R.resolveKind();
7147
7148 // Rebuild the nested-name qualifier, if present.
7149 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007150 if (Old->getQualifierLoc()) {
7151 NestedNameSpecifierLoc QualifierLoc
7152 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7153 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007154 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007155
Douglas Gregor4c9be892011-02-28 20:01:57 +00007156 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007157 }
7158
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007159 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007160 CXXRecordDecl *NamingClass
7161 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7162 Old->getNameLoc(),
7163 Old->getNamingClass()));
7164 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007165 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007166
Douglas Gregor66c45152010-04-27 16:10:10 +00007167 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007168 }
7169
7170 // If we have no template arguments, it's a normal declaration name.
7171 if (!Old->hasExplicitTemplateArgs())
7172 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7173
7174 // If we have template arguments, rebuild them, then rebuild the
7175 // templateid expression.
7176 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007177 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7178 Old->getNumTemplateArgs(),
7179 TransArgs))
7180 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007181
7182 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7183 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184}
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007187ExprResult
John McCall454feb92009-12-08 09:21:05 +00007188TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007189 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7190 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007191 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007192
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007194 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007195 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Mike Stump1eb44332009-09-09 15:08:12 +00007197 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 T,
7200 E->getLocEnd());
7201}
Mike Stump1eb44332009-09-09 15:08:12 +00007202
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007204ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007205TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7206 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7207 if (!LhsT)
7208 return ExprError();
7209
7210 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7211 if (!RhsT)
7212 return ExprError();
7213
7214 if (!getDerived().AlwaysRebuild() &&
7215 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7216 return SemaRef.Owned(E);
7217
7218 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7219 E->getLocStart(),
7220 LhsT, RhsT,
7221 E->getLocEnd());
7222}
7223
7224template<typename Derived>
7225ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007226TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7227 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7228 if (!T)
7229 return ExprError();
7230
7231 if (!getDerived().AlwaysRebuild() &&
7232 T == E->getQueriedTypeSourceInfo())
7233 return SemaRef.Owned(E);
7234
7235 ExprResult SubExpr;
7236 {
7237 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7238 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7239 if (SubExpr.isInvalid())
7240 return ExprError();
7241
7242 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7243 return SemaRef.Owned(E);
7244 }
7245
7246 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7247 E->getLocStart(),
7248 T,
7249 SubExpr.get(),
7250 E->getLocEnd());
7251}
7252
7253template<typename Derived>
7254ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007255TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7256 ExprResult SubExpr;
7257 {
7258 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7259 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7260 if (SubExpr.isInvalid())
7261 return ExprError();
7262
7263 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7264 return SemaRef.Owned(E);
7265 }
7266
7267 return getDerived().RebuildExpressionTrait(
7268 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7269}
7270
7271template<typename Derived>
7272ExprResult
John McCall865d4472009-11-19 22:55:06 +00007273TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007274 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007275 NestedNameSpecifierLoc QualifierLoc
7276 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7277 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007278 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007279
John McCall43fed0d2010-11-12 08:19:04 +00007280 // TODO: If this is a conversion-function-id, verify that the
7281 // destination type name (if present) resolves the same way after
7282 // instantiation as it did in the local scope.
7283
Abramo Bagnara25777432010-08-11 22:01:17 +00007284 DeclarationNameInfo NameInfo
7285 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7286 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007287 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007288
John McCallf7a1a742009-11-24 19:00:30 +00007289 if (!E->hasExplicitTemplateArgs()) {
7290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007291 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007292 // Note: it is sufficient to compare the Name component of NameInfo:
7293 // if name has not changed, DNLoc has not changed either.
7294 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007295 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007296
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007297 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007298 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007299 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007300 }
John McCalld5532b62009-11-23 01:53:49 +00007301
7302 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007303 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7304 E->getNumTemplateArgs(),
7305 TransArgs))
7306 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007308 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007309 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007310 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311}
7312
7313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007314ExprResult
John McCall454feb92009-12-08 09:21:05 +00007315TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007316 // CXXConstructExprs are always implicit, so when we have a
7317 // 1-argument construction we just transform that argument.
7318 if (E->getNumArgs() == 1 ||
7319 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7320 return getDerived().TransformExpr(E->getArg(0));
7321
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7323
7324 QualType T = getDerived().TransformType(E->getType());
7325 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007326 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327
7328 CXXConstructorDecl *Constructor
7329 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007330 getDerived().TransformDecl(E->getLocStart(),
7331 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007333 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007334
Douglas Gregorb98b1992009-08-11 05:31:07 +00007335 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007336 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007337 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7338 &ArgumentChanged))
7339 return ExprError();
7340
Douglas Gregorb98b1992009-08-11 05:31:07 +00007341 if (!getDerived().AlwaysRebuild() &&
7342 T == E->getType() &&
7343 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007344 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007345 // Mark the constructor as referenced.
7346 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007347 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007348 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007349 }
Mike Stump1eb44332009-09-09 15:08:12 +00007350
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007351 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7352 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007353 move_arg(Args),
7354 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007355 E->getConstructionKind(),
7356 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357}
Mike Stump1eb44332009-09-09 15:08:12 +00007358
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359/// \brief Transform a C++ temporary-binding expression.
7360///
Douglas Gregor51326552009-12-24 18:51:59 +00007361/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7362/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007364ExprResult
John McCall454feb92009-12-08 09:21:05 +00007365TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007366 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367}
Mike Stump1eb44332009-09-09 15:08:12 +00007368
John McCall4765fa02010-12-06 08:20:24 +00007369/// \brief Transform a C++ expression that contains cleanups that should
7370/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007371///
John McCall4765fa02010-12-06 08:20:24 +00007372/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007373/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007375ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007376TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007377 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007378}
Mike Stump1eb44332009-09-09 15:08:12 +00007379
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007381ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007383 CXXTemporaryObjectExpr *E) {
7384 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7385 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007387
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 CXXConstructorDecl *Constructor
7389 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007390 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007391 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007392 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007393 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007394
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007396 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007398 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7399 &ArgumentChanged))
7400 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007401
Douglas Gregorb98b1992009-08-11 05:31:07 +00007402 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007403 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007404 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007405 !ArgumentChanged) {
7406 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007407 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007408 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007409 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007410
7411 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7412 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414 E->getLocEnd());
7415}
Mike Stump1eb44332009-09-09 15:08:12 +00007416
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007418ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007419TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007420 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007421 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7422 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007423 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007424
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007426 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007427 Args.reserve(E->arg_size());
7428 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7429 &ArgumentChanged))
7430 return ExprError();
7431
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007433 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007434 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007435 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007436
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007438 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007439 E->getLParenLoc(),
7440 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007441 E->getRParenLoc());
7442}
Mike Stump1eb44332009-09-09 15:08:12 +00007443
Douglas Gregorb98b1992009-08-11 05:31:07 +00007444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007445ExprResult
John McCall865d4472009-11-19 22:55:06 +00007446TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007447 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007448 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007449 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007450 Expr *OldBase;
7451 QualType BaseType;
7452 QualType ObjectType;
7453 if (!E->isImplicitAccess()) {
7454 OldBase = E->getBase();
7455 Base = getDerived().TransformExpr(OldBase);
7456 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007458
John McCallaa81e162009-12-01 22:10:20 +00007459 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007460 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007461 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007462 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007463 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007464 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007465 ObjectTy,
7466 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007467 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007468 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007469
John McCallb3d87482010-08-24 05:47:05 +00007470 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007471 BaseType = ((Expr*) Base.get())->getType();
7472 } else {
7473 OldBase = 0;
7474 BaseType = getDerived().TransformType(E->getBaseType());
7475 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7476 }
Mike Stump1eb44332009-09-09 15:08:12 +00007477
Douglas Gregor6cd21982009-10-20 05:58:46 +00007478 // Transform the first part of the nested-name-specifier that qualifies
7479 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007480 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007481 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007482 E->getFirstQualifierFoundInScope(),
7483 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007484
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007485 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007486 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007487 QualifierLoc
7488 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7489 ObjectType,
7490 FirstQualifierInScope);
7491 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007492 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007493 }
Mike Stump1eb44332009-09-09 15:08:12 +00007494
John McCall43fed0d2010-11-12 08:19:04 +00007495 // TODO: If this is a conversion-function-id, verify that the
7496 // destination type name (if present) resolves the same way after
7497 // instantiation as it did in the local scope.
7498
Abramo Bagnara25777432010-08-11 22:01:17 +00007499 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007500 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007501 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007503
John McCallaa81e162009-12-01 22:10:20 +00007504 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007505 // This is a reference to a member without an explicitly-specified
7506 // template argument list. Optimize for this common case.
7507 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007508 Base.get() == OldBase &&
7509 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007510 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007511 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007512 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007513 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007514
John McCall9ae2f072010-08-23 23:25:46 +00007515 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007516 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007517 E->isArrow(),
7518 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007519 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007520 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007521 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007522 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007523 }
7524
John McCalld5532b62009-11-23 01:53:49 +00007525 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007526 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7527 E->getNumTemplateArgs(),
7528 TransArgs))
7529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007530
John McCall9ae2f072010-08-23 23:25:46 +00007531 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007532 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533 E->isArrow(),
7534 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007535 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007536 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007537 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007538 &TransArgs);
7539}
7540
7541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007542ExprResult
John McCall454feb92009-12-08 09:21:05 +00007543TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007544 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007545 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007546 QualType BaseType;
7547 if (!Old->isImplicitAccess()) {
7548 Base = getDerived().TransformExpr(Old->getBase());
7549 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007550 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007551 BaseType = ((Expr*) Base.get())->getType();
7552 } else {
7553 BaseType = getDerived().TransformType(Old->getBaseType());
7554 }
John McCall129e2df2009-11-30 22:42:35 +00007555
Douglas Gregor4c9be892011-02-28 20:01:57 +00007556 NestedNameSpecifierLoc QualifierLoc;
7557 if (Old->getQualifierLoc()) {
7558 QualifierLoc
7559 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7560 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007561 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007562 }
7563
Abramo Bagnara25777432010-08-11 22:01:17 +00007564 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007565 Sema::LookupOrdinaryName);
7566
7567 // Transform all the decls.
7568 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7569 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007570 NamedDecl *InstD = static_cast<NamedDecl*>(
7571 getDerived().TransformDecl(Old->getMemberLoc(),
7572 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007573 if (!InstD) {
7574 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7575 // This can happen because of dependent hiding.
7576 if (isa<UsingShadowDecl>(*I))
7577 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007578 else {
7579 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007580 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007581 }
John McCall9f54ad42009-12-10 09:41:52 +00007582 }
John McCall129e2df2009-11-30 22:42:35 +00007583
7584 // Expand using declarations.
7585 if (isa<UsingDecl>(InstD)) {
7586 UsingDecl *UD = cast<UsingDecl>(InstD);
7587 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7588 E = UD->shadow_end(); I != E; ++I)
7589 R.addDecl(*I);
7590 continue;
7591 }
7592
7593 R.addDecl(InstD);
7594 }
7595
7596 R.resolveKind();
7597
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007598 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007599 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007600 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007601 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007602 Old->getMemberLoc(),
7603 Old->getNamingClass()));
7604 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007605 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007606
Douglas Gregor66c45152010-04-27 16:10:10 +00007607 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007608 }
Sean Huntc3021132010-05-05 15:23:54 +00007609
John McCall129e2df2009-11-30 22:42:35 +00007610 TemplateArgumentListInfo TransArgs;
7611 if (Old->hasExplicitTemplateArgs()) {
7612 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7613 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007614 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7615 Old->getNumTemplateArgs(),
7616 TransArgs))
7617 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007618 }
John McCallc2233c52010-01-15 08:34:02 +00007619
7620 // FIXME: to do this check properly, we will need to preserve the
7621 // first-qualifier-in-scope here, just in case we had a dependent
7622 // base (and therefore couldn't do the check) and a
7623 // nested-name-qualifier (and therefore could do the lookup).
7624 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007625
John McCall9ae2f072010-08-23 23:25:46 +00007626 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007627 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007628 Old->getOperatorLoc(),
7629 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007630 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007631 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007632 R,
7633 (Old->hasExplicitTemplateArgs()
7634 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007635}
7636
7637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007638ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007639TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007640 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007641 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7642 if (SubExpr.isInvalid())
7643 return ExprError();
7644
7645 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007646 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007647
7648 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7649}
7650
7651template<typename Derived>
7652ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007653TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007654 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7655 if (Pattern.isInvalid())
7656 return ExprError();
7657
7658 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7659 return SemaRef.Owned(E);
7660
Douglas Gregor67fd1252011-01-14 21:20:45 +00007661 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7662 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007663}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007664
7665template<typename Derived>
7666ExprResult
7667TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7668 // If E is not value-dependent, then nothing will change when we transform it.
7669 // Note: This is an instantiation-centric view.
7670 if (!E->isValueDependent())
7671 return SemaRef.Owned(E);
7672
7673 // Note: None of the implementations of TryExpandParameterPacks can ever
7674 // produce a diagnostic when given only a single unexpanded parameter pack,
7675 // so
7676 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7677 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007678 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007679 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007680 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7681 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007682 ShouldExpand, RetainExpansion,
7683 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007684 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007685
Douglas Gregord3731192011-01-10 07:32:04 +00007686 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007687 return SemaRef.Owned(E);
7688
7689 // We now know the length of the parameter pack, so build a new expression
7690 // that stores that length.
7691 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7692 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007693 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007694}
7695
Douglas Gregorbe230c32011-01-03 17:17:50 +00007696template<typename Derived>
7697ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007698TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7699 SubstNonTypeTemplateParmPackExpr *E) {
7700 // Default behavior is to do nothing with this transformation.
7701 return SemaRef.Owned(E);
7702}
7703
7704template<typename Derived>
7705ExprResult
John McCall91a57552011-07-15 05:09:51 +00007706TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7707 SubstNonTypeTemplateParmExpr *E) {
7708 // Default behavior is to do nothing with this transformation.
7709 return SemaRef.Owned(E);
7710}
7711
7712template<typename Derived>
7713ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007714TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7715 MaterializeTemporaryExpr *E) {
7716 return getDerived().TransformExpr(E->GetTemporaryExpr());
7717}
7718
7719template<typename Derived>
7720ExprResult
John McCall454feb92009-12-08 09:21:05 +00007721TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007722 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007723}
7724
Mike Stump1eb44332009-09-09 15:08:12 +00007725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007726ExprResult
John McCall454feb92009-12-08 09:21:05 +00007727TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007728 TypeSourceInfo *EncodedTypeInfo
7729 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7730 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007732
Douglas Gregorb98b1992009-08-11 05:31:07 +00007733 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007734 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007735 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007736
7737 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007738 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007739 E->getRParenLoc());
7740}
Mike Stump1eb44332009-09-09 15:08:12 +00007741
Douglas Gregorb98b1992009-08-11 05:31:07 +00007742template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007743ExprResult TreeTransform<Derived>::
7744TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7745 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7746 if (result.isInvalid()) return ExprError();
7747 Expr *subExpr = result.take();
7748
7749 if (!getDerived().AlwaysRebuild() &&
7750 subExpr == E->getSubExpr())
7751 return SemaRef.Owned(E);
7752
7753 return SemaRef.Owned(new(SemaRef.Context)
7754 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7755}
7756
7757template<typename Derived>
7758ExprResult TreeTransform<Derived>::
7759TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7760 TypeSourceInfo *TSInfo
7761 = getDerived().TransformType(E->getTypeInfoAsWritten());
7762 if (!TSInfo)
7763 return ExprError();
7764
7765 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7766 if (Result.isInvalid())
7767 return ExprError();
7768
7769 if (!getDerived().AlwaysRebuild() &&
7770 TSInfo == E->getTypeInfoAsWritten() &&
7771 Result.get() == E->getSubExpr())
7772 return SemaRef.Owned(E);
7773
7774 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7775 E->getBridgeKeywordLoc(), TSInfo,
7776 Result.get());
7777}
7778
7779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007780ExprResult
John McCall454feb92009-12-08 09:21:05 +00007781TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007782 // Transform arguments.
7783 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007784 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007785 Args.reserve(E->getNumArgs());
7786 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7787 &ArgChanged))
7788 return ExprError();
7789
Douglas Gregor92e986e2010-04-22 16:44:27 +00007790 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7791 // Class message: transform the receiver type.
7792 TypeSourceInfo *ReceiverTypeInfo
7793 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7794 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007795 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007796
Douglas Gregor92e986e2010-04-22 16:44:27 +00007797 // If nothing changed, just retain the existing message send.
7798 if (!getDerived().AlwaysRebuild() &&
7799 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007800 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007801
7802 // Build a new class message send.
7803 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7804 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007805 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007806 E->getMethodDecl(),
7807 E->getLeftLoc(),
7808 move_arg(Args),
7809 E->getRightLoc());
7810 }
7811
7812 // Instance message: transform the receiver
7813 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7814 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007815 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007816 = getDerived().TransformExpr(E->getInstanceReceiver());
7817 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007818 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007819
7820 // If nothing changed, just retain the existing message send.
7821 if (!getDerived().AlwaysRebuild() &&
7822 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007823 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007824
Douglas Gregor92e986e2010-04-22 16:44:27 +00007825 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007826 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007827 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007828 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007829 E->getMethodDecl(),
7830 E->getLeftLoc(),
7831 move_arg(Args),
7832 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833}
7834
Mike Stump1eb44332009-09-09 15:08:12 +00007835template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007836ExprResult
John McCall454feb92009-12-08 09:21:05 +00007837TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007838 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007839}
7840
Mike Stump1eb44332009-09-09 15:08:12 +00007841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007842ExprResult
John McCall454feb92009-12-08 09:21:05 +00007843TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007844 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007845}
7846
Mike Stump1eb44332009-09-09 15:08:12 +00007847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007848ExprResult
John McCall454feb92009-12-08 09:21:05 +00007849TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007850 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007851 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007852 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007853 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007854
7855 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007856
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007857 // If nothing changed, just retain the existing expression.
7858 if (!getDerived().AlwaysRebuild() &&
7859 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007860 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007861
John McCall9ae2f072010-08-23 23:25:46 +00007862 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007863 E->getLocation(),
7864 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865}
7866
Mike Stump1eb44332009-09-09 15:08:12 +00007867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007868ExprResult
John McCall454feb92009-12-08 09:21:05 +00007869TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007870 // 'super' and types never change. Property never changes. Just
7871 // retain the existing expression.
7872 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007873 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007874
Douglas Gregore3303542010-04-26 20:47:02 +00007875 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007876 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007877 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007878 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007879
Douglas Gregore3303542010-04-26 20:47:02 +00007880 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007881
Douglas Gregore3303542010-04-26 20:47:02 +00007882 // If nothing changed, just retain the existing expression.
7883 if (!getDerived().AlwaysRebuild() &&
7884 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007885 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007886
John McCall12f78a62010-12-02 01:19:52 +00007887 if (E->isExplicitProperty())
7888 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7889 E->getExplicitProperty(),
7890 E->getLocation());
7891
7892 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7893 E->getType(),
7894 E->getImplicitPropertyGetter(),
7895 E->getImplicitPropertySetter(),
7896 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897}
7898
Mike Stump1eb44332009-09-09 15:08:12 +00007899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007900ExprResult
John McCall454feb92009-12-08 09:21:05 +00007901TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007902 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007903 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007904 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007905 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007906
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007907 // If nothing changed, just retain the existing expression.
7908 if (!getDerived().AlwaysRebuild() &&
7909 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007910 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007911
John McCall9ae2f072010-08-23 23:25:46 +00007912 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007913 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914}
7915
Mike Stump1eb44332009-09-09 15:08:12 +00007916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007917ExprResult
John McCall454feb92009-12-08 09:21:05 +00007918TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007919 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007920 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007921 SubExprs.reserve(E->getNumSubExprs());
7922 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7923 SubExprs, &ArgumentChanged))
7924 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007925
Douglas Gregorb98b1992009-08-11 05:31:07 +00007926 if (!getDerived().AlwaysRebuild() &&
7927 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007928 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007929
Douglas Gregorb98b1992009-08-11 05:31:07 +00007930 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7931 move_arg(SubExprs),
7932 E->getRParenLoc());
7933}
7934
Mike Stump1eb44332009-09-09 15:08:12 +00007935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007936ExprResult
John McCall454feb92009-12-08 09:21:05 +00007937TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007938 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007939
John McCallc6ac9c32011-02-04 18:33:18 +00007940 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7941 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7942
7943 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00007944 // We built a new blockScopeInfo in call to ActOnBlockStart
7945 // in above, CapturesCXXThis need be set here from the block
7946 // expression.
7947 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7948
Chris Lattner686775d2011-07-20 06:58:45 +00007949 SmallVector<ParmVarDecl*, 4> params;
7950 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007951
7952 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007953 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7954 oldBlock->param_begin(),
7955 oldBlock->param_size(),
7956 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007957 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007958
7959 const FunctionType *exprFunctionType = E->getFunctionType();
7960 QualType exprResultType = exprFunctionType->getResultType();
7961 if (!exprResultType.isNull()) {
7962 if (!exprResultType->isDependentType())
7963 blockScope->ReturnType = exprResultType;
7964 else if (exprResultType != getSema().Context.DependentTy)
7965 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007966 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007967
7968 // If the return type has not been determined yet, leave it as a dependent
7969 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007970 if (blockScope->ReturnType.isNull())
7971 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007972
7973 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007974 if (blockScope->ReturnType->isObjCObjectType()) {
7975 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007976 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007977 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007978 return ExprError();
7979 }
John McCall711c52b2011-01-05 12:14:39 +00007980
John McCallc6ac9c32011-02-04 18:33:18 +00007981 QualType functionType = getDerived().RebuildFunctionProtoType(
7982 blockScope->ReturnType,
7983 paramTypes.data(),
7984 paramTypes.size(),
7985 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007986 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007987 exprFunctionType->getExtInfo());
7988 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007989
7990 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007991 if (!params.empty())
7992 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007993
7994 // If the return type wasn't explicitly set, it will have been marked as a
7995 // dependent type (DependentTy); clear out the return type setting so
7996 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007997 if (blockScope->ReturnType == getSema().Context.DependentTy)
7998 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007999
John McCall711c52b2011-01-05 12:14:39 +00008000 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008001 StmtResult body = getDerived().TransformStmt(E->getBody());
8002 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008003 return ExprError();
8004
John McCallc6ac9c32011-02-04 18:33:18 +00008005#ifndef NDEBUG
8006 // In builds with assertions, make sure that we captured everything we
8007 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008008 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8009 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8010 e = oldBlock->capture_end(); i != e; ++i) {
8011 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008012
Douglas Gregorfc921372011-05-20 15:32:55 +00008013 // Ignore parameter packs.
8014 if (isa<ParmVarDecl>(oldCapture) &&
8015 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8016 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008017
Douglas Gregorfc921372011-05-20 15:32:55 +00008018 VarDecl *newCapture =
8019 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8020 oldCapture));
8021 assert(blockScope->CaptureMap.count(newCapture));
8022 }
John McCallc6ac9c32011-02-04 18:33:18 +00008023 }
8024#endif
8025
8026 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8027 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008028}
8029
Mike Stump1eb44332009-09-09 15:08:12 +00008030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008031ExprResult
John McCall454feb92009-12-08 09:21:05 +00008032TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008033 ValueDecl *ND
8034 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8035 E->getDecl()));
8036 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008037 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008038
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008039 if (!getDerived().AlwaysRebuild() &&
8040 ND == E->getDecl()) {
8041 // Mark it referenced in the new context regardless.
8042 // FIXME: this is a bit instantiation-specific.
8043 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8044
John McCall3fa5cae2010-10-26 07:05:15 +00008045 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008046 }
8047
Abramo Bagnara25777432010-08-11 22:01:17 +00008048 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008049 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008050 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051}
Mike Stump1eb44332009-09-09 15:08:12 +00008052
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008053template<typename Derived>
8054ExprResult
8055TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8056 assert(false && "Cannot transform asType expressions yet");
8057 return SemaRef.Owned(E);
8058}
8059
Douglas Gregorb98b1992009-08-11 05:31:07 +00008060//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008061// Type reconstruction
8062//===----------------------------------------------------------------------===//
8063
Mike Stump1eb44332009-09-09 15:08:12 +00008064template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008065QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8066 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008067 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008068 getDerived().getBaseEntity());
8069}
8070
Mike Stump1eb44332009-09-09 15:08:12 +00008071template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008072QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8073 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008074 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008075 getDerived().getBaseEntity());
8076}
8077
Mike Stump1eb44332009-09-09 15:08:12 +00008078template<typename Derived>
8079QualType
John McCall85737a72009-10-30 00:06:24 +00008080TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8081 bool WrittenAsLValue,
8082 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008083 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008084 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008085}
8086
8087template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008088QualType
John McCall85737a72009-10-30 00:06:24 +00008089TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8090 QualType ClassType,
8091 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008092 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008093 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008094}
8095
8096template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008097QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008098TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8099 ArrayType::ArraySizeModifier SizeMod,
8100 const llvm::APInt *Size,
8101 Expr *SizeExpr,
8102 unsigned IndexTypeQuals,
8103 SourceRange BracketsRange) {
8104 if (SizeExpr || !Size)
8105 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8106 IndexTypeQuals, BracketsRange,
8107 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008108
8109 QualType Types[] = {
8110 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8111 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8112 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008113 };
8114 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8115 QualType SizeType;
8116 for (unsigned I = 0; I != NumTypes; ++I)
8117 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8118 SizeType = Types[I];
8119 break;
8120 }
Mike Stump1eb44332009-09-09 15:08:12 +00008121
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008122 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8123 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008124 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008125 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008126 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008127}
Mike Stump1eb44332009-09-09 15:08:12 +00008128
Douglas Gregor577f75a2009-08-04 16:50:30 +00008129template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008130QualType
8131TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008132 ArrayType::ArraySizeModifier SizeMod,
8133 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008134 unsigned IndexTypeQuals,
8135 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008136 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008137 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008138}
8139
8140template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008141QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008142TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008143 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008144 unsigned IndexTypeQuals,
8145 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008146 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008147 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008148}
Mike Stump1eb44332009-09-09 15:08:12 +00008149
Douglas Gregor577f75a2009-08-04 16:50:30 +00008150template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008151QualType
8152TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008153 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008154 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008155 unsigned IndexTypeQuals,
8156 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008157 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008158 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008159 IndexTypeQuals, BracketsRange);
8160}
8161
8162template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008163QualType
8164TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008165 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008166 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008167 unsigned IndexTypeQuals,
8168 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008169 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008170 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008171 IndexTypeQuals, BracketsRange);
8172}
8173
8174template<typename Derived>
8175QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008176 unsigned NumElements,
8177 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008178 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008179 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008180}
Mike Stump1eb44332009-09-09 15:08:12 +00008181
Douglas Gregor577f75a2009-08-04 16:50:30 +00008182template<typename Derived>
8183QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8184 unsigned NumElements,
8185 SourceLocation AttributeLoc) {
8186 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8187 NumElements, true);
8188 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008189 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8190 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008191 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008192}
Mike Stump1eb44332009-09-09 15:08:12 +00008193
Douglas Gregor577f75a2009-08-04 16:50:30 +00008194template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008195QualType
8196TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008197 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008198 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008199 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008200}
Mike Stump1eb44332009-09-09 15:08:12 +00008201
Douglas Gregor577f75a2009-08-04 16:50:30 +00008202template<typename Derived>
8203QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008204 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008205 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008206 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008207 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008208 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008209 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008210 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008211 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008212 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008213 getDerived().getBaseEntity(),
8214 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008215}
Mike Stump1eb44332009-09-09 15:08:12 +00008216
Douglas Gregor577f75a2009-08-04 16:50:30 +00008217template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008218QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8219 return SemaRef.Context.getFunctionNoProtoType(T);
8220}
8221
8222template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008223QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8224 assert(D && "no decl found");
8225 if (D->isInvalidDecl()) return QualType();
8226
Douglas Gregor92e986e2010-04-22 16:44:27 +00008227 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008228 TypeDecl *Ty;
8229 if (isa<UsingDecl>(D)) {
8230 UsingDecl *Using = cast<UsingDecl>(D);
8231 assert(Using->isTypeName() &&
8232 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8233
8234 // A valid resolved using typename decl points to exactly one type decl.
8235 assert(++Using->shadow_begin() == Using->shadow_end());
8236 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008237
John McCalled976492009-12-04 22:46:56 +00008238 } else {
8239 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8240 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8241 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8242 }
8243
8244 return SemaRef.Context.getTypeDeclType(Ty);
8245}
8246
8247template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008248QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8249 SourceLocation Loc) {
8250 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008251}
8252
8253template<typename Derived>
8254QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8255 return SemaRef.Context.getTypeOfType(Underlying);
8256}
8257
8258template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008259QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8260 SourceLocation Loc) {
8261 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008262}
8263
8264template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008265QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8266 UnaryTransformType::UTTKind UKind,
8267 SourceLocation Loc) {
8268 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8269}
8270
8271template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008272QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008273 TemplateName Template,
8274 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008275 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008276 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008277}
Mike Stump1eb44332009-09-09 15:08:12 +00008278
Douglas Gregordcee1a12009-08-06 05:28:30 +00008279template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008280TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008281TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008282 bool TemplateKW,
8283 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008284 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008285 Template);
8286}
8287
8288template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008289TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008290TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8291 const IdentifierInfo &Name,
8292 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008293 QualType ObjectType,
8294 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008295 UnqualifiedId TemplateName;
8296 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008297 Sema::TemplateTy Template;
8298 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008299 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008300 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008301 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008302 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008303 /*EnteringContext=*/false,
8304 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008305 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008306}
Mike Stump1eb44332009-09-09 15:08:12 +00008307
Douglas Gregorb98b1992009-08-11 05:31:07 +00008308template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008309TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008310TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008311 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008312 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008313 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008314 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008315 // FIXME: Bogus location information.
8316 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8317 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008318 Sema::TemplateTy Template;
8319 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008320 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008321 SS,
8322 Name,
John McCallb3d87482010-08-24 05:47:05 +00008323 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008324 /*EnteringContext=*/false,
8325 Template);
8326 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008327}
Sean Huntc3021132010-05-05 15:23:54 +00008328
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008330ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008331TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8332 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008333 Expr *OrigCallee,
8334 Expr *First,
8335 Expr *Second) {
8336 Expr *Callee = OrigCallee->IgnoreParenCasts();
8337 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008338
Douglas Gregorb98b1992009-08-11 05:31:07 +00008339 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008340 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008341 if (!First->getType()->isOverloadableType() &&
8342 !Second->getType()->isOverloadableType())
8343 return getSema().CreateBuiltinArraySubscriptExpr(First,
8344 Callee->getLocStart(),
8345 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008346 } else if (Op == OO_Arrow) {
8347 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008348 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8349 } else if (Second == 0 || isPostIncDec) {
8350 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008351 // The argument is not of overloadable type, so try to create a
8352 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008353 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008354 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008355
John McCall9ae2f072010-08-23 23:25:46 +00008356 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008357 }
8358 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008359 if (!First->getType()->isOverloadableType() &&
8360 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008361 // Neither of the arguments is an overloadable type, so try to
8362 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008363 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008364 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008365 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008366 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008367 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008368
Douglas Gregorb98b1992009-08-11 05:31:07 +00008369 return move(Result);
8370 }
8371 }
Mike Stump1eb44332009-09-09 15:08:12 +00008372
8373 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008374 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008375 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008376
John McCall9ae2f072010-08-23 23:25:46 +00008377 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008378 assert(ULE->requiresADL());
8379
8380 // FIXME: Do we have to check
8381 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008382 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008383 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008384 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008385 }
Mike Stump1eb44332009-09-09 15:08:12 +00008386
Douglas Gregorb98b1992009-08-11 05:31:07 +00008387 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008388 Expr *Args[2] = { First, Second };
8389 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008390
Douglas Gregorb98b1992009-08-11 05:31:07 +00008391 // Create the overloaded operator invocation for unary operators.
8392 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008393 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008394 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008395 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008396 }
Mike Stump1eb44332009-09-09 15:08:12 +00008397
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008398 if (Op == OO_Subscript) {
8399 SourceLocation LBrace;
8400 SourceLocation RBrace;
8401
8402 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8403 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8404 LBrace = SourceLocation::getFromRawEncoding(
8405 NameLoc.CXXOperatorName.BeginOpNameLoc);
8406 RBrace = SourceLocation::getFromRawEncoding(
8407 NameLoc.CXXOperatorName.EndOpNameLoc);
8408 } else {
8409 LBrace = Callee->getLocStart();
8410 RBrace = OpLoc;
8411 }
8412
8413 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8414 First, Second);
8415 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008416
Douglas Gregorb98b1992009-08-11 05:31:07 +00008417 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008418 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008419 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008420 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8421 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008423
Mike Stump1eb44332009-09-09 15:08:12 +00008424 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008425}
Mike Stump1eb44332009-09-09 15:08:12 +00008426
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008428ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008429TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008430 SourceLocation OperatorLoc,
8431 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008432 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008433 TypeSourceInfo *ScopeType,
8434 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008435 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008436 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008437 QualType BaseType = Base->getType();
8438 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008439 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008440 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008441 !BaseType->getAs<PointerType>()->getPointeeType()
8442 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008443 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008444 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008445 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008446 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008447 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008448 /*FIXME?*/true);
8449 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008450
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008451 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008452 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8453 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8454 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8455 NameInfo.setNamedTypeInfo(DestroyedType);
8456
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008457 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008458
John McCall9ae2f072010-08-23 23:25:46 +00008459 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008460 OperatorLoc, isArrow,
8461 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008462 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008463 /*TemplateArgs*/ 0);
8464}
8465
Douglas Gregor577f75a2009-08-04 16:50:30 +00008466} // end namespace clang
8467
8468#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H